前言
目前openGauss容器版本除了数据的导入导出没有一个很好的升级方式,虽然容器版本的初衷是为了更方便快捷的使用数据库,但是一旦产生了大量的数据或者在生产环境使用了之后做导入导出升级是不方便的,为此开发了容器版本的升级脚本,此脚本的内容源自openGauss lite版本升级脚本,经过一些处理加工迭代后适配到openGauss容器版本,本文涉及openGauss容器版本2.0.0 ~ 2.1.0,2.1.0 ~ 3.0.0的升级流程及一些代码处理和文件解释。
一、文件目录及介绍
[gaussdb@ecs-lee upgrade]$ ls -lrt total 72 -rw-r--r-- 1 gaussdb gaussdb 1100 Apr 1 2022 upgrade_GAUSSV5.sh -rw-r--r-- 1 gaussdb gaussdb 392 Apr 1 2022 upgrade_errorcode.sh -rw-r--r-- 1 gaussdb gaussdb 38662 Jun 22 14:55 upgrade_common.sh -rw-r--r-- 1 gaussdb gaussdb 731 Jun 22 16:26 upgrade_config.sh drwxrwxr-x 2 gaussdb gaussdb 4096 Nov 21 09:06 pkg_2.1.0 drwxrwxr-x 2 gaussdb gaussdb 4096 Nov 21 09:06 pkg_3.0.0 drwxrwxr-x 2 gaussdb gaussdb 4096 Nov 21 09:19 upgrade.log drwxrwxr-x 2 gaussdb gaussdb 4096 Nov 21 09:19 tmp drwxrwxr-x 2 gaussdb gaussdb 4096 Nov 21 09:19 bak
二、文件解释
- upgrade_GAUSSV5.sh :主控文件,调用upgrade_common.sh。 - upgrade_errorcode.sh:错误代码 - upgrade_config.sh:配置信息 - upgrade_common.sh:实际升级文件 - upgrade.log:升级日志 - pkg_2.1.0,pkg_3.0.0:数据库升级根位置 - bak:数据库低版本备份位置 - tmp:数据库临时目录
三、配置文件解释
[mogdb@ecs-lee upgrade]$ cat upgrade_config.sh #!/bin/bash # Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved. # date: 2021-12-22 # version: 1.0 # 数据库监听端口 GAUSS_LISTEN_PORT="5432" # 数据库管理员用户名 GAUSS_ADMIN_USER="mogdb" #数据库升级回退日志路径 GAUSS_LOG_PATH="/home/mogdb/upgrade" #数据库升级根位置 GAUSS_UPGRADE_BASE_PATH="/home/mogdb/upgrade/pkg_3.0.0_beta2" #数据库SQL包位置 GAUSS_SQL_TAR_PATH="/home/mogdb/upgrade/pkg_3.0.0_beta2" #数据库低版本备份位置 GAUSS_BACKUP_BASE_PATH="/home/mogdb/upgrade/bak" #数据库临时目录 GAUSS_TMP_PATH="/home/mogdb/upgrade/tmp" #是否使用存在的bin解压包 GAUSS_UPGRADE_BIN_PATH="" #需要同步的cluster config 列表 GAUSS_UPGRADE_SYNC_CONFIG_LIST=""
四、升级流程追溯
1. 整体升级流程
大致分四步,其中前三步对应相应的回滚。
- upgrade_pre/rollback_pre
升级预处理,进行磁盘检查,版本检查,准备升级文件,安装检查,备份gauss,解压安装包,检查数据库进程,更改升级参数,执行升级前置SQL,更改step。
- upgrade_bin/rollback_bin
查询数据库角色,停库,备份家目录,拷贝安装包,备份config,guc删除废弃参数,开启数据库,更改step。
- upgrade_post/rollback_post
检查数据库进程,执行upgrade sql,更改step。
- upgrade_commit
更改升级参数,更改step。
2. 升级关键流程梳理
- upgrade_pre
- current_step < 0 die “Step file may be changed invalid”
- current_step < 1
- upgrade_pre_step1 (check_disk check_version prepare_sql_all check_pkg bak_gauss decompress_pkg record_step 1)
- upgrade_pre_step2 (check_db_process ‘reload_upgrade_config upgrade_mode 2’ exec_sql record_step 2)
- current_step = 1
- rollback_pre,upgrade_pre_step2
- other “no need do upgrade_pre step”
- upgrade_bin
- current_step < 0 die “Step file may be changed invalid”
- current_step < 2 die “exec upgrade pre first”
- current_step < 3
- upgrade_bin_step4 (record_step 3 query_dn_role stop_dbnode cp_gauss_home_config_to_temp cp_pkg cp_temp_config_to_gauss_home guc_delete start_dbnode record_step 4)
- upgrade_post
- current_step < 0 die “Step file may be changed invalid”
- current_step < 4 die “You should exec upgrade_bin first”
- current_step = 4
- upgrade_post_step56 (check_db_process record_step 5 exec_sql record_step 6)
- current_step = 5
- rollback_post,upgrade_post_step56
- other “no need do upgrade_post step”
- upgrade_commit
- current_step = 0 die “No need commit,upgrade directly”
- current_step -ne 6 die “Now you can’t commit because the steps are wrong”
- other
- ‘reload_upgrade_config upgrade_mode 0’ record_step 0
- rollback_pre
- current_step < 1 “no need do rollback_pre step”
- current_step > 2 die “You should rollback_bin first”
- other
- check_db_process ‘reload_upgrade_config upgrade_mode 2’ record_step 1 exec_sql ‘reload_upgrade_config upgrade_mode 0’ record_step 0
- rollback_bin
- current_step < 3 “no need do rollback_pre step”
- current_step > 4 die “You should rollback_post first”
- other
- record_step 3 query_dn_role stop_dbnode cp_gauss_home_config_to_temp cp_temp_config_to_gauss_home ‘set_upgrade_config upgrade_mode 2’ start_dbnode record_step 2
- rollback_post
- current_step < 5 “Cannot do rollback_post step”
- other
- check_db_process ‘reload_upgrade_config upgrade_mode 2’ record_step 5 exec_sql record_step 4
- prepare_sql_all
- prepare_sql
- upgrade_sql_file=“upgrade_sql/upgrade_catalog_{dbname}/dbname/{action}catalog{dbname}_{temp_old:0:2}_${temp_old:2}.sql”
- upgrade_sql_file=“upgrade_sql/rollback_catalog_{dbname}/dbname/{action}catalog{dbname}_{temp_new:0:2}_${temp_new:2}.sql”
- temp_old 92299 temp_new 92421
- exec_sql
- rollback_pre
- postgres temp_rollback_maindb.sql
- others temp_rollback_otherdb.sql
- rollback_post
- postgres temp_rollback-post_maindb.sql
- others temp_rollback-post_otherdb.sql
- upgrade_pre
- postgres temp_upgrade_maindb.sql
- others temp_upgrade_otherdb.sql
- upgrade_post
- postgres temp_upgrade-post_maindb.sql
- others temp_upgrade-post_otherdb.sql
五、容器外正常输出及流程
- upgrade_pre
[mogdb@ecs-lee upgrade]$ sh upgrade_GAUSSV5.sh -t upgrade_pre Current env value: GAUSSHOME is /home/mogdb/2.0.0, PGDATA is /home/mogdb/2.0.0_data/data. Parse cmd line successfully. Check available disk space successfully. Big upgrade is needed! Old version commitId is f892ccb7, version info is 92299 New version commitId is 03211457, version info is 92421 decompress upgrade_sql.tar.gz successfully. kernel: CentOS Bak gausshome successfully. Bak postgresql.conf successfully. Bak pg_hba.conf successfully. begin decompress pkg in /home/mogdb/upgrade/tmp/install_bin_03211457 Decompress MogDB-2.1.1-CentOS-64bit.tar.bz2 successfully. cp version.cfg successfully input sql password: input sql password: The upgrade_pre step is executed successfully.
- upgrade_bin
[mogdb@ecs-lee upgrade]$ sh upgrade_GAUSSV5.sh -t upgrade_bin Current env value: GAUSSHOME is /home/mogdb/2.0.0, PGDATA is /home/mogdb/2.0.0_data/data. Parse cmd line successfully. Binfile upgrade to new version successfully. Delete guc successfully start gaussdb by cmd: gs_ctl start -D /home/mogdb/2.0.0_data/data -o '-u 92299' --single_node The upgrade_bin step is executed successfully.
- upgrade_post
[mogdb@ecs-lee upgrade]$ sh upgrade_GAUSSV5.sh -t upgrade_post Current env value: GAUSSHOME is /home/mogdb/2.0.0, PGDATA is /home/mogdb/2.0.0_data/data. Parse cmd line successfully. input sql password: input sql password: The upgrade_post step is executed successfully.
- upgrade_commit
[mogdb@ecs-lee upgrade]$ sh upgrade_GAUSSV5.sh -t upgrade_commit Current env value: GAUSSHOME is /home/mogdb/2.0.0, PGDATA is /home/mogdb/2.0.0_data/data. Parse cmd line successfully. The upgrade_commit step is executed successfully.
- help
[mogdb@ecs-lee upgrade]$ sh upgrade_GAUSSV5.sh --help Current env value: GAUSSHOME is /home/mogdb/2.0.0, PGDATA is /home/mogdb/2.0.0_data/data. Usage: upgrade_GAUSSV5.sh [OPTION] Arguments: -h|--help show this help, then exit -t upgrade_pre,upgrade_bin,upgrade_post,rollback_pre,rollback_bin,rollback_post,upgrade_commit query_start_mode,switch_over --min_disk reserved upgrade disk space in MB, default 2048 -m|--mode normal、primary、standby and cascade_standby
- upgrade_mode
upgrade_mode 参数说明: 标示升级模式。该参数不建议用户自己修改。 **取值范围:**整数,0~INT_MAX 0表示不在升级过程中。 1表示在就地升级过程中。 2表示在灰度升级过程中。 默认值: 0