首页 > 其他分享 >KingbaseES集群运维案例之-- V8R3与V8R6集群wal函数应用

KingbaseES集群运维案例之-- V8R3与V8R6集群wal函数应用

时间:2024-03-29 18:45:08浏览次数:28  
标签:wal V8R6 lsn XLOG SYS V8R3 集群 pg LOCATION

案例说明:
KingbaseES V8R3和V8R6集群在通过函数获取wal日志的相关信息时,两个版本的函数名称不同,本案例做了函数应用的对比和总结。

适用版本:
KingbaseES V8R3/R6

一、KingbaseES V8R3相关函数
Tips:
在V8R3的版本,事务日志名称为xlog。

1、查询数据库支持的函数

test=# select proname from sys_proc where proname like '%xlog%';
             proname
----------------------------------
 SYS_CURRENT_XLOG_LOCATION
 SYS_CURRENT_XLOG_INSERT_LOCATION
 SYS_CURRENT_XLOG_FLUSH_LOCATION
 SYS_XLOGFILE_NAME_OFFSET
 SYS_XLOGFILE_NAME
 SYS_XLOG_LOCATION_DIFF
 SYS_LAST_XLOG_RECEIVE_LOCATION
 SYS_LAST_XLOG_REPLAY_LOCATION
 SYS_IS_XLOG_REPLAY_PAUSED
 SYS_XLOG_REPLAY_RESUME
 SYS_SWITCH_XLOG
 SYS_XLOG_REPLAY_PAUSE
(12 rows)

2、xlog切换并查看对应wal日志文件

 test=# select sys_switch_xlog();
 sys_switch_xlog
-----------------
 0/E80002A8
(1 row)

test=# select SYS_XLOGFILE_NAME('0/E80002A8');
    SYS_XLOGFILE_NAME
--------------------------
 0000000300000000000000E8
(1 row)

3、获取当前lsn对应的日志文件及offset

# SQL文本
select SYS_CURRENT_XLOG_LOCATION(),SYS_XLOGFILE_NAME(SYS_CURRENT_XLOG_LOCATION()),
     SYS_XLOGFILE_NAME_OFFSET(SYS_CURRENT_XLOG_LOCATION());

test=# select SYS_CURRENT_XLOG_LOCATION(),SYS_XLOGFILE_NAME(SYS_CURRENT_XLOG_LOCATION()),
        SYS_XLOGFILE_NAME_OFFSET(SYS_CURRENT_XLOG_LOCATION());
 SYS_CURRENT_XLOG_LOCATION |    SYS_XLOGFILE_NAME     |    SYS_XLOGFILE_NAME_OFFSET
---------------------------+--------------------------+--------------------------------
 0/E9000220                | 0000000300000000000000E9 | (0000000300000000000000E9,544)
(1 row)

4、获取当前lsn及flush_lsn和insert_lsn位置

# SQL文本
select  SYS_CURRENT_XLOG_FLUSH_LOCATION(),SYS_CURRENT_XLOG_INSERT_LOCATION(),
    SYS_CURRENT_XLOG_LOCATION();

test=# select  SYS_CURRENT_XLOG_FLUSH_LOCATION(),SYS_CURRENT_XLOG_INSERT_LOCATION(),
test-#     SYS_CURRENT_XLOG_LOCATION();
 SYS_CURRENT_XLOG_FLUSH_LOCATION | SYS_CURRENT_XLOG_INSERT_LOCATION | SYS_CURRENT_XLOG_LOCATION
---------------------------------+----------------------------------+---------------------------
 0/E9000300                      | 0/E9000300                       | 0/E9000300
(1 row)

5、对比lsn之间的差异值

test=# select SYS_XLOG_LOCATION_DIFF('0/8BF6C80','0/8BF6C68');
 SYS_XLOG_LOCATION_DIFF
------------------------
                     24
(1 row)

6、获取主备库之间复制延迟

# 主备库之间流复制状态
test=# select * from sys_stat_replication;
  pid  | usesysid | usename | application_name |  client_addr  | client_hostname | client_port |         backend_
