Chris Weldon bio photo

Chris Weldon

A savvy software engineer and agilist, Chris slings code in C#, but has also been known for commanding fleets of systems. He's currently a Tech Lead at Wolters Kluwer.

Email Twitter Facebook Github

I am setting up monitoring for my PostgreSQL database server, and ran across a cool way to get around specifying the username/password via the command-line every time the checks are run: pg_service.conf. Unfortunately, there is very little documentation on the config file. As best as I can figure out, if you are connecting to a remote host, your definitions should look as follows:

[service.name.here]
dbname=db.name.here
user=user.name.here
host=host.name.here
password=password.here

On a Gentoo Linux server with PostgreSQL 8.4 installed, this file will need to be placed at /etc/postgresql-8.4/pg_service.conf. Then, to reference it, simply export the PGSERVICE environment variable with the value of the name of the service in brackets.