PostgreSQL: FATAL – Peer authentication failed for user (PG::ConnectionBad)

“Peer authentication” means that it’s using a unix socket and expecting the connecting unix user to have the same unix username as the postgresql username.

Since your local unix username is funkdified and you’re trying to connect as user goodsounds over a unix domain socket (local) connection where your pg_hba.conf specifies peer authentication, Pg correctly rejects your connection attempt.

This is the default behaviour for many installs when using unix sockets.

You can:

  • Connect via TCP/IP by specifying a hostname in your database connection settings;
  • edit pg_hba.conf to use md5 password authentication instead of peer authentication for unix sockets (local connection type) so Pg accepts password authentication; or
  • Connect with a PostgreSQL username the same as your unix username and create the user in PostgreSQL if it doesn’t exist yet.

See the docs for pg_hba.conf and the rest of the client authentication chapter of the documentation.

Note that changes to pg_hba.conf do not take effect immediately, you must restart or at least reload PostgreSQL to get it to reread pg_hba.conf.


Oh, also, if you have multiple PostgreSQL versions installed you might have a libpq from one version and a server from another. In this case make sure the location for the unix socket that libpq connects to by default is the same as the server’s unix_socket_directories or override it with (e.g.) host=/tmp in your connection string.

Leave a Comment