start         | backend_xmin |   state   | sent_location | write_location | flush_location | replay_location | sy
nc_priority | sync_state
-------+----------+---------+------------------+---------------+-----------------+-------------+-----------------
--------------+--------------+-----------+---------------+----------------+----------------+-----------------+---
------------+------------
 32377 |       10 | SYSTEM  | node2            | 192.168.1.202 |                 |       35947 | 2023-10-26 15:03
:45.046059+08 |              | streaming | 0/E80001B0    | 0/E80001B0     | 0/E80001B0     | 0/E8000178      |
          2 | sync
(1 row)

# SQL文本
select pid,usename,client_addr,state,
SYS_XLOG_LOCATION_DIFF( SYS_CURRENT_XLOG_LOCATION(),write_location) write_delay,
SYS_XLOG_LOCATION_DIFF( SYS_CURRENT_XLOG_LOCATION(),flush_location) flush_delay,
SYS_XLOG_LOCATION_DIFF( SYS_CURRENT_XLOG_LOCATION(),replay_location) replay_dely
from sys_stat_replication;

test=# select pid,usename,client_addr,state,
test-# SYS_XLOG_LOCATION_DIFF( SYS_CURRENT_XLOG_LOCATION(),write_location) write_delay,
test-# SYS_XLOG_LOCATION_DIFF( SYS_CURRENT_XLOG_LOCATION(),flush_location) flush_delay,
test-# SYS_XLOG_LOCATION_DIFF( SYS_CURRENT_XLOG_LOCATION(),replay_location) replay_dely
test-# from sys_stat_replication;
  pid  | usename |  client_addr  |   state   | write_delay | flush_delay | replay_dely
-------+---------+---------------+-----------+-------------+-------------+-------------
 32377 | SYSTEM  | 192.168.1.202 | streaming |           0 |           0 |           0
(1 row)

7、获取备库lsn信息

test=# select SYS_LAST_XLOG_RECEIVE_LOCATION();
 SYS_LAST_XLOG_RECEIVE_LOCATION
--------------------------------
 0/E90003E0
(1 row)

test=# select SYS_LAST_XLOG_REPLAY_LOCATION();
 SYS_LAST_XLOG_REPLAY_LOCATION
-------------------------------
 0/E90003E0
(1 row)

二、KingbaseES V8R6相关函数

Tips:
在V8R6的版本,事务日志名称为wal。

1、查询数据库支持的函数

test=# select proname from sys_proc where proname like '%wal%';
          proname
----------------------------
 pg_stat_get_wal_senders
 pg_stat_get_wal_receiver
 pg_current_wal_lsn
 pg_current_wal_insert_lsn
 pg_current_wal_flush_lsn
 pg_walfile_name_offset
 pg_walfile_name
 pg_wal_lsn_diff
 pg_last_wal_receive_lsn
 pg_last_wal_replay_lsn
 pg_is_wal_replay_paused
 pg_switch_wal
 pg_wal_replay_pause
 pg_wal_replay_resume
 pg_ls_waldir
 pg_stat_get_wal_buffer
 sys_switch_wal
 sys_current_wal_lsn
 sys_walfile_name_offset
 sys_walfile_name
 sys_current_wal_insert_lsn
 sys_wal_replay_pause
 sys_wal_replay_resume
 sys_is_wal_replay_paused
 sys_stat_get_wal_senders
 sys_wal_lsn_diff
 sys_stat_get_wal_receiver
 sys_current_wal_flush_lsn
 sys_ls_waldir
 sys_stat_get_wal_buffer
 sys_last_wal_receive_lsn
 sys_last_wal_replay_lsn
(32 rows)

2、wal切换并查看对应wal日志文件

test=# select sys_switch_wal();
 sys_switch_wal
----------------
 0/1B0046E8
(1 row)

test=# select pg_walfile_name('0/1B0046E8');
     pg_walfile_name
--------------------------
 00000003000000000000001B
(1 row)

3、获取当前lsn对应的日志文件及offset

