]> begriffs open source - ai-pg/blob - full-docs/txt/libpq-pgservice.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / libpq-pgservice.txt
1
2 32.17. The Connection Service File #
3
4    The connection service file allows libpq connection parameters to be
5    associated with a single service name. That service name can then be
6    specified using the service key word in a libpq connection string, and
7    the associated settings will be used. This allows connection parameters
8    to be modified without requiring a recompile of the libpq-using
9    application. The service name can also be specified using the PGSERVICE
10    environment variable.
11
12    Service names can be defined in either a per-user service file or a
13    system-wide file. If the same service name exists in both the user and
14    the system file, the user file takes precedence. By default, the
15    per-user service file is named ~/.pg_service.conf. On Microsoft
16    Windows, it is named %APPDATA%\postgresql\.pg_service.conf (where
17    %APPDATA% refers to the Application Data subdirectory in the user's
18    profile). A different file name can be specified by setting the
19    environment variable PGSERVICEFILE. The system-wide file is named
20    pg_service.conf. By default it is sought in the etc directory of the
21    PostgreSQL installation (use pg_config --sysconfdir to identify this
22    directory precisely). Another directory, but not a different file name,
23    can be specified by setting the environment variable PGSYSCONFDIR.
24
25    Either service file uses an “INI file” format where the section name is
26    the service name and the parameters are connection parameters; see
27    Section 32.1.2 for a list. For example:
28 # comment
29 [mydb]
30 host=somehost
31 port=5433
32 user=admin
33
34    An example file is provided in the PostgreSQL installation at
35    share/pg_service.conf.sample.
36
37    Connection parameters obtained from a service file are combined with
38    parameters obtained from other sources. A service file setting
39    overrides the corresponding environment variable, and in turn can be
40    overridden by a value given directly in the connection string. For
41    example, using the above service file, a connection string service=mydb
42    port=5434 will use host somehost, port 5434, user admin, and other
43    parameters as set by environment variables or built-in defaults.