Psql: FATAL: the role "postgres" does not exist (with the -h localhost option)

I have Postgres installed on my local machine.

When i do

psql -U postgres -d buzzsumo

it correctly asks for my password for postgres user.

However, when I run

psql -U postgres -d buzzsumo -h localhost

he gives me this error message:

psql: FATAL: role "postgres" does not exist

Why is this so when in the first example I connect to the local server, which is equivalent to passing to localhost?

+5
source share
2 answers

You do not say, but I assume that you are running postgres on MacOS or Linux.

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

Postgres - - , , . pgsql/data/pg_hba.conf, , .

+2

Unix, - TCP/IP (localhost).

local pg_hba.conf, , host, . , .

+2

All Articles