Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FATAL: role "$POSTGRES_USER" does not exist #15

Open
dangernil opened this issue Sep 23, 2020 · 8 comments
Open

FATAL: role "$POSTGRES_USER" does not exist #15

dangernil opened this issue Sep 23, 2020 · 8 comments

Comments

@dangernil
Copy link
Contributor

Error message in nomad Postgres service stderr saying postgress_user does not exits

Docker env does show a postgres_user

ERROR MSG: FATAL: role "$POSTGRES_USER" does not exist

@dangernil dangernil added the bug label Sep 23, 2020
@zhenik
Copy link
Contributor

zhenik commented Sep 23, 2020

@dangernil might need to investigate further the docker image

@dangernil dangernil self-assigned this Sep 25, 2020
@zhenik zhenik added this to the 0.2.0 milestone Sep 30, 2020
dangernil pushed a commit that referenced this issue Sep 30, 2020
* update test command

* comment terraform-required_providers

* update cd/ci test with condition
@pdmthorsrud pdmthorsrud removed the bug label Oct 14, 2020
@zhenik zhenik removed this from the 0.2.0 milestone Oct 21, 2020
@claesgill claesgill self-assigned this Nov 6, 2020
@claesgill claesgill added this to the 0.3.0 milestone Nov 6, 2020
@claesgill claesgill modified the milestones: 0.3.0, 0.4.0 Nov 9, 2020
@claesgill
Copy link
Contributor

claesgill commented Nov 13, 2020

Have been struggling with this issue. The error seems to disappear when using user provided username in the check stanza that is directly rendered into args (fixed in #53 ):

    service {
      ...
      check {
        ...
        command   = "/usr/local/bin/pg_isready"
        args      = ["-U", "${username}"]
        ...
      }

However for some reason it does not like using env variables in the check stanza (thus the issue):

    service {
      ...
      check {
        ...
        command   = "/usr/local/bin/pg_isready"
        args      = ["-U", "$POSTGRES_USER"]
        ...
      }

Problem with the latter is that I think we need to get the username from Vault, but I'm not sure how we can achieve this since the check stanza does not support using Consul template..

Suggestions would be dearly appreciated 🙏 @pdmthorsrud @zhenik @dangernil

@pdmthorsrud
Copy link
Contributor

pdmthorsrud commented Nov 13, 2020

Considering the error msg FATAL: role "$POSTGRES_USER" does not exist, and that it seems to be looking for the string $POSTGRES user, are you sure it is all render properly/syntax is correct? I'm not entirely sure you can access env-variables like that in nomad

EDIT: Shouldn't it be "${POSTGRES_USER}"? https://www.nomadproject.io/docs/runtime/interpolation

@zhenik
Copy link
Contributor

zhenik commented Nov 13, 2020

If I understood you correctly.

If you want access env variable from host container and avoid rendering issues with terraform, you can try to use double $$

args      = ["-U", "$$POSTGRES_USER"]

Also, it is important to notice the service stanza placement. It could be placed both under group and under task.
It will influence check stanza at last. Documentation

I have checked that check is specified for concrete task here https://github.com/fredrikhgrelland/terraform-nomad-postgres/blob/master/conf/nomad/postgres.hcl#L38 , than the placement should not be a problem.

@pdmthorsrud
Copy link
Contributor

pdmthorsrud commented Nov 13, 2020

If I understood you correctly.

If you want access env variable from host container and avoid rendering issues with terraform, you can try to use double $$

args      = ["-U", "$$POSTGRES_USER"]

Oooh, that might be it, I was thinking in the wrong context. Disregard my earlier comment, I am wrong!

@claesgill
Copy link
Contributor

If I understood you correctly.

If you want access env variable from host container and avoid rendering issues with terraform, you can try to use double $$

args      = ["-U", "$$POSTGRES_USER"]

Also, it is important to notice the service stanza placement. It could be placed both under group and under task.
It will influence check stanza at last. Documentation

I have checked that check is specified for concrete task here https://github.com/fredrikhgrelland/terraform-nomad-postgres/blob/master/conf/nomad/postgres.hcl#L38 , than the placement should not be a problem.

This resolves to the following error 😅 :

2020-11-13 13:49:10.371 UTC [114] FATAL:  role "$$POSTGRES_USER" does not exist

I will look more into the documentation you have linked 🤞

@zhenik zhenik removed this from the 0.4.0 milestone Nov 26, 2020
@pdmthorsrud
Copy link
Contributor

pdmthorsrud commented Aug 4, 2021

Eyo, just wanted to mention that this is something that has actually surfaced again. To be frank, I'm guessing it never really went away. What implications it has I'm not sure of. Postgres seems to be working fine while doing queries directly to postgres at least

edit: if someone outside of Skatteetaten sees this I'm sorry, I just linked to an internal project in skatteetaten 🤷

@claesgill claesgill removed their assignment Sep 1, 2021
@nadiia-kotelnikova
Copy link

Will post it here if it can help someone. I had the same error in Kubernetes livenessProbe, that how I specified the command: command: ["/bin/bash", "-c", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants