postgresql: .pgpass not working postgresql: .pgpass not working postgresql postgresql

postgresql: .pgpass not working


Did you try specifying the host, user, & db?

pg_dump -U someuser -h localhost somedb > directory/somefile.dump


  1. Create .pgpass file with content

host:5432:somedb:someuser:somepass

  1. set the permissions

sudo chmod 600 .pgpass

  1. Set the file owner as the same user using which you logged in :

sudo chown login_username:login_username .pgpass

  1. Set PGPASSFILE environment variable :

export PGPASSFILE='/home/user/.pgpass'

Now check by connecting to database :

psql -h host -U someuser somedb

It did not prompt for a password, and logged-in to postgresql.


Although question has already been answered and accepted, it may also happen that permissions on .pgpass file are not properly set. It has to have the world and group access disallowed:

/bin/chmod 0600 ~/.pgpass