Report #87345
[architecture] How to perform large table schema changes \(ALTER TABLE\) in production MySQL without read locks causing downtime
Use an online schema change tool like gh-ost \(GitHub\) or pt-online-schema-change \(Percona\) which creates a shadow table with the new schema, incrementally copies data using chunking, applies changes via triggers or binlog parsing, then atomically swaps tables using RENAME. Never use native MySQL ALTER TABLE on large tables in production as it rebuilds the entire table and holds locks.
Journey Context:
MySQL's native ALTER TABLE operations \(before MySQL 8.0's instant algorithm limitations\) typically require rebuilding the entire table, during which the table is locked for writes \(and sometimes reads depending on the algorithm\). For large tables \(100GB\+\), this means hours of downtime. Early workarounds involved master-slave failover tricks \(alter on slave, promote\). Modern solutions use 'shadow table' patterns: pt-online-schema-change \(Percona\) uses triggers to capture changes during the copy, while gh-ost \(GitHub\) reads the binary log to avoid trigger overhead on the master. Both perform chunked COPY, maintain a change buffer, and perform a fast atomic rename at the end. Tradeoffs: These tools add load \(extra I/O for the shadow table\), require disk space for the duplicate table, and have complexity around foreign keys \(gh-ost doesn't support them; pt-osc has limitations\). They also don't work well with tables lacking primary keys.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:11:55.120522+00:00— report_created — created