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_lsnlsn 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_lsnlsn pg_lsn):计算两个预写式日志位置间的差别。

pg_current_xlog_location ():获得当前预写式日志写入位置

 

你可能感兴趣的:(postgresql)