Howto: Upgrade Postgresql 16 to 17
By SecBurg
Follow these steps to upgrade your existing Postgresql 16 cluster to version 17.
Note: all steps should be done as root (or using sudo).
- use pg_lsclusters to list the current clusters. There should be two available:
# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
16 main 5432 online postgres /var/lib/postgresql/16/main /var/log/postgresql/postgresql-16-main.log
17 main 5433 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
The cluster in version 16 should contain all your current data, while version 17 should be empty.
- now drop the empty new cluster with pg_dropcluster:
# pg_dropcluster 17 main --stop
- verify, that only the old version is left:
# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
16 main 5432 online postgres /var/lib/postgresql/16/main /var/log/postgresql/postgresql-16-main.log
- start the upgrade using pg_upgradecluster, and watch the output:
# pg_upgradecluster 16 main
Stopping old cluster...
Restarting old cluster with restricted connections...
Notice: extra pg_ctl/postgres options given, bypassing systemctl for start operation
Creating new PostgreSQL cluster 17/main ...
[....]
Success. Please check that the upgraded cluster works. If it does,
you can remove the old cluster with
pg_dropcluster 16 main
Ver Cluster Port Status Owner Data directory Log file
16 main 5433 down postgres /var/lib/postgresql/16/main /var/log/postgresql/postgresql-16-main.log
Ver Cluster Port Status Owner Data directory Log file
17 main 5432 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
- at last, drop the old cluster and remove the old packages:
# pg_dropcluster 16 main
# apt purge postgresql-16 postgresql-client-16
Done!