暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

antdb-upgrade大版本升级介绍

原创 SummerMeMTea 2022-08-16
409

antdb-upgrade

环境说明

版本号

os

CentOS Linux release 7.4.1708

old version

postgres (5.0.0 38d39aff1f based on PostgreSQL) 11.6

new version

postgres (6.0zjcmc d8d3241f18 based on PostgreSQL) 12.3

pg_upgrade 是postgresql 大版本升级的得力工具。

  • 数据库系统数据部分通过 new version的pg_upgrade自动升级完成
  • 数据库用户数据部分,主要有两种用法:
  1. 使用pg_upgrade copy物理拷贝方式升级(非copy to/copy from逻辑拷贝)。
  2. 使用pg_upgrade link 硬链接方式升级。

两种方式对比说明:

方式

对比说明

copy

1.数据文件全量copy,请确保磁盘剩余空间足够

2.全量copy,耗时较久

3.升级前,新数据库必须使用new version重新initdb

4.升级时,老数据库必须停止

5.升级时,新数据库必须停止

link

1.数据文件硬连接,请确保老数据路径和新数据路径的文件系统一致。如老数据路径是xfs,则新数据路径也必须是xfs。

2.link方式升级后,老数据库无法启动。

3.升级前,新数据库必须使用new version重新initdb

4.升级时,老数据库必须停止

5.升级时,新数据库必须停止

2种数据库版本的二进制安装过程,这里忽略,请自行研究。

数据库规划信息:

二进制目录

数据目录

端口

old version

/data/sy/adb50oltp/antdb50/bin

/data/sy/adb50oltp/data5

7432

new version

/tmp/antdb60/bin

/data/sy/adb50oltp/data6

8432

1.1升级步骤说明

新数据库重新initdb

1.初始化新数据库

/tmp/antdb60/bin/initdb -D /data/sy/adb50oltp/data6 -E UTF8 --locale=C -k

2.调整配置

log_destination = 'csvlog'

logging_collector = on

log_directory = 'pg_log'

port = '8432'

listen_addresses = '*'

3.启动新数据库

/tmp/antdb60/bin/pg_ctl -D /data/sy/adb50oltp/data6 start

新数据库删除2个schema

postgres=# update pg_database set datallowconn='t' where datname='template0';

postgres=# drop schema dbms_lock,dbms_output cascade;

postgres=# \c template1

template1=# drop schema dbms_lock,dbms_output cascade;

template1=# \c template0

template0=# drop schema dbms_lock,dbms_output cascade;

postgres=# update pg_database set datallowconn='f' where datname='template0';

新数据库停止

/tmp/antdb60/bin/pg_ctl -D /data/sy/adb50oltp/data6 -m fast stop

老数据库停止

pg_ctl -D /data/sy/adb50oltp/data5 -m fast stop

新数据库pg_upgrade检测兼容性

/tmp/antdb60/bin/pg_upgrade -d /data/sy/adb50oltp/data5 -D /data/sy/adb50oltp/data6 -b /data/sy/adb50oltp/antdb50/bin -B /tmp/antdb60/bin -p 7432 -P 8432 -c

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 tables WITH OIDS ok

Checking for invalid "sql_identifier" user columns ok

Checking for presence of required libraries ok

Checking database user is the install user ok

Checking for prepared transactions ok

*Clusters are compatible*

输出 *Clusters are compatible*,说明检测ok。

新数据库升级pg_upgrade

以下2种升级方式,二选一,操作其中一种方式即可。

copy方式升级

升级时,可以指定通过 -j 参数指定并行,此处并行度设置为2

/tmp/antdb60/bin/pg_upgrade -d /data/sy/adb50oltp/data5 -D /data/sy/adb50oltp/data6 -b /data/sy/adb50oltp/antdb50/bin -B /tmp/antdb60/bin -p 7432 -P 8432 -j 2

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 tables WITH OIDS ok

Checking for invalid "sql_identifier" user columns 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 pg_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 pg_xact ok

Copying old pg_xact to new server ok

Setting next transaction ID and epoch for new cluster ok

Deleting files from new pg_multixact/offsets ok

Copying old pg_multixact/offsets to new server ok

Deleting files from new pg_multixact/members ok

Copying old pg_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

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 pg_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

运行结束,会生成2个脚本。

analyze_new_cluster.sh收集数据库统计信息 –必须执行

delete_old_cluster.sh删除老数据库 –可选,如磁盘空间紧张,可执行该脚本,建议保留一段时间后,再执行该脚本

link方式升级

升级时,可以指定通过 -j 参数指定并行,此处并行度设置为2

-k 参数指定使用link硬连接方式升级。

/tmp/antdb60/bin/pg_upgrade -d /data/sy/adb50oltp/data5 -D /data/sy/adb50oltp/data6 -b /data/sy/adb50oltp/antdb50/bin -B /tmp/antdb60/bin -p 7432 -P 8432 -j 2 -k

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 tables WITH OIDS ok

Checking for invalid "sql_identifier" user columns 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 pg_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 pg_xact ok

Copying old pg_xact to new server ok

Setting next transaction ID and epoch for new cluster ok

Deleting files from new pg_multixact/offsets ok

Copying old pg_multixact/offsets to new server ok

Deleting files from new pg_multixact/members ok

Copying old pg_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

Adding ".old" suffix to old global/pg_control ok

If you want to start the old cluster, you will need to remove

the ".old" suffix from /data/sy/adb50oltp/data5/global/pg_control.old.

Because "link" mode was used, the old cluster cannot be safely

started once the new cluster has been started.

Linking user relation 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 pg_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

运行结束,会生成2个脚本。

analyze_new_cluster.sh收集数据库统计信息 –必须执行

delete_old_cluster.sh删除老数据库 –可选,如磁盘空间紧张,可执行该脚本,建议保留一段时间后,再执行该脚本

新数据库启动

/tmp/antdb60/bin/pg_ctl -D /data/sy/adb50oltp/data6 start

参考链接

https://blog.csdn.net/ctypyb2002/article/details/80782235

https://blog.csdn.net/ctypyb2002/article/details/80787903

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论