暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

产品使用-金仓数据库KingbaseES sys_receivewal介绍与使用

原创 数据猿 2023-12-27
252


金仓数据库KingbaseES sys_receivewal介绍与使用

关键字:

KingbaseES、sys_receivewal、人大金仓、KingbaseES、

概述

sys_receivewal从一个正在运行的KingbaseES集群中以流的方式得到WAL日志,通过使用流复制协议接收WAL日志,将其写入到本地WAL文件,并存放于指定目录下。

操作步骤

  1. 搭建集群
  2. 修改主节点的sys_hba.conf文件:

计算机生成了可选文字:
= 下 面 的 部 分 是 为 限 制 连 接 的 设 置 (limit 
t 0 
connection) 
e . e . e . e /13 
1 g 2 . 15 8 . 5 . 212 / 2 
t ru s t 
t ru s t 
host 
a11 
lhost 
a11 
a11 
a11

  1. 在备机中创建revicewal文件夹,并执行以下命令连接到主机数据库:

bin/sys_receivewal -D /home/kingbase/ES/release/kingbase/revicewal -h 192.168.45.216 -p 54330 -U system

  1. 在主机中进入ksql并生成wal日志:

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/ksql 
Type "help" for help 
test* select pg switch wal , 
pg switch wal 
1/9A8 
0 row) 
test* select pg switch wal , 
pg switch wal 
1/11391313713 
0 row) 
test* select pg switch wal , 
pg switch wal 
1/21391313713 
0 row) 
test* select pg switch wal , 
pg switch wal 
1/3131313131313 
0 row) 
test* select pg switch wal , 
pg switch wal 
1 / 3eee148 
0 row) 
-dtest 
-Usystem 
-p 5433e

  1. 此时备机中创建的receivewal文件夹下就会复制主机的wal日志:

计算机生成了可选文字:
/homeJklngbase.'ES/releaseJklngbaseJreVlcewal•' 
正 匯 } 
00000003000000010000000 鬣 p 引 
000000030000000100000003 
000000030000000100000002 
000000030000000100000001 
000000030000000100000000 
囗 
00000003 h'Story 
Last

参数介绍及使用

  1. -W参数:表示强制输入密码。

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/s YS recelvewal 一 D /home/kingbase/ES/ release/kingbase/ revlcewal 
-h 
1 g 2 . 15 8 . 5 . 215 
password. 
ACS YS recelvewal: n 0 t renamlng "eeeeeee3eeeeeeeIeeeeeee4.partiaI" 
segment 1 S n 0 t complete 
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewal- 
-h 
1 g 2 . 15 8 . 5 . 215 
S YS e r rO r 
t 0 0 many command-line arguments 〖 f rs t 1 S · 123 5578ab · ) 
S VS 
-help 
for mo re rmatIOn 
-p 
-p 
5433e 
5433e 
一 U 
一 U 
system 
system 
一 W 
123 5578ab

  1. -d参数,后面接连接串信息。sys_receivewal类似sys_basebackup,不需要制定特定的数据库。

二进制需要database的时候,-d后面可以跟database,也可以跟连接串,例如ksql。(由于需要连接某个database,所以支持“-d 数据库名”);

二进制不需要database的时候,-d后面只能跟字符串,例如sys_basebackup(因为是全实例备份,所以不需要database)

  1. -n参数:表示连接丢失时不循环连接,直接退出。

备机连接成功后,将主机数据库停止,那么会出现连接丢失的情况,此时系统会自动进行循环连接:

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 -h 192 . 158 . 5 . 215 
一 U s ystem 
-p 5433e 
S YS 
S YS 
S YS 
S YS 
S YS 
S YS 
S YS 
I s the 
TCP /IP 
I s the 
TCP /IP 
n 0 t renamlng "eeeeeee3eeeeeeeIeeeeeee6.partiaI 
segment 1 S n 0 t complete 
repllcatlon s t re a m Wa S termlnated before stop polnt 
e r rO r . 
disconnected; waltlng 5 seconds t 0 t ry agaln 
n 0 t C 0 n n e C t t 0 S e rV e r : n 0 t C 0 n n e C t to S e rVe r . 
e r rO r . 
S e rV e r runnlng on host · 1 g 2 . 158 . 5 . 215 
and acceptlng 
c 0 n n e c t 10 n s 0 n port 5 3 3 e ? 
disconnected; waltlng 5 seconds t 0 t ry agaln 
n 0 t C 0 n n e C t t 0 S e rVe r : n 0 t to S e rVe r . 
e r rO r . 
S e rV e r runnlng on host · 1 g 2 . 158 . 5 . 215 
and acceptlng 
c 0 n n e c t 10 n s 0 n port 5 3 3 e ? 
disconnected; waltlng 5 seconds to t ry agaln 
Connection refused 
Connection refused