test=# select pg_current_wal_lsn(),pg_walfile_name(pg_current_wal_lsn()),pg_walfile_name_offset(pg_current_wal_lsn());
 pg_current_wal_lsn |     pg_walfile_name      |      pg_walfile_name_offset      
--------------------+--------------------------+----------------------------------
 5/C0006590         | 0000001B00000005000000C0 | (0000001B00000005000000C0,26000)
(1 row)

4、查看wal日志文件存储目录及修改时间

test=# select * from pg_ls_waldir() order by modification asc;
                   name                   |   size   |      modification      
------------------------------------------+----------+------------------------
 0000001B00000005000000BD                 | 16777216 | 2021-03-01 12:43:26+08
 0000001B00000005000000BE                 | 16777216 | 2021-03-01 12:45:30+08
 0000001A00000005000000B3.partial         | 16777216 | 2021-03-01 13:17:33+08
 0000001B.history                         |      834 | 2021-03-01 13:17:45+08
........
 0000001B00000005000000BC                 | 16777216 | 2021-03-01 15:56:16+08
 0000001A.history                         |      790 | 2021-03-01 17:25:02+08
 00000018.history                         |      702 | 2021-03-01 18:31:40+08
(24 rows)

4、获取当前lsn及flush_lsn和insert_lsn位置

test=# select pg_current_wal_flush_lsn(),pg_current_wal_insert_lsn(),
                    pg_current_wal_lsn();
 pg_current_wal_flush_lsn | pg_current_wal_insert_lsn | pg_current_wal_lsn 
--------------------------+---------------------------+--------------------
 5/C0006590               | 5/C0006590                | 5/C0006590
(1 row)

5、对比lsn之间的差异值

test=# select pg_wal_lsn_diff('0/8BF6C80','0/8BF6C68');
 pg_wal_lsn_diff 
-----------------
              24
(1 row)

6、查询主备库之间复制延迟

test=# select pid,usename,client_addr,state,write_lag,flush_lag,replay_lag from pg_stat_replication;
  pid  | usename |  client_addr  |   state   | write_lag | flush_lag | replay_lag 
-------+---------+---------------+-----------+-----------+-----------+------------
 12208 | esrep   | 192.168.7.243 | streaming |           |           | 
 12224 | esrep   | 192.168.7.249 | streaming |           |           | 
(2 rows)

test=# select pid,usename,client_addr,state,
test-# pg_wal_lsn_diff(pg_current_wal_lsn(),write_lsn) write_delay,
test-# pg_wal_lsn_diff(pg_current_wal_lsn(),flush_lsn) flush_delay,
test-# pg_wal_lsn_diff(pg_current_wal_lsn(),replay_lsn) replay_dely
test-# from pg_stat_replication;
  pid  | usename |  client_addr  |   state   | write_delay | flush_delay | replay_dely 
-------+---------+---------------+-----------+-------------+-------------+-------------
 12208 | esrep   | 192.168.7.243 | streaming |           0 |           0 |           0
 12224 | esrep   | 192.168.7.249 | streaming |           0 |           0 |           0
(2 rows)

7、查看备库flush_lsn及replay_lsn

prod=# select pg_last_wal_receive_lsn();
 pg_last_wal_receive_lsn 
-------------------------
 5/C0006590
(1 row)

prod=# select pg_last_wal_replay_lsn();
 pg_last_wal_replay_lsn 
------------------------
 5/C0006590
(1 row)

prod=# select pg_last_xact_replay_timestamp();
 pg_last_xact_replay_timestamp 
-------------------------------
 2021-03-01 15:19:28.682064+08
(1 row)

三、总结
由于版本差异,KingbaseES V8R3和R6在wal日志相关查询上,使用的函数名称不同,需要根据版本具体应用。

标签:wal,V8R6,lsn,XLOG,SYS,V8R3,集群,pg,LOCATION
From: https://www.cnblogs.com/kingbase/p/17923265.html

