怎么在Postgresql数据库中检查主从复制的进度-创新互联
怎么在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 ():获得当前预写式日志写入位置
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联网站建设公司,的支持。
新闻名称:怎么在Postgresql数据库中检查主从复制的进度-创新互联
文章出自:http://hbruida.cn/article/spjpp.html