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

PostgreSQL学习随笔14 PG10到PG12升级实验 (pg_upgrade)

1650

使pg_upgrade 10升级到12

pg_upgrade

参数

-b (--old-bindir=bindir)旧的集群可执行目录。

-B (--new-bindir=bindir)新的集群可执行目录。

-d (--old-datadir=configdir)旧的集群数据目录。

-D (--new-datadir=configdir)旧的集群数据目录

-k (--link)link模式,相对于克隆模式,克隆模式需要将文件复制到新的集群。

-c (--check):只做“检查”,不改变任何数据。它将进行许多一致性检查。在进行大版本升级前,总是首先使用这个命令来进行升级前的预检。

 

1. 初始化新的PostgreSQL集群。

通过initdb初始化新的集群,并且,要用兼容旧数据库实例的initdb 选项。

/opt/pgsql12/bin/initdb --username=postgres--encoding=UTF8 --lc-collate=C --lc-ctype=C --data-checksums -D opt/pg_root12

 

2. 停掉源库的连接,停掉源库。

/opt/pgsql10/bin/pg_ctl -D opt/pg_root10/-m f stop

 

3. 使用pg_upgrade --check命令,进行大版本的预检。

/opt/pgsql12/bin/pg_upgrade--old-bindir=/opt/pgsql10/bin --new-bindir=/opt/pgsql12/bin--old-datadir=/opt/pg_root10/ --new-datadir=/opt/pg_root12 --link –check

 

备注:“initdb -D$PGDATA -E UTF8 --locale=C -U postgres -W –k”加K选项时初始化数据库集簇会加data-checksums

 

 

4. 执行升级:pg_upgrade去掉-c--check

/opt/pgsql12/bin/pg_upgrade--old-bindir=/opt/pgsql10/bin --new-bindir=/opt/pgsql12/bin--old-datadir=/opt/pg_root10/ --new-datadir=/opt/pg_root12 –link

 

5.

分析新数据库集簇

./analyze_new_cluster.sh

运行此脚本将删除旧集簇的数据文件

./delete_old_cluster.sh

升级结果

postgres@pgexp1-> opt/pgsql12/bin/pg_upgrade --old-bindir=/opt/pgsql10/bin --new-bindir=/opt/pgsql12/bin --old-datadir=/opt/pg_root10/ --new-datadir=/opt/pg_root12 --link

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

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

------------------

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

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 opt/pg_root10/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

Checking for extension updates                              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


文章转载自CP的PostgreSQL厨房,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论