5

I recently installed Postgre version 10 on a linux red hat. I'm trying to configure that psql will prompt a user for password when accessing the database. After changing everything to scram-sha-256. I'm getting this error when accessing psql

psql: FATAL:  password authentication failed for user "postgres"

This is my pg_hba.conf: enter image description here

Any idea how can I fix this? Thanks!

2 Answers 2

10

Postgres store password md5 format as default. If you want to change password encryption you have to follow bellow solution:

P.S: Before start, You have to undo pg_hba.conf file authenticate method to md5

  1. Edit postgresql.conf and change password_encryption to
password_encryption = scram-sha-256
  1. Restart Postgres service (or reload service)

  2. reset the user password

# if use psql cli
\password <user>

# If use SQL command
alter user <user> with password '<password>';
  1. After updating all passwords you should change pg_hba.conf authenticate method to scram-sha-256 and reset service again

Reference: Information about upgrade postgres password authenicate

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

5 Comments

Thanks @Pooya, I've been trying some solutions online but yours work. Thanks!
For step 2 a reload is sufficient.
Yeah, I edited my comment, I am appreciative for tip
@Pooya No luck here. I'm running pg in a Docker, so I'm passing the password in via env var: "POSTGRES_PASSWORD=mypassword". Do I also need to go into the container instance and alter the password, every time I start it up? I haven't tried that yet, but man...this scram stuff has been a headache.
@TsarBomba According to the Postgres image, You can use POSTGRES_HOST_AUTH_METHOD environment for set authenticate method in the Postgres (When init container on first time - without exist postgres filesystem)
1

I know that something that solved to me was in setting a new password (in CMD) when it was necessary to give a password for psql to be recognized:

 set PGPASSWORD= #type here the password you want to set

After setting, you write the following (for example):

psql -h 188.81.81.92 -U postgres -d postgres -p 5432

where -h stands for host, -U for user, -d for the database root, -p for port, using the postgreSQL language.

In windows, it could happen to outcome a problem: error: connection to server (...), which can be solved by typing:

C:\\Program Files\\PostgreSQL\\14\\bin\\psql.exe

this is, you open the file psql.exe and it will work fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.