I have created a .pgpass
file in my home directory which looks like this
localhost:5432:somedb:someuser:somepass
I am using a shell scr
psql (startup.c) calls PQconnectdbParams (fe-connect.c), and then passwordFromFile is called. Here’s a checklist to make sure the pgpass file will be used:
--password
/-W
and password=
in the connection string are unset. Otherwise, the pgpass file will not be used.PGPASSWORD
is unset (echo $PGPASSWORD
). Otherwise, the pgpass file will not be used.$PGPASSFILE
or default ~/.pgpass
or %APPDATA%\postgresql\pgpass.conf
)chmod 600 ~/.pgpass
); otherwise psql
will print a warning.psql
will print a warning.psql
user (e.g. cat ~/.pgpass
); otherwise psql
will ignore it without warning. Make sure that it is owned by the user, and that all its ancestor directories are executable by the user.hostname:port:database:username:password
(The Password File, passwordFromFile). Each field (other than password) can be *
. The characters :
and \
must be escaped \:
and \\
(even in password). The password ends at :
or the end of the line and can include any byte other than \r
, \n
, or \0
. Any lines that aren’t formatted right or don’t match the host and user are ignored without warning as if they were comments.*
. The server’s “pwhost” that is checked is the host
name if non-empty, or the hostaddr
ip address. Otherwise, the line will be ignored without warning.Unfortunately, there is no logging within these files, so if this doesn’t help, then you may need to compile psql
and libpq
yourself and run it in a debugger.