How To Upgrade POSTGRESQL 10 To 11

We will upgrade POSTGRESQL 10 To 11 on CENTOS in this article. Before I begin the redesign procedure, I need to make the accompanying basic cautioning:
You should re-arrange your postgresql.conf and pg_hba.conf records. Since the files will be reset after the redesign.
Install PostgreSQL 11
Postgresql 11 we are installing the following script.
[root@postgres eng]# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
[root@postgres eng]# yum install postgresql11
[root@postgres eng]# yum install postgresql11-server
initdb
We are performing the initdb task in the Postgresql 11 database.
[root@postgres eng]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database … OK
Checking Whether the Upgrade is Applicable
We check the applicability of the upgrade with the command below. (with PostgreSQL user)
-bash-4.2$ /usr/pgsql-1/bin/pg_upgrade –old-bindir=/usr/pgsql-10/bin/ –new-bindir=/usr/pgsql-11/bin/ –old-datadir=/var/lib/pgsql/10/data –new-datadir=/var/lib/pgsql/11/data –check
pgsql-10/ pgsql-11/
-bash-4.2$ /usr/pgsql-11/bin/pg_upgrade –old-bindir=/usr/pgsql-10/bin/ –new-bindir=/usr/pgsql-11/bin/ –old-datadir=/var/lib/pgsql/10/data –new-datadir=/var/lib/pgsql/11/data –check
Performing Consistency Checks on Old Live Server
————————————————
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 presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
*Clusters are compatible*
Stop PostgreSQL 10
If we perform the upgrade without stopping Postgresql 10, we get the following error.
-bash-4.2$ /usr/pgsql-11/bin/pg_upgrade –old-bindir=/usr/pgsql-10/bin/ –new-bindir=/usr/pgsql-11/bin/ –old-datadir=/var/lib/pgsql/10/data –new-datadir=/var/lib/pgsql/11/data
There seems to be a postmaster servicing the old cluster.
Please shutdown that postmaster and try again.
Failure, exiting
-bash-4.2$ logout
[root@postgres eng]# systemctl stop postgresql-10.service
We are ceasing Postgresql 10 (with root user)
[root@postgres eng]# systemctl stop postgresql-10.service
Upgrade
At that point, we change to the Postgres client and run the upgrade command. (with Postgres user)
-bash-4.2$ /usr/pgsql-11/bin/pg_upgrade –old-bindir=/usr/pgsql-10/bin/ –new-bindir=/usr/pgsql-11/bin/ –old-datadir=/var/lib/pgsql/10/data –new-datadir=/var/lib/pgsql/11/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
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
-bash-4.2$
We use the following commands before loading the requested commands.
[root@postgres eng]# systemctl enable postgresql-11.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.
[root@postgres eng]# systemctl start postgresql-11.service
Then we do the desired steps from us.
-bash-4.2$ ./analyze_new_cluster.sh
This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy. When it is done, your system will
have the default level of optimizer statistics.
If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation.
If you would like default statistics as quickly as possible, cancel
this script and run:
“/usr/pgsql-11/bin/vacuumdb” –all –analyze-only
vacuumdb: processing database “postgres”: Generating minimal optimizer statistics (1 target)
vacuumdb: processing database “template1”: Generating minimal optimizer statistics (1 target)
vacuumdb: processing database “postgres”: Generating medium optimizer statistics (10 targets)
vacuumdb: processing database “template1”: Generating medium optimizer statistics (10 targets)
vacuumdb: processing database “postgres”: Generating default (full) optimizer statistics
vacuumdb: processing database “template1”: Generating default (full) optimizer statistics
Done
Delete Old Cluster
Then run the below command. But, be aware that this command deletes the old cluster. That’s why to be sure that PostgreSQL 11 is working before deleting the old cluster.
-bash-4.2$ ./delete_old_cluster.sh
We remove all packages related to Postgresql10. (with root user)
[root@postgres eng]# rpm -qa | grep postgresql
yum remove postgresql10-10.5-1PGDG.rhel7.x86_64
yum remove postgresql10-libs-10.5-1PGDG.rhel7.x86_64
The update process is finished. Now you can connect to the database and look at version 11.
-bash-4.2$ psql
psql (11.0)
Type “help” for help.
postgres=#
