- 升级方案
- gs_upgradectl 介绍
- 数据库升级
随着数据库版本迭代,新特性增加,功能增强,总有一个“点” 会打动你那颗想要做数据库升级的心,但并不是所有的业务系统所使用的数据库都适合升级,需要DBA和业务开发人员充分配合,做好程序适配工作,确定数据库升级的必要性,操作有风险,升级需谨慎
- 禁止直接对生产数据库升级,需要开发测试环境升级后稳定运行一段时间再考虑生产
- 确定好升级方案,预留充足的数据库升级窗口期
升级方案
数据库小版本升级也可以参考补丁升级
数据库大版本升级,常用的升级方式有三种,分别是导入导出、升级工具gs_upgradectl及逻辑复制
- 导入导出:停业务时间与数据量成正比,操作简单风险小
- 升级工具:停业务时间短,但需要对工具各个参数熟练掌握
- 逻辑复制:与导入导出的方式配合使用,提前将历史数据迁移,也可以使用异构数据库数据传输
gs_upgradectl 介绍
本文主要介绍通过gs_upgradectl做版本升级,目前支持就地升级和灰度升级两种升级模式
- 就地升级:升级期间需停止业务进行,一次性升级所有节点。
- 灰度升级:灰度升级支持全业务操作(会产生不超过10s的业务中断),一次性升级所有节点(MogDB2.0.0之后支持)
使用限制
- 升级操作不能和扩容、缩容同时执行。升级前后,数据库的部署方式(配置文件)不能发生变化。
- 不支持虚拟IP。
- 执行升级的过程中请不要手动设置GUC参数。升级前需要确保guc参数enable_stream_replication=on。
- 建议在数据库系统空闲情况下进行升级,尽量避开业务繁忙的时间段(可按照经验判断,如节假日等)。
- 升级前尽可能保证数据库正常。且主DN的数据完全同步到备DN。可以通过gs_om -t status查询。
- 升级前保证数据库互信正常,可以在任意节点上,通过ssh hostname命令,连接另外一个节点进行验证。
- 升级前要保证操作系统处于健康状态,通过gs_checkos工具可以完成操作系统状态检查。
- 请不要修改安装包中解压出来的version.cfg文件。
- 如果升级过程中出现异常导致升级失败,需用户手动回滚,并且必须回滚成功后才能进行下一次升级。
- 升级过程中,必须保持内核版本与om版本一致才可执行om操作。即内核代码和om代码都来自同一个软件包。
- 升级过程中如果系统表新增了字段,升级后通过d命令将查看不到这些新增的字段。此时通过select命令可以查到这些新增的字段。
- 灰度升级中, 业务并发要小于200并发读加200并发写的情况。
- 建议数据库节点磁盘使用率低于80%时再执行升级操作。
命令语法
[om1@node1 ~]$ gs_upgradectl --help
gs_upgradectl is a utility to upgrade a cluster.
Usage:
gs_upgradectl -? | --help
gs_upgradectl -V | --version
gs_upgradectl -t chose-strategy [-l LOGFILE]
gs_upgradectl -t auto-upgrade -X XMLFILE [-l LOGFILE] [--grey]
gs_upgradectl -t auto-rollback -X XMLFILE [-l LOGFILE] [--force]
gs_upgradectl -t commit-upgrade -X XMLFILE [-l LOGFILE]
General options:
-?, --help Show help information for this utility, and exit the command line mode.
-V, --version Show version information.
-t Subcommand for upgrade. It can be chose-strategy, auto-upgrade, auto-rollback, commit-upgrade.
-X Path of the XML configuration file of the later version cluster.
-l Path of log file.
--force Force to rollback when cluster status is not normal
--grey Use grey-binary-upgrade
数据库升级
当前不支持2.0.1 直接升级到3.0.0 版本,需要先升级到2.1再升级到3.0,预计3.0.2版本可以支持直升
下载安装包
MogDB 安装包下载地址
--下载
wget https://cdn-mogdb.enmotech.com/mogdb-media/3.0.0/MogDB-3.0.0-CentOS-x86_64.tar.gz
wget https://cdn-mogdb.enmotech.com/mogdb-media/2.1.1/MogDB-2.1.1-CentOS-x86_64.tar
--解压安装包(以2.1.1为例)
[root@node1 software]# mkdir /opt/mogdb300
[root@node1 software]# tar -xvf MogDB-2.1.1-CentOS-x86_64.tar -C /opt/mogdb210/
upgrade_sql.tar.gz
MogDB-2.1.1-CentOS-64bit.sha256
MogDB-2.1.1-CentOS-64bit.tar.bz2
MogDB-2.1.1-CentOS-64bit-Libpq.tar.gz
MogDB-2.1.1-CentOS-64bit-om.sha256
MogDB-2.1.1-CentOS-64bit-om.tar.gz
MogDB-2.1.1-CentOS-64bit-tools.tar.gz
upgrade_sql.sha256
--解压om工具包(以2.1.1为例)
[root@node1 software]# cd /opt/mogdb211
[root@node1 mogdb211]# tar -zxvf MogDB-2.1.1-CentOS-64bit-om.tar.gz
升级前检查
操作系统状态
[root@node1 mogdb201]# /opt/mogdb201/script/gs_checkos -i A -X /opt/mogdb201/config.xml
Checking items:
A1. [ OS version status ] : Normal
A2. [ Kernel version status ] : Normal
A3. [ Unicode status ] : Normal
A4. [ Time zone status ] : Normal
A5. [ Swap memory status ] : Normal
A6. [ System control parameters status ] : Warning
A7. [ File system configuration status ] : Warning
A8. [ Disk configuration status ] : Normal
A9. [ Pre-read block size status ] : Normal
A10.[ IO scheduler status ] : Normal
A11.[ Network card configuration status ] : Warning
A12.[ Time consistency status ] : Warning
A13.[ Firewall service status ] : Normal
A14.[ THP service status ] : Normal
Total numbers:14. Abnormal numbers:0. Warning numbers:4.
数据库状态
[omm@node1 ~]$ 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 node1 192.168.122.221 6001 /data/mogdb P Primary Normal | 2 node2 192.168.122.157 6002 /data/mogdb S Standby Normal
数据库参数
[omm@node1 ~]$ gsql -p 25000 postgres -r -c "show enable_stream_replication"
enable_stream_replication
---------------------------
on
(1 row)
探活脚本
while true; do date; sleep 1; gsql -p 25000 postgres -c "select 1" ;done > while.log 2>&1 &
配置插件文件
对于2.0 升级到2.1版本来说,这一步是必须操作的,因为没有去判断用户有没有使用插件,所以在升级脚本中默认数据库安装使用插件,在以后的版本中会将插件部分单独拆出来
[root@node1 ~]# cd /opt/mogdb211/script
[root@node1 script]# mkdir static
[root@node1 script]# cd static/
[root@node1 static]# wget https://cdn-mogdb.enmotech.com/mogdb-media/2.1.1/plugins-CentOS-x86-2.1.1.tar.gz
[root@node1 static]# mv plugins-CentOS-x86-2.1.1.tar.gz plugins-CentOS-x86-2.1.0.tar.gz
没有操作此步骤会有如下报错:
执行前置脚本
这步操作所使用的集群配置文件要与2.0.1版本数据库安装部署时的配置文件保持一致
[root@node1 mogdb211]# ./script/gs_preinstall -X /opt/mogdb201/config.xml -U omm -G dbgrp
Parsing the configuration file.
Successfully parsed the configuration file.
Installing the tools on the local node.
Successfully installed the tools on the local node.
Are you sure you want to create trust for root (yes/no)?yes
Please enter password for root
.
.
.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
灰度升级
[omm@node1 ~]$ gs_upgradectl --version
gs_upgradectl (MogDB OM 2.1.1 build 2735d86b) compiled at 2022-03-21 15:10:47 commit 0 last mr
[omm@node1 ~]$ gs_upgradectl -t auto-upgrade -X /opt/mogdb201/config.xml --grey
Static configuration matched with old static configuration files.
Successfully set upgrade_mode to 0.
Checking upgrade environment.
Successfully checked upgrade environment.
Start to do health check.
Successfully checked cluster status.
Upgrade all nodes.
Performing grey rollback.
No need to rollback.
The directory /opt/mogdb/app_f892ccb7 will be deleted after commit-upgrade, please make sure there is no personal data.
Installing new binary.
Successfully backup hotpatch config file.
Sync cluster configuration.
Successfully synced cluster configuration.
Switch symbolic link to new binary directory.
Successfully switch symbolic link to new binary directory.
Upgrade plug-ins to new
Successfully Upgrade the new plug-ins.
Switching all db processes.
Wait for the cluster status normal or degrade.
Successfully switch all process version
The nodes ['node1', 'node2'] have been successfully upgraded to new version. Then do health check.
Start to do health check.
Successfully checked cluster status.
Waiting for the cluster status to become normal.
.
The cluster status is normal.
Upgrade main process has been finished, user can do some check now.
Once the check done, please execute following command to commit upgrade:
gs_upgradectl -t commit-upgrade -X /opt/mogdb201/config.xml
Successfully upgrade nodes.
升级的过程中,会有短暂的数据库中断服务,本次测试中断3秒
升级验证
数据库版本升级完成后,不要立刻提交,需要运行一段时间,如果这期间有问题,可以进行数据库版本回滚,执行auto-rollback操作。
[omm@node1 ~]$ 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 node1 192.168.122.221 25000 6001 /data/mogdb P Primary Normal
2 node2 192.168.122.157 25000 6002 /data/mogdb S Standby Normal
[omm@node1 ~]$ mo
modinfo modprobe modutil mogdb more mount mountpoint
[omm@node1 ~]$ mogdb --version
gaussdb (MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr
[omm@node1 ~]$ gs_om --version
gs_om (MogDB OM 2.1.1 build 2735d86b) compiled at 2022-03-21 15:10:47 commit 0 last mr
升级提交
这一步执行完成后会将老版本的app进行清理,也就不可以进行回滚操作了
[omm@node1 ~]$ gs_upgradectl -t commit-upgrade -X /opt/mogdb201/config.xml
Start to do health check.
Successfully checked cluster status.
Successfully cleaned old install path.
Commit upgrade succeeded.
[omm@node1 ~]$ gs_om --version
gs_om (MogDB OM 2.1.1 build 2735d86b) compiled at 2022-03-21 15:10:47 commit 0 last mr
[omm@node1 ~]$ mogdb -V
gaussdb (MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr
升级3.0.0
2.1.1 升级到3.0.0 重复上面操作步骤即可
- 升级方案
- gs_upgradectl 介绍
- 数据库升级
随着数据库版本迭代,新特性增加,功能增强,总有一个“点” 会打动你那颗想要做数据库升级的心,但并不是所有的业务系统所使用的数据库都适合升级,需要DBA和业务开发人员充分配合,做好程序适配工作,确定数据库升级的必要性,操作有风险,升级需谨慎
- 禁止直接对生产数据库升级,需要开发测试环境升级后稳定运行一段时间再考虑生产
- 确定好升级方案,预留充足的数据库升级窗口期
升级方案
数据库小版本升级也可以参考补丁升级
数据库大版本升级,常用的升级方式有三种,分别是导入导出、升级工具gs_upgradectl及逻辑复制
- 导入导出:停业务时间与数据量成正比,操作简单风险小
- 升级工具:停业务时间短,但需要对工具各个参数熟练掌握
- 逻辑复制:与导入导出的方式配合使用,提前将历史数据迁移,也可以使用异构数据库数据传输
gs_upgradectl 介绍
本文主要介绍通过gs_upgradectl做版本升级,目前支持就地升级和灰度升级两种升级模式
- 就地升级:升级期间需停止业务进行,一次性升级所有节点。
- 灰度升级:灰度升级支持全业务操作(会产生不超过10s的业务中断),一次性升级所有节点(MogDB2.0.0之后支持)
使用限制
- 升级操作不能和扩容、缩容同时执行。升级前后,数据库的部署方式(配置文件)不能发生变化。
- 不支持虚拟IP。
- 执行升级的过程中请不要手动设置GUC参数。升级前需要确保guc参数enable_stream_replication=on。
- 建议在数据库系统空闲情况下进行升级,尽量避开业务繁忙的时间段(可按照经验判断,如节假日等)。
- 升级前尽可能保证数据库正常。且主DN的数据完全同步到备DN。可以通过gs_om -t status查询。
- 升级前保证数据库互信正常,可以在任意节点上,通过ssh hostname命令,连接另外一个节点进行验证。
- 升级前要保证操作系统处于健康状态,通过gs_checkos工具可以完成操作系统状态检查。
- 请不要修改安装包中解压出来的version.cfg文件。
- 如果升级过程中出现异常导致升级失败,需用户手动回滚,并且必须回滚成功后才能进行下一次升级。
- 升级过程中,必须保持内核版本与om版本一致才可执行om操作。即内核代码和om代码都来自同一个软件包。
- 升级过程中如果系统表新增了字段,升级后通过d命令将查看不到这些新增的字段。此时通过select命令可以查到这些新增的字段。
- 灰度升级中, 业务并发要小于200并发读加200并发写的情况。
- 建议数据库节点磁盘使用率低于80%时再执行升级操作。
命令语法
[om1@node1 ~]$ gs_upgradectl --help
gs_upgradectl is a utility to upgrade a cluster.
Usage:
gs_upgradectl -? | --help
gs_upgradectl -V | --version
gs_upgradectl -t chose-strategy [-l LOGFILE]
gs_upgradectl -t auto-upgrade -X XMLFILE [-l LOGFILE] [--grey]
gs_upgradectl -t auto-rollback -X XMLFILE [-l LOGFILE] [--force]
gs_upgradectl -t commit-upgrade -X XMLFILE [-l LOGFILE]
General options:
-?, --help Show help information for this utility, and exit the command line mode.
-V, --version Show version information.
-t Subcommand for upgrade. It can be chose-strategy, auto-upgrade, auto-rollback, commit-upgrade.
-X Path of the XML configuration file of the later version cluster.
-l Path of log file.
--force Force to rollback when cluster status is not normal
--grey Use grey-binary-upgrade
数据库升级
当前不支持2.0.1 直接升级到3.0.0 版本,需要先升级到2.1再升级到3.0,预计3.0.2版本可以支持直升
下载安装包
MogDB 安装包下载地址
--下载
wget https://cdn-mogdb.enmotech.com/mogdb-media/3.0.0/MogDB-3.0.0-CentOS-x86_64.tar.gz
wget https://cdn-mogdb.enmotech.com/mogdb-media/2.1.1/MogDB-2.1.1-CentOS-x86_64.tar
--解压安装包(以2.1.1为例)
[root@node1 software]# mkdir /opt/mogdb300
[root@node1 software]# tar -xvf MogDB-2.1.1-CentOS-x86_64.tar -C /opt/mogdb210/
upgrade_sql.tar.gz
MogDB-2.1.1-CentOS-64bit.sha256
MogDB-2.1.1-CentOS-64bit.tar.bz2
MogDB-2.1.1-CentOS-64bit-Libpq.tar.gz
MogDB-2.1.1-CentOS-64bit-om.sha256
MogDB-2.1.1-CentOS-64bit-om.tar.gz
MogDB-2.1.1-CentOS-64bit-tools.tar.gz
upgrade_sql.sha256
--解压om工具包(以2.1.1为例)
[root@node1 software]# cd /opt/mogdb211
[root@node1 mogdb211]# tar -zxvf MogDB-2.1.1-CentOS-64bit-om.tar.gz
升级前检查
操作系统状态
[root@node1 mogdb201]# /opt/mogdb201/script/gs_checkos -i A -X /opt/mogdb201/config.xml
Checking items:
A1. [ OS version status ] : Normal
A2. [ Kernel version status ] : Normal
A3. [ Unicode status ] : Normal
A4. [ Time zone status ] : Normal
A5. [ Swap memory status ] : Normal
A6. [ System control parameters status ] : Warning
A7. [ File system configuration status ] : Warning
A8. [ Disk configuration status ] : Normal
A9. [ Pre-read block size status ] : Normal
A10.[ IO scheduler status ] : Normal
A11.[ Network card configuration status ] : Warning
A12.[ Time consistency status ] : Warning
A13.[ Firewall service status ] : Normal
A14.[ THP service status ] : Normal
Total numbers:14. Abnormal numbers:0. Warning numbers:4.
数据库状态
[omm@node1 ~]$ 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 node1 192.168.122.221 6001 /data/mogdb P Primary Normal | 2 node2 192.168.122.157 6002 /data/mogdb S Standby Normal
数据库参数
[omm@node1 ~]$ gsql -p 25000 postgres -r -c "show enable_stream_replication"
enable_stream_replication
---------------------------
on
(1 row)
探活脚本
while true; do date; sleep 1; gsql -p 25000 postgres -c "select 1" ;done > while.log 2>&1 &
配置插件文件
对于2.0 升级到2.1版本来说,这一步是必须操作的,因为没有去判断用户有没有使用插件,所以在升级脚本中默认数据库安装使用插件,在以后的版本中会将插件部分单独拆出来
[root@node1 ~]# cd /opt/mogdb211/script
[root@node1 script]# mkdir static
[root@node1 script]# cd static/
[root@node1 static]# wget https://cdn-mogdb.enmotech.com/mogdb-media/2.1.1/plugins-CentOS-x86-2.1.1.tar.gz
[root@node1 static]# mv plugins-CentOS-x86-2.1.1.tar.gz plugins-CentOS-x86-2.1.0.tar.gz
没有操作此步骤会有如下报错:
执行前置脚本
这步操作所使用的集群配置文件要与2.0.1版本数据库安装部署时的配置文件保持一致
[root@node1 mogdb211]# ./script/gs_preinstall -X /opt/mogdb201/config.xml -U omm -G dbgrp
Parsing the configuration file.
Successfully parsed the configuration file.
Installing the tools on the local node.
Successfully installed the tools on the local node.
Are you sure you want to create trust for root (yes/no)?yes
Please enter password for root
.
.
.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
灰度升级
[omm@node1 ~]$ gs_upgradectl --version
gs_upgradectl (MogDB OM 2.1.1 build 2735d86b) compiled at 2022-03-21 15:10:47 commit 0 last mr
[omm@node1 ~]$ gs_upgradectl -t auto-upgrade -X /opt/mogdb201/config.xml --grey
Static configuration matched with old static configuration files.
Successfully set upgrade_mode to 0.
Checking upgrade environment.
Successfully checked upgrade environment.
Start to do health check.
Successfully checked cluster status.
Upgrade all nodes.
Performing grey rollback.
No need to rollback.
The directory /opt/mogdb/app_f892ccb7 will be deleted after commit-upgrade, please make sure there is no personal data.
Installing new binary.
Successfully backup hotpatch config file.
Sync cluster configuration.
Successfully synced cluster configuration.
Switch symbolic link to new binary directory.
Successfully switch symbolic link to new binary directory.
Upgrade plug-ins to new
Successfully Upgrade the new plug-ins.
Switching all db processes.
Wait for the cluster status normal or degrade.
Successfully switch all process version
The nodes ['node1', 'node2'] have been successfully upgraded to new version. Then do health check.
Start to do health check.
Successfully checked cluster status.
Waiting for the cluster status to become normal.
.
The cluster status is normal.
Upgrade main process has been finished, user can do some check now.
Once the check done, please execute following command to commit upgrade:
gs_upgradectl -t commit-upgrade -X /opt/mogdb201/config.xml
Successfully upgrade nodes.
升级的过程中,会有短暂的数据库中断服务,本次测试中断3秒
升级验证
数据库版本升级完成后,不要立刻提交,需要运行一段时间,如果这期间有问题,可以进行数据库版本回滚,执行auto-rollback操作。
[omm@node1 ~]$ 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 node1 192.168.122.221 25000 6001 /data/mogdb P Primary Normal
2 node2 192.168.122.157 25000 6002 /data/mogdb S Standby Normal
[omm@node1 ~]$ mo
modinfo modprobe modutil mogdb more mount mountpoint
[omm@node1 ~]$ mogdb --version
gaussdb (MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr
[omm@node1 ~]$ gs_om --version
gs_om (MogDB OM 2.1.1 build 2735d86b) compiled at 2022-03-21 15:10:47 commit 0 last mr
升级提交
这一步执行完成后会将老版本的app进行清理,也就不可以进行回滚操作了
[omm@node1 ~]$ gs_upgradectl -t commit-upgrade -X /opt/mogdb201/config.xml
Start to do health check.
Successfully checked cluster status.
Successfully cleaned old install path.
Commit upgrade succeeded.
[omm@node1 ~]$ gs_om --version
gs_om (MogDB OM 2.1.1 build 2735d86b) compiled at 2022-03-21 15:10:47 commit 0 last mr
[omm@node1 ~]$ mogdb -V
gaussdb (MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr
升级3.0.0
2.1.1 升级到3.0.0 重复上面操作步骤即可
--执行前置脚本
[root@node1 mogdb300]# ./script/gs_preinstall -X /opt/mogdb201/config.xml -U omm -G dbgrp
--检查版本信息
[omm@node1 ~]$ gs_om -V
gs_om (MogDB OM 3.0.0 build 6ada50db) compiled at 2022-06-30 14:20:56 commit 0 last mr
[omm@node1 ~]$ mogdb -V
gaussdb (MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr
--灰度升级
[omm@node1 ~]$ gs_upgradectl -t auto-upgrade -X /opt/mogdb201/config.xml --grey
--版本查看
[omm@node1 ~]$ mogdb -V
mogdb (MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr
[omm@node1 ~]$ gs_om -V
gs_om (MogDB OM 3.0.0 build 6ada50db) compiled at 2022-06-30 14:20:56 commit 0 last mr
--升级提交
[omm@node1 ~]$ gs_upgradectl -t commit-upgrade -X /opt/mogdb201/config.xml--执行前置脚本
[root@node1 mogdb300]# ./script/gs_preinstall -X /opt/mogdb201/config.xml -U omm -G dbgrp
--检查版本信息
[omm@node1 ~]$ gs_om -V
gs_om (MogDB OM 3.0.0 build 6ada50db) compiled at 2022-06-30 14:20:56 commit 0 last mr
[omm@node1 ~]$ mogdb -V
gaussdb (MogDB 2.1.1 build b5f25b20) compiled at 2022-03-21 14:42:30 commit 0 last mr
--灰度升级
[omm@node1 ~]$ gs_upgradectl -t auto-upgrade -X /opt/mogdb201/config.xml --grey
--版本查看
[omm@node1 ~]$ mogdb -V
mogdb (MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr
[omm@node1 ~]$ gs_om -V
gs_om (MogDB OM 3.0.0 build 6ada50db) compiled at 2022-06-30 14:20:56 commit 0 last mr
--升级提交
[omm@node1 ~]$ gs_upgradectl -t commit-upgrade -X /opt/mogdb201/config.xml