When i try to login from command line like this
psql -h dbserver -U testuser test
then i get this error
psql: FATAL: Ident authentication failed for user "testuser"
This is my
nano -w /var/lib/pgsql/data/pg_hba.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 ident
host all all 192.168.0.1/24 password
There are two ways to login PostgreSQL: By running the "psql" command as a UNIX user which is also configured as PostgreSQL user using so-called IDENT/PEER authentication, e.g., " sudo -u postgres psql ". Via TCP/IP connection using PostgreSQL's own managed username/password (using so-called MD5 authentication).
To authenticate network connections from the PostgreSQL server's machine (non-socket connections) using passwords, you need to match a host connection type instead of local . You can then limit the acceptable addresses to the local loopback devices and allow users to authenticate using md5 or scram-sha-256 .
You can also connect to PostgreSQL database using pgAdmin GUI application. Connect to the database at localhost:5432 using the user name postgres and the password supplied. Now, double click on PostgreSQL 9.4 under the "Servers Groups". pgAdmin will ask you for a password.
You can't specify a non-default user with -U
in psql
when using ident
authentication. You won't be running psql
as that user, so auth will fail.
You must either use sudo -u testuser psql test
or change pg_hba.conf
so that authentication (at least for testuser
on the db test
) uses md5
password authentication, and set a password for testuser
with ALTER USER ... PASSWORD
if they don't have one already.
I saw the following errors in /var/lib/pgsql/data/pg_log/postgresql-Wed.log
:
LOG: provided username (DB_USER) and authenticated username (SHELL_USER) don't match FATAL: Ident authentication failed for user "DB_USER"
The solution in my case was to change all the authentication methods in /var/lib/pgsql/data/pg_hba.conf
to md5
With abovementioned, there can be two reasons for this issue - testuser not existing - wrong password or authentication failure for the user.
Here is what I did to resolve this in Windows:
Check for the Login/Group Roles tab under Server "PostgreSQL". Check if the user is existing. You can also do this by logging to "postgres" user via command "psql -U postgres" and running command "\du"
If user testuser does not exist, create it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With