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

openGauss主备切换之switchover与failover

时间:2024-04-17 11:24:13浏览次数: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/18140131

相关文章

  • openGauss在kubernetes集群环境上的部署
    opengauss实践总结学习心openGauss是一款开源关系型数据库管理系统,深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性;kubernetes也是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效,Kuber......
  • 如何使用pgloader迁移MySQL数据库至openGauss
    pgloader介绍pgloader是一个数据导入工具,使用COPY命令将数据导入到PostgreSQL。pgloader有两种工作模式,一种是从文件导入,一种是迁移数据库。pgloader在两种情况下都使用PostgreSQL的COPY协议高效的传输数据。openGauss兼容PostgreSQL的通信协议以及绝大部分语法,可......
  • openGauss DBMind模式说明
    DBMind模式说明用户可通过gs_dbmind命令调用AI4DB的全部功能,该命令可实现下列基本功能:服务功能:service子命令,包括创建并初始化配置目录、启动后台服务、关闭后台服务等;调用组件:component子命令,AI4DB功能(如索引推荐、参数调优等)可通过该模式进行即时调用;设置参数:set子命令,通过......
  • openGauss DB4AI-Query-模型训练和推断
    DB4AI-Query:模型训练和推断openGauss当前版本支持了原生DB4AI能力,通过引入原生AI算子,简化操作流程,充分利用数据库优化器、执行器的优化与执行能力,获得高性能的数据库内模型训练能力。更简化的模型训练与预测流程、更高的性能表现,让开发者在更短时间内能更专注于模型的调优与数据......
  • openGauss AI特性
    AI特性人工智能技术最早可以追溯到上世纪50年代,甚至比数据库系统的发展历史还要悠久。但是,由于各种各样客观因素的制约,在很长的一段时间内,人工智能技术并没有得到大规模的应用,甚至还经历了几次明显的低谷期。到了近些年,随着信息技术的进一步发展,从前限制人工智能发展的因素已经逐......
  • openGauss AI4DB-数据库自治运维
    AI4DB:数据库自治运维如上文所述,AI4DB主要用于对数据库进行自治运维和管理,从而帮助数据库运维人员减少运维工作量。在实现上,DBMind的AI4DB框架具有监控和服务化的性质,同时也提供即时AI工具包,提供开箱即用的AI运维功能(如索引推荐)。AI4DB的监控平台以开源的Prometheus为主,DBMind提......
  • openGauss DB4AI-Snapshots数据版本管理
    DB4AI-Snapshots数据版本管理DB4AI-Snapshots是DB4AI模块用于管理数据集版本的功能。通过DB4ai-Snapshots组件,开发者可以简单、快速地进行特征筛选、类型转换等数据预处理操作,同时还可以像git一样对训练数据集进行版本控制。数据表快照创建成功后可以像视图一样进行使用,但是一经......
  • openGauss DBMind部署
    DBMind安装和部署1.安装准备1.1环境信息假设在主控节点192.168.100.4上部署DBMind,有一套端口号为19999的集群环境,环境信息如下:nodenode_ipstate主节点192.168.100.1Primary备节点1192.168.100.2Standby备节点2192.168.100.3Standby假设需要在test......
  • openGauss Anomaly-detection-异常检测使用指导
    使用指导假设指标采集系统运行正常,并且用户已经初始化了配置文件目录confpath,则可以通过下述命令实现本特性的功能:仅启动异常检测功能:gs_dbmindservicestart--confconfpath--only-runanomaly_detection对于某一指标,在全部节点上,从timestamps1到timestamps1时间段内的数......
  • openGauss component子命令
    component子命令该子命令可以用于启动DBMind的组件,包括可用于监控指标的exporter,以及AI功能等。该命令可以将用户通过命令行传入的命令转发给对应的子组件,故不同的子组件命令需参考其功能的对应说明,详见后文各个子组件对应章节,此处不再赘述。命令参考用户可以通过--help选项......