Prevent postgresql commands from asking for user password

Strange, but I was looking for this source of configuration, but could not find it.

I am currently using opensuse 11.3 with postgresql 9.

Each postgresql command line that I issue will ask for the current user password, such as psql, createdb, dropdb, and I have to enter the password of the current user (which is postgres) to make it work.

Running dropdb xxx && createdb xxx will ask for the password twice.

Please show me the light!

Thanks: -)


EDIT

Actually, I already work as a postgres user (user on my Linux), so I can psql without supplying a database password, but I still need to provide a password for postgres system users.

So, if there is a dbuser user in the database and im running psql as postgres (linux user), the password for the linux user (postgres) will be requested, not the dbuser password.

+4
source share
3 answers

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

 hostname:port:database:username:password 

See the documentation for more details.

+8
source

If you use openuse, you can create the .pgpass file by doing:

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

With all the necessary information, of course.

+3
source

if you have the .pgpass file .pgpass to allow a specific user to access a specific database (let me call it "myprojectdb"), remind that creatdb and dropdb do not actually act on "myprojectdb", despite the fact that you can ask them to create and delete this db.

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

+2
source

Source: https://habr.com/ru/post/1343408/


All Articles