Search code examples
postgresqlpostgresql-11postgresql-12

Connect to a older Postgresql database


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?


Solution

  • 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)