Connect to a older Postgresql database

Viewed 583

I have PostgreSQL installed in my Linux machine, I'm following a old YT tutorial for work and the instructor is using PostgreSQL 11. I have already used the following command:

sudo apt-get -y install postgresql-11

To install PostgreSQL 11 in my machine, how do I connect to this specific version and not version 12?

2 Answers

Postgress configuration files are located at:

/etc/postgresql/##/main/postgresql.conf

Use your favorite code editor and navigate to the CONNECTIONS AND AUTHENTICATION this will reveal at which port the Postgress database is listening. Connect to you desired version using the -p flag. For me Postgres 11 is using port 5433 and Postgres 12 is using 5432.

psql -h 5433 postgress

Check your version using

SHOW version();

Expected output

                                                          version                                                           
----------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 11.9 (Ubuntu 11.9-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit
(1 row)

The 2nd installed version is probably running on port 5433 rather than 5432. But rather than guessing, you can run pg_lsclusters and see. Then specify that port number whereever you need to connect.

Related