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

这些信息要在主库中查询

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

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

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

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

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?