Friday, June 7, 2019

PostgreSQL Password File

To access a PostgreSQL database, we may use a Password file. We can place the Password file any where and references to it via a PGPASSFILE environment variable. Here is an example on Windows:



C:\Work>type ./pgpass
# hostname:port:database:username:password
foodbhost:5432:foodb:foouser:foopassword

C:\Work>set PGPASSFILE=./pgpass

C:\Work>psql -U foodbuser -h foodbhost foodb
psql (9.6.3)
Type "help" for help.

foodb=>

Using this method, we help separate the DB authentication and authorization from the application logic. 

No comments:

Post a Comment