MySQL problems

MySQL Replication Lag: Where the Replica Falls Behind, and the Fix

2 December 2026

A MySQL replica falls behind at one of two places: transactions not yet received from the source, or received and not yet applied. Seconds_Behind_Source mixes the two and can read 0 while the replica is hours behind. The Performance Schema tells which place it is.

Received or applied

Run this on the replica:

SELECT c.channel_name,
       c.last_queued_transaction                    AS last_received,
       a.last_applied_transaction                   AS last_applied,
       TIMEDIFF(NOW(6),
         a.last_applied_transaction_original_commit_timestamp)
                                                    AS apply_lag,
       c.queueing_transaction                       AS receiving_now,
       a.applying_transaction                       AS applying_now
FROM   performance_schema.replication_connection_status c
JOIN   performance_schema.replication_applier_status_by_worker a
       USING (channel_name);
What you seeWhere to look
The last received transaction is far behind the sourceThe receiver: the network between the two servers, or a source that writes faster than the link carries.
Received is current, applied is behindThe applier: one large transaction, too few applier threads, tables without a primary key, slower disks, or queries on the replica.
Seconds_Behind_Source is NULLA thread is stopped: see replication stopped.

Find the transaction the applier is working on, and for how long:

SELECT worker_id, applying_transaction,
       TIMEDIFF(NOW(6), applying_transaction_start_apply_timestamp)
         AS applying_for
FROM   performance_schema.replication_applier_status_by_worker
WHERE  applying_transaction <> '';

The causes, and the fix in order

  1. One large transaction. A DELETE of millions of rows runs once on the source and once more on the replica, and nothing behind it applies until it ends. Delete in batches of a few thousand rows.
  2. Tables without a primary key. With row-based logging the replica finds each changed row by searching the table; without a primary key or unique index that is a scan per row. Add a primary key. sql_require_primary_key = ON stops new tables without one.
  3. One applier thread. replica_parallel_workers above 1 applies independent transactions at the same time (4 is the default from MySQL 8.0.27). On 8.0, binlog_transaction_dependency_tracking = WRITESET on the source lets more of them run in parallel.
  4. Queries on the replica. A long report holds locks or I/O the applier needs. Move it, or give it its own replica.
  5. A replica on slower disks. It falls behind in every busy hour. Give it the storage of the source.
  6. DDL. An ALTER TABLE that took an hour on the source takes about an hour on the replica, and everything after it waits.

See it coming

Lag of a few seconds is normal and differs for every replica, so a fixed number either wakes people for nothing or says nothing. Radar Engine, the detection layer of dbCove, measures each channel against its own usual, with no agent on the server:

DetectorWhen it fires
Replication lagWatch from 3 minutes or the channel's usual lag at that time, whichever is larger, and only when it is larger than 15 minutes earlier. Warning from 10 minutes. Critical from an hour. A configured SOURCE_DELAY is subtracted.
Replication stoppedA thread of a channel seen running stopped, with or without an error number.
Long transactionA transaction open for an hour or more on the source, the kind that arrives on the replica as one long apply.

The finding says whether the replica is behind on receiving or on applying, and names replica_parallel_workers as the cause when it is 1. dbCove AI answers why a replica fell behind with that replica's own history.

Questions

How do I check replication lag in MySQL?
SHOW REPLICA STATUS gives Seconds_Behind_Source. For a true picture, compare last_applied_transaction_original_commit_timestamp in performance_schema.replication_applier_status_by_worker with the current time, and check last_queued_transaction in replication_connection_status.

Why does Seconds_Behind_Source show 0 when the replica is behind?
It measures the gap between the applier and the receiver. When the receiver itself is behind, for example on a slow link, both are behind the source and the value can read 0.

How do I reduce MySQL replication lag?
Split large transactions, give every table a primary key, set replica_parallel_workers above 1, keep long queries off the replica, and give the replica the disks of the source.

Related problems

Sources