案例说明:

在KingbaseES V8R6版本提供了sys_upgrade的升级工具, 本案例描述了KingbaseES V8R6单机环境下数据库的小版本升级操作,案例涉及的版本从‘(Kingbase) V008R006C005B0041’通过sys_upgrade升级到‘ (Kingbase) V008R006C005B0054’,此案例可以用于生产环境下数据库升级的参考。

适用版本:

KingbaseES V8R6

升级工具sys_upgade:

sys_upgrade — 升级KingbaseES服务器实例。

sys_upgrade 允许将存储在KingbaseES数据文件中的数据升级到一个更高的KingbaseES主版本,而无需进行主版本升级(例如从 V8R6C4 到 V8R6C5)通常所需的数据转储/重载。

sys_upgrade 支持从 V8R6(20211031版本) 及其后版本升级到当前的KingbaseES主版本,包括快照和beta版本。

sys_upgrade 目前暂不支持 Windows 版本的KingbaseES升级。

详情见官网说明:https://help.kingbase.com.cn/v8/admin/reference/ref-server/pgupgrade.html?highlight=sys_upgrade#id4

一、查看升级前后数据库版本信息

#升级前数据库版本
[kingbase@node101 lib]$ cd /opt/Kingbase/ES/V8R6_041/Server/bin
[kingbase@node101 bin]$ ./ksql -V
ksql (Kingbase) V008R006C005B0041 #升级后数据库版本
[kingbase@node101 mnt]$ cd /opt/Kingbase/ES/V8R6_054/Server/bin
[kingbase@node101 bin]$ ./ksql -V
ksql (Kingbase) V008R006C005B0054 ---如果旧版本数据库中有新增插件相关的so 库,而新版本数据库中没有的,需要把相关so 拷贝到新版本数据库lib 目录下。

二、升级前原版本相关参数配置

#升级前版本数据库目录
[kingbase@node101 data]$ pwd
/data/kingbase/v8r6_041/data #关闭原版本的归档
[kingbase@node101 data]$ cat kingbase.conf |grep archive_mode
archive_mode = off # enables archiving; off, on, or always #编辑原版本sys_hba.conf文件
[kingbase@node101 data]$ cp sys_hba.conf sys_hba.conf.old
[kingbase@node101 data]$ sed -i "s/scram-sha-256/trust/g" sys_hba.conf
[kingbase@node101 data]$ cat sys_hba.conf
.......
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 trust
host all all ::0/0 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host replication all 192.168.1.0/24 trust
host all all 0.0.0.0/0 trust ---如上所示,将sys_hba.conf的认证改为trust,升级期间,便于新旧版本之间访问连接。

三、查看原版本字符集相关信息

Tips:

必须保证升级前后版本的数据库字符集及lc_ctype一致。

test=# show server_encoding;
server_encoding
-----------------
UTF8
(1 row) test=# \l+ List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+--------+----------+----------+-------------+-------------------+-------+-------------+--------------------------------------------
prod | system | UTF8 | ci_x_icu | en_US.UTF-8 | | 12 MB | sys_default |
security | system | UTF8 | ci_x_icu | en_US.UTF-8 | | 12 MB | sys_default |
template0 | system | UTF8 | ci_x_icu | en_US.UTF-8 | =c/system +| 12 MB | sys_default | unmodifiable empty database
| | | | | system=CTc/system | | |
template1 | system | UTF8 | ci_x_icu | en_US.UTF-8 | =c/system +| 12 MB | sys_default | default template for newdatabases
| | | | | system=CTc/system | | |
test | system | UTF8 | ci_x_icu | en_US.UTF-8 | | 12 MB | sys_default | default administrative connection database
(5 rows)

四、安装新版本数据库软件及初始化新的实例

Tips:

  • 新版本和旧版本的相关参数:字符集、lc_ctype、数据块大小保证一致。
  • 必须使用旧版本数据库initdb时使用的操作系统用户。
  • 必须使用和旧版本数据库一样的数据库用户,及-U 参数保持一致。
  • block_size 和wal_segsize 必须和旧版本数据库的data 保持一致。
  • initdb 初始化的所有参数必须和旧版本数据库initdb 时保持一致。
  • 若不一致,在后续的升级兼容性检查也会检测出具体信息。
