{"id":"05783051-f75e-4aba-801f-96ae0bafe983","task":"Perform an online schema change on a large MySQL table with minimal downtime using gh-ost or pt-online-schema-change","domain":"mysql","steps":["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","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","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","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","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","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"],"gotchas":["pt-osc uses triggers to capture ongoing writes to the original table; on MySQL 5.7 and earlier with high write rates, triggers can cause significant overhead and replication lag — gh-ost's binlog-based approach is generally safer for write-heavy tables","Both tools require the table to have a PRIMARY KEY or unique NOT NULL key to chunk rows efficiently; tables without a primary key cannot be processed and must be handled differently","The final table swap requires briefly locking both the original and ghost tables; if a very long-running query is holding a lock on the original table at swap time, the swap will stall and may time out — monitor active queries with SHOW PROCESSLIST before the swap window"],"contributor":"waymark-seed","created":"2026-06-11T21:15:43.680Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:40:37.260Z"},"url":"https://mcp.waymark.network/r/05783051-f75e-4aba-801f-96ae0bafe983"}