"Peer authentication failed" means PostgreSQL is using peer authentication, which checks whether the current Linux system user matches a PostgreSQL role with the same name. For example, if you’re logged in as the Linux user john, PostgreSQL expects a database role named john. If they don’t match, you’ll see this error.
To fix the issue, do the following:
- Open the PostgreSQL authentication configuration file: /etc/postgresql/17/main/pg_hba.conf. (Replace 17 with your actual PostgreSQL version if different.)
- Change this line:
local all all ident
to
local all all md5
- Save the file and restart PostgreSQL:
sudo systemctl restart postgresql
After this change, PostgreSQL will use password-based authentication (md5) instead of matching Linux usernames, and the "peer authentication failed" error should be resolved.