#在新版本数据库初始化实例
[kingbase@node101 bin]$ ./initdb -U system -W --enable-ci -E utf8 --lc-ctype="en_US.UTF-8" -D /data/kingbase/v8r6_054/data The files belonging to this database system will be owned by user "kingbase".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
......
Success. You can now start the database server using: ./sys_ctl -D /data/kingbase/v8r6_054/data -l logfile start #查看新版本数据库信息
[kingbase@node101 bin]$ ./ksql -U system test -p 54323
ksql (V8.0)
Type "help" for help. test=# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Descriptio
n
-----------+--------+----------+----------+-------------+-------------------+-------+-------------+--------------------------
------------------
security | system | UTF8 | ci_x_icu | en_US.UTF-8 | | 12 MB | sys_default |
template0 | system | UTF8 | ci_x_icu | en_US.UTF-8 | =c/system +| 12 MB | sys_default | unmodifiable empty databa
se
| | | | | system=CTc/system | | |
template1 | system | UTF8 | ci_x_icu | en_US.UTF-8 | =c/system +| 12 MB | sys_default | default template for new
databases
| | | | | system=CTc/system | | |
test | system | UTF8 | ci_x_icu | en_US.UTF-8 | | 12 MB | sys_default | default administrative co
nnection database
(4 rows)

五、将原版本相关配置文件拷贝到新版本下

[kingbase@node101 data]$ cp kingbase.conf /data/kingbase/v8r6_054/data/
[kingbase@node101 data]$ cp kingbase.auto.conf /data/kingbase/v8r6_054/data/
[kingbase@node101 data]$ cp sys_hba.conf /data/kingbase/v8r6_054/data/

六、版本升级前兼容性检查

#在新版本数据库bin目录下执行sys_upgrade工具
[kingbase@node101 bin]$ ./sys_upgrade -b /opt/Kingbase/ES/V8R6_041/Server/bin -B /opt/Kingbase/ES/V8R6_054/Server/bin -d /data/kingbase/v8r6_041/data -D /data/kingbase/v8r6_054/data -c -p 54325 -P 54323 -U system
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok *Clusters are compatible*
---如上所示,新旧版本之间兼容性检查通过。

七、执行版本升级

Tips:

升级前对原数据库执行物理备份,并停止原版本和新版本数据库服务。

#在新版本数据库bin目录下执行sys_upgrade工具
[kingbase@node101 bin]$ ./sys_upgrade -b /opt/Kingbase/ES/V8R6_041/Server/bin -B /opt/Kingbase/ES/V8R6_054/Server/bin -d /data/kingbase/v8r6_041/data -D /data/kingbase/v8r6_054/data -p 54325 -P 54323 -U system
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok If sys_upgrade fails after this point, you must re-initdb the
new cluster before continuing. Performing Upgrade
------------------
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new sys_xact ok
Copying old sys_xact to new server ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new sys_multixact/offsets ok
Copying old sys_multixact/offsets to new server ok
Deleting files from new sys_multixact/members ok
Copying old sys_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Copying user relation files
ok
Copying wallet files ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to analyze new cluster ok
Creating script to delete old cluster ok Upgrade Complete
----------------
Optimizer statistics are not transferred by sys_upgrade so,
once you start the new server, consider running:
./analyze_new_cluster.sh Running this script will delete the old cluster's data files:
./delete_old_cluster.sh

八、对升级后的数据库执行统计分析

