Using service files

However, .pgpass is not the only file you can use. You can also make use of service files. Here is how it works. If you want to connect to the very same servers over and over again, you can create a .pg_service.conf file. It will hold all of the connection information you need.

Here is an example of a .pg_service.conf file:

Mac:~  hs$ cat .pg_service.conf 
# a sample service [hansservice] host=localhost port=5432 dbname=test user=hs password=abc [paulservice] host=192.168.0.45 port=5432 dbname=xyz user=paul password=cde

To connect to one of the services, just set the environment and connect:

iMac:~ hs$ export PGSERVICE=hansservice  

A connection can now be established without passing parameters to psql:

iMac:~ hs$ psql
psql (11.0)
Type "help" for help. 
test=#  

Alternatively, you can use the following:

psql service=hansservice
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset