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
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.rpmpostgresql15-contrib-15.1-1PGDG.rhel8.x86_64.rpmpostgresql15-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.
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
Post a Comment