相关文章

  • kingbaseES V8R6集群运维案例之---配置priority防止failover切换案例
    案例说明:在一主多备的架构中,需要配置一台备库在主备切换时,不能选举为主库。对于repmgr主备切换主库的选择算法如下:Tips:Repmgr选举候选备节点会以以下顺序选举:LSN---->Priority---->Node_ID。系统会先选举一个LSN比较大者作为候选备节点;如LSN一样,会根据Priority优先级进行比......
  • KingbaseES V8R6集群运维案例之---级联备库upstream节点故障
    KingbaseESV8R6集群运维案例之---级联备库upstream节点故障案例说明:在KingbaseESV8R6集群,构建级联备库后,在其upstream的节点故障后,级联备库如何处理?适用版本:KingbaseESV8R6集群架构:案例一:一、配置集群的recovery参数(allnodes)Tips:关闭备库的aut-recovery机制......
  • java postgres单体库迁移postgres集群库java
    packagecom.slsl.digital.twin.manage.controller.project;importcom.google.common.collect.Lists;importcom.slsl.digital.twin.common.utils.CollectionUtils;importjava.sql.*;importjava.util.*;importjava.util.stream.Collectors;publicclassTest{......
  • 基于containerd 部署 kubernetes 1.28集群
    1、准备说明8台Linux主机,安装Ubuntu20.04系统,其中2台haproxy,3台master节点,3台work节点每台主机不低于2GB内存大小,CPU大于2核心集群中的所有主机网络互通节点中不能存在重复的主机名、mac地址或者product_uuid交换分区配置。kubelet默认是在节点上检测到交换分区时,无法启动......
  • 在Linux中,如何配置和管理LVS集群?
    配置和管理LinuxVirtualServer(LVS)集群涉及以下几个主要步骤:环境准备:操作系统:确保所有参与集群的节点运行兼容的Linux发行版,如CentOS、Ubuntu等。内核支持:确认内核版本支持LVS所需的IP负载均衡模块,如IPVS(IPVirtualServer)。对于较新的内核,IPVS通常已集成。若需编译内核,请......
  • 在Linux中,心跳机制在Linux高可用集群中作用是什么?
    在Linux高可用(HighAvailability,HA)集群中,心跳机制发挥着至关重要的作用,主要体现在以下几个方面:节点状态监测:节点间连通性确认:心跳机制允许集群中的各个节点周期性地向其他节点发送心跳信号(通常是简单的消息或数据包),以此表明自己处于正常运行状态。接收节点通过及时响应或确......
  • KingbaseES V8R6集群运维案例之---主备failover切换原因分析
    案例说明:生产环境,KingbaseESV8R6的集群发生failover切换,分析集群切换的原因。适用版本:KingbaseESV8R6集群架构:137.xx.xx.67主原备库137.xx.xx.94原主库137.xx.xx.68vip地址一、日志分析1、分析原备库hamgr.log如下所示,通过原备库hamgr.log日志获取到具体......
  • KingbaseES V8R6数据库运维案例之---用户权限导致的备份恢复故障
    案例说明:由于限制了用户对数据库的访问,导致在执行‘sys_backup.shinit’初始化物理备份时,执行失败。适用版本:KingbaseESV8R6一、问题现象如下所示,执行‘sys_backup.shinit’初始化物理备份:1、执行初始化失败[kingbase@node201bin]$shsys_backup.shinitERROR:Con......
  • 一套集群实时在线扩容为两套集群方案
    一套集群实时在线扩容为两套集群方案解决问题:当一套集群A承担不了业务压力,需要在A集群在线情况下,扩出来一套与A集群完全一样的B集群,之后从业务层面控制A和B各自承担原A承担的一半业务压力。1、配置A集群1.1A集群创建用户并赋权selectfrompg_userwhere;......
  • 如何实现Redis集群的高可用性
    在实际应用中,确保Redis集群的高可用性是至关重要的。以下是一些常见的实现高可用性的方法和相关代码示例。1、主从复制(Master-SlaveReplication):原理:主节点负责处理数据写入操作,而从节点则从主节点复制数据。这样,即使主节点发生故障,从节点可以升级为主节点,继续提供服务......