MySQL replica SQL thread stalls with 'Waiting for table metadata lock' after direct ALTER TABLE on primary during peak writes
Environment
Primary: MySQL 8.0.27 on Ubuntu 20.04 (systemd), InnoDB, binlog_format=ROW; Replica: MySQL 8.0.27 on Debian 11. Replication via asynchronous binlog/relay. A nightly maintenance job issues ALTER TABLE ... (non-ALGORITHM=INPLACE) on a high-write table during business hours.
Symptoms
Replica SQL thread shows Slave_IO_Running=Yes, Slave_SQL_Running=No. SHOW PROCESSLIST on primary shows ALTER TABLE connection holding MDL lock; many other sessions report 'Waiting for table metadata lock' and DML queuing. Application latency spikes and new writes pile up on primary.
Observations
performance_schema.metadata_locks identifies ALTER TABLE statement (connection 2345) as lock owner; multiple short transactions stuck in 'Waiting for table metadata lock' for same table. Replica relay log entries for that table apply but SQL thread halts where it reaches DDL/DML conflict. No obvious replication error lines in error log.
Already attempted
Tried KILLing the ALTER connection — orchestration recreated and resumed the DDL; stopped and started the replica SQL thread but it immediately blocked at same position; considered 'slave_skip_errors' but rejected due to data-loss risk. No pt-online-schema-change or gh-ost was used.
Question
What's the safe way to unstick replication without risking data inconsistency? How to prevent this class of outage during online DDL in future?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases40% match
PostgreSQL replica SQL apply thread stalls 'waiting for table metadata lock' after large ALTER TABLE on primary
Open0 answers - Databases29% match
MySQL Replica Reports Binlog Checksum Mismatch After Changing Binlog_Format to ROW on Primary
Open0 answers - Databases27% match
PostgreSQL replica apply stalls 'waiting for lock' during bursts of DDL on primary
Solved1 answer - Databases23% match
MySQL replica SQL thread idles and relay logs grow after short network blips — slave lags and no obvious errors
Open0 answers - Databases22% match
MySQL replica lag grows during nightly imports
Open0 answers