After having used createuser
and createdb
to create a user and database both called teamcity
I wanted to log in. Using both of these commands, I never said anything about which host the database was running on, so I would assume that when using psql
it would use the same settings. This is what happens if I do not supply a hostname:
$ psql -U teamcity
psql: FATAL: Peer authentication failed for user "teamcity"
No password prompt and immediate failing. If I supply -W
to force a prompt, the password does not work. I am logged in as a normal unix user, not the postgres
user.
Now, if I supply -h localhost
everything works as it should:
$ psql -h localhost -U teamcity
Password for user teamcity:
Timing is on.
Line style is unicode.
Border style is 2.
Null display is "[NULL]".
Expanded display is used automatically.
psql (10.11 (Debian 10.11-1.pgdg80+1))
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
localhost teamcity@teamcity=> \q
What can explain this behaviour? I assume some of the commands connect to the postgres using unix sockets and some using TCP, but it should be the same database, no matter, right, so why is the authentication failing in some cases?