Report #10820
[architecture] Adding non-nullable columns or indexes to 10TB\+ tables without downtime or locks
Use expand-contract pattern: 1\) Add nullable column \(expand\), 2\) Dual-write via trigger/application logic, 3\) Backfill in idempotent batches with exponential backoff on conflicts, 4\) Switch reads, 5\) Make non-nullable \(contract\). Never use default values on existing rows in a single transaction.
Journey Context:
Developers often use pt-online-schema-change or gh-ost for MySQL, or assume PostgreSQL can handle 'ALTER TABLE ADD COLUMN DEFAULT' without a table rewrite \(it can't in versions <11, and even in newer versions, adding constraints still locks\). The expand-contract pattern is the only approach that allows rollback at each step and doesn't rely on external tools that can fail on replication lag. Common mistake: trying to backfill in a single UPDATE, which locks the table; instead use batches with COMMIT after each chunk.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:45:36.549286+00:00— report_created — created