当前位置:   article > 正文

pgsql之查看主备复制延迟_pg如何查看主从复制延迟

pg如何查看主从复制延迟

查看复制延迟:

10.0及以上:

  1. SELECT
  2. pg_wal_lsn_diff(A .c1, replay_lsn) /(1024 * 1024) AS slave_latency_MB,
  3. pg_wal_lsn_diff(A .c1, sent_lsn) /(1024 * 1024) AS send_latency_MB,
  4. pg_wal_lsn_diff(A .c1, flush_lsn) /(1024 * 1024) AS flush_latency_MB,
  5. state,
  6. backend_start,
  7. now()::timestamp with time zone
  8. FROM pg_stat_replication, pg_current_wal_lsn() AS A(c1)
  9. WHERE client_addr='192.168.46.173' and application_name = 'standby1'
  10. ORDER BY slave_latency_MB, send_latency_MB DESC
  11. LIMIT 1;

注:

192.168.46.173 表示从库ip地址。

pg_wal_lsn_diff(lsn pg_lsnlsn pg_lsn):计算两个预写式日志位置间的差别。

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

 

小于10.0版本:

  1. SELECT
  2. pg_xlog_location_diff(A .c1, replay_lsn) /(1024 * 1024) AS slave_latency_MB,
  3. pg_xlog_location_diff(A .c1, sent_lsn) /(1024 * 1024) AS send_latency_MB,
  4. pg_xlog_location_diff(A .c1, flush_lsn) /(1024 * 1024) AS flush_latency_MB,
  5. state,
  6. backend_start,
  7. now()::timestamp with time zone
  8. FROM pg_stat_replication, pg_current_xlog_location AS A(c1)
  9. WHERE client_addr='192.168.46.173' and application_name = 'standby1'
  10. ORDER BY slave_latency_MB, send_latency_MB DESC
  11. LIMIT 1;

注:

192.168.46.173 表示从库ip地址。

pg_xlog_location_diff(lsn pg_lsnlsn pg_lsn):计算两个预写式日志位置间的差别。

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

 

 

大量数据导入和从库备份导致了大量的主从延迟,延迟的wal日志超过wal_keep_segments

造成了主库上的xlog目录被清理,从库需要的日志被清理掉了,最终复制中断。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/615773
推荐阅读
相关标签
  

闽ICP备14008679号