Report #51792
[architecture] ALTER TABLE on large tables causes downtime or query pile-ups due to exclusive table locks in MySQL/PostgreSQL
Use online schema change tools: \`pt-online-schema-change\` \(Percona\) or \`gh-ost\` \(GitHub\) for MySQL; \`pg\_repack\` or \`ALTER ... WITH \(ONLINE = ON\)\` for PostgreSQL 11\+. These create a shadow table, sync via triggers/binlog, then atomic rename. For application-level changes \(e.g., adding column\), use expand/contract pattern: add new column \(default NULL\), dual-write, backfill, switch reads, drop old.
Journey Context:
Native ALTER TABLE often requires ACCESS EXCLUSIVE locks \(PostgreSQL\) or rebuilds the entire table \(MySQL <5.6\), blocking reads/writes for minutes to hours on terabyte-scale tables. 'Doing it at night' fails in 24/7 systems. Online schema change tools are battle-tested \(GitHub, Shopify\). They trade disk space \(2x table size\) and replication lag tolerance for near-zero lock time \(milliseconds\). Critical caveat: foreign keys are complex \(gh-ost requires special handling, pt-osc uses reverse triggers\). Expand/contract is safer for application logic changes but requires code deployment discipline and handles rollbacks better than DDL changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:25:26.924114+00:00— report_created — created