Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ziyan-junaideen/d4a65534c1a17ca6995c9c974e62d74f to your computer and use it in GitHub Desktop.
Save ziyan-junaideen/d4a65534c1a17ca6995c9c974e62d74f to your computer and use it in GitHub Desktop.
How to install PostgreSQL 9.6 in Ubuntu 16.04

Background

I believe Ubuntu 16.04 comes with PostgreSQL 9.5. Thats good for a start, but it is a matter of time before you have the need of a PostgreSQL 9.6 cluster. For me it was to import a PG backup from Heroku.

The procedure couldn't have been any easier and is described below. If you are interested in upgrading your old cluster to 9.6 afterwards, you may be interested in this.

Instructions

sudo -s 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

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

sudo aptitude update

sudo aptitude install postgresql-9.6 postgresql-client-9.6 postgresql-contrib-9.6

Check

dpkg -l | grep postgresql will give us what is installed and will be some thing like this

ii  postgresql                                                  9.5+173                                            all          object-relational SQL database (supported version)
ii  postgresql-9.5                                              9.5.5-0ubuntu0.16.04                               amd64        object-relational SQL database, version 9.5 server
ii  postgresql-9.6                                              9.6.2-1.pgdg16.04+1                                amd64        object-relational SQL database, version 9.6 server
ii  postgresql-client-9.5                                       9.5.5-0ubuntu0.16.04                               amd64        front-end programs for PostgreSQL 9.5
ii  postgresql-client-9.6                                       9.6.2-1.pgdg16.04+1                                amd64        front-end programs for PostgreSQL 9.6
ii  postgresql-client-common                                    173                                                all          manager for multiple PostgreSQL client versions
ii  postgresql-common                                           173                                                all          PostgreSQL database-cluster manager
ii  postgresql-contrib                                          9.5+173                                            all          additional facilities for PostgreSQL (supported version)
ii  postgresql-contrib-9.5                                      9.5.5-0ubuntu0.16.04                               amd64        additional facilities for PostgreSQL
ii  postgresql-contrib-9.6                                      9.6.2-1.pgdg16.04+1                                amd64        additional facilities for PostgreSQL

pg_lsclusters, will show that your 9.5 and 9.6 main clusters to be "online".

pg_lsclusters 
Ver Cluster Port Status Owner    Data directory               Log file
9.5 main    5432 online postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.5-main.log
9.6 main    5433 online postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.6-main.log
@unfernandito
Copy link

unfernandito commented Feb 24, 2018

sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6

@sgatibaru
Copy link

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

sudo aptitude install postgresql-9.6 postgresql-client-9.6 postgresql-contrib-9.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment