| Server IP : 104.21.25.180 / Your IP : 104.23.197.122 Web Server : Apache/2.4.37 System : Linux almalinux.duckdns.org 4.18.0-553.111.1.el8_10.x86_64 #1 SMP Sun Mar 8 20:06:07 EDT 2026 x86_64 User : ricodeal ( 1046) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/postgresql-docs/html/ |
Upload File : |
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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>33.14. Environment Variables</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="[email protected]" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="libpq-events.html" title="33.13. Event System" /><link rel="next" href="libpq-pgpass.html" title="33.15. The Password File" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">33.14. Environment Variables</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-events.html" title="33.13. Event System">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 33. libpq - C Library">Up</a></td><th width="60%" align="center">Chapter 33. <span xmlns="http://www.w3.org/1999/xhtml" class="application">libpq</span> - C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 10.23 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-pgpass.html" title="33.15. The Password File">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LIBPQ-ENVARS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">33.14. Environment Variables</h2></div></div></div><a id="id-1.7.3.21.2" class="indexterm"></a><p> The following environment variables can be used to select default
connection parameter values, which will be used by
<code class="function">PQconnectdb</code>, <code class="function">PQsetdbLogin</code> and
<code class="function">PQsetdb</code> if no value is directly specified by the calling
code. These are useful to avoid hard-coding database connection
information into simple client applications, for example.
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> <a id="id-1.7.3.21.3.4.1.1.1" class="indexterm"></a>
<code class="envar">PGHOST</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-HOST">host</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.2.1.1" class="indexterm"></a>
<code class="envar">PGHOSTADDR</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-HOSTADDR">hostaddr</a> connection parameter.
This can be set instead of or in addition to <code class="envar">PGHOST</code>
to avoid DNS lookup overhead.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.3.1.1" class="indexterm"></a>
<code class="envar">PGPORT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PORT">port</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.4.1.1" class="indexterm"></a>
<code class="envar">PGDATABASE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-DBNAME">dbname</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.5.1.1" class="indexterm"></a>
<code class="envar">PGUSER</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-USER">user</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.6.1.1" class="indexterm"></a>
<code class="envar">PGPASSWORD</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PASSWORD">password</a> connection parameter.
Use of this environment variable
is not recommended for security reasons, as some operating systems
allow non-root users to see process environment variables via
<span class="application">ps</span>; instead consider using a password file
(see <a class="xref" href="libpq-pgpass.html" title="33.15. The Password File">Section 33.15</a>).
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.7.1.1" class="indexterm"></a>
<code class="envar">PGPASSFILE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PASSFILE">passfile</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.8.1.1" class="indexterm"></a>
<code class="envar">PGSERVICE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SERVICE">service</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.9.1.1" class="indexterm"></a>
<code class="envar">PGSERVICEFILE</code> specifies the name of the per-user
connection service file
(see <a class="xref" href="libpq-pgservice.html" title="33.16. The Connection Service File">Section 33.16</a>).
Defaults to <code class="filename">~/.pg_service.conf</code>, or
<code class="filename">%APPDATA%\postgresql\.pg_service.conf</code> on
Microsoft Windows.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.10.1.1" class="indexterm"></a>
<code class="envar">PGOPTIONS</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-OPTIONS">options</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.11.1.1" class="indexterm"></a>
<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.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.12.1.1" class="indexterm"></a>
<code class="envar">PGSSLMODE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLMODE">sslmode</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.13.1.1" class="indexterm"></a>
<code class="envar">PGREQUIRESSL</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL">requiressl</a> connection parameter.
This environment variable is deprecated in favor of the
<code class="envar">PGSSLMODE</code> variable; setting both variables suppresses the
effect of this one.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.14.1.1" class="indexterm"></a>
<code class="envar">PGSSLCOMPRESSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCOMPRESSION">sslcompression</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.15.1.1" class="indexterm"></a>
<code class="envar">PGSSLCERT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCERT">sslcert</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.16.1.1" class="indexterm"></a>
<code class="envar">PGSSLKEY</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLKEY">sslkey</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.17.1.1" class="indexterm"></a>
<code class="envar">PGSSLROOTCERT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT">sslrootcert</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.18.1.1" class="indexterm"></a>
<code class="envar">PGSSLCRL</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCRL">sslcrl</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.19.1.1" class="indexterm"></a>
<code class="envar">PGREQUIREPEER</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIREPEER">requirepeer</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.20.1.1" class="indexterm"></a>
<code class="envar">PGKRBSRVNAME</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-KRBSRVNAME">krbsrvname</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.21.1.1" class="indexterm"></a>
<code class="envar">PGGSSLIB</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-GSSLIB">gsslib</a> connection parameter.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.22.1.1" class="indexterm"></a>
<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.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.23.1.1" class="indexterm"></a>
<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.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.3.4.24.1.1" class="indexterm"></a>
<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.
</p></li></ul></div><p>
</p><p> The following environment variables can be used to specify default
behavior for each <span class="productname">PostgreSQL</span> session. (See
also the <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a>
and <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a>
commands for ways to set default behavior on a per-user or per-database
basis.)
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> <a id="id-1.7.3.21.4.4.1.1.1" class="indexterm"></a>
<code class="envar">PGDATESTYLE</code> sets the default style of date/time
representation. (Equivalent to <code class="literal">SET datestyle TO
...</code>.)
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.4.4.2.1.1" class="indexterm"></a>
<code class="envar">PGTZ</code> sets the default time zone. (Equivalent to
<code class="literal">SET timezone TO ...</code>.)
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.4.4.3.1.1" class="indexterm"></a>
<code class="envar">PGGEQO</code> sets the default mode for the genetic query
optimizer. (Equivalent to <code class="literal">SET geqo TO ...</code>.)
</p></li></ul></div><p>
Refer to the <acronym class="acronym">SQL</acronym> command <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a>
for information on correct values for these
environment variables.
</p><p> The following environment variables determine internal behavior of
<span class="application">libpq</span>; they override compiled-in defaults.
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> <a id="id-1.7.3.21.5.2.1.1.1" class="indexterm"></a>
<code class="envar">PGSYSCONFDIR</code> sets the directory containing the
<code class="filename">pg_service.conf</code> file and in a future version
possibly other system-wide configuration files.
</p></li><li class="listitem"><p> <a id="id-1.7.3.21.5.2.2.1.1" class="indexterm"></a>
<code class="envar">PGLOCALEDIR</code> sets the directory containing the
<code class="literal">locale</code> files for message localization.
</p></li></ul></div><p>
</p></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-events.html" title="33.13. Event System">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html" title="Chapter 33. libpq - C Library">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-pgpass.html" title="33.15. The Password File">Next</a></td></tr><tr><td width="40%" align="left" valign="top">33.13. Event System </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 10.23 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 33.15. The Password File</td></tr></table></div></body></html>