首页 > 其他分享 >openGauss主备切换之switchover与failover

openGauss主备切换之switchover与failover

时间:2024-04-11 11:13:54浏览次数:11  
标签:switchover dn gs opt failover ctl openGauss data

openGauss 主备切换之 switchover 与 failover
switchover
在主备机正常时,出于维护的需要,将备机切换为主机,可保证切换过程中数据不丢失。

查看集群实例主备状态:1 节点为主库,2 节点为备库。

$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state

1 cen7-og1-02 ... 6001 /opt/openGauss/data/dn P Primary Normal | 2 cen7-og1-03 ... 6002 /opt/openGauss/data/dn S Standby Normal
在备节点执行切换主备操作:

$ gs_ctl switchover -D /opt/openGauss/data/dn
[2021-01-15 02:44:55.125][1034][][gs_ctl]: gs_ctl switchover ,datadir is /opt/openGauss/data/dn
[2021-01-15 02:44:55.125][1034][][gs_ctl]: switchover term (1)
[2021-01-15 02:44:55.137][1034][][gs_ctl]: waiting for server to switchover..............
[2021-01-15 02:45:06.250][1034][][gs_ctl]: done
[2021-01-15 02:45:06.250][1034][][gs_ctl]: switchover completed (/opt/openGauss/data/dn)
确认集群主备状态:1 节点为备库,2 节点为主库。

$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state

1 cen7-og1-02 ... 6001 /opt/openGauss/data/dn P Standby Normal | 2 cen7-og1-03 ... 6002 /opt/openGauss/data/dn S Primary Normal
保存数据库主备机器信息:确保 gs_om -t refreshconf 命令执行成功,否则再次重启会影响数据库状态。

$ gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.
failover
在主机异常时,将备机切换为主机。

查看集群实例主备状态:1 节点为备库,2 节点为主库。

$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state

1 cen7-og1-02 ... 6001 /opt/openGauss/data/dn P Standby Normal | 2 cen7-og1-03 ... 6002 /opt/openGauss/data/dn S Primary Normal
备节点执行主备切换操作:

$ gs_ctl failover -D /opt/openGauss/data/dn
[2021-01-15 03:33:13.803][17292][][gs_ctl]: gs_ctl failover ,datadir is /opt/openGauss/data/dn
[2021-01-15 03:33:13.803][17292][][gs_ctl]: failover term (1)
[2021-01-15 03:33:13.810][17292][][gs_ctl]: waiting for server to failover...
[2021-01-15 03:33:14.823][17292][][gs_ctl]: done
[2021-01-15 03:33:14.823][17292][][gs_ctl]: failover completed (/opt/openGauss/data/dn)
确认集群主备状态:双主状态。

$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state

1 cen7-og1-02 ... 6001 /opt/openGauss/data/dn P Primary Normal | 2 cen7-og1-03 ... 6002 /opt/openGauss/data/dn S Primary Normal
在确定降为备机的节点关闭并以 standy 模式启动 openGauss 服务:

$ gs_ctl start -D /opt/openGauss/data/dn -M standby
[2021-01-15 03:03:08.695][9126][][gs_ctl]: gs_ctl started,datadir is /opt/openGauss/data/dn
[2021-01-15 03:03:08.864][9126][][gs_ctl]: waiting for server to start...
......
[2021-01-15 03:03:10.921][9126][][gs_ctl]: done
[2021-01-15 03:03:10.921][9126][][gs_ctl]: server started (/opt/openGauss/data/dn)
确认集群状态:1 节点为主库,2 节点为备库,但备库需要修复。

$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Degraded
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state

1 cen7-og1-02 ... 6001 /opt/openGauss/data/dn P Primary Normal | 2 cen7-og1-03 ... 6002 /opt/openGauss/data/dn S Standby Need repair(WAL)
在备库所在节点执行修复命令:

[omm@cen7-og1-03 ~]$ gs_ctl build -D /opt/openGauss/data/dn
[2021-01-15 03:23:57.702][30784][][gs_ctl]: gs_ctl incremental build ,datadir is /opt/openGauss/data/dn
waiting for server to shut down.... done
server stopped
[2021-01-15 03:23:58.726][30784][][gs_ctl]: fopen build pid file "/opt/openGauss/data/dn/gs_build.pid" success
[2021-01-15 03:23:58.726][30784][][gs_ctl]: fprintf build pid file "/opt/openGauss/data/dn/gs_build.pid" success
[2021-01-15 03:23:58.727][30784][][gs_ctl]: fsync build pid file "/opt/openGauss/data/dn/gs_build.pid" success
......
[2021-01-15 03:24:02.833][30784][dn_6001_6002][gs_ctl]: done
[2021-01-15 03:24:02.833][30784][dn_6001_6002][gs_ctl]: server started (/opt/openGauss/data/dn)
[2021-01-15 03:24:02.833][30784][dn_6001_6002][gs_ctl]: fopen build pid file "/opt/openGauss/data/dn/gs_build.pid" success
[2021-01-15 03:24:02.833][30784][dn_6001_6002][gs_ctl]: fprintf build pid file "/opt/openGauss/data/dn/gs_build.pid" success
[2021-01-15 03:24:02.835][30784][dn_6001_6002][gs_ctl]: fsync build pid file "/opt/openGauss/data/dn/gs_build.pid" success
确认集群状态:正常。

