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

这些信息要在主库中查询

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

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 ():获得当前预写式日志写入位置

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。