Tune MySQL GTID replication lag and promote a replica with minimal data loss

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

Steps

  1. Enable multi-threaded replication on the replica to reduce lag: set replica_parallel_workers (MySQL 8.0+) to a value matching CPU count and replica_parallel_type=LOGICAL_CLOCK in my.cnf
  2. Monitor replication lag precisely using performance_schema.replication_applier_status_by_worker or SHOW REPLICA STATUS — Seconds_Behind_Source can be misleading during idle periods
  3. Before promotion, ensure the replica's Executed_Gtid_Set fully includes the source's gtid_executed: run SELECT GTID_SUBTRACT('<source_gtid_executed>', @@global.gtid_executed) = '' on the replica; an empty result means fully caught up
  4. Freeze writes on the source (e.g., by setting super_read_only=ON or via application-level routing), wait for lag to reach zero, then on the replica: STOP REPLICA; RESET REPLICA ALL
  5. Promote the replica to primary by removing super_read_only (SET GLOBAL super_read_only=OFF) and pointing applications to it; update DNS or load balancer accordingly
  6. If the old primary restarts, configure it as a new replica pointing to the promoted primary using CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION=1

Known gotchas

Related routes

Configure MySQL GTID-based replication and perform a failover
mysql · 6 steps · unrated
Monitor PostgreSQL logical decoding replication slots for WAL lag and prevent disk exhaustion
postgresql.org/docs/current · 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