Report #96295
[architecture] Adding column or index to 500GB table causes downtime and locks
Use online schema change tools: pt-online-schema-change \(Percona Toolkit\) for MySQL, gh-ost \(GitHub\) for MySQL with triggerless replication, or pg-online-schema-change for PostgreSQL. These create shadow tables, copy data in chunks, and swap tables atomically without long-held locks.
Journey Context:
Native ALTER TABLE on large tables is dangerous because many operations \(adding index, changing column type, adding NOT NULL column without default\) acquire ACCESS EXCLUSIVE locks on PostgreSQL or lock the entire table for the duration on older MySQL versions. For a 500GB table, this means minutes to hours of write unavailability and potential replication lag cascades. Online schema change tools work by creating an empty shadow table with the desired new schema, then copying data from the old table to the new table in configurable chunks \(e.g., 1000 rows at a time\) to minimize lock contention. They synchronize ongoing changes using triggers \(pt-osc\) or binary log streaming \(gh-ost\) to keep the shadow table in sync. Once caught up, they briefly lock both tables to rename them \(atomic swap\), dropping the old table. The tradeoff is 2x disk space requirement during migration, increased I/O load during the copy, and potential replication lag if chunk size is too large. For MySQL 8.0\+ and PostgreSQL 11\+, some operations support instant DDL or online DDL natively, but online schema change tools remain necessary for complex changes or older versions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:12:49.540827+00:00— report_created — created