首页 > 其他分享 >KingbaseES V8R6集群运维案例之---查看主备流复制之间的延迟

KingbaseES V8R6集群运维案例之---查看主备流复制之间的延迟

时间:2023-10-10 18:01:32浏览次数:51  
标签:delay wal last V8R6 运维 lsn --- replay pg

案例说明:
在主备流复制集群运维过程中,对于同步复制节点,在读写分离环境应用需要强一致性访问时,需要监控主备之间流复制的延迟。

适用版本:
KingbaseES V8R6

一、主库查询流复制延迟

1、 通过sys_stat_replication
获取sent_lsn、write_lsn、flush_lsn、replay_lsn获取备库延迟信息

1)执行语句

select usename,application_name,client_addr,state,  
pg_wal_lsn_diff(pg_current_wal_insert_lsn(), sent_lsn) sent_delay,   
pg_wal_lsn_diff(pg_current_wal_insert_lsn(), write_lsn) write_delay,   
pg_wal_lsn_diff(pg_current_wal_insert_lsn(), flush_lsn) flush_delay,   
pg_wal_lsn_diff(pg_current_wal_insert_lsn(), replay_lsn) replay_delay   
from pg_stat_replication;

2)执行结果

prod=# select usename,application_name,client_addr,state,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(), sent_lsn) sent_delay,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(), write_lsn) write_delay,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(), flush_lsn) flush_delay,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(), replay_lsn) replay_delay
prod-# from pg_stat_replication;
 usename | application_name |  client_addr  |   state   | sent_delay | write_delay | flush_delay | replay_delay
---------+------------------+---------------+-----------+------------+-------------+-------------+--------------
 esrep   | node2            | 192.168.1.202 | streaming |          0 |           0 |           0 |            0
(1 row)

2、通过slot获取延迟信息

restart_lsn        最老的WAL日志的LSN 在复制槽中
数据库会把所有复制槽里restart_lsn最小的作为最老的LSN,这个LSN往后的所有较新的日志都会保留下来。

1)查询语句

select slot_name,plugin,slot_type,database,active,                       
xmin,catalog_xmin,  
pg_wal_lsn_diff(pg_current_wal_insert_lsn(),restart_lsn) restart_delay   
from pg_replication_slots; 

2)查询结果

prod=# select slot_name,plugin,slot_type,database,active,
prod-# xmin,catalog_xmin,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(),restart_lsn) restart_delay
prod-# from pg_replication_slots;
   slot_name   | plugin | slot_type | database | active | xmin | catalog_xmin | restart_delay
---------------+--------+-----------+----------+--------+------+--------------+---------------
 repmgr_slot_2 |        | physical  |          | t      | 2130 |              |             0
(1 row)

3)查询语句

select slot_name,plugin,slot_type,database,temporary,active,active_pid,  
xmin,catalog_xmin,  
pg_wal_lsn_diff(pg_current_wal_insert_lsn(),restart_lsn) restart_delay,   
pg_wal_lsn_diff(pg_current_wal_insert_lsn(),confirmed_flush_lsn) flush_delay   
from pg_replication_slots; 

4)查询结果

prod=# select slot_name,plugin,slot_type,database,temporary,active,active_pid,
prod-# xmin,catalog_xmin,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(),restart_lsn) restart_delay,
prod-# pg_wal_lsn_diff(pg_current_wal_insert_lsn(),confirmed_flush_lsn) flush_delay
prod-# from pg_replication_slots;
   slot_name   | plugin | slot_type | database | temporary | active | active_pid | xmin | catalog_xmin | restart_
delay | flush_delay
---------------+--------+-----------+----------+-----------+--------+------------+------+--------------+---------
------+-------------
 repmgr_slot_2 |        | physical  |          | f         | t      |      10895 | 2130 |              |
    0 |
(1 row)

二、从备库执行

1)查询语句

select pg_is_in_recovery(),pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(), 
       pg_last_xact_replay_timestamp();

2)查询结果

test=# select pg_is_in_recovery(),pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(),
test-#        pg_last_xact_replay_timestamp();
 pg_is_in_recovery | pg_last_wal_receive_lsn | pg_last_wal_replay_lsn | pg_last_xact_replay_timestamp
-------------------+-------------------------+------------------------+-------------------------------
 t                 | 2/1D000B50              | 2/1D000B50             | 2023-10-10 11:50:16.738548+08
(1 row)

3)查询语句

select pg_is_in_recovery(),pg_is_wal_replay_paused(), pg_last_wal_receive_lsn(),
 pg_last_wal_replay_lsn(),pg_last_xact_replay_timestamp();

4)查询结果

test=# select pg_is_in_recovery(),pg_is_wal_replay_paused(), pg_last_wal_receive_lsn(),
test-#  pg_last_wal_replay_lsn(),pg_last_xact_replay_timestamp();
 pg_is_in_recovery | pg_is_wal_replay_paused | pg_last_wal_receive_lsn | pg_last_wal_replay_lsn | pg_last_xact_re
