Perform an online schema change on a large MySQL table with minimal downtime using gh-ost or pt-online-schema-change

domain: mysql · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Assess the table size, current replication lag, and write rate before starting; online schema change tools work by creating a shadow table, copying rows in chunks, applying ongoing changes via triggers (pt-osc) or binary log tailing (gh-ost), then performing an atomic table swap
  2. For pt-online-schema-change: run pt-online-schema-change --alter '<ALTER statement>' --execute h=<host>,D=<db>,t=<table>; key flags include --chunk-time (target chunk processing time in seconds), --max-lag (pause if replication lag exceeds this), and --critical-load to abort on high load
  3. For gh-ost (preferred for replicated environments): run gh-ost --alter '<ALTER statement>' --database <db> --table <table> --host <replica> --allow-on-master (if running against master); gh-ost reads the binary log from a replica rather than using triggers, reducing load on the primary
  4. Monitor the progress via gh-ost's interactive socket (echo status | nc -U /tmp/gh-ost.<table>.sock) or pt-osc output; both tools log estimated completion time and current lag
  5. Both tools perform an atomic RENAME at the end to swap the original and ghost tables — this swap is very fast (milliseconds) but requires a brief metadata lock; ensure no long-running transactions hold the table at swap time
  6. Test the ALTER on a staging environment with representative data volume first; verify that all indexes, foreign keys, and constraints on the ghost table match the intended post-change schema before production execution

Known gotchas

Related routes

Run an online schema change on a large MySQL table using gh-ost
mysql · 6 steps · unrated
Configure online schema changes with pt-online-schema-change (pt-osc) on MySQL
mysql · 6 steps · unrated
Apply expand-contract pattern for zero-downtime schema changes in PostgreSQL
postgresql · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans