1

After installing and opening the psql shell, it throws this error BEFORE even asking the password I had set during install:

psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "postgres"

I enter the default user ("postgres") and it immediately throws the error before prompting me to enter the password as everyone else's shell.

Tried to look at the pg_hba.conf file and changing the METHOD from scram-sha-256 (the one that was originally set) to md5 and password, but no good.

I know I can just set it to trust but that doesn't seem right. Why is this happening? How can it be an installing mistake if it doesn't even wait for me to the enter the password?

  • 1
    What is "the psql shell"? People who say that are usually on Windows and are talking about some kind of bat file which is wrapper, not the real `psql` binary. – jjanes Nov 17 '22 at 22:51
  • 1
    If a password is supplied by .pgpass file or by PGPASSWORD environment, then psql (without -W option) will not prompt for a password, but will just use the one supplied. – jjanes Nov 17 '22 at 22:53
  • Yes, I'm trying to use PostgreSQL on Windows (my desktop at work). It comes with an app called SQL Shell (psql) and the pgAdmin 4 app. When I open the SQL Shell and try to connect, it throws the error. Also, I can't find the .pgpass file on %appdata% or anywhere else, even though i'm checking for hidden items on the Explorer. –  Nov 18 '22 at 12:18

2 Answers2

2

First of all, check did you set up a password for the 'postgres' user. Then try to change in the file /var/lib/pgsql/data/pg_hba.conf all values 'ident' to 'scram-sha-256' And then restart server: sudo systemctl restart postgresql.service

vitallium
  • 61
  • 3
0

Open terminal.

Log in to your postgres sql: sudo -u postgres psql postgres

You have to set up a new password for postgre so now After you see the postgres prompt type in: \password postgres

Enter your new password, confirm it and reopen postgres again. This should work.