Making use of .pgpass

A very common way to store login information is via the use of .pgpass files. The idea is simple: put a file called .pgpass into your home directory and put your login information there. The format is simple:

hostname:port:database:username:password  

An example would be:

192.168.0.45:5432:mydb:xy:abc  

PostgreSQL offers some nice additional functionality: most fields can contain *. Here is an example:

*:*:*:xy:abc  

This means that on every host, on every port, for every database, the user called xy will use abc as the password. To make PostgreSQL use the .pgpass file, make sure that the right file permissions are in place:

chmod 0600 ~/.pgpass  

.pgpass can also be used on a Windows system. In this case, the file can be ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.