Contributed by Fabien Loudet, Linux SysAdmin at Rosetta Stone
The format to use for each line in the file:
hostname:port:database:username:password
Only the owner of the file should have read and write access to it:
chmod 0600 ~/.pgpass
Enjoy passwordless authentication! As long as the connection parameters are properly set in the .pgpass file, you should not be prompted for password
psql -h hostname -U username -h hostname -d database
BONUS: Use password-less authentication on backup scripts with pg_dump
and its -w
option:
pg_dump -h hostname -U username -d database -w > dump.bak