From PostgreSQL wiki
Most access to the database, including the psql program, goes through the libpq library. This library includes a feature where if you specify a file called .pgpass (or the file referenced by PGPASSFILE) you can put the password needed to connect as a user in there. This allows automating routine administration tasks through mechanisms like cron.
The format of the .pgpass file is the following:
When the password contains a colon (:), it must be escaped by a backslash (\:).
the character '*' can match any value in any of the fields (except password)
n.b.: if the environment variable PGPASSWORD is set, then the ~/.pgpass file is not read
Example PGPASSFILE value for a path with spaces on Windows 7 64-bit:
set PGPASSFILE=C:\Program Files\someapp\pgpass.conf
Note that the environment variable value must not use " (double quotes).