Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preventing postgresql commands from keep asking for user password

It's strange, but i've searched around for this source of configuration but couldnt find it out.

Im currently using opensuse 11.3 with postgresql 9.

Every postgresql command line that i issue will ask the current user password, like psql, createdb, dropdb, and i have to enter the password of the current user (which is postgres) to make it work.

Doing dropdb xxx && createdb xxx will ask the password twice.

Please show me the light !

Thank you :-)


EDIT

Actually im already running as a postgres user (a user in my linux), so i can psql without supplying the database password, but i still have to supply the password for the system user postgres.

So if the database has a user of dbuser, and im running psql as the postgres (linux user), a password for the linux user (postgres) will be asked, not the dbuser password.

like image 432
Albert Gan Avatar asked Mar 12 '11 04:03

Albert Gan


2 Answers

You can create a ~/.pgpass file (%APPDATA%\postgresql\pgpass.conf on Windows) with a line in the following format:

hostname:port:database:username:password

See the documentation for details.

like image 163
Anomie Avatar answered Sep 30 '22 23:09

Anomie


If you're on opensuse you should be able to create a .pgpass file by running:

echo "hostname:port:database:username:password" > ~/.pgpass
chmod 0600 ~/.pgpass

With all of the correct information of course.

like image 26
CraigKerstiens Avatar answered Sep 30 '22 22:09

CraigKerstiens