1

I work with PostgreSQL 9.2 and have command:

psql -h localhost -U testdb -d postgis

This command has the ability to connect database without password. I want to enter a password.

My pg_hba.cconf is:

local   all             all                                     password
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
2
  • have you restarted the server after you changed config file? Commented Oct 27, 2013 at 18:28
  • @IgorRomanchenko: A reload should suffice. Commented Oct 27, 2013 at 18:42

1 Answer 1

1

Password-less access requires that one of several authentication methods is configured accordingly. More details in these related answers:
pgadmin gives me the error: no password supplied
Run batch file with psql command without password

In particular, localhost is not a "local connection" in the pg_hba.conf file in the second one. Since you are connecting with -h localhost, only the lines starting with host in your pg_hba.conf file are applicable, so a password should be required.

Remaining explanations:

  • You did not reload since the config file was changed.

  • You are not showing the right (or complete) pg_hba.conf (or inadvertently connecting to the wrong db cluster. Port 5432?) and there is in fact a line with peer or ident authentication that comes before other host lines.

  • Your installation has a .pgpass file in place, that grants access to the system user you are running the command with. For details, refer to the second linked answer.

The last one seems most likely.

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

Comments

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.