gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
13KB

  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>33.14. 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 V1.79.1" /><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 12.4 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>
  3. The following environment variables can be used to select default
  4. connection parameter values, which will be used by
  5. <code class="function">PQconnectdb</code>, <code class="function">PQsetdbLogin</code> and
  6. <code class="function">PQsetdb</code> 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. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  10. <a id="id-1.7.3.21.3.4.1.1.1" class="indexterm"></a>
  11. <code class="envar">PGHOST</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-HOST">host</a> connection parameter.
  12. </p></li><li class="listitem"><p>
  13. <a id="id-1.7.3.21.3.4.2.1.1" class="indexterm"></a>
  14. <code class="envar">PGHOSTADDR</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-HOSTADDR">hostaddr</a> connection parameter.
  15. This can be set instead of or in addition to <code class="envar">PGHOST</code>
  16. to avoid DNS lookup overhead.
  17. </p></li><li class="listitem"><p>
  18. <a id="id-1.7.3.21.3.4.3.1.1" class="indexterm"></a>
  19. <code class="envar">PGPORT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PORT">port</a> connection parameter.
  20. </p></li><li class="listitem"><p>
  21. <a id="id-1.7.3.21.3.4.4.1.1" class="indexterm"></a>
  22. <code class="envar">PGDATABASE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-DBNAME">dbname</a> connection parameter.
  23. </p></li><li class="listitem"><p>
  24. <a id="id-1.7.3.21.3.4.5.1.1" class="indexterm"></a>
  25. <code class="envar">PGUSER</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-USER">user</a> connection parameter.
  26. </p></li><li class="listitem"><p>
  27. <a id="id-1.7.3.21.3.4.6.1.1" class="indexterm"></a>
  28. <code class="envar">PGPASSWORD</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PASSWORD">password</a> connection parameter.
  29. Use of this environment variable
  30. is not recommended for security reasons, as some operating systems
  31. allow non-root users to see process environment variables via
  32. <span class="application">ps</span>; instead consider using a password file
  33. (see <a class="xref" href="libpq-pgpass.html" title="33.15. The Password File">Section 33.15</a>).
  34. </p></li><li class="listitem"><p>
  35. <a id="id-1.7.3.21.3.4.7.1.1" class="indexterm"></a>
  36. <code class="envar">PGPASSFILE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-PASSFILE">passfile</a> connection parameter.
  37. </p></li><li class="listitem"><p>
  38. <a id="id-1.7.3.21.3.4.8.1.1" class="indexterm"></a>
  39. <code class="envar">PGSERVICE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SERVICE">service</a> connection parameter.
  40. </p></li><li class="listitem"><p>
  41. <a id="id-1.7.3.21.3.4.9.1.1" class="indexterm"></a>
  42. <code class="envar">PGSERVICEFILE</code> specifies the name of the per-user
  43. connection service file. If not set, it defaults
  44. to <code class="filename">~/.pg_service.conf</code>
  45. (see <a class="xref" href="libpq-pgservice.html" title="33.16. The Connection Service File">Section 33.16</a>).
  46. </p></li><li class="listitem"><p>
  47. <a id="id-1.7.3.21.3.4.10.1.1" class="indexterm"></a>
  48. <code class="envar">PGOPTIONS</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-OPTIONS">options</a> connection parameter.
  49. </p></li><li class="listitem"><p>
  50. <a id="id-1.7.3.21.3.4.11.1.1" class="indexterm"></a>
  51. <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.
  52. </p></li><li class="listitem"><p>
  53. <a id="id-1.7.3.21.3.4.12.1.1" class="indexterm"></a>
  54. <code class="envar">PGSSLMODE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLMODE">sslmode</a> connection parameter.
  55. </p></li><li class="listitem"><p>
  56. <a id="id-1.7.3.21.3.4.13.1.1" class="indexterm"></a>
  57. <code class="envar">PGREQUIRESSL</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL">requiressl</a> connection parameter.
  58. This environment variable is deprecated in favor of the
  59. <code class="envar">PGSSLMODE</code> variable; setting both variables suppresses the
  60. effect of this one.
  61. </p></li><li class="listitem"><p>
  62. <a id="id-1.7.3.21.3.4.14.1.1" class="indexterm"></a>
  63. <code class="envar">PGSSLCOMPRESSION</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCOMPRESSION">sslcompression</a> connection parameter.
  64. </p></li><li class="listitem"><p>
  65. <a id="id-1.7.3.21.3.4.15.1.1" class="indexterm"></a>
  66. <code class="envar">PGSSLCERT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCERT">sslcert</a> connection parameter.
  67. </p></li><li class="listitem"><p>
  68. <a id="id-1.7.3.21.3.4.16.1.1" class="indexterm"></a>
  69. <code class="envar">PGSSLKEY</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLKEY">sslkey</a> connection parameter.
  70. </p></li><li class="listitem"><p>
  71. <a id="id-1.7.3.21.3.4.17.1.1" class="indexterm"></a>
  72. <code class="envar">PGSSLROOTCERT</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT">sslrootcert</a> connection parameter.
  73. </p></li><li class="listitem"><p>
  74. <a id="id-1.7.3.21.3.4.18.1.1" class="indexterm"></a>
  75. <code class="envar">PGSSLCRL</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-SSLCRL">sslcrl</a> connection parameter.
  76. </p></li><li class="listitem"><p>
  77. <a id="id-1.7.3.21.3.4.19.1.1" class="indexterm"></a>
  78. <code class="envar">PGREQUIREPEER</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-REQUIREPEER">requirepeer</a> connection parameter.
  79. </p></li><li class="listitem"><p>
  80. <a id="id-1.7.3.21.3.4.20.1.1" class="indexterm"></a>
  81. <code class="envar">PGGSSENCMODE</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-GSSENCMODE">gssencmode</a> connection parameter.
  82. </p></li><li class="listitem"><p>
  83. <a id="id-1.7.3.21.3.4.21.1.1" class="indexterm"></a>
  84. <code class="envar">PGKRBSRVNAME</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-KRBSRVNAME">krbsrvname</a> connection parameter.
  85. </p></li><li class="listitem"><p>
  86. <a id="id-1.7.3.21.3.4.22.1.1" class="indexterm"></a>
  87. <code class="envar">PGGSSLIB</code> behaves the same as the <a class="xref" href="libpq-connect.html#LIBPQ-CONNECT-GSSLIB">gsslib</a> connection parameter.
  88. </p></li><li class="listitem"><p>
  89. <a id="id-1.7.3.21.3.4.23.1.1" class="indexterm"></a>
  90. <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.
  91. </p></li><li class="listitem"><p>
  92. <a id="id-1.7.3.21.3.4.24.1.1" class="indexterm"></a>
  93. <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.
  94. </p></li><li class="listitem"><p>
  95. <a id="id-1.7.3.21.3.4.25.1.1" class="indexterm"></a>
  96. <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.
  97. </p></li></ul></div><p>
  98. </p><p>
  99. The following environment variables can be used to specify default
  100. behavior for each <span class="productname">PostgreSQL</span> session. (See
  101. also the <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a>
  102. and <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a>
  103. commands for ways to set default behavior on a per-user or per-database
  104. basis.)
  105. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  106. <a id="id-1.7.3.21.4.4.1.1.1" class="indexterm"></a>
  107. <code class="envar">PGDATESTYLE</code> sets the default style of date/time
  108. representation. (Equivalent to <code class="literal">SET datestyle TO
  109. ...</code>.)
  110. </p></li><li class="listitem"><p>
  111. <a id="id-1.7.3.21.4.4.2.1.1" class="indexterm"></a>
  112. <code class="envar">PGTZ</code> sets the default time zone. (Equivalent to
  113. <code class="literal">SET timezone TO ...</code>.)
  114. </p></li><li class="listitem"><p>
  115. <a id="id-1.7.3.21.4.4.3.1.1" class="indexterm"></a>
  116. <code class="envar">PGGEQO</code> sets the default mode for the genetic query
  117. optimizer. (Equivalent to <code class="literal">SET geqo TO ...</code>.)
  118. </p></li></ul></div><p>
  119. Refer to the <acronym class="acronym">SQL</acronym> command <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a>
  120. for information on correct values for these
  121. environment variables.
  122. </p><p>
  123. The following environment variables determine internal behavior of
  124. <span class="application">libpq</span>; they override compiled-in defaults.
  125. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  126. <a id="id-1.7.3.21.5.2.1.1.1" class="indexterm"></a>
  127. <code class="envar">PGSYSCONFDIR</code> sets the directory containing the
  128. <code class="filename">pg_service.conf</code> file and in a future version
  129. possibly other system-wide configuration files.
  130. </p></li><li class="listitem"><p>
  131. <a id="id-1.7.3.21.5.2.2.1.1" class="indexterm"></a>
  132. <code class="envar">PGLOCALEDIR</code> sets the directory containing the
  133. <code class="literal">locale</code> files for message localization.
  134. </p></li></ul></div><p>
  135. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-pgpass.html">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">Home</a></td><td width="40%" align="right" valign="top"> 33.15. The Password File</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1