We assume that we have version PostgreSQL v 11 server installed and running.
First install new version, for example PostgreSQL 12. :
$ sudo apt -y install postgresql-12 postgresql-client-12
A successful installation prints a message. The PostgreSQL service is started and set to come up after every system reboot.
$ systemctl status postgresql.service ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Sun 2021-10-06 10:23:46 UTC; 6min ago Main PID: 8159 (code=exited, status=0/SUCCESS) Tasks: 0 (limit: 2362) CGroup: /system.slice/postgresql.service Oct 06 10:23:46 deb10 systemd[1]: Starting PostgreSQL RDBMS… Oct 06 10:23:46 deb10 systemd[1]: Started PostgreSQL RDBMS.
Keep in mind new server starts at port 5433, but old server running on port 5432.
Run pg_lsclusters
, your 11 and 12 main clusters should be “online”.
Ver Cluster Port Status Owner Data directory Log file 11 main 5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log 12 main 5433 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
There already is a cluster “main” for 12 (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 11/main
when 12/main
also exists. The recommended procedure is to remove the 12 cluster with pg_dropcluster
and then upgrade with pg_upgradecluster
.
Stop the 12 cluster and drop it.
$ sudo pg_dropcluster 12 main --stop
In my case, I had to stop the old server service:
$ sudo systemctl stop postgresql
Upgrade the 11 cluster to the latest version.
$ sudo pg_upgradecluster 11 main
Check that the upgraded cluster works, then remove the 11 cluster.
$ sudo pg_dropcluster 11 main
After all your data check you can remove your old packages.
$ sudo apt-get purge postgresql-11 postgresql-client-11
And we well done. )
Similar Posts:
- how to install PostgreSQL 12 on Ubuntu / Debian 10,11
- postresql: move data directory to another location
- How to create Dblink between Oracle & PostgreSQL
- postgresql: how to reset forgotten postgres password
- how to restore postgreSQL database with template using pg_dump