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

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

Ex: localhost:5432:mydatabase:lorenz:lorensxyz

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


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

  • 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


You should use .pgpass. The entry could look like


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.