play_timestamp
-------------------+-------------------------+-------------------------+------------------------+----------------
---------------
 t                 | f                       | 2/1D000B50              | 2/1D000B50             | 2023-10-10 11:5
0:16.738548+08
(1 row)

5)查询语句

SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn()
THEN 0
ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())
END AS log_delay;

6)查询结果

test=# SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn()
test-# THEN 0
test-# ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())
test-# END AS log_delay;
 log_delay
-----------
         0
(1 row)

三、查看主备之间的延迟wal差异量

1)查看主库

prod=# SELECT pg_current_wal_lsn();
 pg_current_wal_lsn
--------------------
 2/1D000B50
(1 row)

2)查看备库

select pg_is_in_recovery(),pg_is_wal_replay_paused(), pg_last_wal_receive_lsn(), 
pg_last_wal_replay_lsn(), pg_last_xact_replay_timestamp();


test=# select pg_is_in_recovery(),pg_is_wal_replay_paused(), pg_last_wal_receive_lsn(),
test-# pg_last_wal_replay_lsn(), pg_last_xact_replay_timestamp();

 pg_is_in_recovery | pg_is_wal_replay_paused | pg_last_wal_receive_lsn | pg_last_wal_replay_lsn | pg_last_xact_re
play_timestamp
-------------------+-------------------------+-------------------------+------------------------+----------------
---------------
 t                 | f                       | 1/1D000B50              | 1/1D000B50             | 2023-10-10 11:5
0:16.738548+08
(1 row)

3)查看lsn差异函数

pg_wal_lsn_diff(lsn pg_lsn, lsn pg_lsn)
pg_xlog_location_diff (location pg_lsn, location pg_lsn)


4)获取wal日志差异
prod=# select pg_wal_lsn_diff('2/1D000B50','1/1D000B50');
 pg_wal_lsn_diff
-----------------
      4294967296
(1 row)

prod=# select round(4294967296/pow(1024,3.0),2) missing_lsn_GiB;
 missing_lsn_GiB
-----------------
            4.00
(1 row)

四、总结
可以通过脚本的方式监控主备流复制之间的延迟,第一时间获悉集群运行状态。

标签:delay,wal,last,V8R6,运维,lsn,---,replay,pg
From: https://www.cnblogs.com/tiany1224/p/17755363.html

相关文章

  • 封装el-select
    效果:给select组件传入option请求方法,父组件无需再进行其他操作 <template><el-selectv-model="selectValue"multipleclearable@change="emitChange"value-key="id"placeholder="请选择车辆"><el-optionv-for="iteminop......
  • HashMap-二叉树
        ......
  • k8s-pod
    deployment模版apiVersion:apps/v1#指定api版本,此值必须在kubectlapi-versions中。业务场景一般首选”apps/v1“kind:Deployment#指定创建资源的角色/类型metadata:#资源的元数据/属性name:demo#资源的名字,在同一个namespace......
  • HashMap-红黑树
       ......
  • 虚拟桌宠模拟器:VPet-Simulator,一个开源的桌宠软件, 可以内置到任何WPF应用程序
    虚拟桌宠模拟器:VPet-Simulator,一个开源的桌宠软件,可以内置到任何WPF应用程序虚拟桌宠模拟器一个开源的桌宠软件,可以内置到任何WPF应用程序获取虚拟桌宠模拟器OnSteam(免费)或通过Nuget内置到你的WPF应用程序1.虚拟桌宠模拟器详细介绍虚拟桌宠模拟器是一款桌宠软件,......
  • ADYCGP-Numerical Reports
     ......
  • 通俗理解GAN -- 基础认知
     Smiling&Weeping----你已春风摇曳,我仍一身旧雪 1.GAN的基本思想GAN全称对抗生成网络,顾名思义是生成模型的一种,而他的训练则是一种对抗博弈状态中的。下面我们举例来解释一下GAN的基本思想。假如你是一名篮球运动员,你想在下次比赛......
  • FreeRTOS 和 RT-Thread 功能差别对比
    软件定时器FreeRTOS:定时器函数在task中被调用,居于任务调度的定时器RT-Thread:定时器函数既可以配置为在task中被调用,也可以配置为在tick中断中被调用 ......
  • April Fools Day Contest 2021 A. Is it rated - 2
    询问若干个问题,每个问题用一段字符串表示,存在空格。每个问题一行,对于每个回答,只需要输出\(NO\)。view1#include<bits/stdc++.h>chars[1000005];voidsolve(){ while(fgets(s,1000005,stdin)!=NULL){ std::cout<<"NO"<<std::endl;//fgets从流中读取,读取失......
  • pydantic学习与使用-17.使用 json_encoders 格式化 datetime 类型
    前言使用datetime日期类型时,想格式化成自定义的"%Y-%m-%d%H:%M:%S"格式datetime类型frompydanticimportBaseModelfromdatetimeimportdatetime#上海悠悠wx:283340479#blog:https://www.cnblogs.com/yoyoketang/classUserInfo(BaseModel):id:intna......