Skip to main content

Zero-Downtime PostgreSQL Migrations in Production

How to change a live PostgreSQL schema without taking the app down: the expand-and-contract pattern, online DDL with CONCURRENTLY and NOT VALID, batched backfills, and the lock monitoring that lets you do it with confidence.

15items
Back to all checklists
Database OperationsAdvanced
postgresqldatabase-migrationszero-downtimeddlschema
Progress0 / 15 completed
0%

Plan every change as expand, migrate, then contract

Critical

Set lock_timeout on every migration so a stuck DDL fails fast

Critical

Add columns without rewriting the whole table

Build indexes with CREATE INDEX CONCURRENTLY

Critical

Add NOT NULL with a CHECK constraint, not in one shot

Critical

Add foreign keys in two steps with NOT VALID

Change a column type by adding a new column, not ALTER TYPE

Backfill data in small batches, never one big UPDATE

Critical

Make the app write both old and new shapes during the switch

Critical

Never rename a live column or table in place

Drop columns and tables only after nothing reads them

Critical

Use a migration tool that can run statements outside a transaction

Rehearse the migration on a production-sized copy and time the locks

Watch locks and blocking queries while the migration runs

Critical

Watch replication lag and dead tuples during big backfills

Sponsored
Carbon Ads

More checklists

Also worth your time on this topic