
上QQ阅读APP看书,第一时间看更新
How to do it…
A password file contains the usual five fields that we require when connecting, as shown here:
host:port:dbname:user:password
Change this to the following:
myhost:5432:postgres:sriggs:moresecure
The password file is located using an environment variable named PGPASSFILE. If PGPASSFILE is not set, then a default filename and location must be searched for, as follows:
- On *nix systems, look for ~/.pgpass
- On Windows systems, look for %APPDATA%\postgresql\pgpass.conf, where %APPDATA% is the application data subdirectory in the path (for me, that would be C:\)
Don't forget to set the file permissions on the file, so that security is maintained. File permissions are not enforced on Windows, though the default location is secure. On *nix systems, you must issue the following: chmod 0600 ~/.pgpass.
If you forget to do this, the PostgreSQL client will ignore the .pgpass file. While the psql tool will issue a clear warning, many other clients will just fail silently, so don't forget!