Nightmares trying to get Postgresql 10 on ubuntu-14.04

Got this working. It’s not easy or obvious or documented any way that I can find. There seems to be a pretty large difference between what the CircleCI 2.0 docs say to do, and what you actually have to do. Especially when wanting to use a more modern toolsets like PG10.

  1. Using the docker image for pg10
    docker:

    • image: circleci/build-image:ubuntu-14.04
      environment:
      RAILS_ENV: test
      PGHOST: 127.0.0.1
      PGUSER: root
    • image: circleci/postgres:10.4-alpine-ram
      environment:
      POSTGRES_USER: root
  2. Upgrade the PG client to 10.x in the steps, but do it in a way that prevents the build from failing when the upgrade returns a failure code due to PG9.x failing to start:

sudo apt-get install postgresql-client-10.3 || true

  1. We had to do a couple one-off things, that could be ENV specific, but when running one-off SQL scripts you have to explicitly set sudo -h postgres psql -f path/to/file.sql -h localhost since PG is running in a different container. Also, our schema load was seeming to hang. It’s loading the schema via a SQL dump instead of a typical Ruby dump (PG10 has partitions and support for partitions in ruby schema dumps are not yet supported), so we had to do a || true hack there as well to allow the build to continue, eg:

bundle exec rake db:schema:load || true

I know a lot of this isn’t the best way to get things running, but after literal days of wasting time in SSH sessions in CircleCI builds and shooting in the dark, reading old outdated content, reading inaccurate support articles, we pretty much just had to make something up that worked and move on with our lives.