[Fixed]-Django โ€“ (OperationalError) FATAL: Ident authentication failed for user "username"

42๐Ÿ‘

โœ…

Your pg_hba.conf is configured to use โ€˜identโ€™ authentication for connections from localhost (127.0.0.1). You need it to be changed to md5 for your database and user combination.

๐Ÿ‘คCraig Ringer

8๐Ÿ‘

@Craig is right, have to update the authentication method of the database user in the file pg_hba.conf, here what Iโ€™ve done:

sudo nano /var/lib/pgsql/data/pg_hba.conf

Go to the bottom of the file, then change the method from ident to md5 on the IPv4 and IPv6 rows:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5  # <- here
# IPv6 local connections:
host    all             all             ::1/128                 md5  # <- and here
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

Happy Coding ๐Ÿ™‚

๐Ÿ‘คMehady

2๐Ÿ‘

  local   all             all                                     peer

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust < from ident to trust 
# IPv6 local connections:
host    all             all             ::1/128                 trust < i changed this from ident to trust 
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident

Donโ€™t forget to restart postgresql:

sudo systemctl restart postgresql
๐Ÿ‘คchihab mg

0๐Ÿ‘

Had the same Error, only to resolve in my case instead of md5 I used trust. This is because 1) Django needs SELECT, INSERT, DELETE and UPDATE permissions and 2) using the postgres user does not require a password.

๐Ÿ‘คDajuan Mcdonald

Leave a comment