#在新版本数据库bin目录下执行分析脚本
[kingbase@node101 bin]$ ./analyze_new_cluster.sh
This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy. When it is done, your system will
have the default level of optimizer statistics. If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation. If you would like default statistics as quickly as possible, cancel
this script and run:
"/opt/Kingbase/ES/V8R6_054/Server/bin/vacuumdb" -U system --all --analyze-only vacuumdb: error: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.KINGBASE.54321"? Done
---以上错误,需要修改脚本中数据库连接服务端口(默认:54321) #修改脚本中数据库连接端口
[kingbase@node101 bin]$ cat analyze_new_cluster.sh |grep vacuum
echo ' "/opt/Kingbase/ES/V8R6_054/Server/bin/vacuumdb" -U system --all --analyze-only'
"/opt/Kingbase/ES/V8R6_054/Server/bin/vacuumdb" -U system --all --analyze-in-stages -p 54323 #执行脚本分析
[kingbase@node101 bin]$ ./analyze_new_cluster.sh
This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy. When it is done, your system will
have the default level of optimizer statistics. If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation. If you would like default statistics as quickly as possible, cancel
this script and run:
"/opt/Kingbase/ES/V8R6_054/Server/bin/vacuumdb" -U system --all --analyze-only vacuumdb: processing database "prod": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "security": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "test": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "prod": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "security": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "template1": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "test": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "prod": Generating default (full) optimizer statistics
vacuumdb: processing database "security": Generating default (full) optimizer statistics
vacuumdb: processing database "template1": Generating default (full) optimizer statistics
vacuumdb: processing database "test": Generating default (full) optimizer statistics Done
---如上所示,数据库分析完成。

九、查看新版本数据库数据(应该和原版本数据一致)

[kingbase@node101 bin]$ ./ksql -U system test -p 54323
ksql (V8.0)
Type "help" for help. test=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+----------+-------------+-------------------
prod | system | UTF8 | ci_x_icu | en_US.UTF-8 |
security | system | UTF8 | ci_x_icu | en_US.UTF-8 |
template0 | system | UTF8 | ci_x_icu | en_US.UTF-8 | =c/system +
| | | | | system=CTc/system
template1 | system | UTF8 | ci_x_icu | en_US.UTF-8 | system=CTc/system+
| | | | | =c/system
test | system | UTF8 | ci_x_icu | en_US.UTF-8 |
(5 rows) prod=# select * from t1 limit 10;
id | name
----+----------
1 | 524fe608
2 | a281abeb
3 | 12596181
4 | 8c6964fd
5 | 53dabd51
6 | 681f8e17
7 | 7f4747d7
8 | 05fb8475
9 | 53c67d00
10 | 6b993d5e
(10 rows)

十、删除原版本数据

#在新版本数据库bin目录下执行清理脚本
[kingbase@node101 bin]$ pwd
/opt/Kingbase/ES/V8R6_054/Server/bin
[kingbase@node101 bin]$ ./delete_old_cluster.sh #原版本data目录下数据已经被删除
[kingbase@node101 data]$ ls -lh
total 0 ---如上所示,原版本数据库相关数据文件被删除。

十一、恢复升级版本后的sys_hba.conf

[kingbase@node101 data]$ sed -i "s/trust/scram-sha-256/g" sys_hba.conf

十二、升级中常见故障问题

1、新旧版本数据库lc_ctype不同

2、新旧版本数据库block size不同

以上故障问题,在创建新版本实例前,必须查看旧版本数据库的相关配置,保证新版本创建的实例数据库配置和旧版本一致。

