PostgreSQL大版本升级(pg_upgrade)11.7升12.2

原版本:11.7
安装路径:/usr/local/pgsql/bin/
数据目录路径:/usr/local/pgsql/data/

新版本:12.2
安装路径:/usr/local/pgsql12/bin/
数据目录路径:/usr/local/pgsql12/data/

升级步骤

1)安装高版本的数据库,并且初始化数据库–具体安装步骤省略

2)停低版本数据库

[postgres@rhel6wcb pgsql]$ psql
psql (11.7)
Type "help" for help.

postgres@postgres=>\db
       List of tablespaces
    Name    |  Owner   | Location 
------------+----------+----------
 pg_default | postgres | 
 pg_global  | postgres | 
(2 rows)
postgres@postgres=>create table t1(id int);
CREATE TABLE

[postgres@rhel6wcb pgsql]$ pg_ctl stop
waiting for server to shut down....2020-12-21 20:17:04.018 CST [30185] LOG:  received fast shutdown request
2020-12-21 20:17:04.019 CST [30185] LOG:  aborting any active transactions
2020-12-21 20:17:04.020 CST [30185] LOG:  background worker "logical replication launcher" (PID 30192) exited with exit code 1
2020-12-21 20:17:04.020 CST [30187] LOG:  shutting down
2020-12-21 20:17:04.051 CST [30185] LOG:  database system is shut down
 done
server stopped

3)检查新旧版本的兼容性

[postgres@rhel6wcb bin]$ /usr/local/pgsql12/bin/pg_upgrade  -b /usr/local/pgsql/bin/ -B /usr/local/pgsql12/bin/ -d /usr/local/pgsql/data/ -D /usr/local/pgsql12/data/ -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*

4)进行版本升级

[postgres@rhel6wcb bin]$ /usr/local/pgsql12/bin/pg_upgrade  -b /usr/local/pgsql/bin/ -B /usr/local/pgsql12/bin/ -d /usr/local/pgsql/data/ -D /usr/local/pgsql12/data/ 
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
    

5)升级后的检查、vacuum

[postgres@rhel6wcb bin]$ /usr/local/pgsql12/bin/psql 
psql (12.2)
Type "help" for help.

postgres@postgres=>select * from t1;
 id 
----
(0 rows)
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值