开发者

preventing postgresql commands from keep asking for user password

开发者 https://www.devze.com 2023-02-16 21:04 出处:网络
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.

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.


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.


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.


if you have a .pgpass file setup to allow a certain user access to a certain database (let's call it "myprojectdb"), recall that creatdb and dropdb aren't really acting on "myprojectdb" despite the fact that you may be asking them to create and drop that db.

You'll most likely want to add postgres' internal tables to your pgpass permissions (postgres / templates). Also don't forget to add the --no-password option on both createdb and dropdb to ignore interactive prompts (note this will only work if the user specified with the -U option can modify the internal postgres tables)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号