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

openGauss管理指南——实例主备切换

原创 李先生 2021-12-28
1404

openGauss管理指南——实例主备切换


实例主备切换

操作场景

  • openGauss在运行过程中,数据库管理员可能需要手工对数据库节点做主备切换。例如发现数据库节点主备failover后需要恢复原有的主备角色,或怀疑硬件故障需要手动进行主备切换。级联备机不能直接转换为主机,只能先通过switchover或者failover成为备机,然后再切换为主机。

说明:

  • 主备切换为维护操作,确保openGauss状态正常,所有业务结束后,再进行切换操作。
  • 在开启极致RTO时,不支持级联备机。级联备机因为极致RTO开启情况下,备机不支持连接无法同步数据。

环境说明

openGauss信息

主机名称 IP地址
opengauss 192.168.60.190
opengauss1 192.168.60.191
[omm@opengauss ~]$ gs_om -t status --detail [ Cluster State ] cluster_state : Normal redistributing : No current_az : AZ_ALL [ Datanode State ] node node_ip port instance state ----------------------------------------------------------------------------- 1 opengauss 192.168.60.190 5432 6001 /opengauss/data/db1 P Primary Normal 2 opengauss1 192.168.60.191 5432 6002 /opengauss/data/db1 S Standby Normal [omm@opengauss ~]$

操作步骤

  1. 以操作系统用户omm登录数据库任意节点,执行如下命令,查看主备情况。

    gs_om -t status --detail
  2. 以操作系统用户omm登录准备切换为主节点的备节点,执行如下命令。

    gs_ctl switchover -D /home/omm/cluster/dn1/

    /home/omm/cluster/dn1/为备数据库节点的数据目录。

    须知: 对于同一数据库,上一次主备切换未完成,不能执行下一次切换。对于业务正在操作时,发起switchover,可能主机的线程无法停止导致switchover显示超时,实际后台仍然在运行,等主机线程停止后,switchover即可完成。比如在主机删除一个大的分区表时,可能无法响应switchover发起的信号。

    主机故障时,可以在备机执行如下命令。

    gs_ctl failover -D /home/omm/cluster/dn1/
  3. switchover或failover成功后,执行如下命令记录当前主备机器信息。

    gs_om -t refreshconf

切换示例

  • ​ 将数据库节点备实例切换为主实例。

检查主备状态

  • ​ 以操作系统用户omm登录数据库任意节点,执行如下命令,查看主备情况。
gs_om -t status --detail [omm@opengauss ~]$ gs_om -t status --detail [ Cluster State ] cluster_state : Normal redistributing : No current_az : AZ_ALL [ Datanode State ] node node_ip port instance state ----------------------------------------------------------------------------- 1 opengauss 192.168.60.190 5432 6001 /opengauss/data/db1 P Primary Normal 2 opengauss1 192.168.60.191 5432 6002 /opengauss/data/db1 S Standby Normal [omm@opengauss ~]$

switchover切换

  • ​ 以操作系统用户omm登录准备切换为主节点的备节点,执行如下命令。
gs_ctl switchover -D /home/omm/cluster/dn1/ [omm@opengauss1 ~]$ gs_ctl switchover -D /opengauss/data/db1/ [2021-12-07 10:33:33.509][49804][][gs_ctl]: gs_ctl switchover ,datadir is /opengauss/data/db1 [2021-12-07 10:33:33.509][49804][][gs_ctl]: switchover term (1) [2021-12-07 10:33:33.514][49804][][gs_ctl]: waiting for server to switchover........... [2021-12-07 10:33:41.569][49804][][gs_ctl]: done [2021-12-07 10:33:41.569][49804][][gs_ctl]: switchover completed (/opengauss/data/db1) [omm@opengauss1 ~]$
  • /home/omm/cluster/dn1/为备数据库节点的数据目录。

  • 对于同一数据库,上一次主备切换未完成,不能执行下一次切换。对于业务正在操作时,发起switchover,可能主机的线程无法停止导致switchover显示超时,实际后台仍然在运行,等主机线程停止后,switchover即可完成。比如在主机删除一个大的分区表时,可能无法响应switchover发起的信号。

刷新信息

  • switchover成功后,执行如下命令记录保存当前主备机器信息。
gs_om -t refreshconf [omm@opengauss1 ~]$ gs_om -t refreshconf Generating dynamic configuration file for all nodes. Successfully generated dynamic configuration file.

状态检查

gs_om -t status --detail [omm@opengauss ~]$ gs_om -t status --detail [ Cluster State ] cluster_state : Normal redistributing : No current_az : AZ_ALL [ Datanode State ] node node_ip port instance state ----------------------------------------------------------------------------- 1 opengauss 192.168.60.190 5432 6001 /opengauss/data/db1 P Standby Normal 2 opengauss1 192.168.60.191 5432 6002 /opengauss/data/db1 S Primary Normal [omm@opengauss ~]$

异常处理

异常判断标准如下:

  • 业务压力下,主备实例切换时间长,这种情况不需要处理。
  • 其他备机正在build的情况下,主机需要发送日志到备机后,才能降备,导致主备切换时间长。这种情况不需要处理,但应尽量避免build过程中进行主备切换。
  • 切换过程中,因网络故障、磁盘满等原因造成主备实例连接断开,出现双主现象时,此时请参考如下步骤修复。

警告: 出现双主状态后,请按如下步骤恢复成正常的主备状态。否则可能会造成数据丢失。

  1. 执行以下命令查询数据库当前的实例状态。
gs_om -t status --detail
  • 若查询结果显示两个实例的状态都为Primary,这种状态为异常状态。
  1. 确定降为备机的节点,在节点上执行如下命令关闭服务。
gs_ctl stop -D /home/omm/cluster/dn1/
  1. 执行以下命令,以standby模式启动备节点。
gs_ctl start -D /home/omm/cluster/dn1/ -M standby
  1. 保存数据库主备机器信息。
gs_om -t refreshconf
  1. 查看数据库状态,确认实例状态恢复。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论