I just installed postgresql and pgadmin from the repos on Fedora 36. I set up the initial postgres role and database, and logged in with the postgres user
sudo su - postgres
psql
From there, I set up a new user with an encrypted password: CREATE ROLE john WITH ENCRYPTED PASSWORD '123';
I also added this line to my pg_hba.conf:
host all all 127.0.0.1/32 scram-sha-256
Now, from unix, as the root user, if I try: psql -U john -W -h 127.0.0.1, I get this error:
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: Ident authentication failed for user "john"
pgadmin also fails to login to the database with a similar error message.
But if I go into pg_hba.conf and disable this line:
host all all 127.0.0.1/32 ident
All of a sudden, I can login from both pgadmin and with the psql -U john -W -h 127.0.0.1 command from the root user.
Am I doing something wrong? Why do I need to disable ident auth entirely for this to work? I don't see any way to force password auth, rather than ident auth from the psql client, or in pgadmin.
Edit - this is my pg_hba.conf:
local all all peer
#host all all 127.0.0.1/32 ident
host all all ::1/128 ident
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
host all all 127.0.0.1/32 scram-sha-256
This is basically the default that came with postgres from the repos, but I:
- Commented out the one
identline - Added the last line
pg_hbawe need to see the entire file. Please, paste it into the question (ommting comments and blank lines). Also we could need user name and database name, since it is possible to craft pg_hba to act differently for different users and databases.