Test against Postgres 12

Hi!

Could you please advise on how to test against Postgres 12? The approach suggested by the documentation does not work for me.

Should I need something like this? Install Postgresql 11

Failing build: https://travis-ci.org/diowa/ruby2-rails5-bootstrap-heroku/builds/634230908

Ref:

You could debug to confirm that the postgres is running at 5433 as specified.

Trying to adapt your .yml to Bionic:

os: linux
dist: bionic

language: ruby

services:
  - postgresql

rvm:
  - 2.7.0

addons:
  chrome: stable
  postgresql: '12'
  apt:
    packages:
      - postgresql-12
      - postgresql-client-12
      - postgresql-server-dev-12

cache:
  bundler: true
  directories:
    - node_modules
  yarn: true

env:
  global:
    # DON'T DO THIS. DO NOT COMMIT YOUR MASTER KEY TO THE SOURCE CODE.
    # Ref: https://docs.travis-ci.com/user/encryption-keys/
    - RAILS_MASTER_KEY=b8cc3ac9ab8a3280b03af3d29b2e50ca

before_install:
  - nvm install 12
  - node -v
  - npm i -g yarn@^1.15.2
  - yarn
  - LATEST_CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"`
  - curl "https://chromedriver.storage.googleapis.com/${LATEST_CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
  - unzip chromedriver_linux64.zip -d ~/bin
  - sudo pg_dropcluster --stop 12 main
  - sudo pg_upgradecluster 11 main
  - sudo pg_ctlcluster 12 main restart
  - sudo pg_dropcluster 11 main

before_script:
  - psql -c 'create database travis_ci_test;' -U postgres
2 Likes

works like a charm! thx.
https://travis-ci.com/github/zeroplexer/ch.bfh.bti7081.s2020.blue/jobs/329807096

1 Like

Thanks, it took 5 minutes for the service to start but it worked

Marked as solution

1 Like

Thanks, it took 5 minutes for the service to start but it worked

Yes, mine too. Very strange - and of course there are no more detailed logs. Is this script available anywhere?

None of this is necessary. I believe a Travis CI configuration WITHOUT the postgresql service will work better. Just use the addons. You can check a config here: https://travis-ci.org/github/psycopg/psycopg3/jobs/685827089/config

TL;DR

language: python
addons:
    postgresql: '12'
    apt:
      packages:
        - postgresql-12
        - postgresql-client-12
env:
    global:
        - PGVER=12
        - PGPORT=5433
install:
  - pip install tox
  - test ${TOXENV:0:2} != py || psql -c 'create database psycopg3_test'

All that was from psycopg3 and dvazzaro.

2 Likes

Hi Andrew-Chen-Wang,

I can confirm that your solution works, and I’ve marked it as solution because requires less changes and does not use sudo commands

Btw, I’ve noticed that $ travis_setup_postgresql 12

takes 5 minutes on Bionic: https://travis-ci.org/github/diowa/ruby2-rails5-bootstrap-heroku/builds/687758601

but it is almost immediate on Xenial: https://travis-ci.org/github/diowa/ruby2-rails5-bootstrap-heroku/builds/687758829

Should I open a new discussion?

Open a new discussion regarding why it takes so long on Bionic? I think it’d be beneficial. I’d like more people to push towards using PostgreSQL 12 since there are a lot of internal improvements. It doesn’t seem like a systemctl issue since Redis starts up quickly for me…

1 Like

Yes this one works @Andrew-Chen-Wang but only on port 5433 I believe. I’ve been experimenting with environment variables a bit and didn’t notice any impact. I’ve got it working like this:

addons:
  apt:
    packages:
      - postgresql-12
      - postgresql-client-12

before_install:
  - sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/12/main/postgresql.conf
  - sudo cp /etc/postgresql/{9.3,12}/main/pg_hba.conf
  - sudo pg_ctlcluster 12 main restart

Build time reduced from ~ 11 min to just ~ 3 min.

I encountered the same problem, but with the default image for Python 3.7. Solved with:

  - sudo cp /etc/postgresql/10/main/pg_hba.conf /etc/postgresql/12/main/pg_hba.conf
  - sudo pg_ctlcluster 12 main restart
  - sh -c 'until pg_isready -p 5433; do echo "Waiting for the DB to be up..."; sleep 2; done'
  - psql -U postgres -p 5433 -c "CREATE USER testuser WITH PASSWORD 'secret' LOGIN;"
  - psql -U postgres -p 5433 -c "CREATE DATABASE grammarquiz OWNER testuser;"
  - psql -U testuser -p 5433 -f scripts/populate_db/schema.sql grammarquiz
  - psql -U testuser -p 5433 -q -f tests/database_content.sql grammarquiz

I need to use pg_isready because restarting the database doesn’t immediately leave it in an usable state so I cannot populate it with test data immediately.

The result is this:

1 Like

By using the dist: focal image the PostgreSQL 12 start time dropped down to a few seconds.