1

I have set pgpassword in .bashrc:

vim .bashrc 
export PGPASSWORD=pass_for_postgresql

It is no need to type password for command psql -U postgres. When i dump a table from db1 into db2 with :

pg_dump -U postgres -t table db1 | psql -U postgres -W db2

The command will ask me to type password. I have googled an article to dicuss this
http://www.londatiga.net/it/database-it/how-to-use-postgresql-pgdump-in-crontab-without-password/

Create a ~/.pgpass file in user’s home directory with the following format:

hostname:port:database:username:password
Ex: localhost:5432:mydatabase:lorenz:lorensxyz

There are many databases here,how can write the .pgpass file then?

localhost:5432:db1,db2,db3,db4:postgres:pass

How can make PG_DUMP work for all databases without asking password?

1
  • 1
    Yes, making it prompt for a password is what -W does. If you don't want that, don't use -W. This is no different between psql and pg_dump.
    – jjanes
    Commented Mar 27, 2023 at 14:34

1 Answer 1

2

You should use .pgpass. The entry could look like

localhost:5432:*:postgres:pass

to work with any database in the cluster. Make sure that the file has no permissions for anybody but the owner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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