grafclouds.com / documents / training / devops-challenges / zero-downtime-schema-migration

Add a NOT NULL Column to a 50M-Row Prod Table

Intermediate ~14 min read
Databases

Scenario

Product needs a new column on the busiest table in your PostgreSQL database — roughly 50 million rows, sitting directly on the application's hot path with constant reads and writes, plus a couple of read replicas hanging off the primary. The requirement says the column must be NOT NULL with a sensible value for every existing row. The table cannot take meaningful downtime: if it locks up, the product locks up.

The Quick Fix on the Table

A teammate has the migration ready to go: one ALTER TABLE ... ADD COLUMN ... DEFAULT ... NOT NULL statement, run during business hours. One statement, one deploy, done by lunch. It works instantly on their laptop database, so how bad can it be?

Interview · Round 1

The quick fix is on the table and the room is waiting for your call. Would you sign off on it? Take a position and justify it — out loud or on paper — before revealing the analysis.