加上-n参数表示连接丢失时不循环连接,直接退出:

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewal- 
S YS recelvewal: n 0 t renamlng "eeeeeee3eeeeeeeIeeeeeee8.partiaI" 
segment 1 S n 0 t complete 
S YS e r rO r 
repllcatlon s t re a m Wa S termlnated before stop polnt 
S YS e r rO r 
disconnected 
-h 192 . 15 8 . 5 . 215 
一 U s ystem 
-p 5433e 
一 n

  1. -V参数:表示查看版本

C:\Users\liujie2\AppData\Local\Temp\msohtmlclip1\02\clip_image008.png

  1. -v参数:表示启用详细输出模式

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/ release/kingbase/ revlcewal 
S YS recelvewal: starting 10g streamlng a t 1/8eeeeee (timeline 3 ) 
S YS recelvewal: finished segment a t I/geeeeee (timeline 3 ) 
S VS recelvewal: finished segment a t I/Aeeeeee (timeline 3 ) 
-h 192 . 15 8 . 5 . 215 
一 U s ystem 
-p 5433e

  1. -Z参数:表示启动压缩模式

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/ release/kingbase/ revlcewal -h 192 . 158 . 5 . 215 一 U s ystem -p 5433e 一 v 一 Z g 
S YS recelvewal: starting 10g streamlng a t I/Aeeeeee (timeline 3 ) 
S YS recelvewal: finished segment a t I/Beeeeee (timeline 3 )

-Z后指定压缩级别0-9,0表示不压缩,9表示最大压缩,此时备份目录中的wal日志将会是.gz的格式:

计算机生成了可选文字:
000000030000000100000008 
000000030000000100000007 
00000003000000010000000E 
000000030000000100000005 
00000003000000010000000 
000000030000000100000003 
000000030000000100000002 
000000030000000100000001 
000000030000000100000000 
囗 
00000003 h'Story

  1. -E参数:表示指定lsn。当接收到的wal的lsn大于此参数指定的lsn后,会停止接收,并正常退出。

假设当前接收到的wal的lsn为11,若指定的lsn已经存在,则正常退出;否则将在接收的WAL的LSN大于指定值时停止:

