Postgresql 11.2: Cannot connect

I’m having trouble getting a build working with Postgresql 11.2. As with previous attempts, the latest build fails when an attempt is made to run a command via psql.

Here’s the configuration:

    - CC_TEST_REPORTER_ID=eca569d89e2a8d954a3e28ef958ce10e912eef6570bbdabbb28297e11948efa8
language: ruby
  - gem update --system
  - gem install bundler
  - 2.6.2
  - postgresql
  - xenial
  postgresql: "11.2"
      - postgresql-11
  - psql -c "select * from pg_settings where name = 'port';"
  - psql -c 'create database kpdotcom_test;' -U postgres
  - cp config/database.yml.travis config/database.yml
  - bundle exec rake db:schema:load
  - curl -L > ./cc-test-reporter
  - chmod +x ./cc-test-reporter
  - ./cc-test-reporter before-build
  - bundle exec rake
  - ./cc-test-reporter after-build -t simplecov --exit-code $TRAVIS_TEST_RESULT

I cannot figure out what is preventing psql from finding the Postgresql 11.2 service. Any help would be very much appreciated.

Without looking into too much details yet, it appears to me that the package is found and configured to run on the next-available port, 5433:

I would imagine that your psql by default will connect to port 5432, but nothing is listening on that port.

Hi Hiro,

Thanks for your reply. I tried your suggestion by setting PGPORT=5433 but unfortunately psql is still not connecting:

There must be something else I’m missing.


Actually, I see that psql is still looking for the PostgreSQL server on port 5432 so setting the PGPORT environment variable has not had any effect. :thinking:

I had this problem too. Here’s the config file that fixed it for me:

This script:

  1. Shuts down all 9.* postgreSQL databases
  2. installs 11.2 (at the time of this writing)
  3. copies the authentication information from the old 9.6 configuration
  4. creates a role called “travis”
language: ruby
rvm: 2.6.2
  - 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  
  - 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
  - postgresql
  postgresql: "11.2"
1 Like

Thanks very much for your response, @jondoesntgit. Much appreciated. And apologies for the delay in replying. You’re suggestion worked for me!

Happy to help.

I was stuck on this issue for like 3 hours, and your comment solved it, thank you so much @jondoesntgit