Pg dump without a password

Sometimes you want to make a database dump without providing the password.

Providing it in the command is a security issue if the history is recorded.

Hence, the user that does the command should have this file in his home directory:



This only works if this file has permissions 600:

$ chmod 600 ~/.pgpass

This lets you connect as a Postgres user who requires a password without having to actually enter the password. You don't even need the -p or --password.

Or, instead of using a .pgpass file, set an ENV named PGPASSWORD with your Postgres database password. For Heroku you would be able to do this like so:

$ heroku config:set PGPASSWORD=secretPassword