PostgreSQL upgrade on Red Hat 7

Following instructions from here
Select version: 9.6 (I needed 9.6 because of my specific product requirements)
Select platform: RHEL7
Install the repository RPM: yum install

yum install postgresql96 postgresql96-server postgresql96-libs postgresql96-contrib
/usr/pgsql-9.6/bin/postgresql96-setup initdb

My previous PostgreSQL was 9.2 and it was installed from RHEL repo, so all directories and configs are standards.

This is important! You can’t use pg_upgrade in this particular upgrade, because they *censored* changed “unix_socket_directory parameter” to “unix_socket_directories”. Check this out – Luckily there’s a workaround:

mv /usr/bin/pg_ctl{,-orig}
echo '#!/bin/bash' > /usr/bin/pg_ctl
echo '"$0"-orig "${@/unix_socket_directory/unix_socket_directories}"' >>  /usr/bin/pg_ctl
chmod +x /usr/bin/pg_ctl

Let’s stop the old PostgreSQL 9.2 service and disable it
systemctl stop postgresql
systemctl disable postgresql

Finally actual upgrade:

su - postgres
#with --check first
/usr/pgsql-9.6/bin/pg_upgrade --old-bindir=/usr/bin/ --new-bindir=/usr/pgsql-9.6/bin/ --old-datadir=/var/lib/pgsql/data --new-datadir=/var/lib/pgsql/9.6/data/ --check
#if everything is ok, then
/usr/pgsql-9.6/bin/pg_upgrade --old-bindir=/usr/bin/ --new-bindir=/usr/pgsql-9.6/bin/ --old-datadir=/var/lib/pgsql/data --new-datadir=/var/lib/pgsql/9.6/data/

Undo the “hack”:
mv -f /usr/bin/pg_ctl{-orig,}

systemctl enable postgresql-9.6
systemctl start postgresql-9.6
systemctl status postgresql-9.6

Let’s run this

su - postgres

and also check DB version

psql -d 
SHOW server_version;


Leave a comment

You must be logged in to post a comment.