Migrations that lock the table

Back to list2026-05-17
You

Adding a NOT NULL column locked our table for two minutes. How do people avoid that?

ChatGPT

Split it: add the column nullable, backfill in batches, add a validated check constraint, then set NOT NULL. Each step takes a brief lock instead of one long one, and the backfill can be paused if replication lag grows.