Is Replication Slave ever going to catch up? When?!

August 29, 2012
Author
Aurimas Mikalauskas
Share this Post:

If you ever had a replication slave that is severely behind, you probably noticed that it’s not catching up with a busy master at a steady pace. Instead, the “Seconds behind master” is going up and down so you can’t really tell whether the replica is catching up or not by looking at just few samples, unless these are spread apart. And even then you can’t tell at a glance when it is going to catch up.

Normally, the “severely behind” thing should not happen, but it does often happen in our consulting practice:

 

    • sometimes replication would break and then it needs to catch up after it is fixed,

 

    • other times new replication slave is built from a backup which is normally hours behind,

 

    • or, it could be that replication slave became too slow to catch up due to missing index

 

Whatever the case is, single question I am being asked by the customer every time this happens is this: When is the replica going to catch up?”

I used to tell them “I don’t know, it depends..” and indeed it is not an easy question to answer. There are few reasons catching up is so unstable:

 

    1. If you have restarted the server, or started a new one, caches are cold and there’s a lot of IO happening,

 

    1. Not all queries are created equal – some would run for seconds, while others can be instant,

 

    1. Batch jobs: some sites would run nightly tasks like building statistics tables or table checksum – these are usually very intense and cause slave to backup slightly.

 

I didn’t like my own answer to The question, so I decided to do something about it. And because I love awk, I did that something in awk:

I don’t know if this is ever going to become a part of a Percona Toolkit, however since it’s pretty much a one-liner, I just keep it in my snippets pool for easy copy’n’paste.

Here’s a piece of an output from a server that was almost 27 days behind just yesterday:

Of course, it is still not perfectly accurate and it does not account for any potential changes in queries, workload, warm-up, nor the time it takes to run the mysql cli, but it does give you an idea and direction that replication slave is going. Note, negative values mean replication isn’t catching up, but values themselves are mostly meaningless.

Here’s what the weird acronyms stand for:

 

    • s_behind – current Seconds_Behind_Master value

 

    • d_behind – number of days behind based on current s_behind

 

    • c_sec_s – how many seconds per second were caught up during last interval

 

    • eta_d – this is ETA based on last interval

 

    • O_c_sec_s – overall catch-up speed in seconds per second

 

    • O_eta_d – ETA based on overall catch-up speed (in days)

 

    • O_eta_h – same like previous but in hours

 

Let me know if you ever find this useful.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved