如何查看主從復(fù)制的狀態(tài),且備庫應(yīng)用落后了多少字節(jié)
這些信息要在主庫中查詢
查看流復(fù)制的信息可以使用主庫上的視圖
select pid,state,client_addr,sync_priority,sync_state from pg_stat_replication;
pg_stat_replication中幾個字?jǐn)嘤涗浟税l(fā)送wal的位置及備庫接收到的wal的位置、
sent_location--發(fā)送wal的位置
write_location--備庫接收到的wal的位置
flush_location—備庫寫wal日志到磁盤的位置
replay_location—備庫應(yīng)用日志的位置
查看備庫落后主庫多少字節(jié)
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;
級聯(lián)復(fù)制
select pg_xlog_location_diff(pg_last_xlog_replay_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication;
補(bǔ)充:pgsql之查看主備復(fù)制延遲
查看復(fù)制延遲:
10.0及以上:
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):計算兩個預(yù)寫式日志位置間的差別。
pg_current_wal_lsn():獲得當(dāng)前預(yù)寫式日志寫入位置
小于10.0版本:
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):計算兩個預(yù)寫式日志位置間的差別。
pg_current_xlog_location ():獲得當(dāng)前預(yù)寫式日志寫入位置
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- PostgreSQL 邏輯復(fù)制 配置操作
- postgresql流復(fù)制原理以及流復(fù)制和邏輯復(fù)制的區(qū)別說明
- PostgreSQL 流復(fù)制異步轉(zhuǎn)同步的操作
- PostgreSQL流復(fù)制參數(shù)max_wal_senders的用法說明
- CentOS PostgreSQL 12 主從復(fù)制(主從切換)操作