Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b57e30c

Browse files
committed
Doc: clarify location of libpq's default service file on Windows.
The documentation didn't specify the name of the per-user service file on Windows, and extrapolating from the pattern used for other config files gave the wrong answer. The fact that it isn't consistent with the others sure seems like a bug, but it's far too late to change that now; we'd just penalize people who worked it out in the past. So, simply document the true state of affairs. In passing, fix some gratuitous differences between the discussions of the service file and the password file. Julien Rouhaud, per question from Dominique Devienne. Backpatch to all supported branches. I (tgl) also chose to back-patch the part of commit ba356a3 that touched libpq.sgml's description of the service file --- in hindsight, I'm not sure why I didn't do so at the time, as it includes some fairly essential information. Discussion: https://postgr.es/m/CAFCRh-_mdLrh8eYVzhRzu4c8bAFEBn=rwoHOmFJcQOTsCy5nig@mail.gmail.com
1 parent 29d1115 commit b57e30c

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7216,9 +7216,11 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
72167216
<primary><envar>PGSERVICEFILE</envar></primary>
72177217
</indexterm>
72187218
<envar>PGSERVICEFILE</envar> specifies the name of the per-user
7219-
connection service file. If not set, it defaults
7220-
to <filename>~/.pg_service.conf</>
7219+
connection service file
72217220
(see <xref linkend="libpq-pgservice">).
7221+
Defaults to <filename>~/.pg_service.conf</filename>, or
7222+
<filename>%APPDATA%\postgresql\.pg_service.conf</filename> on
7223+
Microsoft Windows.
72227224
</para>
72237225
</listitem>
72247226

@@ -7468,11 +7470,11 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
74687470
The file <filename>.pgpass</filename> in a user's home directory can
74697471
contain passwords to
74707472
be used if the connection requires a password (and no password has been
7471-
specified otherwise). On Microsoft Windows the file is named
7472-
<filename>%APPDATA%\postgresql\pgpass.conf</> (where
7473-
<filename>%APPDATA%</> refers to the Application Data subdirectory in
7473+
specified otherwise). On Microsoft Windows the file is named
7474+
<filename>%APPDATA%\postgresql\pgpass.conf</filename> (where
7475+
<filename>%APPDATA%</filename> refers to the Application Data subdirectory in
74747476
the user's profile).
7475-
Alternatively, a password file can be specified
7477+
Alternatively, the password file to use can be specified
74767478
using the connection parameter <xref linkend="libpq-connect-passfile">
74777479
or the environment variable <envar>PGPASSFILE</envar>.
74787480
</para>
@@ -7531,26 +7533,34 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
75317533
<para>
75327534
The connection service file allows libpq connection parameters to be
75337535
associated with a single service name. That service name can then be
7534-
specified by a libpq connection, and the associated settings will be
7536+
specified in a libpq connection string, and the associated settings will be
75357537
used. This allows connection parameters to be modified without requiring
7536-
a recompile of the libpq application. The service name can also be
7538+
a recompile of the libpq-using application. The service name can also be
75377539
specified using the <envar>PGSERVICE</envar> environment variable.
75387540
</para>
75397541

75407542
<para>
7541-
The connection service file can be a per-user service file
7542-
at <filename>~/.pg_service.conf</filename> or the location
7543-
specified by the environment variable <envar>PGSERVICEFILE</envar>,
7544-
or it can be a system-wide file
7545-
at <filename>`pg_config --sysconfdir`/pg_service.conf</filename> or in the directory
7546-
specified by the environment variable
7547-
<envar>PGSYSCONFDIR</envar>. If service definitions with the same
7548-
name exist in the user and the system file, the user file takes
7549-
precedence.
7543+
Service names can be defined in either a per-user service file or a
7544+
system-wide file. If the same service name exists in both the user
7545+
and the system file, the user file takes precedence.
7546+
By default, the per-user service file is named
7547+
<filename>~/.pg_service.conf</filename>.
7548+
On Microsoft Windows, it is named
7549+
<filename>%APPDATA%\postgresql\.pg_service.conf</filename> (where
7550+
<filename>%APPDATA%</filename> refers to the Application Data subdirectory
7551+
in the user's profile). A different file name can be specified by
7552+
setting the environment variable <envar>PGSERVICEFILE</envar>.
7553+
The system-wide file is named <filename>pg_service.conf</filename>.
7554+
By default it is sought in the <filename>etc</filename> directory
7555+
of the <productname>PostgreSQL</productname> installation
7556+
(use <literal>pg_config --sysconfdir</literal> to identify this
7557+
directory precisely). Another directory, but not a different file
7558+
name, can be specified by setting the environment variable
7559+
<envar>PGSYSCONFDIR</envar>.
75507560
</para>
75517561

75527562
<para>
7553-
The file uses an <quote>INI file</quote> format where the section
7563+
Either service file uses an <quote>INI file</quote> format where the section
75547564
name is the service name and the parameters are connection
75557565
parameters; see <xref linkend="libpq-paramkeywords"> for a list. For
75567566
example:
@@ -7561,9 +7571,22 @@ host=somehost
75617571
port=5433
75627572
user=admin
75637573
</programlisting>
7564-
An example file is provided at
7574+
An example file is provided in
7575+
the <productname>PostgreSQL</productname> installation at
75657576
<filename>share/pg_service.conf.sample</filename>.
75667577
</para>
7578+
7579+
<para>
7580+
Connection parameters obtained from a service file are combined with
7581+
parameters obtained from other sources. A service file setting
7582+
overrides the corresponding environment variable, and in turn can be
7583+
overridden by a value given directly in the connection string.
7584+
For example, using the above service file, a connection string
7585+
<literal>service=mydb port=5434</literal> will use
7586+
host <literal>somehost</literal>, port <literal>5434</literal>,
7587+
user <literal>admin</literal>, and other parameters as set by
7588+
environment variables or built-in defaults.
7589+
</para>
75677590
</sect1>
75687591

75697592

0 commit comments

Comments
 (0)