Install a new version of PostgreSQL server

January 5, 2018
Install a new version of PostgreSQL server. dpkg-query -l postgresql* Looks like the Debian upgrade included PostgreSQL 9.6, but I still need to upgrade from 9.1 to 9.6. Run `pg_lsclusters`, your 9.1 and 9.6 main clusters should be “online”.
pg_lsclusters Ver Cluster Port Status Owner Data directory Log file 9.1 main 5432 online postgres /var/lib/postgresql/9.1/main /var/log/postgresql/postgresql-9.1-main.log
There already is a cluster “main” for 9.6 (since this is created by default on package installation). This is done so that a fresh installation works out of the box without the need to create a cluster first, but of course it clashes when you try to upgrade 9.1/main when 9.6/main also exists. The recommended procedure is to remove the 9.6 cluster with `pg_dropcluster` and then upgrade with `pg_upgradecluster`. Stop the 9.6 cluster and drop it.
sudo pg_dropcluster 9.6 main –stop
Upgrade the 9.1 cluster to the latest version.
sudo pg_upgradecluster 9.1 main
Your 9.1 cluster should now be “down”.
pg_lsclusters Ver Cluster Port Status Owner Data directory Log file 9.1 main 5433 down postgres /var/lib/postgresql/9.1/main /var/log/postgresql/postgresql-9.1-main.log 9.6 main 5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log
Check that the upgraded cluster works, then remove the 9.1 cluster.
sudo pg_dropcluster 9.1 main
After all you may totally remove version 9.1 from the server:
sudo apt-get –purge remove postgresql-client-9.1 postgresql-9.1

posted in Postgres by nico