[Fixed] How do I fix scram authentication errors when connecting DBeaver to a docker postgresql container? – Postgresql

by
Ali Hasan
dbeaver postgresql

Quick Fix: Change pg_hba.conf back to allow connections without scram, connect with DBeaver client , re-encrypt the password this time using scram, restore the original scram line in the pg_hba.conf and restart the database.

The Solutions:

Solution 1: Adjust PostgreSQL Configuration to Fix SCRAM Authentication Errors

  1. Edit pg_hba.conf to Disable SCRAM Requirement Temporarily:

    Edit your pg_hba.conf file to allow connections without SCRAM encryption by commenting out the "host all all all scram-sha-256" line and adding "host all all all trust" instead.

  2. Restart PostgreSQL:

    Restart your PostgreSQL server using "docker-compose down; docker-compose up -d; docker-compose logs -f".

  3. Connect to PostgreSQL with DBeaver:

    Connect to your PostgreSQL database using DBeaver.

  4. Change User Passwords to Use SCRAM Encryption:

    For each user with a password not encrypted in SCRAM, reset their password using the DBeaver "Security" menu. Enter the same password twice to maintain the value but encrypt it using SCRAM.

  5. Verify Password Encryption:

    Run the SQL query "SELECT rolname, rolpassword ~ ‘^SCRAM-SHA-256$’ AS has_upgraded FROM pg_authid WHERE rolcanlogin;" to check if the passwords are now encrypted in SCRAM.

  6. Re-enable SCRAM Requirement in pg_hba.conf:

    Edit pg_hba.conf again, comment out the "host all all all trust" line, and restore the "host all all all scram-sha-256" line.

  7. Restart PostgreSQL Again:

    Restart your PostgreSQL server once more.

  8. Reconnect DBeaver:

    Reconnect to your PostgreSQL database with DBeaver. You should now be able to log in without any SCRAM authentication errors.

Q&A

What is the error of scram authentication?

The password in the posgres database is using md5, not scram.

Why is the md5 password not accepted?

The upgraded version of postegresql requires that only scram encryption be used by clients and the md5 password not accepted.

How to change the password to be scram encrypted?

Connect to the database with the md5 password via a client like DBeaver and then change the password via the client to the same password.

Video Explanation:

The following video, titled "How to Fix PostgreSQL Connection to Server at Localhost (::1) Port ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

In This Video We Will See How to Fix PostgreSQL Connection to Server at Localhost (::1) Port 5432 Failed Connection Refused ...