3

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.

ISSUE

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

QUESTION

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

2 Answers 2

4

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:

localhost:*:*:postgres:postgres
127.0.0.1:*:*:postgres:postgres

After a restart of postgresql all was well :)

2
  • Thanks! Helped me on postgresql 11, Ubuntu 16.04. Jan 29, 2019 at 13:24
  • This is what I've been looking for
    – imans77
    Apr 15, 2019 at 14:41
0

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

postgres=#

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .