暂无图片
pg怎么检查主从一致?
我来答
分享
暂无图片 匿名用户
pg怎么检查主从一致?

pg怎么检查主从一致?

我来答
添加附件
收藏
分享
问题补充
2条回答
默认
最新
Lucifer三思而后行
暂无图片

流复制不需要查一致性吧,看差异就好和复制进度即可~

一、大小差异

在主库上执行:

select application_name, pg_size_pretty(pg_xlog_location_diff(pg_current_xlog_location(), replay_location)) as diff from pg_stat_replication; 或者: select application_name, client_addr, cur_xlog || '/' || cur_offset as cur_xlog, sent_xlog || '/' || sent_offset as sent_xlog, replay_xlog || '/' || replay_offset as replay_xlog, pg_size_pretty(( ((cur_xlog * 255 * 16 ^ 6) + cur_offset) - ((sent_xlog * 255 * 16 ^ 6) + sent_offset) )::numeric) as master_lag, pg_size_pretty(( ((sent_xlog * 255 * 16 ^ 6) + sent_offset) - ((replay_xlog * 255 * 16 ^ 6) + replay_offset) )::numeric) as slave_lag, pg_size_pretty(( ((cur_xlog * 255 * 16 ^ 6) + cur_offset) - ((replay_xlog * 255 * 16 ^ 6) + replay_offset) )::numeric) as total_lag from ( select application_name, client_addr, ('x' || lpad(split_part(sent_location::text,'/', 1), 8, '0'))::bit(32)::bigint as sent_xlog, ('x' || lpad(split_part(replay_location::text, '/', 1), 8, '0'))::bit(32)::bigint as replay_xlog, ('x' || lpad(split_part(sent_location::text, '/', 2), 8, '0'))::bit(32)::bigint as sent_offset, ('x' || lpad(split_part(replay_location::text, '/', 2), 8, '0'))::bit(32)::bigint as replay_offset, ('x' || lpad(split_part(pg_current_xlog_location()::text, '/', 1), 8, '0'))::bit(32)::bigint as cur_xlog, ('x' || lpad(split_part(pg_current_xlog_location()::text, '/', 2), 8, '0'))::bit(32)::bigint as cur_offset from pg_stat_replication ) as s;

二、时间差异

在从库上执行:

select now() - pg_last_xact_replay_timestamp() as replication_delay;

如何查看主从复制的状态,且备库应用落后了多少字节

这些信息要在主库中查询

查看流复制的信息可以使用主库上的视图

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;

希望能帮助到你~

暂无图片 评论
暂无图片 有用 0
暂无图片
薛晓刚

可以在主库上ps -ef|grep wal看到这个在变化在王从库送。有send的关键字就对了。

暂无图片 评论
暂无图片 有用 1
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