Friday, 19 February 2021

How to upgrade PostgreSQL9.5 to 12

PostgreSQL9.5 is the end of life now. You can use the steps mentioned in the below video to upgrade PostgreSQL9.5 to 12.


Before upgrade please make sure sufficient disk space is available. Some extensions like. PostGIS will not be upgraded during this process. You may drop the extension from 9.5, installed it on Postgres12, and create the extension. It's recommended to take a backup before doing the up-gradation process on the production environment.
Please find the below list of commands used in the up-gradation process. # Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL9.5:
sudo yum install -y postgresql95-server
# Initialize the database and start service:
sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
# Install PostgreSQL12:
# Initialize the database and start service:
sudo yum install -y postgresql12-server
# PostgeSQL upgrade command syntax
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
# PostgeSQL Cluster compatibity check
pg_upgrade -b oldbindir -B newbindir -d oldconfigdir -D newconfigdir [option...]
/usr/pgsql-12/bin/pg_upgrade --old-bindir /usr/pgsql-9.5/bin/ --new-bindir /usr/pgsql-12/bin/ --old-datadir /var/lib/pgsql/9.5/data/ --new-datadir /var/lib/pgsql/12/data --link --check
# Upgrade Command /usr/pgsql-12/bin/pg_upgrade --old-bindir /usr/pgsql-9.5/bin/ --new-bindir /usr/pgsql-12/bin/ --old-datadir /var/lib/pgsql/9.5/data/ --new-datadir /var/lib/pgsql/12/data --link