openGauss
开源数据库
openGauss社区官网
开源社区
openGauss1.1.0主备检查与角色切换
openGauss1.1.0 主备检查与角色切换
在上一篇文章《openGauss 1.1.0 主备部署(1 主+2 备+1 级联备)》中,我们已经搭建了常见于生产环境的数据库架构(1 主 2 备 1 级联备),如下图所示:

本文将基于已搭建的主备环境进行日常维护操作演示,如:健康检查、Switchover、Failover 等常见操作。希望文章内容对大家有所帮助。
健康状态检查
1. 通过 gs_om 工具检查集群健康状态
查询集群整体状态
[omm@prod ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
-------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Primary Normal
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Standby Normal
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Cascade Normal
## 说明:--detail参数通过在每个数据库节点执行gs_ctl query命令进行查询并汇总结果,来获取openGauss的详细信息。
P: 节点的初始角色是Primary,数据库安装后就不再变动,从系统静态文件读取。 S: 节点的初始角色是Standby,数据库安装后就不再变动,从系统静态文件读取。 |
查询集群各个节点信息
[omm@prod ~]$ gs_om -t status --all
-----------------------------------------------------------------------
cluster_state : Normal
redistributing : No
-----------------------------------------------------------------------
node : 1
node_name : prod.opengauss.com
instance_id : 6001
node_ip : ***.***.***.***
data_path : /gauss/data/db1
type : Datanode
instance_state : Normal
static_connections : 3
HA_state : Normal
instance_role : Primary
-----------------------------------------------------------------------
node : 2
node_name : stb1.opengauss.com
instance_id : 6002
node_ip : ***.***.***.***
data_path : /gauss/data/db1
type : Datanode
instance_state : Normal
instance_role : Standby
HA_state : Streaming
sender_sent_location : 0/7006260
sender_write_location : 0/7006260
sender_flush_location : 0/7006260
sender_replay_location : 0/7006260
receiver_received_location: 0/7006260
receiver_write_location : 0/7006260
receiver_flush_location : 0/7006260
receiver_replay_location : 0/7006260
sync_percent : 100%
sync_state : Async
-----------------------------------------------------------------------
node : 3
node_name : stb2.opengauss.com
instance_id : 6003
node_ip : ***.***.***.***
data_path : /gauss/data/db1
type : Datanode
instance_state : Normal
instance_role : Standby
HA_state : Streaming
sender_sent_location : 0/7006260
sender_write_location : 0/7006260
sender_flush_location : 0/7006260
sender_replay_location : 0/7006260
receiver_received_location: 0/7006260
receiver_write_location : 0/7006260
receiver_flush_location : 0/7006260
receiver_replay_location : 0/7006260
sync_percent : 100%
sync_state : Async
-----------------------------------------------------------------------
node : 4
node_name : casstb.opengauss.com
instance_id : 6004
node_ip : ***.***.***.***4
data_path : /gauss/data/db1
type : Datanode
instance_state : Normal
instance_role : Cascade Standby
## 说明:--all参数将在每个数据库节点查询系统表并汇总结果,从而获取openGauss所有节点的信息
2. 通过系统函数检查数据同步状态
查询 wal 日志传送状态
## 主节点(***.***.***.***) 信息查询
postgres=# \pset expanded
postgres=# select * from pg_stat_get_wal_senders();
-[ RECORD 1 ]--------------+----------------------------------------
pid | 140307005830912
sender_pid | 3734
local_role | Primary
peer_role | Standby
peer_state | Normal
state | Streaming
catchup_start | 2021-01-21 11:09:21.015018+08
catchup_end | 2021-01-21 11:09:21.015136+08
sender_sent_location | 0/7006E68
sender_write_location | 0/7006E68
sender_flush_location | 0/7006E68
sender_replay_location | 0/7006E68
receiver_received_location | 0/7006E68
receiver_write_location | 0/7006E68
receiver_flush_location | 0/7006E68
receiver_replay_location | 0/7006E68
sync_percent | 100%
sync_state | Async
sync_priority | 0
sync_most_available | Off
channel | ***.***.***.***:26001-->***.***.***.***:40076
-[ RECORD 2 ]--------------+----------------------------------------
pid | 140306989049600
sender_pid | 3735
local_role | Primary
peer_role | Standby
peer_state | Normal
state | Streaming
catchup_start | 2021-01-21 11:09:21.018418+08
catchup_end | 2021-01-21 11:09:21.018525+08
sender_sent_location | 0/7006E68
sender_write_location | 0/7006E68
sender_flush_location | 0/7006E68
sender_replay_location | 0/7006E68
receiver_received_location | 0/7006E68
receiver_write_location | 0/7006E68
receiver_flush_location | 0/7006E68
receiver_replay_location | 0/7006E68
sync_percent | 100%
sync_state | Async
sync_priority | 0
sync_most_available | Off
channel | ***.***.***.***:26001-->***.***.***.***:58760
## 级联备节点(***.***.***.***4) 信息查询
postgres=# \pset x
postgres=# select * from pg_stat_get_wal_receiver();
-[ RECORD 1 ]--------------+----------------------------------------
receiver_pid | 2533
local_role | Cascade Standby
peer_role | Standby
peer_state | Normal
state | Normal
sender_sent_location | 0/7006E68
sender_write_location | 0/7006E68
sender_flush_location | 0/7006E68
sender_replay_location | 0/7006D50
receiver_received_location | 0/7006E68
receiver_write_location | 0/7006E68
receiver_flush_location | 0/7006E68
receiver_replay_location | 0/7006E68
sync_percent | 100%
channel | ***.***.***.***4:42128<--***.***.***.***:26001
查询复制状态
postgres=# select * from pg_stat_get_stream_replications();
local_role | static_connections | db_state | detail_information
------------+--------------------+----------+--------------------
Primary | 3 | Normal | Normal
postgres=# select * from dbe_perf.get_global_replication_slots();
node_name | slot_name | plugin | slot_type | datoid | database | active | x_min | catalog_xmin | restart_lsn | dummy_standby
-------------------+-----------+--------+-----------+--------+----------+--------+-------+--------------+-------------+---------------
dn_6001_6002_6003 | dn_6003 | | physical | 0 | | t | | | 0/7007958 | f
dn_6001_6002_6003 | dn_6002 | | physical | 0 | | t | | | 0/7007958 | f
postgres=# \pset x
Expanded display is on.
postgres=# select * from dbe_perf.get_global_replication_stat();
-[ RECORD 1 ]------------+-------------------
node_name | dn_6001_6002_6003
pid | 140307005830912
usesysid | 10
usename | omm
application_name |
client_addr | ***.***.***.***
client_hostname | stb1.opengauss.com
client_port | 40076
backend_start |
state | Streaming
sender_sent_location | 0/7007A70
receiver_write_location | 0/7007A70
receiver_flush_location | 0/7007A70
receiver_replay_location | 0/7007A70
sync_priority | 0
sync_state | Async
-[ RECORD 2 ]------------+-------------------
node_name | dn_6001_6002_6003
pid | 140306989049600
usesysid | 10
usename | omm
application_name |
client_addr | ***.***.***.***
client_hostname | stb2.opengauss.com
client_port | 58760
backend_start |
state | Streaming
sender_sent_location | 0/7007A70
receiver_write_location | 0/7007A70
receiver_flush_location | 0/7007A70
receiver_replay_location | 0/7007A70
sync_priority | 0
sync_state | Async
3. 检查远程复制相关参数
postgres=# select name,setting from pg_settings where name like '%replconninfo%';
name | setting
---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
replconninfo1 | localhost=***.***.***.*** localport=26001 localheartbeatport=26005 localservice=26004 remotehost=***.***.***.*** remoteport=26001 remoteheartbeatport=26005 remoteservice=26004
replconninfo2 | localhost=***.***.***.*** localport=26001 localheartbeatport=26005 localservice=26004 remotehost=***.***.***.*** remoteport=26001 remoteheartbeatport=26005 remoteservice=26004
replconninfo3 | localhost=***.***.***.*** localport=26001 localheartbeatport=26005 localservice=26004 remotehost=***.***.***.***4 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004
## 说明:
## localport --> 同步日志传输端口
## localheartbeatport --> 集群心跳端口
## localservice --> 主备通讯端口
postgres=# select name,setting from pg_settings where name like '%standby%';
name | setting
---------------------------------+------------------------
hot_standby | on
hot_standby_feedback | off
max_standby_archive_delay | 3000
max_standby_streaming_delay | 3000
standby_shared_buffers_fraction | 0.3
synchronous_standby_names | ANY 1(dn_6002,dn_6003)
## 参数说明:
## hot_standby --> 是否允许备机在恢复过程中连接和查询
## hot_standby_feedback --> 是否允许将备机上执行查询的最小事务号反馈给主机,当该参数为on时,主机仅允许清理小于备机反馈回来的事务号的旧版本数据
## max_standby_archive_delay和max_standby_streaming_delay --> 备机查询冲突时,设置备机取消查询之前所等待的时间(默认3s)
## standby_shared_buffers_fraction --> 备机可以使用的最大shared_buffers百分比
## synchronous_standby_names --> 备机名称列表
postgres=# select name,setting from pg_settings where name like '%repli%';
name | setting
----------------------------+---------
data_replicate_buffer_size | 131072
enable_data_replicate | off
enable_mix_replication | off
enable_stream_replication | on
max_replication_slots | 8
replication_type | 1
session_replication_role | origin
## 参数说明:
## data_replicate_buffer_size --> 发送端与接收端传递数据页时,队列所占用的内存大小(默认128MB)
## enable_data_replicate --> on表示导入数据行存表时主备数据采用数据页的方式进行同步 || off表示导入数据行存表时主备数据采用WAL日志方式进行同步
## enable_mix_replication --> 控制主备、主从之间WAL日志及数据复制的方式,默认off表示,关闭WAL日志、数据页混合复制模式
## enable_stream_replication --> 控制主备是否进行数据和日志同步,默认on表示打开主备同步
## max_replication_slots --> 设置主机端日志复制最大slot数
## session_replication_role --> 会话复制角色(origin(源端)||replica(目标端)||local表示函数执行复制时会检测当前登录数据库的角色并采取相应的操作)
## replication_type --> 标记当前HA模式是单主机模式、主备从模式还是一主多备模式(用户无法修改该参数)
## 2 表示单主机模式,此模式无法扩展备机。
## 1 表示使用一主多备模式,全场景覆盖,推荐使用。当设置为1时,会强制把enable_data_replicate参数设置为off。
## 0 表示主备从模式,目前此模式暂不支持。
主备角色切换(switchover)
在实际工作中,偶尔会碰到主节点系统或硬件需要维护的场景。在此时,我们需要实现数据零丢失进行主备切换,将主节点的业务迁移到备节点去,然后关闭原先的主节点进行维护。
switchover 的注意事项:
- 对于同一数据库,上一次主备切换未完成,不能执行下一次切换。
- 对于业务正在操作时,发起 switchover,可能主机的线程无法停止导致 switchover 显示超时,实际后台仍然在运行,等主机线程停止后,switchover 即可完成。比如在主机删除一个大的分区表时,可能无法响应 switchover 发起的信号。
1. 检查主备集群状态
[omm@prod ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
-------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Primary Normal |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Standby Normal |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Cascade Normal
## 集群状态正常,可以进行switchover操作
## 级联备库状态查询(在级联备库查询) || 备库***.***.***.***目前正在向级联备库***.***.***.***4同步数据
postgres=# \pset x
Expanded display is on.
postgres=# select * from pg_stat_get_wal_receiver();
-[ RECORD 1 ]--------------+----------------------------------------
receiver_pid | 2245
local_role | Cascade Standby
peer_role | Standby
peer_state | Normal
state | Normal
sender_sent_location | 0/7005640
sender_write_location | 0/7005640
sender_flush_location | 0/7005640
sender_replay_location | 0/7005528
receiver_received_location | 0/7005640
receiver_write_location | 0/7005640
receiver_flush_location | 0/7005640
receiver_replay_location | 0/7005640
sync_percent | 100%
channel | ***.***.***.***4:46578<--***.***.***.***:26001
2. 切换主/备角色
本次在备库 ... 上执行 switchover 操作。
[omm@stb2 ~]$ gs_ctl switchover -D /gauss/data/db1
[2021-01-21 17:03:52.629][2996][][gs_ctl]: gs_ctl switchover ,datadir is /gauss/data/db1
[2021-01-21 17:03:52.629][2996][][gs_ctl]: switchover term (1)
[2021-01-21 17:03:52.633][2996][][gs_ctl]: waiting for server to switchover...............
[2021-01-21 17:04:04.698][2996][][gs_ctl]: done
[2021-01-21 17:04:04.698][2996][][gs_ctl]: switchover completed (/gauss/data/db1)
3. 检查集群状态
[omm@prod ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
-------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Standby Normal |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Primary Normal |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Cascade Normal
## 级联备库状态查询(在级联备库查询) || 此时级联备库自动切换数据源,从新的备库(***.***.***.***)同步日志数据
postgres=# \pset x
Expanded display is on.
postgres=# select * from pg_stat_get_wal_receiver();
-[ RECORD 1 ]--------------+----------------------------------------
receiver_pid | 2505
local_role | Cascade Standby
peer_role | Standby
peer_state | Normal
state | Normal
sender_sent_location | 0/7005F00
sender_write_location | 0/7005F00
sender_flush_location | 0/7005F00
sender_replay_location | 0/7005F00
receiver_received_location | 0/7005F00
receiver_write_location | 0/7005F00
receiver_flush_location | 0/7005F00
receiver_replay_location | 0/7005F00
sync_percent | 100%
channel | ***.***.***.***4:58796<--***.***.***.***:26001
4. 保存集群主备机器信息(刷新动态配置文件)
[omm@stb2 ~]$ gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.
## 将集群配置信息写入集群动态配置文件:/gauss/app/bin/cluster_dynamic_config
## 如果不执行该操作,下次主备集群启动时会报错
故障切换至级联备机(Failover)
当生产环境对于灾备级别的 RPO 要求不是非常严格时,为了降低容灾成本,最大限度减小灾备数据同步对生产环境的影响,往往会选择将灾备数据中心的备库设置为级联备机的角色。
那么,当生产环境数据中心发生灾难,全部故障时,只能使用灾备数据中心的级联备机进行 Failover,接管生产业务。前提:模拟生产数据中心故障,强行关闭实验环境中的主节点和两个备节点,仅剩级联备机一个节点。
Failover 注意事项:
- 级联备机不能直接转换为主机,只能先通过 switchover 或 failover 成为备机,然后再成为主机;
- 在执行主、备切换测试前,请确保已经更改默认的初始用户密码,否则可能测试失败。
1. 查询集群状态(在级联备机操作)
Tips: 这里需要吐槽一下/当主备集群的操作系统全部挂掉,仅剩级联备份时,使用 gs_om 工具的等待时间竟然需要 15 分钟之久,这个简直无法接受,这个等待时间需要优化。
[omm@casstb ~]$ date && gs_om -t status --detail && date ## 为了测试需要多长时间,特意使用date标记......
Thu Jan 21 17:50:19 CST 2021
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
--------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Unknown Unknown |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Unknown Unknown |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Unknown Unknown |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Cascade Need repair(Disconnected)
Thu Jan 21 18:05:47 CST 2021
- 手动检查集群各节点状态
gs_om 工具等待时间太长,可以手动根据配置信息检查所有节点状态
## 查询集群静态配置文件信息
[omm@prod ~]$ gs_om -t view
NodeHeader:
version:301
time:1609922310
nodeCount:4
node:1
azName:AZ1
azPriority:1
node :1
nodeName:prod.opengauss.com
ssh channel :
sshChannel 1:***.***.***.***
datanodeCount :1
datanode 1:
datanodeLocalDataPath :/gauss/data/db1
datanodeXlogPath :
datanodeListenIP 1:***.***.***.***
datanodePort :26000
datanodeLocalHAIP 1:***.***.***.***
datanodeLocalHAPort :26001
dn_replication_num: 4
datanodePeer0DataPath :/gauss/data/db1
datanodePeer0HAIP 1:***.***.***.***
datanodePeer0HAPort :26001
datanodePeer1DataPath :/gauss/data/db1
datanodePeer1HAIP 1:***.***.***.***
datanodePeer1HAPort :26001
datanodePeer2DataPath :/gauss/data/db1
datanodePeer2HAIP 1:***.***.***.***4
datanodePeer2HAPort :26001
azName:AZ1
azPriority:1
node :2
... ...
node :3
... ...
node :4
... ...
## 查询流复制状态
postgres=# select * from pg_stat_get_stream_replications();
local_role | static_connections | db_state | detail_information
-----------------+--------------------+-------------+--------------------
Cascade Standby | 3 | Need repair | Disconnected
## 最后分别登陆各个集群节点,检查节点的健康状态
2. 级联备节点执行 failover
[omm@casstb ~]$ gs_ctl failover -D /gauss/data/db1
[2021-01-21 18:09:34.613][8529][][gs_ctl]: gs_ctl failover ,datadir is /gauss/data/db1
[2021-01-21 18:09:34.613][8529][][gs_ctl]: failover term (1)
[2021-01-21 18:09:34.618][8529][][gs_ctl]: waiting for server to failover.....
[2021-01-21 18:09:36.635][8529][][gs_ctl]: done
[2021-01-21 18:09:36.635][8529][][gs_ctl]: failover completed (/gauss/data/db1)
Tips: 官方文档说“级联备机不能直接转换为主机,只能先通过 switchover 或 failover 成为备机,然后再成为主机”,然而,gs_ctl 的 switchover 命令和 failover 命令并没有参数设置级联备为普通备,只能直接对级联备进行 failover 操作,并没有发现什么异常。
3. 刷新动态配置文件报错(当其他节点操作系统故障时,这一步就不用做了)
Tips: 当主备集群操作系统全部关闭,仅剩级联备份时,使用 gs_om 工具时,等待时间竟然需要 15 分钟之久,这个简直无法接受,代码还需要完善。(操作系统启动后,gs_om 工具恢复正常,不再需要等待那么久)
[omm@casstb ~]$ date && gs_om -t refreshconf && date
Thu Jan 21 18:13:01 CST 2021
Generating dynamic configuration file for all nodes.
[GAUSS-50205] : Failed to write dynamic configuration file. Error:
[GAUSS-51230] : The number of master dn must equal to 1.
## 将集群配置信息写入集群动态配置文件:/gauss/app/bin/cluster_dynamic_config
4. 重启数据库(新 Primary)
## 关闭数据库
[omm@casstb ~]$ gs_ctl stop -D /gauss/data/db1
[2021-01-21 18:33:57.786][12292][][gs_ctl]: gs_ctl stopped ,datadir is /gauss/data/db1
waiting for server to shut down........ done
server stopped
## 以Primary模式启动数据库
[omm@casstb ~]$ gs_ctl start -D /gauss/data/db1 -M primary
5. 查看集群状态
[omm@casstb ~]$ gs_om -t status --detail ## 其他节点操作系统未启动,依然需要等待15分钟
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
--------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Unknown Unknown |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Unknown Unknown |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Unknown Unknown |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
## 查询复制状态
postgres=# select * from pg_stat_get_stream_replications();
local_role | static_connections | db_state | detail_information
------------+--------------------+----------+--------------------
Primary | 3 | Normal | Normal
6. 故障节点恢复
检查集群状态
## 其他节点的操作系统恢复后,gs_om功能恢复正常
[omm@casstb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Degraded
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
-----------------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Down Manually stopped |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Down Manually stopped |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Down Manually stopped |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
刷新动态配置文件并重启集群
## 刷新动态配置文件
[omm@casstb ~]$ gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.
## 重启集群
[omm@casstb ~]$ gs_om -t restart
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
Starting cluster.
=========================================
Waiting for check cluster state...
Waiting for check cluster state...
Waiting for check cluster state...
Waiting for check cluster state...
Waiting for check cluster state...
[GAUSS-51607] : Failed to start cluster. After startup, the last check results were Degraded. Please check manually.
## 查看集群状态
[omm@casstb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Degraded
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
----------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Standby Normal |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Standby Need repair(WAL) |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
重建问题备节点(在问题节点 ... 上处理)
[omm@stb1 ~]$ gs_ctl build -D /gauss/data/db1 -b full
[omm@casstb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
-------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Standby Normal |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Standby Normal |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
## 说明:虽然集群状态角色已经切换完毕,但是集群标签(如:P/S/C)并没有变更过来,这个需要修改
附录:集群“双主”问题处理
## 检查集群状态
[omm@casstb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
-------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Standby Normal |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Primary Normal |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
## 重启问题旧的主节点(***.***.***.***)
[omm@stb2 ~]$ gs_ctl stop -D /gauss/data/db1
[omm@stb2 ~]$ gs_ctl start -D /gauss/data/db1 -M standby
## 查看集群状态
[omm@casstb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Degraded
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
--------------------------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Standby Need repair(Disconnected) |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Need repair(WAL) |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Standby Need repair(WAL) |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
## 重建备节点
[omm@prod ~]$ gs_ctl build -D /gauss/data/db1
[omm@stb1 ~]$ gs_ctl build -D /gauss/data/db1
[omm@stb2 ~]$ gs_ctl build -D /gauss/data/db1 -M cascade_standby ## 重建级联备机需要加上-M cascade_standby参数
## 查看集群状态(已恢复正常)
[omm@casstb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state |
-------------------------------------------------------------------------------
1 prod.opengauss.com ***.***.***.*** 6001 /gauss/data/db1 P Standby Normal |
2 stb1.opengauss.com ***.***.***.*** 6002 /gauss/data/db1 S Standby Normal |
3 stb2.opengauss.com ***.***.***.*** 6003 /gauss/data/db1 S Cascade Normal |
4 casstb.opengauss.com ***.***.***.***4 6004 /gauss/data/db1 C Primary Normal
## 刷新动态配置文件
[omm@casstb ~]$ gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.
## 将集群配置信息写入集群动态配置文件:/gauss/app/bin/cluster_dynamic_config