As the lead for a MySQL fleet, how do you decide whether a large-table change runs as native online DDL, through gh-ost or through pt-online-schema-change?
answer
- native first, tool when it copies
- triggers versus the binlog
- throttle, pause, postpone cut-over
- foreign keys narrow the choice
- replicas apply DDL afterwards
basics
~20 sUse MySQL's native INSTANT DDL whenever the change allows it; for changes that rebuild or copy a large hot table, use gh-ost, which reads the binlog and can be throttled, or pt-online-schema-change, which uses triggers but handles foreign keys.
solid answer
~50 sI start from what MySQL can do natively. If the change supports `ALGORITHM=INSTANT`, it runs natively with a short `lock_wait_timeout`; no tool beats a metadata-only change. For an `INPLACE` rebuild on a big table I weigh the native limits: it cannot be paused or throttled, the online log is bounded, and replicas only start it after the source finishes, so they lag. Anything that needs `ALGORITHM=COPY` on a hot table, like `INT` to `BIGINT` on an `AUTO_INCREMENT` key or `CONVERT TO CHARACTER SET`, goes through a tool. gh-ost is my default there: triggerless, it reads row-based binlog events as a fake replica, throttles on lag and load, pauses on command and can postpone cut-over. pt-online-schema-change is the choice when foreign keys are involved, since gh-ost does not support them, at the cost of a trigger write on every DML. I standardise the decision table, dry runs, throttle thresholds and a cut-over window.
go deeper
Recall that native instant changes need no tool, and that gh-ost and pt-online-schema-change copy big tables without blocking writes.
Explain how each tool keeps its copy current, triggers for pt-online-schema-change and the binlog for gh-ost, and how both swap tables at the end.
Show you can run either tool safely: dry runs, throttle thresholds, replica lag, foreign-key handling and a bounded cut-over that can be retried.
Defend a fleet policy that ranks native DDL, gh-ost and pt-online-schema-change by change type, table size and foreign keys, and say what you monitor so integer exhaustion never forces a rushed copy.
## The decision a lead actually owns Every team running MySQL at scale eventually needs a policy for changing big, busy tables. Individual engineers can look up syntax; the lead decides **which mechanism is allowed for which change**, what guardrails are mandatory, and who reviews the exceptions. There is no single right answer, because the options trade write overhead, operational control, foreign-key support and replica behaviour differently. ## Option 1: native online DDL MySQL's own `ALTER TABLE` has three algorithms. - **`INSTANT`** edits only metadata: adding, dropping or renaming a column, changing a default, appending an `ENUM` member without changing its storage size. It is the obvious first choice and needs no tool. Its costs are the brief exclusive metadata lock and the limit of 64 instant row versions per table in MySQL 8.4. - **`INPLACE`** rebuilds or builds indexes inside InnoDB while allowing concurrent DML. Its limits on a large table are real: **it cannot be paused or throttled**, concurrent writes are buffered in an online log capped by `innodb_online_alter_log_max_size`, a failed operation is expensive to roll back, and **a replica only starts the DDL after the source finishes it**, holding back the DML that came after it. - **`COPY`** blocks writes for the duration, so on a hot table it is an outage. ## Option 2: gh-ost gh-ost creates an empty **ghost table** with the new definition, copies rows across in chunks (`--chunk-size`, 1000 by default) and keeps it current by **reading the binary log as if it were a replica**, applying each row event for the original table to the ghost table. - **Requirements.** Row-based binlog with a `FULL` row image (8.4's default `binlog_format` is `ROW`, though the variable itself is deprecated), and a shared `PRIMARY KEY` or non-null `UNIQUE KEY` between the old and new tables. - **Control.** It throttles on replica lag (`--max-lag-millis`, measured with its own heartbeat) and on server status (`--max-load`), bails out on `--critical-load`, accepts interactive commands such as `throttle` over a socket, and can hold the final swap with `--postpone-cut-over-flag-file`. - **Cut-over.** By default an atomic table swap that holds its locks for at most `--cut-over-lock-timeout-seconds` (3 by default) and retries if it cannot finish. - **Limits.** It does **not support foreign keys** on the migrated table (it bails out when it finds one), existing triggers are carried over to the new table only when you pass `--include-triggers`, and without `--execute` it only runs a no-op validation. `--attempt-instant-ddl` makes it try MySQL's instant DDL first. ## Option 3: pt-online-schema-change pt-online-schema-change also copies into a new table, but keeps it in sync with **`AFTER INSERT`, `AFTER UPDATE` and `AFTER DELETE` triggers** that run inside the application's own transactions, then swaps the tables with an atomic `RENAME TABLE`. - **Strengths.** It handles **foreign keys** through `--alter-foreign-keys-method` (`rebuild_constraints` where the child tables are small, or the riskier `drop_swap`), and it can copy existing triggers with `--preserve-triggers`. - **Guardrails.** It sizes chunks to `--chunk-time` (0.5 seconds by default), pauses on `--max-load` (`Threads_running=25` by default), aborts on `--critical-load` (`Threads_running=50` by default), waits for replicas within `--max-lag` (1 second by default), and does nothing without `--execute`. - **Costs.** Every write to the table pays for the trigger's extra write, and throttling only pauses the row copy: the triggers keep firing however loaded the server is. ## A comparison to standardise on | Concern | Native `INPLACE` | gh-ost | pt-online-schema-change | |---|---|---|---| | Keeps the copy current via | InnoDB's online log | binlog stream | triggers | | Pause or throttle mid-change | no | yes, fully | row copy only | | Foreign keys | yes | not supported | yes, with a method | | Extra load on application writes | low | none at write time | a trigger write per DML | | Replica behaviour | DDL replays after the source finishes | row events replicate as normal | row events replicate as normal | | Control over the final swap | none | postpone, retry, bounded lock | atomic rename | ## The policy itself A defensible fleet standard looks like this: 1. **Native `INSTANT` first**, always with an explicit `ALGORITHM=INSTANT` and a short session `lock_wait_timeout`. 2. **Native `INPLACE`** only below an agreed table size or duration, where the replica lag it causes is acceptable. 3. **gh-ost for everything else** on tables without foreign keys; **pt-online-schema-change** where foreign keys must stay. 4. **Mandatory dry runs**, throttle thresholds per cluster, enough free disk for a full copy, and a cut-over window outside peak hours. 5. **Watch the integer ceiling early.** When an `AUTO_INCREMENT` column reaches its type's maximum (2,147,483,647 for a signed `INT`), the next generated value fails. The `INT` to `BIGINT` fix is a full copy, so alert at a fraction of the range that leaves weeks for a throttled migration. Review the policy when the topology changes: a cluster that adopts foreign keys, triggers or a different replication setup can move a table from one column of the table to another.
- Why can't pt-online-schema-change fully relieve a MySQL primary that becomes overloaded mid-migration?Its --max-load and --max-lag checks pause only the chunked row copy. The AFTER INSERT, UPDATE and DELETE triggers it installed keep running inside every application transaction, because removing them would lose changes. On a very busy table that trigger overhead remains until the migration finishes or is aborted, which is the main argument for a triggerless tool.
- What does gh-ost need from MySQL's binary log before it can migrate a table?gh-ost reads row-based events, so the server it streams from must write binlog_format=ROW with a FULL row image; on a replica it also needs replica updates logged. It connects as a replica, filters events for the original table and applies them to the ghost table. Encrypted binary logs are not supported.
- How do you schedule a gh-ost cut-over for a quiet hour while letting the row copy run during the day?Start gh-ost with --postpone-cut-over-flag-file pointing at a file. It copies rows and keeps applying binlog events, but does not swap tables while the file exists. Deleting the file, or sending the cut-over interactive command, triggers the swap at the hour you choose.
- gh-ost installs triggers on the original table to capture changes
- pt-online-schema-change's throttling also pauses its triggers
- Native INPLACE DDL can be paused when replicas start lagging
- gh-ost works on any table, including ones with foreign keys
- Online schema-change tools need no metadata lock at cut-over
- INT to BIGINT on an AUTO_INCREMENT key can run as INSTANT
Assumes MySQL 8.4 (INSTANT as the default algorithm, 64 instant row versions, binlog_format ROW by default but deprecated), gh-ost v1.1.11 and pt-online-schema-change 3.7.1.