14

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?

0

1 Answer 1

15

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

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry I am newbie to postgres, please share the complete psql command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.