Using the latest Postgres in Circle-CI

Postgres is included in the base image of Circle-CI, however, sometimes you need a feature such as jsonb_set that is only available from 9.5 and above.

So you have no other choice but to upgrade to the latest version, luckily the steps are very straightforward:

dependencies:
  pre:
    - sudo apt-get remove --purge postgresql postgresql-9.4
    - 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
    - sudo apt-get install postgresql postgresql-contrib
    - sudo service postgresql start