How do you configure PostgreSQL to allow the default postgres user to login without a password from localhost?
There are several similar questions, such as this and this, but none of the suggestions to modify pg_hba.conf
have worked for me. However, based on my understanding of the pg_hba.conf
rules, I should be able to accomplish this with either the peer
or trust
options.
I'm trying to run a command like:
sudo psql --user=postgres --no-password --command="blah;" -h 127.0.0.1
If I try this line in my pg_hba.conf
:
local all postgres trust
my command fails with the error:
psql: FATAL: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", SSL on
FATAL: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", SSL off
If I tried this line:
local all postgres peer
my command fails with the same error.
How do I fix this?
conf file and change all local connections from md5 to trust. By doing this, you can log in to the PostgreSQL database server without using a password. The "C:\Program Files\PostgreSQL\12\data" is the data directory. PostgreSQL will not require a password to login.
When you specify -h 127.0.0.1
that is not a "local" connection - it's a host (=TCP based) connection. So a line starting with local
will not match for such a connection.
To make that entry work, do not specify a hostname or port for psql
, then it will use a "local" connection through named pipes.
Alternatively, you can local
with host
and then add 127.0.0.1
as the (client) IP address to "trust".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With