Skip to main content
Data EngineeringNov 9, 20266 min read

Zero-Downtime PostgreSQL Migrations at Scale

A practical expand-and-contract workflow for evolving production tables, adding indexes concurrently, and deploying safely behind rolling releases.

MN

Meera Nair

Staff Data Engineer

#PostgreSQL#Migrations#Zero Downtime#SQL
Zero-Downtime PostgreSQL Migrations at Scale

Why Naive Schema Changes Trigger Production Outages

Adding a column with a non-constant rewrite or creating a standard index on a busy table acquires locks that stall incoming reads and writes. During rolling container deploys, old and new application code run side by side for several minutes.

The expand-and-contract pattern decouples schema evolution into backward-compatible steps so old replicas never crash on missing columns.

The Three-Step Expand & Contract Sequence

Always split destructive renames or type changes across separate deployments:

  • 1. Expand: Add nullable columns or create indexes with CONCURRENTLY
  • 2. Dual-Write & Backfill: Update code to write both fields and backfill batches safely
  • 3. Contract: Remove legacy reads and drop deprecated columns once traffic shifts
sqlmigrations/042_add_tenant_index.sql
-- Safe index creation without blocking active reads or writes
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_invoices_tenant_created
  ON invoices (tenant_id, created_at DESC);
Continue Reading

Related Engineering Notes

All Articles
09 / Let's Ship Together

Have a product roadmap ready to accelerate?

Partner directly with Arrowsoft designers, full-stack engineers, and cloud architects to move from concept to production without drag.