If you’re getting a FATAL: Ident authentication failed for user [username] Error when attempting to connect to postgres as a specific user, chances are you need to change some security settings.

Postgresql, by default, only allows you to connect to postgres if the postgres username is the same as your username on the operating system. In other words, if you’re logged in to your computer as frank, you can, in general, only connect to the postgres server as the frank user.

To allow connection as any existing postgres user, the following lines need to be added to the pg_hba.conf:

local all all trust
host all all 127.0.0.1/32 trust

Note that if there is a line in the file like:

local all all ident sameuser

Then the extra lines you add need to be above this line.

If you don’t know where to find this file, on ubuntu it can be found at:

/etc/postgresql/[version]/main/pg_hba.conf

This path should be similar on other linux distributions.

  1. John says:

    Wouldn’t it be better to use md5 instead of trust for security purposes?

  2. Tim says:

    You’re right, using md5 instead of trust would be more secure, but would require you to enter your password each time you logged in. Obviously you wouldn’t use the above method on a production machine, but instead would possibly have a more complicated and secure option where specific user access is managed independently.

    In short, if there are other users on the same machine who should not have access, replace the words trust with md5.