antdb-upgrade
pg_upgrade 是postgresql 大版本升级的得力工具。
- 数据库系统数据部分通过 new version的pg_upgrade自动升级完成
- 数据库用户数据部分,主要有两种用法:
- 使用pg_upgrade copy物理拷贝方式升级(非copy to/copy from逻辑拷贝)。
- 使用pg_upgrade link 硬链接方式升级。
两种方式对比说明:
2种数据库版本的二进制安装过程,这里忽略,请自行研究。
数据库规划信息:
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