Nextcloud

How to Upgrade PostgreSQL from 15 to 16

This-one-logo-cloud-only9-center-purple-bk-h450-w650.png

By jplee ~ Published – 2023/11/30

The new PostgreSQL 16 database has been released. There are multiple ways to upgrade from the old version 15, and the easiest one is by using the pg_lsclusters tool. Here is a quick tutorial for Ubuntu (or Debian) systems. And, please, do not forget to back up your data!

Step 1:  Update packages and install the new PostgreSQL 16 database.

sudo apt update && sudo apt upgrade -y
sudo apt install postgresql-16 postgresql-server-dev-16
Step 2:  After you install it, your current clusters will have two version of postgresql. you can check it using this command.
sudo pg_lsclusters

Step 3:  You need to stop the new version in order to upgrade it, using the following command.

sudo pg_dropcluster 16 main --stop
Step 4:  If you check it using pg_lsclusters again, there will be only 1 listed of the online versions.
sudo pg_lsclusters
Step 5: Now start the upgrade process using the following command.
sudo pg_upgradecluster 15 main
If “success” you can safely remove the old version using pg_dropcluster.
sudo pg_dropcluster 15 main
Now remove the old package of postgresql 15 using following command.
sudo apt purge postgresql-15 postgresql-client-15
You may check your current clusters using pg_lsclusters command again.
sudo pg_lsclusters

Start the PostgreSQL service.

sudo systemctl start postgresql.service

Finally, you can check the version of postgreSQL, using the following command.

sudo psql --version 
Login as the PostgreSQL user.
sudo su - postgres

Check the new PostgreSQL version.

psql -c "SELECT version();"

After the upgrade, the vaccumdb command is use to optimize statistics and analyze the new cluster.  Run the vaccumdb command to analyze the new cluster.

/usr/lib/postgresql/16/bin/vacuumdb --all --analyze-in-stages 
Go back to the regular Terminal user.
logout 

That’s it. You are done. It is really easy right!  Happy upgrading!!!!!

Congratulations, you now have your own personal data on your own secured Nextcloud system!

We at Ahuitech create clouds systems that allow you to have complete control of your Data.

Ahuitech – Cloud Creations are always in your Control

Leave a Reply

Your email address will not be published. Required fields are marked *