您好,登錄后才能下訂單哦!
怎么在Postgresql數據庫中檢查主從復制的進度?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
查看流復制的信息可以使用主庫上的視圖
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—備庫應用日志的位置
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;
級聯復制
select pg_xlog_location_diff(pg_last_xlog_replay_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication;
補充:pgsql之查看主備復制延遲
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):計算兩個預寫式日志位置間的差別。
pg_current_wal_lsn():獲得當前預寫式日志寫入位置
小于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):計算兩個預寫式日志位置間的差別。
pg_current_xlog_location ():獲得當前預寫式日志寫入位置
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。