Installing and Connecting to Multiple Versions of PostgreSQL on a Linux Machine

You might have various projects and would want to have multiple versions of PostgreSQL installed on your machine. This guide would just be a set of commands and changing of ports :-D


sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

sudo apt-get update  


Run the above commands and you now have multiple versions of PostgreSQL on your apt-get, install anyone of your choice.
To change the port PostgreSQL runs on, you need to edit the configuration file for the version installed using the following command:

sudo nano /etc/postgresql/VERSION/main/postgresql.conf


Where VERSION is the version installed e.g. 9.5



Finally, to connect to any version of the PostgreSQL installed, run the following:
sudo -u postgres psql -p PORT

Where PORT is the port specified (5433) in our case.

This also applies to when connecting using a tool such as PgAdmin.

Comments

Popular Posts