Report #45734
[architecture] How to safely rename a column in a production database without downtime
Use the expand-contract pattern: 1\) Deploy 'expand' code that writes to both old and new columns but reads from old; 2\) Backfill new column in batches \(e.g., 1000 rows/sec\) with throttle; 3\) Deploy 'contract' code that reads from new column; 4\) Remove writes to old column; 5\) Drop old column. Never rename in-place; it requires exclusive table locks.
Journey Context:
Direct ALTER TABLE RENAME requires ACCESS EXCLUSIVE lock, blocking reads/writes for the duration. Common mistake is using 'online schema change' tools \(gh-ost, pt-online-schema-change\) just for renames—they're for heavy alters. The expand-contract is the only way to maintain backward/forward compatibility during rolling deployments. Key insight: the application must be tolerant of reading from old schema while new code deploys, hence the double-write phase. Backfill must be throttled to avoid replica lag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:14:30.659634+00:00— report_created — created