KingbaseES V8R6 运维系列 --单机小版本升级的更多相关文章

  1. SQL Server自动化运维系列——关于邮件通知那点事(.Net开发人员的福利)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 邮件作为一种非常便利的预警实现方式,在及时性和易用性 ...

  2. SQL Server自动化运维系列——监控跑批Job运行状态(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在上一篇文章中已经分析了SQL SERVER中关于邮 ...

  3. saltstack自动化运维系列⑤之saltstack的配置管理详解

    saltstack自动化运维系列⑤之saltstack的配置管理详解 配置管理初始化: a.服务端配置vim /etc/salt/master file_roots: base: - /srv/sal ...

  4. saltstack自动化运维系列④之saltstack的命令返回结果mysql数据库写入

    saltstack自动化运维系列④之saltstack的命令返回结果mysql数据库写入salt的返回值写入mysql数据库:可参考:https://docs.saltstack.com/en/lat ...

  5. saltstack自动化运维系列③之saltstack的常用模块使用

    saltstack自动化运维系列③之saltstack的常用模块使用 1.命令的常用方法: 指定主机运行命令 # salt 'mini1' cmd.run 'date'mini1: Fri Apr 7 ...

  6. saltstack自动化运维系列②之saltstack的数据系统

    saltstack自动化运维系列②之saltstack的数据系统 grains:搜集minion启动时的系统信息,只有在minion启动时才会搜集,grains更适合做一些静态的属性值的采集,例如设备 ...

  7. SQL Server自动化运维系列——监控性能指标脚本(Power Shell)

    需求描述 一般在生产环境中,有时候需要自动的检测指标值状态,如果发生异常,需要提前预警的,比如发邮件告知,本篇就介绍如果通过Power shell实现状态值监控 监控值范围 根据经验,作为DBA一般需 ...

  8. SQL Server自动化运维系列——监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  9. SQL Server自动化运维系列——关于数据收集(多服务器数据收集和性能监控)

    需求描述 在生产环境中,很多情况下需要采集数据,用以定位问题或者形成基线. 关于SQL Server中的数据采集有着很多种的解决思路,可以采用Trace.Profile.SQLdiag.扩展事件等诸多 ...

  10. SQL Server自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

随机推荐

  1. Vue+SpringBoot+ElementUI实战学生管理系统-8.班级管理模块

    1.章节介绍 前一篇介绍了专业管理模块,这一篇编写班级管理模块,需要的朋友可以拿去自己定制.:) 2.获取源码 源码是捐赠方式获取,详细请QQ联系我 :)! 3.实现效果 班级列表 修改班级 4.模块 ...

  2. Nginx开启gzip提升访问效率

    说明 最近网站考虑开启gzip压缩试试效果,gzip是nginx服务器的ngx_http_gzip_module模块提供的在线实时数据压缩功能. 通过开启gzip功能,可对服务器响应的数据进行压缩处理 ...

  3. org.apache.http.client.ClientProtocolException: URI does not specify a valid host name:localhost:xxx

    今天部署应用的时候遇到的,总结一下我知道的有2个原因: 1.地址前要加http://  这就是标题报错的原因,他用的是localhost:xxx 2.地址本身拼错了也会报这个,例如地址:http:// ...

  4. win32 - Shell菜单项的创建

    #include <windows.h> #include <shobjidl_core.h> #include <windowsx.h> #include < ...

  5. 时序数据库timescaleDB安装

    一:前言相关 环境:Red Hat 8.3.1-5安装程序:PostgreSQL 14.1,TimescaleDB 2.5.1,cmake3.22.1PostgreSQL编译安装需要cmake3.4以 ...

  6. 硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件

    前言   有了原理图,可以设计硬件PCB,在设计PCB之间还有一个协同优先动作,就是映射封装,原理图库的元器件我们是自己设计的.为了更好的表述封装设计过程,本文描述了创建晶振封装(DIP),将原理图的 ...

  7. 项目实战:Qt + 树莓派3B+ 智能笔筒系统

    红胖子(红模仿)的博文大全:开发技术集合(包含Qt实用技术.树莓派.三维.OpenCV.OpenGL.ffmpeg.OSG.单片机.软硬结合等等)持续更新中-(点击传送门)   需求   1.基于树莓 ...

  8. 【算法day3】小和、荷兰国旗、快排

    小和问题 现有数组[1,3,4,2,5] 1左边是0(小于1),所以1的小和为0 3左边是1(小于3),所以3的小和为1 4左边是1.3(均小于4),所以4的小和为1+3=4 2左边是1.3.4(只有 ...

  9. 探索Terraform实践:优化基础设施管理

    Terraform 是管理基础设施及代码(IaC)最常用的工具之一,它能使我们安全且可预测地对基础设施应用更改. Terraform作为一个强大的基础设施即代码工具,为开发人员和运维团队提供了一种简单 ...

  10. mySQL清除数据表数据/删除表

    一.sql清空表数据的三种方式: 1.truncate – 删除所有数据,保留表结构,不能撤销还原,速度快 2.delete – 是逐行删除,不适合大量数据删除,速度极慢 3.drop – 删除表,表 ...