I have a remote machine and I am trying to log-in into a postgres database with the following command (run as Linux root user via ssh, i.e. locally on that machine):
# psql -d mydatabase -U postgres -W
Password for user postgres: <here goes my password>
psql: FATAL: Peer authentication failed for user "postgres"
For some reason this fails (tried ~5 times).
But when I login to the same database using pgAdmin (i.e. remotely) with same role (postgres) and same password, it logs in successfully every time.
What's wrong with psql command I use? If it is correct, can you suggest any troubleshooting steps?
EDIT: So the problem is that in pg_hba.conf remote and local connections are treated differently. Remote ones are configured properly. The question is why locals don't work.
For locals, I have in pg_hba.conf:
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
Do I understand correctly that for localhost connections it first tries peer authentication, and if it fails it doesn't attempt md5 and just returns error?