How to update PostgreSQL on Debian Linux

I was updating my machine earlier today and received this message.


PostgreSQL is a powerful open-source relational database management system. It provides a platform for efficiently storing, organizing, and querying structured data. Renowned for its extensibility, PostgreSQL supports advanced features such as ACID transactions, multi-version concurrency control (MVCC), and support for various data types. With a strong community and active development, PostgreSQL is favored for its reliability, scalability, and support for complex SQL queries. It finds use in a wide range of applications, from small projects to large-scale enterprise systems, offering users a robust and customizable solution for managing and retrieving their data.

Version 14 has been deprecated and some manual interaction is required to update to the latest version. Today I will explain the steps needed to resolve it.

=====================================================================================

Update and Install Packages

sudo apt-get update

sudo apt-get install postgresql-15 postgresql-client-15

This command will update and install the necessary packages for the new version of postgresql

=====================================================================================

OPTIONAL:

By default the new installation will create a cluster named “15/main” If you already have one named that you need to delte it or change it in order to prevent conflicts.

Delete Cluster

sudo pg_dropcluster –stop [cluster_name]

If the cluster is not running you can omit –stop

Change Name

sudo pg_renamecluster [cluster_name] [newname]

=====================================================================================

Update Existing Cluster

If you have a cluster you would like to keep you can update it using the following command

sudo pg_upgradecluster 14 main

14 main is most likely the default you are going to have, but remember to change the name to avoid conflicts with the update

=====================================================================================

Remove Old Packages

sudo apt-get remove postgresql-14 postgresql-client-14

=====================================================================================

Additional Command

You may not need these but they could be helpful

pg_lsclusters

Used to view clusters. Like the ls command