隨著數據庫版本迭代,新特性增加,功能增強,總有一個“點” 會打動你那顆想要做數據庫升級的心,但并不是所有的業務系統所使用的數據庫都適合升級,需要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版本可以支持直升
下載安裝包
--下載
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
「喜歡這篇文章,您的關注和贊賞是給作者最好的鼓勵」
關注作者
【版權聲明】本文為墨天輪用戶原創內容,轉載時必須標注文章的來源(墨天輪),文章鏈接,文章作者等基本信息,否則作者和墨天輪有權追究責任。如果您發現墨天輪中有涉嫌抄襲或者侵權的內容,歡迎發送郵件至:contact@modb.pro進行舉報,并提供相關證據,一經查實,墨天輪將立刻刪除相關內容。




