Upgrading a PostgreSQL cluster
After a Debian upgrade, don't immediately purge obsolete packages until the PostgreSQL cluster is upgraded. You need the old PostgreSQL binaries to upgrade the cluster.
Say that the previous Debian came with PostgreSQL 13 and the upgraded Debian
comes with PostgreSQL 15. The PostgreSQL version 13 is now obsolete, but the
server or client packages are still installed. Install the latest packages
(postgresql-15 and postgresql-client-15).
Be aware that the installation of postgresql-15 will automatically create a
default cluster 15/main. If you want to upgrade the 13/main cluster, you
need to remove the already existing 15 cluster using pg_dropcluster.
# Verify that two main clusters are "online".
pg_lsclusters
# Stop the 15 cluster and drop it.
sudo pg_dropcluster 15 main --stop
Upgrade the existing clusters with pg_upgradecluster.
# Upgrade the 13 cluster to the latest version.
sudo pg_upgradecluster 13 main
# Your 13 cluster should now be "down" and you can verify by running.
pg_lsclusters
# Check that the upgraded cluster works, then remove the 13 cluster.
sudo pg_dropcluster 13 main
The old server and client packages are no longer supported. After the existing
clusters are upgraded, the postgresql-13 and postgresql-client-13 packages
should be removed.
sudo apt purge '~o'
Tip
For details see:
zless /usr/share/doc/postgresql-common/README.Debian.gz