gooderp18绿色标准版
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

331 lines
24KB

  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>19.1. Setting Parameters</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="runtime-config.html" title="Chapter 19. Server Configuration" /><link rel="next" href="runtime-config-file-locations.html" title="19.2. File Locations" /></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">19.1. Setting Parameters</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="runtime-config.html" title="Chapter 19. Server Configuration">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="runtime-config.html" title="Chapter 19. Server Configuration">Up</a></td><th width="60%" align="center">Chapter 19. Server Configuration</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="runtime-config-file-locations.html" title="19.2. File Locations">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="CONFIG-SETTING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">19.1. Setting Parameters</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="config-setting.html#CONFIG-SETTING-NAMES-VALUES">19.1.1. Parameter Names and Values</a></span></dt><dt><span class="sect2"><a href="config-setting.html#CONFIG-SETTING-CONFIGURATION-FILE">19.1.2. Parameter Interaction via the Configuration File</a></span></dt><dt><span class="sect2"><a href="config-setting.html#CONFIG-SETTING-SQL-COMMAND-INTERACTION">19.1.3. Parameter Interaction via SQL</a></span></dt><dt><span class="sect2"><a href="config-setting.html#id-1.6.6.4.5">19.1.4. Parameter Interaction via the Shell</a></span></dt><dt><span class="sect2"><a href="config-setting.html#CONFIG-INCLUDES">19.1.5. Managing Configuration File Contents</a></span></dt></dl></div><div class="sect2" id="CONFIG-SETTING-NAMES-VALUES"><div class="titlepage"><div><div><h3 class="title">19.1.1. Parameter Names and Values</h3></div></div></div><p>
  3. All parameter names are case-insensitive. Every parameter takes a
  4. value of one of five types: boolean, string, integer, floating point,
  5. or enumerated (enum). The type determines the syntax for setting the
  6. parameter:
  7. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  8. <span class="emphasis"><em>Boolean:</em></span>
  9. Values can be written as
  10. <code class="literal">on</code>,
  11. <code class="literal">off</code>,
  12. <code class="literal">true</code>,
  13. <code class="literal">false</code>,
  14. <code class="literal">yes</code>,
  15. <code class="literal">no</code>,
  16. <code class="literal">1</code>,
  17. <code class="literal">0</code>
  18. (all case-insensitive) or any unambiguous prefix of one of these.
  19. </p></li><li class="listitem"><p>
  20. <span class="emphasis"><em>String:</em></span>
  21. In general, enclose the value in single quotes, doubling any single
  22. quotes within the value. Quotes can usually be omitted if the value
  23. is a simple number or identifier, however.
  24. (Values that match a SQL keyword require quoting in some contexts.)
  25. </p></li><li class="listitem"><p>
  26. <span class="emphasis"><em>Numeric (integer and floating point):</em></span>
  27. Numeric parameters can be specified in the customary integer and
  28. floating-point formats; fractional values are rounded to the nearest
  29. integer if the parameter is of integer type. Integer parameters
  30. additionally accept hexadecimal input (beginning
  31. with <code class="literal">0x</code>) and octal input (beginning
  32. with <code class="literal">0</code>), but these formats cannot have a fraction.
  33. Do not use thousands separators.
  34. Quotes are not required, except for hexadecimal input.
  35. </p></li><li class="listitem"><p>
  36. <span class="emphasis"><em>Numeric with Unit:</em></span>
  37. Some numeric parameters have an implicit unit, because they describe
  38. quantities of memory or time. The unit might be bytes, kilobytes, blocks
  39. (typically eight kilobytes), milliseconds, seconds, or minutes.
  40. An unadorned numeric value for one of these settings will use the
  41. setting's default unit, which can be learned from
  42. <code class="structname">pg_settings</code>.<code class="structfield">unit</code>.
  43. For convenience, settings can be given with a unit specified explicitly,
  44. for example <code class="literal">'120 ms'</code> for a time value, and they will be
  45. converted to whatever the parameter's actual unit is. Note that the
  46. value must be written as a string (with quotes) to use this feature.
  47. The unit name is case-sensitive, and there can be whitespace between
  48. the numeric value and the unit.
  49. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
  50. Valid memory units are <code class="literal">B</code> (bytes),
  51. <code class="literal">kB</code> (kilobytes),
  52. <code class="literal">MB</code> (megabytes), <code class="literal">GB</code>
  53. (gigabytes), and <code class="literal">TB</code> (terabytes).
  54. The multiplier for memory units is 1024, not 1000.
  55. </p></li><li class="listitem"><p>
  56. Valid time units are
  57. <code class="literal">us</code> (microseconds),
  58. <code class="literal">ms</code> (milliseconds),
  59. <code class="literal">s</code> (seconds), <code class="literal">min</code> (minutes),
  60. <code class="literal">h</code> (hours), and <code class="literal">d</code> (days).
  61. </p></li></ul></div><p>
  62. If a fractional value is specified with a unit, it will be rounded
  63. to a multiple of the next smaller unit if there is one.
  64. For example, <code class="literal">30.1 GB</code> will be converted
  65. to <code class="literal">30822 MB</code> not <code class="literal">32319628902 B</code>.
  66. If the parameter is of integer type, a final rounding to integer
  67. occurs after any units conversion.
  68. </p></li><li class="listitem"><p>
  69. <span class="emphasis"><em>Enumerated:</em></span>
  70. Enumerated-type parameters are written in the same way as string
  71. parameters, but are restricted to have one of a limited set of
  72. values. The values allowable for such a parameter can be found from
  73. <code class="structname">pg_settings</code>.<code class="structfield">enumvals</code>.
  74. Enum parameter values are case-insensitive.
  75. </p></li></ul></div></div><div class="sect2" id="CONFIG-SETTING-CONFIGURATION-FILE"><div class="titlepage"><div><div><h3 class="title">19.1.2. Parameter Interaction via the Configuration File</h3></div></div></div><p>
  76. The most fundamental way to set these parameters is to edit the file
  77. <code class="filename">postgresql.conf</code><a id="id-1.6.6.4.3.2.2" class="indexterm"></a>,
  78. which is normally kept in the data directory. A default copy is
  79. installed when the database cluster directory is initialized.
  80. An example of what this file might look like is:
  81. </p><pre class="programlisting">
  82. # This is a comment
  83. log_connections = yes
  84. log_destination = 'syslog'
  85. search_path = '"$user", public'
  86. shared_buffers = 128MB
  87. </pre><p>
  88. One parameter is specified per line. The equal sign between name and
  89. value is optional. Whitespace is insignificant (except within a quoted
  90. parameter value) and blank lines are
  91. ignored. Hash marks (<code class="literal">#</code>) designate the remainder
  92. of the line as a comment. Parameter values that are not simple
  93. identifiers or numbers must be single-quoted. To embed a single
  94. quote in a parameter value, write either two quotes (preferred)
  95. or backslash-quote.
  96. If the file contains multiple entries for the same parameter,
  97. all but the last one are ignored.
  98. </p><p>
  99. Parameters set in this way provide default values for the cluster.
  100. The settings seen by active sessions will be these values unless they
  101. are overridden. The following sections describe ways in which the
  102. administrator or user can override these defaults.
  103. </p><p>
  104. <a id="id-1.6.6.4.3.4.1" class="indexterm"></a>
  105. The configuration file is reread whenever the main server process
  106. receives a <span class="systemitem">SIGHUP</span> signal; this signal is most easily
  107. sent by running <code class="literal">pg_ctl reload</code> from the command line or by
  108. calling the SQL function <code class="function">pg_reload_conf()</code>. The main
  109. server process also propagates this signal to all currently running
  110. server processes, so that existing sessions also adopt the new values
  111. (this will happen after they complete any currently-executing client
  112. command). Alternatively, you can
  113. send the signal to a single server process directly. Some parameters
  114. can only be set at server start; any changes to their entries in the
  115. configuration file will be ignored until the server is restarted.
  116. Invalid parameter settings in the configuration file are likewise
  117. ignored (but logged) during <span class="systemitem">SIGHUP</span> processing.
  118. </p><p>
  119. In addition to <code class="filename">postgresql.conf</code>,
  120. a <span class="productname">PostgreSQL</span> data directory contains a file
  121. <code class="filename">postgresql.auto.conf</code><a id="id-1.6.6.4.3.5.4" class="indexterm"></a>,
  122. which has the same format as <code class="filename">postgresql.conf</code> but
  123. is intended to be edited automatically, not manually. This file holds
  124. settings provided through the <a class="xref" href="sql-altersystem.html" title="ALTER SYSTEM"><span class="refentrytitle">ALTER SYSTEM</span></a> command.
  125. This file is read whenever <code class="filename">postgresql.conf</code> is,
  126. and its settings take effect in the same way. Settings
  127. in <code class="filename">postgresql.auto.conf</code> override those
  128. in <code class="filename">postgresql.conf</code>.
  129. </p><p>
  130. External tools may also
  131. modify <code class="filename">postgresql.auto.conf</code>. It is not
  132. recommended to do this while the server is running, since a
  133. concurrent <code class="command">ALTER SYSTEM</code> command could overwrite
  134. such changes. Such tools might simply append new settings to the end,
  135. or they might choose to remove duplicate settings and/or comments
  136. (as <code class="command">ALTER SYSTEM</code> will).
  137. </p><p>
  138. The system view
  139. <a class="link" href="view-pg-file-settings.html" title="51.70. pg_file_settings"><code class="structname">pg_file_settings</code></a>
  140. can be helpful for pre-testing changes to the configuration files, or for
  141. diagnosing problems if a <span class="systemitem">SIGHUP</span> signal did not have the
  142. desired effects.
  143. </p></div><div class="sect2" id="CONFIG-SETTING-SQL-COMMAND-INTERACTION"><div class="titlepage"><div><div><h3 class="title">19.1.3. Parameter Interaction via SQL</h3></div></div></div><p>
  144. <span class="productname">PostgreSQL</span> provides three SQL
  145. commands to establish configuration defaults.
  146. The already-mentioned <a class="xref" href="sql-altersystem.html" title="ALTER SYSTEM"><span class="refentrytitle">ALTER SYSTEM</span></a> command
  147. provides a SQL-accessible means of changing global defaults; it is
  148. functionally equivalent to editing <code class="filename">postgresql.conf</code>.
  149. In addition, there are two commands that allow setting of defaults
  150. on a per-database or per-role basis:
  151. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  152. The <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a> command allows global
  153. settings to be overridden on a per-database basis.
  154. </p></li><li class="listitem"><p>
  155. The <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a> command allows both global and
  156. per-database settings to be overridden with user-specific values.
  157. </p></li></ul></div><p>
  158. Values set with <code class="command">ALTER DATABASE</code> and <code class="command">ALTER ROLE</code>
  159. are applied only when starting a fresh database session. They
  160. override values obtained from the configuration files or server
  161. command line, and constitute defaults for the rest of the session.
  162. Note that some settings cannot be changed after server start, and
  163. so cannot be set with these commands (or the ones listed below).
  164. </p><p>
  165. Once a client is connected to the database, <span class="productname">PostgreSQL</span>
  166. provides two additional SQL commands (and equivalent functions) to
  167. interact with session-local configuration settings:
  168. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  169. The <a class="xref" href="sql-show.html" title="SHOW"><span class="refentrytitle">SHOW</span></a> command allows inspection of the
  170. current value of all parameters. The corresponding function is
  171. <code class="function">current_setting(setting_name text)</code>.
  172. </p></li><li class="listitem"><p>
  173. The <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> command allows modification of the
  174. current value of those parameters that can be set locally to a
  175. session; it has no effect on other sessions.
  176. The corresponding function is
  177. <code class="function">set_config(setting_name, new_value, is_local)</code>.
  178. </p></li></ul></div><p>
  179. In addition, the system view <a class="link" href="view-pg-settings.html" title="51.86. pg_settings"><code class="structname">pg_settings</code></a> can be
  180. used to view and change session-local values:
  181. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  182. Querying this view is similar to using <code class="command">SHOW ALL</code> but
  183. provides more detail. It is also more flexible, since it's possible
  184. to specify filter conditions or join against other relations.
  185. </p></li><li class="listitem"><p>
  186. Using <a class="xref" href="sql-update.html" title="UPDATE"><span class="refentrytitle">UPDATE</span></a> on this view, specifically
  187. updating the <code class="structname">setting</code> column, is the equivalent
  188. of issuing <code class="command">SET</code> commands. For example, the equivalent of
  189. </p><pre class="programlisting">
  190. SET configuration_parameter TO DEFAULT;
  191. </pre><p>
  192. is:
  193. </p><pre class="programlisting">
  194. UPDATE pg_settings SET setting = reset_val WHERE name = 'configuration_parameter';
  195. </pre><p>
  196. </p></li></ul></div></div><div class="sect2" id="id-1.6.6.4.5"><div class="titlepage"><div><div><h3 class="title">19.1.4. Parameter Interaction via the Shell</h3></div></div></div><p>
  197. In addition to setting global defaults or attaching
  198. overrides at the database or role level, you can pass settings to
  199. <span class="productname">PostgreSQL</span> via shell facilities.
  200. Both the server and <span class="application">libpq</span> client library
  201. accept parameter values via the shell.
  202. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  203. During server startup, parameter settings can be
  204. passed to the <code class="command">postgres</code> command via the
  205. <code class="option">-c</code> command-line parameter. For example,
  206. </p><pre class="programlisting">
  207. postgres -c log_connections=yes -c log_destination='syslog'
  208. </pre><p>
  209. Settings provided in this way override those set via
  210. <code class="filename">postgresql.conf</code> or <code class="command">ALTER SYSTEM</code>,
  211. so they cannot be changed globally without restarting the server.
  212. </p></li><li class="listitem"><p>
  213. When starting a client session via <span class="application">libpq</span>,
  214. parameter settings can be
  215. specified using the <code class="envar">PGOPTIONS</code> environment variable.
  216. Settings established in this way constitute defaults for the life
  217. of the session, but do not affect other sessions.
  218. For historical reasons, the format of <code class="envar">PGOPTIONS</code> is
  219. similar to that used when launching the <code class="command">postgres</code>
  220. command; specifically, the <code class="option">-c</code> flag must be specified.
  221. For example,
  222. </p><pre class="programlisting">
  223. env PGOPTIONS="-c geqo=off -c statement_timeout=5min" psql
  224. </pre><p>
  225. </p><p>
  226. Other clients and libraries might provide their own mechanisms,
  227. via the shell or otherwise, that allow the user to alter session
  228. settings without direct use of SQL commands.
  229. </p></li></ul></div></div><div class="sect2" id="CONFIG-INCLUDES"><div class="titlepage"><div><div><h3 class="title">19.1.5. Managing Configuration File Contents</h3></div></div></div><p>
  230. <span class="productname">PostgreSQL</span> provides several features for breaking
  231. down complex <code class="filename">postgresql.conf</code> files into sub-files.
  232. These features are especially useful when managing multiple servers
  233. with related, but not identical, configurations.
  234. </p><p>
  235. <a id="id-1.6.6.4.6.3.1" class="indexterm"></a>
  236. In addition to individual parameter settings,
  237. the <code class="filename">postgresql.conf</code> file can contain <em class="firstterm">include
  238. directives</em>, which specify another file to read and process as if
  239. it were inserted into the configuration file at this point. This
  240. feature allows a configuration file to be divided into physically
  241. separate parts. Include directives simply look like:
  242. </p><pre class="programlisting">
  243. include 'filename'
  244. </pre><p>
  245. If the file name is not an absolute path, it is taken as relative to
  246. the directory containing the referencing configuration file.
  247. Inclusions can be nested.
  248. </p><p>
  249. <a id="id-1.6.6.4.6.4.1" class="indexterm"></a>
  250. There is also an <code class="literal">include_if_exists</code> directive, which acts
  251. the same as the <code class="literal">include</code> directive, except
  252. when the referenced file does not exist or cannot be read. A regular
  253. <code class="literal">include</code> will consider this an error condition, but
  254. <code class="literal">include_if_exists</code> merely logs a message and continues
  255. processing the referencing configuration file.
  256. </p><p>
  257. <a id="id-1.6.6.4.6.5.1" class="indexterm"></a>
  258. The <code class="filename">postgresql.conf</code> file can also contain
  259. <code class="literal">include_dir</code> directives, which specify an entire
  260. directory of configuration files to include. These look like
  261. </p><pre class="programlisting">
  262. include_dir 'directory'
  263. </pre><p>
  264. Non-absolute directory names are taken as relative to the directory
  265. containing the referencing configuration file. Within the specified
  266. directory, only non-directory files whose names end with the
  267. suffix <code class="literal">.conf</code> will be included. File names that
  268. start with the <code class="literal">.</code> character are also ignored, to
  269. prevent mistakes since such files are hidden on some platforms. Multiple
  270. files within an include directory are processed in file name order
  271. (according to C locale rules, i.e. numbers before letters, and
  272. uppercase letters before lowercase ones).
  273. </p><p>
  274. Include files or directories can be used to logically separate portions
  275. of the database configuration, rather than having a single large
  276. <code class="filename">postgresql.conf</code> file. Consider a company that has two
  277. database servers, each with a different amount of memory. There are
  278. likely elements of the configuration both will share, for things such
  279. as logging. But memory-related parameters on the server will vary
  280. between the two. And there might be server specific customizations,
  281. too. One way to manage this situation is to break the custom
  282. configuration changes for your site into three files. You could add
  283. this to the end of your <code class="filename">postgresql.conf</code> file to include
  284. them:
  285. </p><pre class="programlisting">
  286. include 'shared.conf'
  287. include 'memory.conf'
  288. include 'server.conf'
  289. </pre><p>
  290. All systems would have the same <code class="filename">shared.conf</code>. Each
  291. server with a particular amount of memory could share the
  292. same <code class="filename">memory.conf</code>; you might have one for all servers
  293. with 8GB of RAM, another for those having 16GB. And
  294. finally <code class="filename">server.conf</code> could have truly server-specific
  295. configuration information in it.
  296. </p><p>
  297. Another possibility is to create a configuration file directory and
  298. put this information into files there. For example, a <code class="filename">conf.d</code>
  299. directory could be referenced at the end of <code class="filename">postgresql.conf</code>:
  300. </p><pre class="programlisting">
  301. include_dir 'conf.d'
  302. </pre><p>
  303. Then you could name the files in the <code class="filename">conf.d</code> directory
  304. like this:
  305. </p><pre class="programlisting">
  306. 00shared.conf
  307. 01memory.conf
  308. 02server.conf
  309. </pre><p>
  310. This naming convention establishes a clear order in which these
  311. files will be loaded. This is important because only the last
  312. setting encountered for a particular parameter while the server is
  313. reading configuration files will be used. In this example,
  314. something set in <code class="filename">conf.d/02server.conf</code> would override a
  315. value set in <code class="filename">conf.d/01memory.conf</code>.
  316. </p><p>
  317. You might instead use this approach to naming the files
  318. descriptively:
  319. </p><pre class="programlisting">
  320. 00shared.conf
  321. 01memory-8GB.conf
  322. 02server-foo.conf
  323. </pre><p>
  324. This sort of arrangement gives a unique name for each configuration file
  325. variation. This can help eliminate ambiguity when several servers have
  326. their configurations all stored in one place, such as in a version
  327. control repository. (Storing database configuration files under version
  328. control is another good practice to consider.)
  329. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="runtime-config.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="runtime-config.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="runtime-config-file-locations.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 19. Server Configuration </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 19.2. File Locations</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1