暂无图片
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
打赏 0
暂无图片
薛晓刚

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

暂无图片 评论
暂无图片 有用 1
打赏 0
回答交流
Markdown


请输入正文
提交
相关推荐
pg xact_rollback突增
回答 2
已采纳
xactrollback过高,首先从数据库层面看并没有特别严重的影响。这个值不完全只有显式的rollback,比如执行语句出错系统也会自动的rollback,例如:postgresbegin;BEGI
以下时间函数中,查询结果带有时区值的有 ?
回答 1
已采纳
AcurrenttimeCcurrenttimestamp
基于Pacemaker的PostgreSQL HA pgsql-data-status disconnect
回答 1
这是复制的问题,看下pg的log
pg修改模式名称
回答 1
您好,检查一下应用访问的用户权限,是否有访问数据库所有模式下的所有表或数据库对象
在PostgreSQL数据库,如果postgresql.conf参数文件中logging_collect设置为“on”,那么SysLogger辅助进程会收集哪些进程的stderr输出?
回答 1
已采纳
选ABCDAPostmaster进程BAutoVacuum辅助进程CWalWriter辅助进程D服务进程
pg应该选什么版本
回答 2
已采纳
用最新的14吧。可以信赖
在PG数据库中以下哪个查看时间的SQL语句不会显示出时区信息?
回答 5
已采纳
Cselectcurrentdate;
pg数据库中,\l 命令可以查看所有数据库
回答 1
已采纳
B
闯关题目解析,题目答案有问题吧
回答 2
已采纳
麻烦您联系下小墨VX:modb666给您具体的反馈,感谢您的支持!😊
(HA)哪些架构实现PG的高可用?
回答 3
已采纳
以下是对提供的选项A、B、C、D是否实现PostgreSQL(PG)高可用的解释:A. patronizookeeper(etcd)postgresqlvippatroni:Patroni是