如何查看主從復制的狀態,且備庫應用落后了多少字節
這些信息要在主庫中查詢
查看流復制的信息可以使用主庫上的視圖
1
|
select pid,state,client_addr,sync_priority,sync_state from pg_stat_replication; |
pg_stat_replication中幾個字斷記錄了發送wal的位置及備庫接收到的wal的位置、
sent_location--發送wal的位置
write_location--備庫接收到的wal的位置
flush_location—備庫寫wal日志到磁盤的位置
replay_location—備庫應用日志的位置
查看備庫落后主庫多少字節
1
2
|
select pg_xlog_location_diff(pg_current_xlog_location(),replay_location)/1024/1024 as MB from pg_stat_replication; select pg_xlog_location_diff(pg_current_xlog_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication; |
級聯復制
1
|
select pg_xlog_location_diff(pg_last_xlog_replay_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication; |
補充:pgsql之查看主備復制延遲
查看復制延遲:
10.0及以上:
1
2
3
4
5
6
7
8
9
10
11
|
SELECT pg_wal_lsn_diff(A .c1, replay_lsn) /(1024 * 1024) AS slave_latency_MB, pg_wal_lsn_diff(A .c1, sent_lsn) /(1024 * 1024) AS send_latency_MB, pg_wal_lsn_diff(A .c1, flush_lsn) /(1024 * 1024) AS flush_latency_MB, state, backend_start, now():: timestamp with time zone FROM pg_stat_replication, pg_current_wal_lsn() AS A(c1) WHERE client_addr= '192.168.46.173' and application_name = 'standby1' ORDER BY slave_latency_MB, send_latency_MB DESC LIMIT 1; |
注:
192.168.46.173 表示從庫ip地址。
pg_wal_lsn_diff(lsn pg_lsn, lsn pg_lsn):計算兩個預寫式日志位置間的差別。
pg_current_wal_lsn():獲得當前預寫式日志寫入位置
小于10.0版本:
1
2
3
4
5
6
7
8
9
10
11
|
SELECT pg_xlog_location_diff(A .c1, replay_lsn) /(1024 * 1024) AS slave_latency_MB, pg_xlog_location_diff(A .c1, sent_lsn) /(1024 * 1024) AS send_latency_MB, pg_xlog_location_diff(A .c1, flush_lsn) /(1024 * 1024) AS flush_latency_MB, state, backend_start, now():: timestamp with time zone FROM pg_stat_replication, pg_current_xlog_location AS A(c1) WHERE client_addr= '192.168.46.173' and application_name = 'standby1' ORDER BY slave_latency_MB, send_latency_MB DESC LIMIT 1; |
注:
192.168.46.173 表示從庫ip地址。
pg_xlog_location_diff(lsn pg_lsn, lsn pg_lsn):計算兩個預寫式日志位置間的差別。
pg_current_xlog_location ():獲得當前預寫式日志寫入位置
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。如有錯誤或未考慮完全的地方,望不吝賜教。
原文鏈接:https://blog.csdn.net/zhangchen881222/article/details/80668837