僅看 Seconds_Behind_Master(SBM)判斷延遲,**大部分情況可接受但不夠精準**,需綜合多指標。
SHOW SLAVE STATUS\G
Master_Log_File: mysql-bin.000327
Read_Master_Log_Pos: 668711237
Relay_Log_File: mysql-relay-bin.002999
Relay_Log_Pos: 214736858
Relay_Master_Log_File: mysql-bin.000327
Exec_Master_Log_Pos: 654409041
Relay_Log_Space: 229039311
Seconds_Behind_Master: 3296
SHOW FULL PROCESSLIST\G
-- IO 執行緒
Id: 6, State: Waiting for master to send event, Time: 22005006
-- SQL 執行緒
Id: 7, State: Updating, Time: 3293, Info: UPDATE ...
差值 = SQL 執行緒比 IO 執行緒慢多少個 binlog 事件。
-- Master
SHOW BINARY LOGS;
+------------------+--------------+
| Log_name | File_size |
+------------------+--------------+
| mysql-bin.000009 | 1073742063 |
| mysql-bin.000010 | 107374193 |
+------------------+--------------+
-- Slave 狀態
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 668711237
Relay_Master_Log_File: mysql-bin.000009
Exec_Master_Log_Pos: 654409041
-- 當前 binlog 剩餘事件
1073742063 - 654409041 = 419,333,022 events
-- 加上下一個 binlog 已產生事件
107374193 + 419,333,022 = 526,707,215 events 總延遲
在**第三方監控節點**同時對 Master/Slave 發起:
SHOW BINARY LOGS (Master)SHOW SLAVE STATUS\G (Slave)💡 核心心法:SBM 只是「SQL 執行緒覺得自己落後多久」,**真實延遲 = Master 已生成事件 - Slave 已執行事件**,需雙端採樣計算。