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?
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.