Preparation
- OS user pg13
- pg13 data directory/pg13/data
- pg14 data directory/pg14-8k/data2
- Ensure that the plug-ins in the pg13 and pg14 databases are consistent
- The initialization of pg13 and the initialization of pg14 must be initialized with operating system user pg13
Check before upgrading
Note: The old and new cluster port numbers cannot be consistent, otherwise the upgrade will fail. [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*
Upgrade
--link The new version uses hard links to copy data to the specified file directory. [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 **Note 1: Upgrade 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 ---------------- **Note 2: Analyze statistical information** 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
After the upgrade is completed, several files will be generated in the pg13 home directory (for subsequent use):
[root@sdw2 pg13]# pwd /home/pg13 [root@sdw2 pg13]#ll -lhtr ......... -rw-r----- 1 pg13 pg13 270 February 10 09:33 loadable_libraries.txt (load plug-in information) -rwx------ 1 pg13 pg13 31 February 10 10:04 delete_old_cluster.sh (delete old version of data) -rw------- 1 pg13 pg13 135 February 10 10:04 update_extensions.sql (upgrade plug-in) [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
Collect statistical information
Since running pg_upgrade will not bring over the statistical information, you need to analyze the entire database.
-j is parallel [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
Upgrade plug-in
1 Log in to the database
[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 Check the plug-in status
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 | planning track 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 Upgrade plug-in
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 | planning track 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) Note: pageinspect has been upgraded from 1.8 to 1.9 pg_stat_statements upgraded from 1.8 to 1.9
Delete old version
[pg13@sdw2 ~]$ sh /home/pg13/delete_old_cluster.sh