案例说明:
在KingbaseES V8R3集群一主二备的架构中,配置了流复制为同步(sync)模式,但是集群启动后,流复制状态中显示备库是async模式(备库和主库数据已经同步),从备库的recovery.log日志也可以看到,备库启动后被复制模式设置为async模式。如下图备库recovery.log:
适用版本: KingbaseES V8R3
一、问题分析1、检测复制模式配置(all nodes)
[kingbase@node101 bin]$ cat ../data/kingbase.conf |grep standby_name
##synchronous_standby_names = '' # standby servers that provide sync rep
synchronous_standby_names='1 (node1,node2,node3)'
---如上所示,所有节点都已配置为同步模式,如果是异步模式,需要配置synchronous_standby_names=''。
2、检查kingbase.auto.conf
[kingbase@node101 bin]$ cat ../data/kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by ALTER SYSTEM command.
SYNCHRONOUS_STANDBY_NAMES = ''
---检查发现,所有节点的kingbase.auto.conf文件,在集群启动后,自动配置了SYNCHRONOUS_STANDBY_NAMES = ''。
3、检查HAmodule.conf文件
如下所示,参数sync_flag=0:
三、配置sync_flag测试
测试1:sync_flag=1
1)配置sync_flag=1(同步集群)
[kingbase@node101 bin]$ cat ../etc/HAmodule.conf |grep -i sync
#1->synchronous cluster,0->asynchronous cluster ,default 1.example:SYNC_FLAG=1
SYNC_FLAG=1
2)配置synchronous_standby_names参数(同步模式)
[kingbase@node101 bin]$ cat ../data/kingbase.conf |grep standby_name
##synchronous_standby_names = '' # standby servers that provide sync rep
synchronous_standby_names='1 (node1,node2)'
3)查看流复制同步模式
# 集群节点信息
TEST=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replicatio
n_delay
---------+---------------+-------+--------+-----------+---------+------------+-------------------+-----------
--------
0 | 192.168.1.101 | 54321 | up | 0.500000 | primary | 0 | true | 0
1 | 192.168.1.102 | 54321 | up | 0.500000 | standby | 0 | false | 0
(2 rows)
# 流复制状态
TEST=# select * from sys_stat_replication;
PID | USESYSID | USENAME | APPLICATION_NAME | CLIENT_ADDR | CLIENT_HOSTNAME | CLIENT_PORT | BACK
END_START | BACKEND_XMIN | STATE | SENT_LOCATION | WRITE_LOCATION | FLUSH_LOCATION | REPLAY_LOCAT
ION | SYNC_PRIORITY | SYNC_STATE
-------+----------+---------+------------------+---------------+-----------------+-------------+-------------
------------------+--------------+-----------+---------------+----------------+----------------+-------------
----+---------------+------------
21298 | 10 | SYSTEM | node2 | 192.168.1.102 | | 41374 | 2023-03-08 1
1:42:28.203822+08 | | streaming | 0/D50000D0 | 0/D50000D0 | 0/D50000D0 | 0/D50000D0
| 2 | sync
(1 row)
---如上所示,集群流复制处于同步(sync)复制模式。
测试2:sync_flag=0
1)配置sync_flag=0(异步集群)
[kingbase@node101 bin]$ cat ../etc/HAmodule.conf |grep -i sync
#1->synchronous cluster,0->asynchronous cluster ,default 1.example:SYNC_FLAG=1
SYNC_FLAG=0
2)配置synchronous_standby_names参数(同步模式)
[kingbase@node101 bin]$ cat ../data/kingbase.conf |grep standby_name
##synchronous_standby_names = '' # standby servers that provide sync rep
synchronous_standby_names='1 (node1,node2)'
3)查看流复制同步模式
# 如下所示,synchronous_standby_names被置空
TEST=# show synchronous_standby_names ;
synchronous_standby_names
---------------------------
(1 row)
# 流复制状态
TEST=# select * from sys_stat_replication;
PID | USESYSID | USENAME | APPLICATION_NAME | CLIENT_ADDR | CLIENT_HOSTNAME | CLIENT_PORT | BACK
END_START | BACKEND_XMIN | STATE | SENT_LOCATION | WRITE_LOCATION | FLUSH_LOCATION | REPLAY_LOCAT
ION | SYNC_PRIORITY | SYNC_STATE
-------+----------+---------+------------------+---------------+-----------------+-------------+-------------
------------------+--------------+-----------+---------------+----------------+----------------+-------------
----+---------------+------------
18002 | 10 | SYSTEM | node2 | 192.168.1.102 | | 51784 | 2023-03-08 1
4:01:27.693014+08 | | streaming | 0/D70000D0 | 0/D70000D0 | 0/D70000D0 | 0/D70000D0
| 0 | async
(1 row)
---如上所示,流复制的复制模式为async。
3)查看主库kingbase.auto.conf
[kingbase@node101 bin]$ cat ../data/kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by ALTER SYSTEM command.
SYNCHRONOUS_STANDBY_NAMES = ''
---如上所示,文件中配置SYNCHRONOUS_STANDBY_NAMES = ''
4)查看备库recovery.log
四、总结
如下图sync_flag配置:
sync_flag配置说明:
1->synchronous cluster ,default 1
0->asynchronous cluster
在配置集群流复制为同步(sync)复制模式时,必须在HAmodule.conf中设置sync_flag=1,如果设置为0,其优先级高于synchronous_standby_names配置,集群重启后,将集群复制模式自动设置为异步(async)