I have freshly installed postgresql 9.4 on my ubuntu 14.10 box and I have run \password as the postgres user and given it the password postgres:

$> sudo -u postgres psql
=# \password
Enter new password: postgres
Enter it again: postgres
=# \q

I have also updated the /etc/postgresql/9.4/main/postgresql.conf with listen_addresses='localhost' and restarted postgresql.


When I run psql -U postgres -h localhost I am still prompted for a password.


What else should I try in order to prevent being prompted for a password while executing psql commands locally?


I finally found the answer here. The issue was that I was missing the ~/.pgpass file. So I created one with access permission 600 (this is important) and added the following lines:


After a restart of postgresql all was well :)

| improve this answer | |
  • Thanks! Helped me on postgresql 11, Ubuntu 16.04. – Andrey Artemyev Jan 29 '19 at 13:24
  • This is what I've been looking for – imans77 Apr 15 '19 at 14:41

I finally find the answer and it works fine for me.

Change postgres user’s password

PostgreSQL is provided with a default user named ‘postgres’. For this, we will use this role and change its password. Run following command to jump into postgreSQL cmd.

sudo -u postgres psql postgres

Enter your root/sudo password. This will take you to the psql cmd which will be prompted like


Here ‘postgres’ is the username you’re currently logged in with. Now run following command to change password.

\password postgres

This will prompt you to enter your new password for user ‘postgres’ and then will ask you to confirm it by reentering it. You’re done with possible solution.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.