计算机生成了可选文字:
(kingbase@ 
100 引 . host 
1 g 2 . 15 8 . 5 . 215 
(kingbase@ 
100 引 . host 
1 g 2 . 15 8 . 5 . 215 
S YS n 0 t 
kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 
kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 
renamlng "eeeeeee3eeeeeeeIeeeeee13.partiaI 
segment 1 S n 0 t complete 
一 h 
-h 
一 U 
一 U 
S YS t e m 
system 
一 p 
-p 
5 3 3 e 
5433e 
一 E 
一 E 
1/1eeeeeee 
1/13eeeeee

计算机生成了可选文字:
Usage: 
Optlons 
000000030000000100000011 
000000030000000100000010 
00000003000000010000000F

  1. -S参数:表示要求sys_receivewal使用现有的复制槽。

首先使用--create-slot创建复制槽:

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 
S YS e r rO r 
COLIId n 0 t send replicatlon command · START REPLICATION · 
repllcatlon 
ERROR 
S YS recelvewal: disconnected; waltlng 5 seconds t 0 t ry agaln 
S YS e r rO r 
COLIId n 0 t send replicatlon command · START REPLICATION . 
repllcatlon 
ERROR 
S YS recelvewal: disconnected; waltlng 5 seconds t 0 t ry agaln 
一 h 1 g 2 . 15 8 . 5 . 215 
一 U system 
slot" does 
slot" does 
一 p 5 3 3 e 
n 0 t e XI S t 
n 0 t e XI S t 
-slot—recelvewal slot 
_ S n 0 u S 
-create-slot 
0 = re 0 e 1 V 
一 S n 0 u S 
ACLkingbase@10ca1host kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 -h 1 g 2 . 158 . 5 . 215 一 U s ystem 一 p 5 3 3 e 
(kingbase@localhost kingbase)s bin/sys recelvewal 一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 -h 1 g 2 . 158 . 5 . 215 
一 U system -p 5433e 
-slot—recelvewal slot 
slot --synchronous

再次创建会报错,加上--if-not-exists,该槽已经存在时不会抛出错误:

计算机生成了可选文字:
(kingbase@localhost kingbase)s bin/sys recelvewal 
YS e r rO r 
COLIId n 0 t send repllcatlon 
(kingbase@localhost kingbase)s bin/sys recelvewal 
一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 一 h 
command · CREATE REPLICATION SLOT "recelvewal slot" 
一 D /home/kingbase/ES/re1ease/kingbase/rev1cewa1 一 h 
1 g 2 . 15 8 . 5 . 215 一 U 
PHYSICAL · 
ERROR 
1 g 2 . 15 8 . 5 . 215 一 U 
system 一 p 5 3 3 e 
repllcatlon slot 
system 一 p 5 3 3 e 
-create-slot 
-slot—recelvewal slot 
"recelvewal slot" already e XI s t s 
-create-slot 
-slot—recelvewal slot 
-if-not-exlsts

在主库上使用select * from pg_replication_slots;命令查看复制槽:

计算机生成了可选文字:
test* select 、 from pg repllcatlon slots 
slot n a me 丨 plugin 丨 slot type 丨 datoid 
database 
tempora ry 
a C t 1 V e 
actlve_pld 
Xmln 
12 g 1 
catalog 
Xmln 
re s t a rt Isn 
1/7eeee58 
1/1ceee1313 
丨 confirmed flush Isn 
re m r slot 1 
re 0 e 1 V S 0 t 
丨 physical | 
丨 physical |

在备库中执行bin/sys_receivewal -D /home/kingbase/ES/release/kingbase/revicewal -h 192.168.45.216 -U system -p 54330 -S receivewal_slot命令后,再次查看复制槽:

计算机生成了可选文字:
test* select 、 
slot n a me 
i rmed flush Isn 
repmgr slot 1 
from pg repllcatlon slots 
database 
database 
tempora ry 
tempora ry 
a C t 1 V e 
a C t 1 V e 
丨 actlve_pid 
2 15 
丨 actlve_pid 
2 15 
Xmln 
12 g 1 
Xmln 
12 g 1 
丨 catalog xmln 丨 re s t a rt Isn 丨 conf 
丨 1/7eeee58 
I I/Iceeeeee 
丨 catalog xmln 丨 re s t a rt Isn 丨 conf 
丨 1/7eeee58 
丨 1/1Deeeeee 
丨 plugin 丨 slot type 
丨 datoid 
丨 physical 
丨 physical 
recelvewal slot 丨 
〖 2 rows) 
test* insert 1 n t 0 t 1 values(I) 
I N SERT 
test* select pg 
pg s w 
1/1DeeeeA8 
0 row) 
test* select 、 
slot n a me 
i rmed flush Isn 
repmgr slot 1 
〖 2 rows) 
S WI t 0 Wa 
from pg repllcatlon slots 
丨 plugin 丨 
slot type 
physical 
physical 
丨 datoid

使用drop-slot删除复制槽:

bin/sys_receivewal -D /home/kingbase/ES/release/kingbase/revicewal -h 192.168.45.216 -U system -p 54330 --drop-slot --slot=receivewal_slot

计算机生成了可选文字:
test* select 、 from pg 
slot n a me 丨 plugin 
repmgr slot 1 丨 
〖 1 row) 
repllcatlon 
丨 slot type 
丨 physical 
slots 
丨 datoid 
database 
tempora ry 
a C t 1 V e 
actlve_pld 
Xmln 
12 g 1 
丨 catalog xmin 丨 re s t a rt Isn 丨 confirmed flush Isn 
丨 1/7131313658 |

  1. --synchronous参数表示在收到wal数据后立刻刷入磁盘。如果sys_receivewal的复制客户端在服务器上配置为同步后备,则应该指定该选项,以确保能及时向服务器发送响应。此外,--no-sync可以使sys_receivewal不强制将WAL数据刷回磁盘,该参数--synchronous冲突

参考资料

《KingbaseES产品手册-sys_receivewal》

最后修改时间:2023-12-27 10:24:36
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论