How to upgrade PostgreSQL To Latest version PostgreSQL 13 in CWP/Centos 7/8/el7/el8
In this tutorial I’ll show you how you can upgrade PostgreSQL from older version to latest version at the time of writing 13 is the latest version, This is tested in CWP and other servers running centos 7 and 8 i.e. el7/el8.
The upgrade procedure is little bit complicated and you need to follow the below steps one by one :
Step 1 :
Backup all the data
mkdir /home/pgsql chown -R postgres:postgres /home/pgsql su - postgres pg_dumpall > /home/pgsql/backup exit
Step 2 :
Uninstalling/removing the current version of PostgreSQL :
systemctl stop postgresql mv /var/lib/pgsql/data/ /home/pgsql/data.old rpm -e --nodeps postgresql postgresql-devel postgresql-libs postgresql-server
If you already installed from official repo i.e. version 9,10,11 and 12 (skip this steps if you didn’t used official repo to install pgsql) do this :
systemctl stop postgresql-# mv /var/lib/pgsql/#/data/ /home/pgsql/#/data.old rpm -e --nodeps postgresql# postgresql#-devel postgresql#-libs postgresql#-server
replace “#”with the version number i.e. 9/10/11/12
Step 3 :
Now install the Latest version og PostgreSQL :
EL7/Centos 7 :
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum install -y yum-utils centos-release-scl-rh yum-config-manager --disable centos-sclo-rh yum --enablerepo=centos-sclo-rh install llvm-toolset-7-clang yum install postgresql13-server postgresql13-devel
EL8/Centos 8 :
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm dnf -qy module disable postgresql dnf install postgresql13-server postgresql13-devel
Step 4 :
Now copying the configuration file to new installation of PostgreSQL :
Centos 7/8/EL7/EL8 :
su - postgres mv /var/lib/pgsql/13/data/pg_hba.conf /var/lib/pgsql/13/data/pg_hba.conf.bak wget -O https://blog.alphagnu.com/upload/pg_hba.conf /var/lib/pgsql/13/data/pg_hba.conf chown -R postgres:postgres /var/lib/pgsql/13/data/pg_hba.conf /usr/pgsql-13/bin/initdb exit
if you have used official repo to install pgsql (skip this step if you didn’t installed any pgsql from official repo before) :
su - postgres /usr/pgsql-13/bin/initdb cp /home/pgsql/#/data.old/pg_hba.conf /var/lib/pgsql/13/data/ cp /home/pgsql/#/data.old/postgresql.conf /var/lib/pgsql/13/data/ exit
replace “#” with version number you used above
Step 5 :
Now start PostgreSQL and enable it to start on boot :
systemctl enable postgresql-13 systemctl start postgresql-13
Step 6 :
Restore the previous backups done in Step 1
su - postgres psql -d postgres -f /home/pgsql/backup
Step 7 :
Create symlink of new version of service :
rm -rf /usr/lib/systemd/system/postgresql.service ln -s /usr/lib/systemd/system/postgresql-13.service /usr/lib/systemd/system/postgresql.service systemctl stop postgresql-13.service systemctl enable postgresql systemctl restart postgresql
EXTRA upgrading phpPgAdmin in CWP :
cd /usr/local/cwpsrv/var/services yum install cwpPgphp -y yum reinstall cwpPgphp -y mv phpPgAdmin phpPgAdmin.bak wget https://github.com/phppgadmin/phppgadmin/releases/download/REL_7-13-0/phpPgAdmin-7.13.0.zip unzip phpPgAdmin-7.13.0.zip mv phpPgAdmin-7.13.0 phpPgAdmin rm -rf phpPgAdmin-7.13.0.zip
That’s it, you’re now ready to use it.