$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state

1 cen7-og1-02 ... 6001 /opt/openGauss/data/dn P Primary Normal | 2 cen7-og1-03 ... 6002 /opt/openGauss/data/dn S Standby Normal
保存数据库主备机器信息:确保 gs_om -t refreshconf 命令执行成功,否则再次重启会影响数据库状态。

$ gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.

标签:switchover,dn,gs,opt,failover,ctl,openGauss,data
From: https://www.cnblogs.com/helloopenGauss/p/18128420

相关文章

  • openGauss1.1.0主备集群节点的添加和删除
    openGauss1.1.0主备集群节点的添加和删除在上一篇文章《openGauss1.1.0主备部署(1主+2备+1级联备)》中,我们已经搭建了常见于生产环境的数据库架构(1主2备1级联备),如下图所示:本文将基于已搭建的主备环境进行集群节点的删除和添加操作,希望相关操作内容对大家有所帮助。......
  • openGauss监控场景处理
    openGauss监控场景处理死锁数量异常判断方法:selectsum(deadlocks)asdeadlocksfromdbe_perf.GLOBAL_STAT_DATABASE异常分析:请求与保持条件:获取资源的进程可以同时申请新的资源。非剥夺条件:已经分配的资源不能从该进程剥夺。循环等待条件:多个进程构成环路,并且每个进程......
  • openGauss与PostgreSQL对比测试SSL之自签名CA证书单向认证测试
    openGauss与PostgreSQL对比测试SSL之自签名CA证书单向认证测试本文测试自签名CA证书的单向认证:客户端只验证服务器证书的有效性,而服务器端不验证客户端证书的有效性。服务器加载证书信息并发送给客户端,客户端使用根证书来验证服务器端证书的有效性。服务端证书的客户......
  • openGauss2.0.0极简版安装
    openGauss2.0.0极简版安装openGauss的安装在官方文档的描述中,一直以企业生产环境为标准进行安装部署。但在个人基本的功能测试需求下,这样的安装操作显得有些复杂。在openGauss2.0.0版本中(2021.03.31发布)新增了极简版的软件包,极简版安装的使用主体主要针对高校和个人测试......
  • OpenGauss数据库之Python驱动快速入门
    OpenGauss数据库之Python驱动openGauss是一款开源关系型数据库管理系统,采用木兰宽松许可证v2发行。openGauss内核源自PostgreSQL,深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性。可是目前针对于OpenGauss数据库的Python应用程序的开发少......
  • Oracle数据表搬迁到openGauss
    Oracle数据表搬迁到openGauss搬迁方法Oracle数据表搬迁到openGauss数据库比较容易想到的两个工具是oracle_fdw及Ora2Pg。oracle_fdworacle_fdw是嵌入在目标端数据库里的一个扩展插件,允许在目标端数据库里访问其他异构数据库的表,openGauss数据库目前也支持这一插件。......
  • openGauss 列存表PSort索引
    openGauss列存表PSort索引概述PSort(Partialsort)Index是在列存表的列上建的聚簇索引。CUDesc上有每个CU的min和max值,但如果业务的数据模型较为离散,查询时通过min和max值去过滤CU会出现大量的CU误读取,例如每个CU的min和max跨度都比较大时,其查询效率......
  • openGauss数据与PostgreSQL的差异对比
    openGauss数据与PostgreSQL的差异对比前言openGauss数据库已经发布2.0.1版本了,中启乘数科技是一家专业的专注于极致性能的数据库服务提供商,所以也关注openGauss数据库的特性。因为openGauss是从PostgreSQL发展出来的,所以我们详细讲解对比一下openGauss与原生Po......
  • 一键部署openGauss2.0.1 CentOS 7.6
    一键部署openGauss2.0.1[CentOS7.6]本文档目的是为了帮助高校学生提供基于CentOS7.6操作系统,实现openGauss数据库一键式安装的脚本。该脚本执行成功后,所有关于openGauss数据库的文件将保存在/gaussdb目录中。脚本内容中“...”请替换为服务器实际的私有IP地址。脚......
  • openGauss 2.1.0 闪回特性
    openGauss2.1.0闪回特性openGauss2.1.0于2021年9月30日发布,是openGauss的一个Preview版本,该版本生命周期仅为半年。该版本的新增功能如下:存储过程兼容性增强SQL引擎能力增强支持Ustore存储引擎支持段页式存储基于Paxos分布式一致性协议的高可用AI4DB和......