PostgreSQL upgrade on Red Hat 7
Installation
Following instructions from here https://www.postgresql.org/download/linux/redhat/:
Select version: 9.6 (I needed 9.6 because of my specific product requirements)
Select platform: RHEL7
Install the repository RPM: yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm
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.
Upgrade
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 – https://www.postgresql.org/docs/9.3/release-9-3.html#AEN114343. 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 analyze_new_cluster.sh:
su - postgres
/var/lib/pgsql/analyze_new_cluster.sh
and also check DB version
psql -d
SHOW server_version;
\q
Links:
https://www.postgresql.org/download/linux/redhat/
https://dba.stackexchange.com/questions/50135/pg-upgrade-unrecognized-configuration-parameter-unix-socket-directory
https://www.postgresql.org/docs/9.3/release-9-3.html#AEN114343
https://support.code42.com/Administrator/6/Planning_and_installing/PostgreSQL_upgrade_on_Red_Hat
http://www.uptimemadeeasy.com/databases/upgrade-postgresql/