Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waiting until slave has been synchronized

Is there any SQL (or PHP command) that can be used to either force a master to propagate changes to slaves and/or wait until the changes have been propagated to all slaves?

like image 417
paullb Avatar asked Oct 20 '25 02:10

paullb


2 Answers

You can use the function SOURCE_POS_WAIT(). Call this function in an SQL expression on the replica, and it will block (not return) until the replica has executed up to specified log file & position.

SELECT SOURCE_POS_WAIT('mysql-bin.000042', 8675309);

See https://dev.mysql.com/doc/refman/8.0/en/replication-functions-synchronization.html#function_source-pos-wait

Before MySQL 8.0.26, use MASTER_POS_WAIT() which was the old name for this function.

like image 76
Bill Karwin Avatar answered Oct 21 '25 16:10

Bill Karwin


Standard MySQL replication is asynchronous. You'd have to check the slaves yourself - possible, but there's no built-in command to do all the work for you.

MySQL 5.5 brings semisynchronous replication, which I've no experience with.

There's also synchronous replication via things like Galera. We use a Galera-based variant of MySQL, Percona XtraDB Cluster, at work.

like image 20
ceejayoz Avatar answered Oct 21 '25 15:10

ceejayoz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!