如何确定日志中剩余多少数据
我有 2 台使用 MySQL 设置的服务器。它使用标准复制设置,只有一个从属,没有循环复制。
有没有一种方法可以以编程方式告知从站在从二进制日志读取数据方面落后了多远?
如果我运行以下语句:
SHOW MASTER STATUS;
在主机上运行,并
SHOW SLAVE STATUS;
在从机上运行,我可以比较主机状态中的 Position 列和从机状态中的 Read_Master_Log_Pos 列,以确定从机落后多远。
但是,只有从属设备从主设备正在写入的同一个文件中读取数据时,这才有效。因此,如果从属设备仍在读取先前的日志文件,因为它落后了,我无法弄清楚如何确定还剩下多少数据,直到它赶上主设备所在的当前位置。仅使用 SQL 的解决方案是最佳的,但我对其他解决方案持开放态度。希望不需要读取包含日志文件的目录。
I have 2 servers set up using MySQL. It's using a standard replication setup, with one slave, no circular replication.
Is there a way to programmatically tell how far behind the slave is in reading the data from the binary log?
If I run the statement:
SHOW MASTER STATUS;
On the master, and run
SHOW SLAVE STATUS;
on the slave, I can compare the Position column from master status, and the Read_Master_Log_Pos column from slave status to determine how far behind the slave is.
However, this only works if the slave is reading from the same file the master is writing to. So if the slave is still reading a previous log file, because it is running behind, I can't figure out how to determine how much data is left until it catches up to the current position that the master is at. A solution using only SQL would be optimal, but I'm open to other solutions. Hopefully not one that requires reading the directory containing the log files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢使用 SHOW SLAVE STATUS 中的“Seconds_behind_master”字段来确定主从服务器是否已赶上。作为一名二级警卫,我还对两台服务器上的特定表(即经常更新的表)进行 COUNT(*) 查询,然后比较记录计数。
I like to use the 'Seconds_behind_master' field from SHOW SLAVE STATUS in order to determine if the MASTER-SLAVE servers are caught up. As a secondary guard I also to a COUNT(*) query on a specific table (ie one that gets updated frequently) on both servers and then compare the record counts.