2 32.16. The Password File #
4 The file .pgpass in a user's home directory can contain passwords to be
5 used if the connection requires a password (and no password has been
6 specified otherwise). On Unix systems, the directory can be specified
7 by the HOME environment variable, or if undefined, the home directory
8 of the effective user. On Microsoft Windows the file is named
9 %APPDATA%\postgresql\pgpass.conf (where %APPDATA% refers to the
10 Application Data subdirectory in the user's profile). Alternatively,
11 the password file to use can be specified using the connection
12 parameter passfile or the environment variable PGPASSFILE.
14 This file should contain lines of the following format:
15 hostname:port:database:username:password
17 (You can add a reminder comment to the file by copying the line above
18 and preceding it with #.) Each of the first four fields can be a
19 literal value, or *, which matches anything. The password field from
20 the first line that matches the current connection parameters will be
21 used. (Therefore, put more-specific entries first when you are using
22 wildcards.) If an entry needs to contain : or \, escape this character
23 with \. The host name field is matched to the host connection parameter
24 if that is specified, otherwise to the hostaddr parameter if that is
25 specified; if neither are given then the host name localhost is
26 searched for. The host name localhost is also searched for when the
27 connection is a Unix-domain socket connection and the host parameter
28 matches libpq's default socket directory path. In a standby server, a
29 database field of replication matches streaming replication connections
30 made to the primary server. The database field is of limited usefulness
31 otherwise, because users have the same password for all databases in
34 On Unix systems, the permissions on a password file must disallow any
35 access to world or group; achieve this by a command such as chmod 0600
36 ~/.pgpass. If the permissions are less strict than this, the file will
37 be ignored. On Microsoft Windows, it is assumed that the file is stored
38 in a directory that is secure, so no special permissions check is made.