Updating from PostgreSQL 11 to PostgreSQL 15

Upgrade PostgreSQL from 11 to 15

PostgreSQL 15 is the default for UCS 5.2 and by now also for UCS 5.0. But PostgreSQL 11 has been the default for UCS 5.0 for a long time.

There is no automatic migration from 11 to 15 before or after the update to UCS 5.2, the installed PostgreSQL version is retained.

The following steps are necessary on a UCS 5.0 or 5.2 system for updating PostgreSQL 11 to PostgreSQL 15

:bulb:
The following commands are one-liners. You can simply triple-click on a line to completely select it for easy copy-and-paste. But still: Always double-check your command prompt before issueing a command!

if dpkg -l univention-postgresql-11 | grep ^ii; then
  [ -f /usr/sbin/univention-pkgdb-scan ] && chmod -x /usr/sbin/univention-pkgdb-scan
  service postgresql stop
  rm -rf /etc/postgresql/15
  apt-get install --reinstall postgresql-15
  ucr set postgres15/autostart='yes'
  systemctl unmask postgresql@15-main.service
  pg_dropcluster 15 main --stop
  service postgresql start
  [ -e /var/lib/postgresql/15/main ] && mv /var/lib/postgresql/15/main /var/lib/postgresql/15/main.old
  pg_upgradecluster 11 main
  univention-install --yes univention-postgresql-15
  ucr commit /etc/postgresql/15/main/*
  chown -R postgres:postgres /var/lib/postgresql/15
  [ ! -e /etc/postgresql/15/main/conf.d/ ] && mkdir /etc/postgresql/15/main/conf.d/ && chown postgres:postgres /etc/postgresql/15/main/conf.d/
  service postgresql restart
  [ -f /usr/sbin/univention-pkgdb-scan ] && chmod +x /usr/sbin/univention-pkgdb-scan
else
  echo "PostgreSQL 11 not installed. Nothing to migrate"
fi

Then check the actual version that is used:

$ pg_lsclusters -h
15 main 5432 online postgres /var/lib/postgresql/15/main /var/log/postgresql/postgresql-15-main.log

Once the new database / data inventory has been verified, the PostgreSQL 11 data can be removed / the software package uninstalled:

pg_dropcluster 11 main --stop
service postgresql restart
apt-get purge postgresql-11

Upgrade password encryption from MD5 to SCRAM-SHA-256

After upgrading to UCS 5.2, PostgreSQL 15 may still be configured to use md5 password encryption. It is recommended to migrate PostgreSQL password encryption to scram-sha-256.

The password encryption migration is independent of the PostgreSQL 11 to PostgreSQL 15 upgrade and requires additional steps for existing database users and service accounts.

For prerequisites and the complete migration procedure, see:

Migrate PostgreSQL password encryption from MD5 to SCRAM-SHA-256

4 Likes