How to Upgrade PostgreSQL

  In this article, we will explain , How to upgrade from postgres 13 to postgres 15.1 version. This will be considered as major upgrade.

Minor upgrade is like upgrading from 9.5 version to 9.7 version. For minor upgrade, You just need to upgrade the rpms. Which We will do that in another article.

Database Upgrade Steps:

1. Download Latest RPMs

Below URL can be used to downlaod rpms for PostgreSQL version 15.1 for Linux x86_64 Platforms
https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-8.2-x86_64/

Our required rpms are listed below:

 

postgresql15-libs-15.1-1PGDG.rhel8.x86_64.rpm
postgresql15-devel-15.1-1PGDG.rhel8.x86_64.rpm
postgresql15-15.1-1PGDG.rhel8.x86_64.rpm   
postgresql15-contrib-15.1-1PGDG.rhel8.x86_64.rpm 
postgresql15-server-15.1-1PGDG.rhel8.x86_64.rpm 

Make sure to install the rpms in below sequence only. Otherwise you will dependency errors.

[root@postgredb pg_13]# yum localinstall  /tmp/postgresql15-libs-15.1-1PGDG.rhel8.x86_64.rpm

[root@postgredb pg_13]# yum localinstall  /tmp/postgresql15-devel-15.1-1PGDG.rhel8.x86_64.rpm

[root@postgredb pg_13]# yum localinstall  /tmp/postgresql15-15.1-1PGDG.rhel8.x86_64.rpm

[root@postgredb pg_13]# yum localinstall  /tmp/postgresql15-server-15.1-1PGDG.rhel8.x86_64.rpm

[root@postgredb pg_13]# yum localinstall  /tmp/postgresql15-contrib-15.1-1PGDG.rhel8.x86_64.rpm

2. Initialise New PostgreSQL database.

postgredb $ /usr/pgsql-15.1/bin/initdb -D /var/lib/pgsql/15/data

3. Run upgrade with check option.

Run below command to check if everything is fine before actual upgrade:

/usr/pgsql-15/bin/pg_upgrade -d  /var/lib/pgsql/13/data -D /var/lib/pgsql/15/data -b /usr/pgsql-13/bin -B /usr/pgsql-15/bin  -c

It will ask to stop existing PostgreSQL database i.e. version 13 database. Stop it and also disable it so that actual upgrade process can be started:

systemctl stop postgresql-13.service

systemctl disable postgresql-13.service

4.Run the Upgrade:

/usr/pgsql-15/bin/pg_upgrade -d  /var/lib/pgsql/13/data -D /var/lib/pgsql/15/data -b /usr/pgsql-13/bin -B /usr/pgsql-15/bin

Note "--link" option can be used to use existing postgresql data files.

Time it will take to upgrade depends on database size, once done, start the newly upgraded database as below:

/usr/pgsql-15/bin/pg_ctl start -D /var/lib/pgsql/15/data

Now you can verify the version of database as below using postgres used

[root@postgredb pg_13]# su - postgres

[root@postgredb pg_13]$ psql my_database

postgres=# select version();

version --------------------------------------------------------------------------- PostgreSQL 15.1 on x86_64-pc-linux-gnu (1 row)

Comments

Popular posts from this blog

How to Install PostgreSQL on Linux

Ora2pg Mirgation Tool

Oracle vs PostgreSQL Comparison