Upgrade PostgreSQL

older/wrong versions.

First check which PostgreSQL is running

jitsejan@jjsvps:~$ sudo service postgresql status

Probably this will list version 9.3 running on port 5432.

Add the PostgreSQL repository to the sources to be able to update to newer versions.

jitsejan@jjsvps:~$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
jitsejan@jjsvps:~$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Now update the system to retrieve data from the new repository.

jitsejan@jjsvps:~$ sudo apt-get update
jitsejan@jjsvps:~$ sudo apt-get upgrade

Next we can install version 9.4 of PostgreSQL.

jitsejan@jjsvps:~$ sudo apt-get install postgresql-9.4

If you check the status again, you will see two instances of PostgreSQL running.

jitsejan@jjsvps:~$ sudo service postgresql status

Optionally the old version can be removed.

jitsejan@jjsvps:~$ sudo apt-get remove --purge postgresql-9.3