Report #97220
[architecture] Schema migrations lock tables for minutes and cause downtime on large tables
Use expand-contract with dual writes: \(1\) add the new column/table, \(2\) backfill in small batches and deploy code that writes to both old and new, \(3\) switch reads to the new schema, \(4\) stop writing to the old schema, \(5\) drop it. Never rename or drop in the same deploy that introduces the replacement.
Journey Context:
A single ALTER TABLE that renames, drops, or changes a column type acquires an ACCESS EXCLUSIVE lock and can rewrite the heap, blocking every query for the table's duration. The safe path keeps old and new schema alive across multiple deploys so every running app version stays compatible. Dual writes prevent the new schema from lagging behind; batch backfills with sleeps protect replica lag. Tools like pgroll automate this, but the pattern is database-agnostic. The hard part is discipline: each phase must be reversible and observable before you move to the next.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:44:47.272864+00:00— report_created — created