psql: FATAL: role “postgres” does not exist (with -h localhost option)

孤者浪人 提交于 2020-01-14 09:36:17

问题


I have Postgres installed in my local machine.

When I execute

psql -U postgres -d buzzsumo

it correctly asks for my password to the user postgres.

However, when I run

psql -U postgres -d buzzsumo -h localhost

it gives me this error message:

psql: FATAL: role "postgres" does not exist

Why is this the case, when in the first example I am connecting to my local server, which is equivalent to passing in localhost?


回答1:


You don't say but I'm guessing you're running postgres on either on MacOS or Linux.

The first form (with no -h) connects via a "unix socket". The second form, with "-h localhost" connects via TCP/IP to localhost (IP address 127.0.0.1).

Postgres treats these two types of connections differently - or at least, it can do so. If you check the "pgsql/data/pg_hba.conf" file to see what authentication mechanisms are configured for the two types of connections.




回答2:


Your first example connects via Unix socket, the second one via TCP/IP local loop (localhost).

For the first example, you need the connection type local in pg_hba.conf, for the second lines starting with host are relevant. You probably have defined different authentication methods for these classes of connections.



来源:https://stackoverflow.com/questions/14845348/psql-fatal-role-postgres-does-not-exist-with-h-localhost-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!