Report #95711
[architecture] Zero-downtime schema migrations \(renaming columns, changing types\)
Use the Expand-Contract pattern: \(1\) Add new column \(Expand\), \(2\) Dual-write to old and new columns in application code, \(3\) Backfill existing data in batches, \(4\) Switch reads to new column, \(5\) Remove old column \(Contract\). For large tables, use online schema change tools \(gh-ost, pt-online-schema-change, pg-online-schema-change\) to avoid locking.
Journey Context:
Direct ALTER TABLE on large tables \(millions\+ rows\) creates exclusive locks, blocking reads/writes for minutes or hours. Renaming columns instantly breaks existing deployed code. The Expand-Contract pattern \(also called Parallel Change\) allows blue-green deployment: old code writes to old column, new code writes to both. Backfills must be batched and throttled to avoid table bloat and replication lag. Online schema change tools create shadow tables, sync via triggers/binlog, then atomic rename — but they don't solve application-level logic changes. Warning: Foreign keys complicate this; drop FKs during migration or maintain them carefully. This is the industry standard for continuous deployment of databases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:14:05.487779+00:00— report_created — created