MySQL & InnoDB (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How do you perform Zero-Downtime Online Schema Changes (Online DDL vs gh-ost / pt-online-schema-change)?
senior LevelForms
In Simple Words:
Altering a 500 GB table (ALTER TABLE orders ADD COLUMN ...) locks the table or consumes massive disk I/O:
- InnoDB Online DDL: MySQL 8.0 supports instant column addition (
ALGORITHM=INSTANT), modifying only metadata in milliseconds. - gh-ost / pt-online-schema-change (For complex alters):
- Creates a shadow table with the new schema.
- Copies historical data in small chunked batches.
- Uses binlog stream capture (
gh-ost) or triggers (pt-osc) to replicate live ongoing writes to the shadow table. - Swaps tables atomically using
RENAME TABLE orders TO orders_old, orders_new TO orders;.