]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/libpq-envars.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / libpq-envars.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>32.15. Environment Variables</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="libpq-events.html" title="32.14. Event System" /><link rel="next" href="libpq-pgpass.html" title="32.16. The Password File" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">32.15. Environment Variables</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-events.html" title="32.14. Event System">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 32. libpq — C Library">Up</a></td><th width="60%" align="center">Chapter 32. <span class="application">libpq</span> — C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-pgpass.html" title="32.16. The Password File">Next</a></td></tr></table><hr /></div><div class="sect1" id="LIBPQ-ENVARS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">32.15. Environment Variables <a href="#LIBPQ-ENVARS" class="id_link">#</a></h2></div></div></div><a id="id-1.7.3.22.2" class="indexterm"></a><p>
3    The following environment variables can be used to select default
4    connection parameter values, which will be used by
5    <a class="xref" href="libpq-connect.html#LIBPQ-PQCONNECTDB"><code class="function">PQconnectdb</code></a>, <a class="xref" href="libpq-connect.html#LIBPQ-PQSETDBLOGIN"><code class="function">PQsetdbLogin</code></a> and
6    <a class="xref" href="libpq-connect.html#LIBPQ-PQSETDB"><code class="function">PQsetdb</code></a> if no value is directly specified by the calling
7    code.  These are useful to avoid hard-coding database connection
8    information into simple client applications, for example.
9
10    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
11       <a id="id-1.7.3.22.3.4.1.1.1" class="indexterm"></a>
12       <code class="envar">PGHOST</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-HOST">host</a> connection parameter.
13      </p></li><li class="listitem"><p>
14       <a id="id-1.7.3.22.3.4.2.1.1" class="indexterm"></a>
15       <code class="envar">PGSSLNEGOTIATION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLNEGOTIATION">sslnegotiation</a> connection parameter.
16      </p></li><li class="listitem"><p>
17       <a id="id-1.7.3.22.3.4.3.1.1" class="indexterm"></a>
18       <code class="envar">PGHOSTADDR</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-HOSTADDR">hostaddr</a> connection parameter.
19       This can be set instead of or in addition to <code class="envar">PGHOST</code>
20       to avoid DNS lookup overhead.
21      </p></li><li class="listitem"><p>
22       <a id="id-1.7.3.22.3.4.4.1.1" class="indexterm"></a>
23       <code class="envar">PGPORT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PORT">port</a> connection parameter.
24      </p></li><li class="listitem"><p>
25       <a id="id-1.7.3.22.3.4.5.1.1" class="indexterm"></a>
26       <code class="envar">PGDATABASE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-DBNAME">dbname</a> connection parameter.
27       </p></li><li class="listitem"><p>
28       <a id="id-1.7.3.22.3.4.6.1.1" class="indexterm"></a>
29       <code class="envar">PGUSER</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-USER">user</a> connection parameter.
30      </p></li><li class="listitem"><p>
31       <a id="id-1.7.3.22.3.4.7.1.1" class="indexterm"></a>
32       <code class="envar">PGPASSWORD</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PASSWORD">password</a> connection parameter.
33       Use of this environment variable
34       is not recommended for security reasons, as some operating systems
35       allow non-root users to see process environment variables via
36       <span class="application">ps</span>; instead consider using a password file
37       (see <a class="xref" href="libpq-pgpass.html" title="32.16. The Password File">Section 32.16</a>).
38      </p></li><li class="listitem"><p>
39       <a id="id-1.7.3.22.3.4.8.1.1" class="indexterm"></a>
40       <code class="envar">PGPASSFILE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PASSFILE">passfile</a> connection parameter.
41      </p></li><li class="listitem"><p>
42       <a id="id-1.7.3.22.3.4.9.1.1" class="indexterm"></a>
43       <code class="envar">PGREQUIREAUTH</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIRE-AUTH">require_auth</a> connection parameter.
44      </p></li><li class="listitem"><p>
45       <a id="id-1.7.3.22.3.4.10.1.1" class="indexterm"></a>
46       <code class="envar">PGCHANNELBINDING</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-CHANNEL-BINDING">channel_binding</a> connection parameter.
47      </p></li><li class="listitem"><p>
48       <a id="id-1.7.3.22.3.4.11.1.1" class="indexterm"></a>
49       <code class="envar">PGSERVICE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SERVICE">service</a> connection parameter.
50      </p></li><li class="listitem"><p>
51       <a id="id-1.7.3.22.3.4.12.1.1" class="indexterm"></a>
52       <code class="envar">PGSERVICEFILE</code> specifies the name of the per-user
53       connection service file
54       (see <a class="xref" href="libpq-pgservice.html" title="32.17. The Connection Service File">Section 32.17</a>).
55       Defaults to <code class="filename">~/.pg_service.conf</code>, or
56       <code class="filename">%APPDATA%\postgresql\.pg_service.conf</code> on
57       Microsoft Windows.
58      </p></li><li class="listitem"><p>
59       <a id="id-1.7.3.22.3.4.13.1.1" class="indexterm"></a>
60       <code class="envar">PGOPTIONS</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-OPTIONS">options</a> connection parameter.
61      </p></li><li class="listitem"><p>
62       <a id="id-1.7.3.22.3.4.14.1.1" class="indexterm"></a>
63       <code class="envar">PGAPPNAME</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-APPLICATION-NAME">application_name</a> connection parameter.
64      </p></li><li class="listitem"><p>
65       <a id="id-1.7.3.22.3.4.15.1.1" class="indexterm"></a>
66       <code class="envar">PGSSLMODE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLMODE">sslmode</a> connection parameter.
67      </p></li><li class="listitem"><p>
68       <a id="id-1.7.3.22.3.4.16.1.1" class="indexterm"></a>
69       <code class="envar">PGREQUIRESSL</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL">requiressl</a> connection parameter.
70       This environment variable is deprecated in favor of the
71       <code class="envar">PGSSLMODE</code> variable; setting both variables suppresses the
72       effect of this one.
73      </p></li><li class="listitem"><p>
74       <a id="id-1.7.3.22.3.4.17.1.1" class="indexterm"></a>
75       <code class="envar">PGSSLCOMPRESSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCOMPRESSION">sslcompression</a> connection parameter.
76      </p></li><li class="listitem"><p>
77       <a id="id-1.7.3.22.3.4.18.1.1" class="indexterm"></a>
78       <code class="envar">PGSSLCERT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCERT">sslcert</a> connection parameter.
79      </p></li><li class="listitem"><p>
80       <a id="id-1.7.3.22.3.4.19.1.1" class="indexterm"></a>
81       <code class="envar">PGSSLKEY</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLKEY">sslkey</a> connection parameter.
82      </p></li><li class="listitem"><p>
83       <a id="id-1.7.3.22.3.4.20.1.1" class="indexterm"></a>
84       <code class="envar">PGSSLCERTMODE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCERTMODE">sslcertmode</a> connection parameter.
85      </p></li><li class="listitem"><p>
86       <a id="id-1.7.3.22.3.4.21.1.1" class="indexterm"></a>
87       <code class="envar">PGSSLROOTCERT</code>  behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT">sslrootcert</a> connection parameter.
88      </p></li><li class="listitem"><p>
89       <a id="id-1.7.3.22.3.4.22.1.1" class="indexterm"></a>
90       <code class="envar">PGSSLCRL</code>  behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCRL">sslcrl</a> connection parameter.
91      </p></li><li class="listitem"><p>
92       <a id="id-1.7.3.22.3.4.23.1.1" class="indexterm"></a>
93       <code class="envar">PGSSLCRLDIR</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCRLDIR">sslcrldir</a> connection parameter.
94      </p></li><li class="listitem"><p>
95       <a id="id-1.7.3.22.3.4.24.1.1" class="indexterm"></a>
96       <code class="envar">PGSSLSNI</code>  behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLSNI">sslsni</a> connection parameter.
97      </p></li><li class="listitem"><p>
98       <a id="id-1.7.3.22.3.4.25.1.1" class="indexterm"></a>
99       <code class="envar">PGREQUIREPEER</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIREPEER">requirepeer</a> connection parameter.
100      </p></li><li class="listitem"><p>
101       <a id="id-1.7.3.22.3.4.26.1.1" class="indexterm"></a>
102       <code class="envar">PGSSLMINPROTOCOLVERSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSL-MIN-PROTOCOL-VERSION">ssl_min_protocol_version</a> connection parameter.
103      </p></li><li class="listitem"><p>
104       <a id="id-1.7.3.22.3.4.27.1.1" class="indexterm"></a>
105       <code class="envar">PGSSLMAXPROTOCOLVERSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSL-MAX-PROTOCOL-VERSION">ssl_max_protocol_version</a> connection parameter.
106      </p></li><li class="listitem"><p>
107       <a id="id-1.7.3.22.3.4.28.1.1" class="indexterm"></a>
108       <code class="envar">PGGSSENCMODE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-GSSENCMODE">gssencmode</a> connection parameter.
109      </p></li><li class="listitem"><p>
110       <a id="id-1.7.3.22.3.4.29.1.1" class="indexterm"></a>
111       <code class="envar">PGKRBSRVNAME</code>  behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-KRBSRVNAME">krbsrvname</a> connection parameter.
112      </p></li><li class="listitem"><p>
113       <a id="id-1.7.3.22.3.4.30.1.1" class="indexterm"></a>
114       <code class="envar">PGGSSLIB</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-GSSLIB">gsslib</a> connection parameter.
115      </p></li><li class="listitem"><p>
116       <a id="id-1.7.3.22.3.4.31.1.1" class="indexterm"></a>
117       <code class="envar">PGGSSDELEGATION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-GSSDELEGATION">gssdelegation</a> connection parameter.
118      </p></li><li class="listitem"><p>
119       <a id="id-1.7.3.22.3.4.32.1.1" class="indexterm"></a>
120       <code class="envar">PGCONNECT_TIMEOUT</code>  behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-CONNECT-TIMEOUT">connect_timeout</a> connection parameter.
121      </p></li><li class="listitem"><p>
122       <a id="id-1.7.3.22.3.4.33.1.1" class="indexterm"></a>
123       <code class="envar">PGCLIENTENCODING</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-CLIENT-ENCODING">client_encoding</a> connection parameter.
124      </p></li><li class="listitem"><p>
125       <a id="id-1.7.3.22.3.4.34.1.1" class="indexterm"></a>
126       <code class="envar">PGTARGETSESSIONATTRS</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS">target_session_attrs</a> connection parameter.
127      </p></li><li class="listitem"><p>
128       <a id="id-1.7.3.22.3.4.35.1.1" class="indexterm"></a>
129       <code class="envar">PGLOADBALANCEHOSTS</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-LOAD-BALANCE-HOSTS">load_balance_hosts</a> connection parameter.
130      </p></li><li class="listitem"><p>
131       <a id="id-1.7.3.22.3.4.36.1.1" class="indexterm"></a>
132       <code class="envar">PGMINPROTOCOLVERSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-MIN-PROTOCOL-VERSION">min_protocol_version</a> connection parameter.
133      </p></li><li class="listitem"><p>
134       <a id="id-1.7.3.22.3.4.37.1.1" class="indexterm"></a>
135       <code class="envar">PGMAXPROTOCOLVERSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-MAX-PROTOCOL-VERSION">max_protocol_version</a> connection parameter.
136      </p></li></ul></div><p>
137   </p><p>
138    The following environment variables can be used to specify default
139    behavior for each <span class="productname">PostgreSQL</span> session.  (See
140    also the <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a>
141    and <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a>
142    commands for ways to set default behavior on a per-user or per-database
143    basis.)
144
145    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
146       <a id="id-1.7.3.22.4.4.1.1.1" class="indexterm"></a>
147       <code class="envar">PGDATESTYLE</code> sets the default style of date/time
148       representation.  (Equivalent to <code class="literal">SET datestyle TO
149       ...</code>.)
150      </p></li><li class="listitem"><p>
151       <a id="id-1.7.3.22.4.4.2.1.1" class="indexterm"></a>
152       <code class="envar">PGTZ</code> sets the default time zone.  (Equivalent to
153       <code class="literal">SET timezone TO ...</code>.)
154      </p></li><li class="listitem"><p>
155       <a id="id-1.7.3.22.4.4.3.1.1" class="indexterm"></a>
156       <code class="envar">PGGEQO</code> sets the default mode for the genetic query
157       optimizer.  (Equivalent to <code class="literal">SET geqo TO ...</code>.)
158      </p></li></ul></div><p>
159
160    Refer to the <acronym class="acronym">SQL</acronym> command <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a>
161    for information on correct values for these
162    environment variables.
163   </p><p>
164    The following environment variables determine internal behavior of
165    <span class="application">libpq</span>; they override compiled-in defaults.
166
167    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
168       <a id="id-1.7.3.22.5.2.1.1.1" class="indexterm"></a>
169       <code class="envar">PGSYSCONFDIR</code> sets the directory containing the
170       <code class="filename">pg_service.conf</code> file and in a future version
171       possibly other system-wide configuration files.
172      </p></li><li class="listitem"><p>
173       <a id="id-1.7.3.22.5.2.2.1.1" class="indexterm"></a>
174       <code class="envar">PGLOCALEDIR</code> sets the directory containing the
175       <code class="literal">locale</code> files for message localization.
176      </p></li></ul></div><p>
177   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-events.html" title="32.14. Event System">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html" title="Chapter 32. libpq — C Library">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-pgpass.html" title="32.16. The Password File">Next</a></td></tr><tr><td width="40%" align="left" valign="top">32.14. Event System </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 32.16. The Password File</td></tr></table></div></body></html>