Upgrade to PostgreSQL 12
Introduction
Upgrading to PostgreSQL 12 is a simple procedure requiring minimum downtime.
The process consists of 3 steps:
- Installing PostgreSQL 12 without a new cluster
- Migrating the database
- Optionally dropping the old cluster
Installing PostgreSQL 12
Install PostgreSQL 12 and drop the default cluster:
apt update
apt install --yes postgresql-12
pg_dropcluster 12 main --stop
Upgrade the existing cluster to PostgreSQL 12
For example if you currently use PostgreSQL 11:
pg_upgradecluster 11 main
# Success. Please check that the upgraded cluster works. If it does,
# you can remove the old cluster with
# pg_dropcluster 11 main
# Ver Cluster Port Status Owner Data directory Log file
# 11 main 5433 down postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
# Ver Cluster Port Status Owner Data directory Log file
# 12 main 5432 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
Optionally drop the old cluster and uninstall the old version of PostgreSQL
Once you have established that your upgraded database is working as expected you can drop the old cluster then uninstall the old version.
For example if you were previously using PostgreSQL 11:
# Drop the cluster
pg_dropcluster 11 main
# Uninstall the old packages
sudo apt purge --yes postgresql-11 postgresql-client-11