Database Reference
In-Depth Information
How to do it...
First, create a file named
pg_service.conf
with the following contents:
[dbservice1]
host=postgres1
port=5432
dbname=postgres
You can then either copy it into place at
/etc/pg_service.conf
or another agreed central
location. You can then set the environment variable
PGSYSCONFDIR
to that directory location.
Now, you can then specify a connection string like the following:
service=dbservice1 user=sriggs
The service can also be set using an environment variable named
PGSERVICE
.
How it works...
This applies to libpq connections only, so does not apply to JDBC.
The connection service file can also be used to specify the user, though that would mean that
the username would be shared.
pg_service.conf
and
.pgpass
can work together, or you can use just
onr
or the other,
as you choose. Note that the
pg_service.conf
file is shared, and so is not a suitable place
for passwords.
Troubleshooting a failed connection
This section is all about what you should do when things go wrong.
Bear in mind that 90% of problems are just misunderstandings, and you'll be on track again
fairly quickly.
How to do it...
F
Check whether the database name and username are accurate: You may be
requesting a service on one system when the database you require is on another
system. Recheck your credentials. Check especially that you haven't mixed things
up so that you are using the database name as the username and/or the username
as the database name. If you receive "too many connections", then you may need to
disconnect another session before you can connect, or wait for the administrator to
re-enable the connections.