Report #5614
[architecture] Table locking and replication lag during ALTER TABLE on large MySQL instances
Use online schema change tools \(gh-ost or pt-online-schema-change\) that create ghost tables, synchronize via binlog/triggers, and perform atomic cutover
Journey Context:
MySQL's native ALTER TABLE \(until 8.0 instant DDL for limited cases\) rewrites the entire table, holding exclusive locks for hours on large tables \(millions\+ rows\), blocking reads/writes and causing downtime. The 'ghost' or 'shadow' table approach creates a new empty table with the target schema, populates it in small throttled chunks \(to avoid replica lag\), uses triggers or binlog streaming to keep it synchronized with ongoing changes, then performs an atomic RENAME TABLE swap \(which is metadata-only\). Tradeoffs: Requires ~2x disk space during migration. Adds replication lag if not throttled. Cannot handle foreign keys easily \(gh-ost refuses them; pt-osc drops and recreates them\). Risk of data inconsistency if cutover fails mid-rename. Not suitable for tables with heavy trigger usage \(conflict with pt-osc\). Essential for high-availability production MySQL/MariaDB where native online DDL is insufficient or unsafe.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:45:02.738541+00:00— report_created — created