5

I just installed PostgreSQL 13 on Windows 10. In the command prompt I did:

C:\Users\Max>cd ../postgres

I then tried to do the createdb command and got this error message:

createdb: error: could not connect to database template1: FATAL:  password authentication failed for user "Max"

After some research I know that if I don’t specify a database user with -U username option, it takes the OS username.

When I cd into the postgres user, why does it still use the user "Max"? Is there a way I can change it to authenticate as postgres when I'm in C:\Users\Max so I don't have to specify the username every time?

1 Answer 1

5

Nevermind I found the answer.

  • Right click on Windows icon and click “System”

  • Scroll down to “Advanced System Settings”

  • Click Environment Variables

  • In “System variables”, click “New”:

    Variable Name: PGUSER

    Variable Value: postgres

2
  • For anyone wondering, you may have to close and reopen your existing terminal session for the environment variable to take effect. Alternatively, you could run set PGUSER=postgres to also set it for the existing session. Then as long as you have set the environment variable in the instructions above, subsequent sessions should already have it set.
    – Cloud
    Commented Sep 11, 2022 at 11:25
  • Thank you, really :)
    – asiftunga
    Commented Sep 24, 2022 at 2:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .