Nightmares trying to get Postgresql 10 on ubuntu-14.04

postgresql

#1

What is the trick to using pg10 on a CircleCI docker build? I have tried just about everything I can think of, but all I end up with is pg9.6 running side by side with pg10, or mismatched versions between psql & the server.

Currently building with:
docker:
- image: circleci/build-image:ubuntu-14.04-XXL-upstart-1189-5614f37
command: /sbin/init
- image: circleci/postgres:10.4-alpine-ram
environment:
POSTGRES_USER: my_user
POSTGRES_PASSWORD: my_pass
POSTGRES_DB: my_db

It seems like I need to manually stop and remove all traces of pg9, then install 10.x? Pg10 has been officially out since November '17, it feels like this should be so much easier. Hours and hours of lost time …


#2

It seems like I need to manually stop and remove all traces of pg9, then install 10.x?

Do you mean the PostgreSQL client on your primary build container (circleci/build-image:ubuntu...)? As far as I know you cannot uninstall anything from your running secondary container (circleci/postgres:10.4-alpine-ram) since your commands are not run on that machine.

So, if you can add more information as to how you are uninstalling things, that might help. That said, perhaps it would be easier to drop the second container and just install PostgreSQL server in your primary build machine. The fetch from the Ubuntu software repository will be so quick that I doubt you’ll notice much of a slower build.


#3

That’s good advice, I will give that a shot.

I wanted to use the Docker PG build, since that’s how all the documentation recommends, and then attempting to uninstall the local PG9, but it was not working correctly.


#4

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.


Circleci Migration Issues (Postgres)
#5

I had some problems installing the postgres cliwnt on Ubuntu. Doesn’t sound like the same problem, but here’s a link if it helps Basic Database example (not ruby)


#6

This image should generally not be used. It contains all of the same tools that were included in CircleCI 1.0 and based on an OS that is now EOL. The purpose of this image is to ease the transition from 1.0 to 2.0

You should use a language specific image instead, this will make your experience on 2.0 100x better.


#7

Where is that documented?


#8

That’s a great question. I am not sure if its explicitly documented.

This section discussed best practices around using language specific images but I suppose it assumes you made it that far in the documentation.

@smartalek could we review this and make it more explicit? That image (circleci/build-image:ubuntu-14.04) should really not be used unless there is a very good reason.


#9

IMO the migration tool that auto-creates the CircleCI 2.0 config file should make these facts abundantly clear.


#10

Yep @levlaz, just filed a ticket for this. @justinperkins, we’ll make this clearer moving forward. If that means updating the migration tool doc, so be it! :slight_smile: