废话不多说,直接上货
操作系统:centos7.6
一、PG13的部署
PG13的部署略,可以参考其他文档
二、PG16的部署
centos7版本PG16已经不再被支持使用yum 方式安装了。选用二进制包安装PG16
# 初始化PG16
sudo -u postgres /usr/pgsql-16/bin/initdb -D /data/postgres/pgdata16
三、pg_upgrade介绍
略
四、升级前的检查
# 检查
pg_upgrade -c -b /usr/pgsql-13/bin -B /usr/pgsql-16/bin -d /data/postgres/pgdata13 -D /data/postgres/pgdata16
# 检查输出没问题后, 开始执行升级
【局部】检查结果
# 执行升级操作,PG13 升级到PG16
[postgres@xfzcvmmw185024:/data/postgres]$pg_upgrade -b /usr/pgsql-13/bin -B /usr/pgsql-16/bin -d /data/postgres/pgdata13 -D /data/postgres/pgdata16
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 system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Checking for user-defined encoding conversions ok
Checking for user-defined postfix operators ok
Checking for incompatible polymorphic functions 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
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Setting locale and encoding for new cluster ok
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 oldest XID for new cluster 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 delete old cluster ok
Checking for extension updates ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/usr/pgsql-16/bin/vacuumdb --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
[postgres@xfzcvmmw185024:/data/postgres]$
五、升级操作
# 升级
pg_upgrade -b /usr/pgsql-13/bin -B /usr/pgsql-16/bin -d /data/postgres/pgdata13 -D /data/postgres/pgdata16
六、补充
pg_upgrade使用期间注意的问题:
- 注意额外的插件
- 注意函数、存储过程、触发器等