How to update the PostgreSQL version on your puppetserver
Our puppetserver uses puppetdb which users PostgreSQL as the persistent datastore in the back.
So far everything is self-contained on the same VM and PostgreSQL is more less managed by the puppetdb module.
The puppetdb module takes care of setting up the PostgreSQL server and uses the upstream PostgreSQL yum module for the binaries. By default it uses PostgreSQL in version 9.6.
Lately, it was announced that puppetdb will start requiring PostgreSQL at least in version 11. Time to start to upgrade our PostgreSQL installation to be ready.
Since the upstream yum repository allows to install multiple version in parallel the migration can be done with little downtime and also supports easy roll-back.
In general we followed the following guide: PostgreSQL upgrade on CentOS.
These were our steps we did:
yum install -y \
https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql13-server postgresql13-contrib
su - postgres -c "/usr/pgsql-13/bin/postgresql-13-setup initdb"
su - postgres -c "/usr/pgsql-13/bin/pg_upgrade \
--old-bindir=/usr/pgsql-9.6/bin/ \
--new-bindir=/usr/pgsql-13/bin/ \
--old-datadir=/var/lib/pgsql/9.6/data/ \
--new-datadir=/var/lib/pgsql/13/data/ \
--check"
# all looks good
cp /var/lib/pgsql/13/data/pg_hba.conf /tmp/
cp /var/lib/pgsql/9.6/data/pg_hba.conf /var/lib/pgsql/13/data/pg_hba.conf
systemctl stop puppetserver
systemctl stop puppetdb
systemctl stop postgresql-9.6
su - postgres -c "/usr/pgsql-13/bin/pg_upgrade \
--old-bindir=/usr/pgsql-9.6/bin/ \
--new-bindir=/usr/pgsql-13/bin/ \
--old-datadir=/var/lib/pgsql/9.6/data/ \
--new-datadir=/var/lib/pgsql/13/data/"
systemctl start postgresql-13
systemctl start puppetdb
# validate
systemctl status postgresql-13
systemctl status puppetdb
# start
systemctl start puppetserver
Now let’s commit the switch to our ibox modules that drives the puppetdb and postgresql configuration.
Done!
Now we can also remove the old installation:
yum remove -y postgresql96*
rm -rf '/var/lib/pgsql/9.6/data'