0

When I deploy postgres like the following snippet everything works:

.
.
.
  env:
     - name: POSTGRES_USER
       value: a
.
.
.

But when I deploy it by configMap or secret for example:

        env:
          - name: POSTGRES_USER
            valueFrom:
              secretKeyRef:
                name: postgres
                key: username

when I execute psql -U it returns: psql: error: could not connect to server: FATAL: role "a" does not exist

I checked environment POSTGRES_USER and this variable is set to a

1
  • I forgot to mention image version. it was postgres:12.3 Commented Jan 30, 2022 at 15:23

1 Answer 1

1

Accordingly to the documentation from the PostgreSQL image:

The only variable required is POSTGRES_PASSWORD, the rest are optional.

You're defining a custom role, which is okay but you're not passing the POSTGRES_PASSWORD which is mandatory. It's possible the role is not created at all if you don't pass the password.

Another important comment from the documentation:

Warning: the Docker specific variables will only have an effect if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.

If this is not a playground/stateless environment and you're loading existing data, the startup script won't look at the environment variables and you should use credentials that were previously configured.

Sign up to request clarification or add additional context in comments.

1 Comment

tnx for your answer. but I passed the password in the ... parts. and when I pass it directly through docker environment it works (but not works through kuber config map or secret). I think its kubernetes related problem and not related to postgres image (imagine kubernetes starts the container and then sets the environment variable after starting the postgres).

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.