Some people have recently come across an error with the circleci/postgres
image that looks something like this:
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
The PostgreSQL Docker Team pushed a breaking change as a patch release for several PostgreSQL versions. While a breaking change in a patch release is unfortunate, this change was done for the sake of security.
The Problem
Newer upstream PostgreSQL Docker images, and thus the CircleCI images, now require a password for use. If you were previously using passwordless access to a PostgreSQL DB within CircleCI, it will likely fail.
Affected Versions
Here’s a list of versions for where this change takes affect. This may not be a complete list. Even if you’re using an unaffected version, you can always implement one of the solutions below to future proof from this change.
- v12.2 and up
- v11.7 and up
- v10.12 and up
- v9.6.17 and up
- v9.5.21 and up
Solutions
Option 1 - Implement a password
You can set a password for PostgreSQL using the environment variable POSTGRES_PASSWORD
. Then you’d need to simply use that password when connecting to the DB. Here’s how you would add it to your CircleCI config:
job:
build:
docker:
- image: circleci/postgres:9.6
environment:
#...
POSTGRES_PASSWORD: password
#...
Option 2 - Disable the password requirement
You can disable the new password requirement basically reverting to original behavior of the PostgreSQL image. This is done by setting the environment variable POSTGRES_HOST_AUTH_METHOD
to “trust”. Here’s how you would add it to your CircleCI config:
job:
build:
docker:
- image: circleci/postgres:9.6
environment:
#...
POSTGRES_HOST_AUTH_METHOD: trust
#...
Any questions or additional information to add? Please post them here.