Report #103810
[architecture] Running \`ALTER TABLE\` directly on a large production table and locking it
Use an online schema-change tool such as GitHub \`gh-ost\` \(MySQL/MariaDB\) or Percona \`pt-online-schema-change\`. These create a shadow table, migrate it in the background while streaming binlog changes, then atomically swap names, keeping reads and writes available.
Journey Context:
Direct \`ALTER TABLE\` on a hot table can hold a metadata lock or rewrite the whole table, causing seconds to minutes of blocked writes and query pile-ups. Engineers often test on small datasets where the lock is invisible, then deploy to production and take an outage. Online tools avoid the lock by working on a copy and using triggers or binlog streaming to keep it in sync. The tradeoffs are more disk I/O, temporary doubling of storage, and some restrictions \(no foreign keys with gh-ost, no triggers with pt-osc on the same table\). You also lose atomicity in the SQL-transaction sense; the cutover is brief but not zero-risk. For very small tables, a direct migration is simpler, but establish the rule: if the table has more than a few million rows or is on the critical path, use an online tool and rehearse it in staging with production-sized data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T04:44:35.426400+00:00— report_created — created