How to upgrade postgresql-15 to postgresql-16 using pg_upgradeclusters in ubuntu 22.04

Gembit Soultan Shirazi
2 min readSep 20, 2023
Image from kinsta.com

Hi All,

It is quite sometime i am not writing about devops things. Today, I will write about upgrading the postgresql using pg_upgradecluster in ubuntu 22.04.

As you know, the postgresql 16 has been launched couple days ago, in 14 September 2023, and it has a lot major improvements related with performance and bugs fixing.

And now i want to explain to you, on how to upgrade it to a new version step by step.

  1. Please install the new version of postgresql-16
  2. after you install it, your current clusters will have two version of postgresql. you can check it using this command.
sudo pg_lsclusters

3. as you can see above, your clusters now have at least more than 1 version of postgresql (15 and 16). Postgresql automatically create a new directory for 16 version

4. You need to stop the new version in order to upgrade it. using this command.

sudo pg_dropcluster 16 main --stop

And if you check it using pg_lsclusters will be only 1 list of the online version.

5. Now we starting the upgrade proses using this command line

sudo pg_upgradecluster 15 main

as you can see at the image above, if success you can safely remove the old version using pg_dropcluster.

sudo pg_dropcluster 15 main

Now remove the old package of postgresql using this command

sudo apt purge postgresql-15 postgresql-client-15

you can check your current clusters using pg_lsclusters command. it should be like the image below.

Thats it. it is done. It is really easy right. Happy upgrading.

--

--

Gembit Soultan Shirazi

VP Of Technology - Impack Pratama, Head Of Tech Urbanhire.com, Founder of Foodina.id, CoFounder of Pasarpolis.com, Geeks, CTO, Consultant and Lecturer