Reputation: 1508
I'm having trouble with a build of a Rails application for a PostgreSQL 11.2 database.
Here's the .travis.yml
file:
rvm:
- 2.6.1
dist: xenial
services:
- postgresql
addons:
postgresql: "11.2"
apt:
packages:
- postgresql-11
before_script:
- psql --version
- psql -c 'create database kpdotcom_test;' -U postgres
- cp config/database.yml.travis config/database.yml
- bundle exec rake db:schema:load
However, the build fails:
Any suggestions would be gratefully appreciated.
Upvotes: 6
Views: 1255
Reputation: 719
Jonathan Wheeler's answer helped me a lot. However I needed to install postgres 11 on focal
distro whereas the initial post uses xenial
.
Turned out I had to tweak a little bit travis' config file. I thought that might help anyone trying to install postgres 11 on focal
. Basically you need to:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
)echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql-pgdg.list
)sudo apt -y update && sudo apt -y install postgresql-11 postgresql-client-11
)port = 5433/port = 5432
)peer/trust
)sudo chmod 750 /var/lib/postgresql/11/main
Here is the script:
before_install:
- sudo apt -y remove postgresql\*
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql-pgdg.list
- sudo apt -y update
- sudo apt -y install postgresql-11 postgresql-client-11
- sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/11/main/postgresql.conf
- sudo sed -i 's/local all postgres peer/local all postgres trust/' /etc/postgresql/11/main/pg_hba.conf
- sudo chmod 750 /var/lib/postgresql/11/main
- sudo service postgresql restart 11
I could keep before_script
as it was given by Jonathan Wheeler.
If unsure, you can check the postgres port adding a temp line in the script: echo $(sudo cat /etc/postgresql/11/main/pg_hba.conf)
and search for port = 543
in the logs.
Same for postgres auth method:
echo $(sudo cat /etc/postgresql/11/main/postgresql.conf)
Upvotes: 0
Reputation: 2699
I had this problem too. Here's the config file that fixed it for me:
This script:
language: ruby
rvm: 2.6.2
before_install:
- sudo apt-get update
- sudo apt-get --yes remove postgresql\*
- sudo apt-get install -y postgresql-11 postgresql-client-11
- sudo cp /etc/postgresql/{9.6,11}/main/pg_hba.conf
- sudo service postgresql restart 11
before_script:
- psql --version
- psql -c 'CREATE DATABASE {{your database name here}};' -U postgres
- psql -c 'CREATE ROLE travis SUPERUSER LOGIN CREATEDB;' -U postgres
- cp config/database.yml.travis config/database.yml
script: bundle exec rake spec
services:
- postgresql
addons:
postgresql: "11.2"
Upvotes: 5