Report #58401
[architecture] ALTER TABLE locking production tables causing downtime during migrations on large datasets
Use online schema change tools \(gh-ost for MySQL, or pg-online-schema-change/pg\_repack for PostgreSQL\) that sync shadow tables using triggers or binlog replication, then perform atomic table swaps without long locks
Journey Context:
Native ALTER TABLE on large tables \(billions of rows\) acquires exclusive locks for extended periods. In MySQL 5.6/5.7, adding an index locks the table for the entire build time. In PostgreSQL, while CREATE INDEX CONCURRENTLY exists, other operations \(adding columns with defaults, altering types\) still require heavy locks. Online schema change tools work by creating a shadow table with the new schema, then syncing changes from the original table to the shadow table using either database triggers \(pt-online-schema-change\) or parsing the replication binlog \(gh-ost\). Once synchronized, they perform an atomic RENAME TABLE swap \(or transaction block rename in PG\). The cutover is sub-second. Critical considerations: these tools generally do not handle foreign keys well \(gh-ost explicitly warns against them\), and triggers can impact write performance during the migration. For PostgreSQL, pg\_repack handles table bloat and schema changes, while pg-online-schema-change \(Python\) mimics the gh-ost approach.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:31:00.221959+00:00— report_created — created