注:新老的集群端口号不能一致,否则升级失败
[pg13@sdw2 ~]$ /pg14-8k/bin/pg_upgrade --old-datadir=/pg13/data --new-datadir=/pg14-8k/data2 --old-bindir=/pg13/bin --new-bindir=/pg14-8k/bin --old-port=5432 --new-port=35432 --socketdir=/pg14-8k/data2 --check
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 user-defined encoding conversions ok
Checking for user-defined postfix operators 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
*Clusters are compatible*
--link 新版本采用硬链接的方式将数据复制到指定的文件目录
[pg13@sdw2 ~]$ /pg14-8k/bin/pg_upgrade --old-datadir=/pg13/data --new-datadir=/pg14-8k/data2 --old-bindir=/pg13/bin --new-bindir=/pg14-8k/bin --old-port=5432 --new-port=35432 --socketdir=/pg14-8k/data2 --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 user-defined encoding conversions ok
Checking for user-defined postfix operators 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 /pg13/data/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 delete old cluster ok
Checking for extension updates notice
**注意点1:升级extensions**
Your installation contains extensions that should be updated
with the ALTER EXTENSION command. The file
update_extensions.sql
when executed by psql by the database superuser will update
these extensions.
Upgrade Complete
----------------
**注意点2:分析统计信息**
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/pg14-8k/bin/vacuumdb --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
升级完成后,会在pg13 home目录下生成几个文件(后续用):
[root@sdw2 pg13]# pwd
/home/pg13
[root@sdw2 pg13]# ll -lhtr
.........
-rw-r----- 1 pg13 pg13 270 2月 10 09:33 loadable_libraries.txt(加载插件信息)
-rwx------ 1 pg13 pg13 31 2月 10 10:04 delete_old_cluster.sh(删除老版本的数据)
-rw------- 1 pg13 pg13 135 2月 10 10:04 update_extensions.sql(升级插件)
[root@sdw2 pg13]# more loadable_libraries.txt
could not load library "pglogical": ERROR: could not access file "pglogical": No such file or directory
In database: postgres
could not load library "$libdir/pglogical": ERROR: could not access file "$libdir/pglogical": No such file or directory
In database: postgres
由于运行pg_upgrade并不会把统计信息带过来,所以需要分析一下全库
-j为并行
[pg13@sdw2 ~]$ /pg14-8k/bin/vacuumdb --all --analyze-in-stages -p 35432 -h /pg14-8k/data2 -j 6
vacuumdb: processing database "dbt": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "dbt1": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "dbt2": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "postgres": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "dbt": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "dbt1": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "dbt2": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "postgres": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "template1": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "dbt": Generating default (full) optimizer statistics
vacuumdb: processing database "dbt1": Generating default (full) optimizer statistics
vacuumdb: processing database "dbt2": Generating default (full) optimizer statistics
vacuumdb: processing database "postgres": Generating default (full) optimizer statistics
vacuumdb: processing database "template1": Generating default (full) optimizer statistics
1 登陆数据库
[pg13@sdw2 ~]$ /pg14-8k/bin/psql -p 35432 -h /pg14-8k/data2 -d postgres
psql (14.1)
Type "help" for help.
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+-------
public | ct | table | pg13
public | t1 | table | pg13
public | t2 | table | pg13
public | t3 | table | pg13
public | t4 | table | pg13
public | t_demo | table | pg13
public | t_goods | table | pg13
public | t_hash | table | pg13
public | t_insert1 | table | pg13
public | t_order | table | pg13
public | t_parallel1 | table | pg13
public | t_parallel2 | table | pg13
public | t_pj | table | pg13
public | t_product | table | pg13
public | t_pub | table | pg13
public | t_pub2 | table | pg13
public | t_pub3 | table | pg13
public | t_pub4 | table | pg13
public | t_pub5 | table | pg13
public | t_pub6 | table | pg13
public | t_pub7 | table | pg13
public | t_pub8 | table | pg13
public | t_pub9 | table | pg13
public | t_table | table | pg13
public | t_table1 | table | pg13
public | t_trunate | table | pg13
public | t_wishlist | table | pg13
public | tab1 | table | pg13
public | tab2 | table | pg13
public | tab3 | table | pg13
public | test_big2 | table | pg13
(31 rows)
2 查看插件情况
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+------------------------------------------------------------------------
bloom | 1.0 | public | bloom access method - signature file based index
pageinspect | 1.8 | public | inspect the contents of database pages at a low level
pg_stat_statements | 1.8 | public | track planning and execution statistics of all SQL statements executed
pg_trgm | 1.5 | public | text similarity measurement and index searching based on trigrams
pgstattuple | 1.5 | public | show tuple-level statistics
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(6 rows)
3 升级插件
postgres=# \i update_extensions.sql
You are now connected to database "postgres" as user "pg13".
ALTER EXTENSION
ALTER EXTENSION
ALTER EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+------------------------------------------------------------------------
bloom | 1.0 | public | bloom access method - signature file based index
pageinspect | 1.9 | public | inspect the contents of database pages at a low level
pg_stat_statements | 1.9 | public | track planning and execution statistics of all SQL statements executed
pg_trgm | 1.6 | public | text similarity measurement and index searching based on trigrams
pgstattuple | 1.5 | public | show tuple-level statistics
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(6 rows)
注意:pageinspect已经从1.8升级到了1.9
pg_stat_statements从1.8升级到1.9
[pg13@sdw2 ~]$ sh /home/pg13/delete_old_cluster.sh