26

I'm using Bitbucket pipeline with PosgreSQL for CI/CD. According to this documentation PostgreSQL service has been described in bitbucket-pipelines.yml this way:

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine

It worked just fine until now. But all my latest pipelines failed with following error:

   Error: Database is uninitialized and superuser password is not specified.
   You must specify POSTGRES_PASSWORD for the superuser. Use
   "-e POSTGRES_PASSWORD=password" to set it in "docker run".

   You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
   without a password. This is *not* recommended. See PostgreSQL
   documentation about "trust":
   https://www.postgresql.org/docs/current/auth-trust.html

How can I fix it? There was no changes in bitbucket-pipelines.yml file which could be the reason of such error..

3 Answers 3

26

Looks like the reason is docker image's updates (github issue). Latest versions do not allow to connect to DB without a password from anywhere. So you need to specify username/password:

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine
      environment:
         POSTGRES_DB: pipelines
         POSTGRES_USER: test_user
         POSTGRES_PASSWORD: test_user_password

Or if you still don't want to use password, you can just set POSTGRES_HOST_AUTH_METHOD=trust environment variable:

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine
      environment:
        POSTGRES_HOST_AUTH_METHOD: trust
Sign up to request clarification or add additional context in comments.

3 Comments

How do you open those settings?
@LukasSalich it is inside bitbucket-pipelines.yml file.
In the end, there was a different problem with bad command for running container so it's not related.
6

This is a very recent change, as of about a week ago. One way to avoid it is to hardcode your postgres version to not the latest, eg changing to postgres:9.5.18 or postgres:9.5.20-alpine

Another way is to pass a fake password:

services:
  db:
    image: postgres
    ports:
      - "8001:5432"
    environment:
      - POSTGRES_PASSWORD=fake_password

See the discussion here: https://github.com/docker-library/postgres/issues/681

Comments

2

If you are having issues connecting Django to PostgreSQL via Docker for the first time, then add the POSTGRES_HOST_AUTH_METHOD: trust to your docker-compose.yml file:

db: image: postgres:11 environment: POSTGRES_HOST_AUTH_METHOD: trust

This solve the connection issue for me.

Please also be aware that "This is not recommended. See PostgreSQL documentation about "trust": https://www.postgresql.org/docs/current/auth-trust.html"

3 Comments

if this is NOT RECOMMENDED, why suggest it? Alerting that it is not recommended is good, but also providing why you suggest it or providing a work around over it. Will definitely help. Just an Opinion.
A good work around this is to specify a POSTGRES_PASSWORD for the superuser. You can use "-e POSTGRES_PASSWORD=password" to set it in "docker run"
"not recommended" is for a production environment. When inside a docker and running on your local machine there is practically no concern. In fact, it makes a lot of sense!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.