Zend certified PHP/Magento developer

How to make latest PostgreSQL version upgrade the default version in Ubuntu Focal Fossa

Beforehand, I will admit that I am quite frustrated after attempting to upgrade my version of PostgreSQL-12 to PostgreSQL-16 in my virtual machine (Windows Subsystem for Linux2 Ubuntu 20.04.6 LTS Focal Fossa). So please forgive my frustration. It’s not personal. Nonetheless, like Rich from ReviewTechUSA say, “Let’s get into it.”

After conducting further research, it seems that Ubuntu handles subsequent upgrading of a PostgreSQL version by keeping both the original and upgraded versions. I discovered this after running the command sudo service PostgreSQL start resulting in the following output:

 * Starting PostgreSQL 12 database server                                                                        [ OK ]
 * Starting PostgreSQL 16 database server                                                                        [ OK ]
➜  ~ sudo service postgresql status
12/main (port 5432): online
16/main (port 5433): online
➜  ~

I now understand and respect why Ubuntu maintains both versions after an upgrade. However, I need version 16 to be the default such that all psql and pg commands defer to version 16 instead of 12. For example, I need the command line tools pg_dump and pg_restore to use the features associated with version 16 and not version 12. Moreover, the psql command should start a session in version 16 and not in version 12. Please help me to achieve this. Thank you so much for your attention and participation.

FYI – Currently, the command pg_restore –version points to PostgreSQL-12:

➜  ~ pg_restore --version
pg_restore (PostgreSQL) 12.16 (Ubuntu 12.16-1.pgdg20.04+1)
➜  ~