简体   繁体   中英

How to determine that MySQL replication is complete?

I have a scenario in which MySQL will be deployed in 2 separate regional data-centers. Datacenter 1 - Active (taking traffic) Datacenter 2 - Passive. There will be data replication set up between MySQL in the two data centers. When there is a failover, the active and passive data centers will be flipped.

How to find out that data replication is complete before Datacenter 2 can be made Active for accepting new requests. Is there a way to programmatically check the depth of the replication queue? I want to make sure that all the data in the replication queue inflight from datacenter 1 is inserted in datacenter 2 first before it can be marked as Active and new requests can be accepted.

I understand that this design will reduce the application's availability during this failover, but that is OK. The application favors consistency over availability so need to make sure that all the previous updates to the db (inflight from other DC) are complete before new updates can be applied.

thanks!

One of the ways to check is to run SHOW SLAVE STATUS . This will return a fair amount of information such as what is being replicated, master and slave log positions and the replication status. But just to determine whether its up to date is to check the seconds behind master. If the seconds behind master value is 0 then replication is up to date, above zero is the number of seconds behind.

Although one thing I've noticed, is just because it says 5 seconds behind doesn't always necessarily mean that there's 5 seconds left, depending on what is causing the delay.

When you run the SHOW SLAVE STATUS from a MySQL client, on the command line/terminal, you better off using \G instead of ; as it will format better for you to read the details.

eg SHOW SLAVE STATUS\G instead of SHOW SLAVE STATUS;

Its also a good idea to double check the values of Slave_IO_Running and Slave_SQL_Running are both yes, if either of these are no, the seconds behind master can show 0, but it means replication is not running and the databases are not up to date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM