您好,登录后才能下订单哦!
怎么在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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。