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.

734 lines
57KB

  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.8. Error Reporting and Logging</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-query.html" title="19.7. Query Planning" /><link rel="next" href="runtime-config-statistics.html" title="19.9. Run-time Statistics" /></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.8. Error Reporting and Logging</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="runtime-config-query.html" title="19.7. Query Planning">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-statistics.html" title="19.9. Run-time Statistics">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="RUNTIME-CONFIG-LOGGING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">19.8. Error Reporting and Logging</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHERE">19.8.1. Where to Log</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN">19.8.2. When to Log</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT">19.8.3. What to Log</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG">19.8.4. Using CSV-Format Log Output</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#id-1.6.6.11.7">19.8.5. Process Title</a></span></dt></dl></div><a id="id-1.6.6.11.2" class="indexterm"></a><div class="sect2" id="RUNTIME-CONFIG-LOGGING-WHERE"><div class="titlepage"><div><div><h3 class="title">19.8.1. Where to Log</h3></div></div></div><a id="id-1.6.6.11.3.2" class="indexterm"></a><a id="id-1.6.6.11.3.3" class="indexterm"></a><div class="variablelist"><dl class="variablelist"><dt id="GUC-LOG-DESTINATION"><span class="term"><code class="varname">log_destination</code> (<code class="type">string</code>)
  3. <a id="id-1.6.6.11.3.4.1.1.3" class="indexterm"></a>
  4. </span></dt><dd><p>
  5. <span class="productname">PostgreSQL</span> supports several methods
  6. for logging server messages, including
  7. <span class="systemitem">stderr</span>, <span class="systemitem">csvlog</span> and
  8. <span class="systemitem">syslog</span>. On Windows,
  9. <span class="systemitem">eventlog</span> is also supported. Set this
  10. parameter to a list of desired log destinations separated by
  11. commas. The default is to log to <span class="systemitem">stderr</span>
  12. only.
  13. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  14. file or on the server command line.
  15. </p><p>
  16. If <span class="systemitem">csvlog</span> is included in <code class="varname">log_destination</code>,
  17. log entries are output in <span class="quote">“<span class="quote">comma separated
  18. value</span>”</span> (<acronym class="acronym">CSV</acronym>) format, which is convenient for
  19. loading logs into programs.
  20. See <a class="xref" href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG" title="19.8.4. Using CSV-Format Log Output">Section 19.8.4</a> for details.
  21. <a class="xref" href="runtime-config-logging.html#GUC-LOGGING-COLLECTOR">logging_collector</a> must be enabled to generate
  22. CSV-format log output.
  23. </p><p>
  24. When either <span class="systemitem">stderr</span> or
  25. <span class="systemitem">csvlog</span> are included, the file
  26. <code class="filename">current_logfiles</code> is created to record the location
  27. of the log file(s) currently in use by the logging collector and the
  28. associated logging destination. This provides a convenient way to
  29. find the logs currently in use by the instance. Here is an example of
  30. this file's content:
  31. </p><pre class="programlisting">
  32. stderr log/postgresql.log
  33. csvlog log/postgresql.csv
  34. </pre><p>
  35. <code class="filename">current_logfiles</code> is recreated when a new log file
  36. is created as an effect of rotation, and
  37. when <code class="varname">log_destination</code> is reloaded. It is removed when
  38. neither <span class="systemitem">stderr</span>
  39. nor <span class="systemitem">csvlog</span> are included
  40. in <code class="varname">log_destination</code>, and when the logging collector is
  41. disabled.
  42. </p><div class="note"><h3 class="title">Note</h3><p>
  43. On most Unix systems, you will need to alter the configuration of
  44. your system's <span class="application">syslog</span> daemon in order
  45. to make use of the <span class="systemitem">syslog</span> option for
  46. <code class="varname">log_destination</code>. <span class="productname">PostgreSQL</span>
  47. can log to <span class="application">syslog</span> facilities
  48. <code class="literal">LOCAL0</code> through <code class="literal">LOCAL7</code> (see <a class="xref" href="runtime-config-logging.html#GUC-SYSLOG-FACILITY">syslog_facility</a>), but the default
  49. <span class="application">syslog</span> configuration on most platforms
  50. will discard all such messages. You will need to add something like:
  51. </p><pre class="programlisting">
  52. local0.* /var/log/postgresql
  53. </pre><p>
  54. to the <span class="application">syslog</span> daemon's configuration file
  55. to make it work.
  56. </p><p>
  57. On Windows, when you use the <code class="literal">eventlog</code>
  58. option for <code class="varname">log_destination</code>, you should
  59. register an event source and its library with the operating
  60. system so that the Windows Event Viewer can display event
  61. log messages cleanly.
  62. See <a class="xref" href="event-log-registration.html" title="18.12. Registering Event Log on Windows">Section 18.12</a> for details.
  63. </p></div></dd><dt id="GUC-LOGGING-COLLECTOR"><span class="term"><code class="varname">logging_collector</code> (<code class="type">boolean</code>)
  64. <a id="id-1.6.6.11.3.4.2.1.3" class="indexterm"></a>
  65. </span></dt><dd><p>
  66. This parameter enables the <em class="firstterm">logging collector</em>, which
  67. is a background process that captures log messages
  68. sent to <span class="systemitem">stderr</span> and redirects them into log files.
  69. This approach is often more useful than
  70. logging to <span class="application">syslog</span>, since some types of messages
  71. might not appear in <span class="application">syslog</span> output. (One common
  72. example is dynamic-linker failure messages; another is error messages
  73. produced by scripts such as <code class="varname">archive_command</code>.)
  74. This parameter can only be set at server start.
  75. </p><div class="note"><h3 class="title">Note</h3><p>
  76. It is possible to log to <span class="systemitem">stderr</span> without using the
  77. logging collector; the log messages will just go to wherever the
  78. server's <span class="systemitem">stderr</span> is directed. However, that method is
  79. only suitable for low log volumes, since it provides no convenient
  80. way to rotate log files. Also, on some platforms not using the
  81. logging collector can result in lost or garbled log output, because
  82. multiple processes writing concurrently to the same log file can
  83. overwrite each other's output.
  84. </p></div><div class="note"><h3 class="title">Note</h3><p>
  85. The logging collector is designed to never lose messages. This means
  86. that in case of extremely high load, server processes could be
  87. blocked while trying to send additional log messages when the
  88. collector has fallen behind. In contrast, <span class="application">syslog</span>
  89. prefers to drop messages if it cannot write them, which means it
  90. may fail to log some messages in such cases but it will not block
  91. the rest of the system.
  92. </p></div></dd><dt id="GUC-LOG-DIRECTORY"><span class="term"><code class="varname">log_directory</code> (<code class="type">string</code>)
  93. <a id="id-1.6.6.11.3.4.3.1.3" class="indexterm"></a>
  94. </span></dt><dd><p>
  95. When <code class="varname">logging_collector</code> is enabled,
  96. this parameter determines the directory in which log files will be created.
  97. It can be specified as an absolute path, or relative to the
  98. cluster data directory.
  99. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  100. file or on the server command line.
  101. The default is <code class="literal">log</code>.
  102. </p></dd><dt id="GUC-LOG-FILENAME"><span class="term"><code class="varname">log_filename</code> (<code class="type">string</code>)
  103. <a id="id-1.6.6.11.3.4.4.1.3" class="indexterm"></a>
  104. </span></dt><dd><p>
  105. When <code class="varname">logging_collector</code> is enabled,
  106. this parameter sets the file names of the created log files. The value
  107. is treated as a <code class="function">strftime</code> pattern,
  108. so <code class="literal">%</code>-escapes can be used to specify time-varying
  109. file names. (Note that if there are
  110. any time-zone-dependent <code class="literal">%</code>-escapes, the computation
  111. is done in the zone specified
  112. by <a class="xref" href="runtime-config-logging.html#GUC-LOG-TIMEZONE">log_timezone</a>.)
  113. The supported <code class="literal">%</code>-escapes are similar to those
  114. listed in the Open Group's <a class="ulink" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html" target="_top">strftime
  115. </a> specification.
  116. Note that the system's <code class="function">strftime</code> is not used
  117. directly, so platform-specific (nonstandard) extensions do not work.
  118. The default is <code class="literal">postgresql-%Y-%m-%d_%H%M%S.log</code>.
  119. </p><p>
  120. If you specify a file name without escapes, you should plan to
  121. use a log rotation utility to avoid eventually filling the
  122. entire disk. In releases prior to 8.4, if
  123. no <code class="literal">%</code> escapes were
  124. present, <span class="productname">PostgreSQL</span> would append
  125. the epoch of the new log file's creation time, but this is no
  126. longer the case.
  127. </p><p>
  128. If CSV-format output is enabled in <code class="varname">log_destination</code>,
  129. <code class="literal">.csv</code> will be appended to the timestamped
  130. log file name to create the file name for CSV-format output.
  131. (If <code class="varname">log_filename</code> ends in <code class="literal">.log</code>, the suffix is
  132. replaced instead.)
  133. </p><p>
  134. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  135. file or on the server command line.
  136. </p></dd><dt id="GUC-LOG-FILE-MODE"><span class="term"><code class="varname">log_file_mode</code> (<code class="type">integer</code>)
  137. <a id="id-1.6.6.11.3.4.5.1.3" class="indexterm"></a>
  138. </span></dt><dd><p>
  139. On Unix systems this parameter sets the permissions for log files
  140. when <code class="varname">logging_collector</code> is enabled. (On Microsoft
  141. Windows this parameter is ignored.)
  142. The parameter value is expected to be a numeric mode
  143. specified in the format accepted by the
  144. <code class="function">chmod</code> and <code class="function">umask</code>
  145. system calls. (To use the customary octal format the number
  146. must start with a <code class="literal">0</code> (zero).)
  147. </p><p>
  148. The default permissions are <code class="literal">0600</code>, meaning only the
  149. server owner can read or write the log files. The other commonly
  150. useful setting is <code class="literal">0640</code>, allowing members of the owner's
  151. group to read the files. Note however that to make use of such a
  152. setting, you'll need to alter <a class="xref" href="runtime-config-logging.html#GUC-LOG-DIRECTORY">log_directory</a> to
  153. store the files somewhere outside the cluster data directory. In
  154. any case, it's unwise to make the log files world-readable, since
  155. they might contain sensitive data.
  156. </p><p>
  157. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  158. file or on the server command line.
  159. </p></dd><dt id="GUC-LOG-ROTATION-AGE"><span class="term"><code class="varname">log_rotation_age</code> (<code class="type">integer</code>)
  160. <a id="id-1.6.6.11.3.4.6.1.3" class="indexterm"></a>
  161. </span></dt><dd><p>
  162. When <code class="varname">logging_collector</code> is enabled,
  163. this parameter determines the maximum amount of time to use an
  164. individual log file, after which a new log file will be created.
  165. If this value is specified without units, it is taken as minutes.
  166. The default is 24 hours.
  167. Set to zero to disable time-based creation of new log files.
  168. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  169. file or on the server command line.
  170. </p></dd><dt id="GUC-LOG-ROTATION-SIZE"><span class="term"><code class="varname">log_rotation_size</code> (<code class="type">integer</code>)
  171. <a id="id-1.6.6.11.3.4.7.1.3" class="indexterm"></a>
  172. </span></dt><dd><p>
  173. When <code class="varname">logging_collector</code> is enabled,
  174. this parameter determines the maximum size of an individual log file.
  175. After this amount of data has been emitted into a log file,
  176. a new log file will be created.
  177. If this value is specified without units, it is taken as kilobytes.
  178. The default is 10 megabytes.
  179. Set to zero to disable size-based creation of new log files.
  180. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  181. file or on the server command line.
  182. </p></dd><dt id="GUC-LOG-TRUNCATE-ON-ROTATION"><span class="term"><code class="varname">log_truncate_on_rotation</code> (<code class="type">boolean</code>)
  183. <a id="id-1.6.6.11.3.4.8.1.3" class="indexterm"></a>
  184. </span></dt><dd><p>
  185. When <code class="varname">logging_collector</code> is enabled,
  186. this parameter will cause <span class="productname">PostgreSQL</span> to truncate (overwrite),
  187. rather than append to, any existing log file of the same name.
  188. However, truncation will occur only when a new file is being opened
  189. due to time-based rotation, not during server startup or size-based
  190. rotation. When off, pre-existing files will be appended to in
  191. all cases. For example, using this setting in combination with
  192. a <code class="varname">log_filename</code> like <code class="literal">postgresql-%H.log</code>
  193. would result in generating twenty-four hourly log files and then
  194. cyclically overwriting them.
  195. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  196. file or on the server command line.
  197. </p><p>
  198. Example: To keep 7 days of logs, one log file per day named
  199. <code class="literal">server_log.Mon</code>, <code class="literal">server_log.Tue</code>,
  200. etc, and automatically overwrite last week's log with this week's log,
  201. set <code class="varname">log_filename</code> to <code class="literal">server_log.%a</code>,
  202. <code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code>, and
  203. <code class="varname">log_rotation_age</code> to <code class="literal">1440</code>.
  204. </p><p>
  205. Example: To keep 24 hours of logs, one log file per hour, but
  206. also rotate sooner if the log file size exceeds 1GB, set
  207. <code class="varname">log_filename</code> to <code class="literal">server_log.%H%M</code>,
  208. <code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code>,
  209. <code class="varname">log_rotation_age</code> to <code class="literal">60</code>, and
  210. <code class="varname">log_rotation_size</code> to <code class="literal">1000000</code>.
  211. Including <code class="literal">%M</code> in <code class="varname">log_filename</code> allows
  212. any size-driven rotations that might occur to select a file name
  213. different from the hour's initial file name.
  214. </p></dd><dt id="GUC-SYSLOG-FACILITY"><span class="term"><code class="varname">syslog_facility</code> (<code class="type">enum</code>)
  215. <a id="id-1.6.6.11.3.4.9.1.3" class="indexterm"></a>
  216. </span></dt><dd><p>
  217. When logging to <span class="application">syslog</span> is enabled, this parameter
  218. determines the <span class="application">syslog</span>
  219. <span class="quote">“<span class="quote">facility</span>”</span> to be used. You can choose
  220. from <code class="literal">LOCAL0</code>, <code class="literal">LOCAL1</code>,
  221. <code class="literal">LOCAL2</code>, <code class="literal">LOCAL3</code>, <code class="literal">LOCAL4</code>,
  222. <code class="literal">LOCAL5</code>, <code class="literal">LOCAL6</code>, <code class="literal">LOCAL7</code>;
  223. the default is <code class="literal">LOCAL0</code>. See also the
  224. documentation of your system's
  225. <span class="application">syslog</span> daemon.
  226. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  227. file or on the server command line.
  228. </p></dd><dt id="GUC-SYSLOG-IDENT"><span class="term"><code class="varname">syslog_ident</code> (<code class="type">string</code>)
  229. <a id="id-1.6.6.11.3.4.10.1.3" class="indexterm"></a>
  230. </span></dt><dd><p>
  231. When logging to <span class="application">syslog</span> is enabled, this parameter
  232. determines the program name used to identify
  233. <span class="productname">PostgreSQL</span> messages in
  234. <span class="application">syslog</span> logs. The default is
  235. <code class="literal">postgres</code>.
  236. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  237. file or on the server command line.
  238. </p></dd><dt id="GUC-SYSLOG-SEQUENCE-NUMBERS"><span class="term"><code class="varname">syslog_sequence_numbers</code> (<code class="type">boolean</code>)
  239. <a id="id-1.6.6.11.3.4.11.1.3" class="indexterm"></a>
  240. </span></dt><dd><p>
  241. When logging to <span class="application">syslog</span> and this is on (the
  242. default), then each message will be prefixed by an increasing
  243. sequence number (such as <code class="literal">[2]</code>). This circumvents
  244. the <span class="quote">“<span class="quote">--- last message repeated N times ---</span>”</span> suppression
  245. that many syslog implementations perform by default. In more modern
  246. syslog implementations, repeated message suppression can be configured
  247. (for example, <code class="literal">$RepeatedMsgReduction</code>
  248. in <span class="productname">rsyslog</span>), so this might not be
  249. necessary. Also, you could turn this off if you actually want to
  250. suppress repeated messages.
  251. </p><p>
  252. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  253. file or on the server command line.
  254. </p></dd><dt id="GUC-SYSLOG-SPLIT-MESSAGES"><span class="term"><code class="varname">syslog_split_messages</code> (<code class="type">boolean</code>)
  255. <a id="id-1.6.6.11.3.4.12.1.3" class="indexterm"></a>
  256. </span></dt><dd><p>
  257. When logging to <span class="application">syslog</span> is enabled, this parameter
  258. determines how messages are delivered to syslog. When on (the
  259. default), messages are split by lines, and long lines are split so
  260. that they will fit into 1024 bytes, which is a typical size limit for
  261. traditional syslog implementations. When off, PostgreSQL server log
  262. messages are delivered to the syslog service as is, and it is up to
  263. the syslog service to cope with the potentially bulky messages.
  264. </p><p>
  265. If syslog is ultimately logging to a text file, then the effect will
  266. be the same either way, and it is best to leave the setting on, since
  267. most syslog implementations either cannot handle large messages or
  268. would need to be specially configured to handle them. But if syslog
  269. is ultimately writing into some other medium, it might be necessary or
  270. more useful to keep messages logically together.
  271. </p><p>
  272. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  273. file or on the server command line.
  274. </p></dd><dt id="GUC-EVENT-SOURCE"><span class="term"><code class="varname">event_source</code> (<code class="type">string</code>)
  275. <a id="id-1.6.6.11.3.4.13.1.3" class="indexterm"></a>
  276. </span></dt><dd><p>
  277. When logging to <span class="application">event log</span> is enabled, this parameter
  278. determines the program name used to identify
  279. <span class="productname">PostgreSQL</span> messages in
  280. the log. The default is <code class="literal">PostgreSQL</code>.
  281. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  282. file or on the server command line.
  283. </p></dd></dl></div></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-WHEN"><div class="titlepage"><div><div><h3 class="title">19.8.2. When to Log</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt id="GUC-LOG-MIN-MESSAGES"><span class="term"><code class="varname">log_min_messages</code> (<code class="type">enum</code>)
  284. <a id="id-1.6.6.11.4.2.1.1.3" class="indexterm"></a>
  285. </span></dt><dd><p>
  286. Controls which <a class="link" href="runtime-config-logging.html#RUNTIME-CONFIG-SEVERITY-LEVELS" title="Table 19.1. Message Severity Levels">message
  287. levels</a> are written to the server log.
  288. Valid values are <code class="literal">DEBUG5</code>, <code class="literal">DEBUG4</code>,
  289. <code class="literal">DEBUG3</code>, <code class="literal">DEBUG2</code>, <code class="literal">DEBUG1</code>,
  290. <code class="literal">INFO</code>, <code class="literal">NOTICE</code>, <code class="literal">WARNING</code>,
  291. <code class="literal">ERROR</code>, <code class="literal">LOG</code>, <code class="literal">FATAL</code>, and
  292. <code class="literal">PANIC</code>. Each level includes all the levels that
  293. follow it. The later the level, the fewer messages are sent
  294. to the log. The default is <code class="literal">WARNING</code>. Note that
  295. <code class="literal">LOG</code> has a different rank here than in
  296. <a class="xref" href="runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES">client_min_messages</a>.
  297. Only superusers can change this setting.
  298. </p></dd><dt id="GUC-LOG-MIN-ERROR-STATEMENT"><span class="term"><code class="varname">log_min_error_statement</code> (<code class="type">enum</code>)
  299. <a id="id-1.6.6.11.4.2.2.1.3" class="indexterm"></a>
  300. </span></dt><dd><p>
  301. Controls which SQL statements that cause an error
  302. condition are recorded in the server log. The current
  303. SQL statement is included in the log entry for any message of
  304. the specified
  305. <a class="link" href="runtime-config-logging.html#RUNTIME-CONFIG-SEVERITY-LEVELS" title="Table 19.1. Message Severity Levels">severity</a>
  306. or higher.
  307. Valid values are <code class="literal">DEBUG5</code>,
  308. <code class="literal">DEBUG4</code>, <code class="literal">DEBUG3</code>,
  309. <code class="literal">DEBUG2</code>, <code class="literal">DEBUG1</code>,
  310. <code class="literal">INFO</code>, <code class="literal">NOTICE</code>,
  311. <code class="literal">WARNING</code>, <code class="literal">ERROR</code>,
  312. <code class="literal">LOG</code>,
  313. <code class="literal">FATAL</code>, and <code class="literal">PANIC</code>.
  314. The default is <code class="literal">ERROR</code>, which means statements
  315. causing errors, log messages, fatal errors, or panics will be logged.
  316. To effectively turn off logging of failing statements,
  317. set this parameter to <code class="literal">PANIC</code>.
  318. Only superusers can change this setting.
  319. </p></dd><dt id="GUC-LOG-MIN-DURATION-STATEMENT"><span class="term"><code class="varname">log_min_duration_statement</code> (<code class="type">integer</code>)
  320. <a id="id-1.6.6.11.4.2.3.1.3" class="indexterm"></a>
  321. </span></dt><dd><p>
  322. Causes the duration of each completed statement to be logged
  323. if the statement ran for at least the specified amount of time.
  324. If this value is specified without units, it is taken as milliseconds.
  325. Setting this to zero prints all statement durations.
  326. Minus-one (the default) disables logging statement durations.
  327. For example, if you set it to <code class="literal">250ms</code>
  328. then all SQL statements that run 250ms or longer will be
  329. logged. Enabling this parameter can be helpful in tracking down
  330. unoptimized queries in your applications.
  331. Only superusers can change this setting.
  332. </p><p>
  333. For clients using extended query protocol, durations of the Parse,
  334. Bind, and Execute steps are logged independently.
  335. </p><div class="note"><h3 class="title">Note</h3><p>
  336. When using this option together with
  337. <a class="xref" href="runtime-config-logging.html#GUC-LOG-STATEMENT">log_statement</a>,
  338. the text of statements that are logged because of
  339. <code class="varname">log_statement</code> will not be repeated in the
  340. duration log message.
  341. If you are not using <span class="application">syslog</span>, it is recommended
  342. that you log the PID or session ID using
  343. <a class="xref" href="runtime-config-logging.html#GUC-LOG-LINE-PREFIX">log_line_prefix</a>
  344. so that you can link the statement message to the later
  345. duration message using the process ID or session ID.
  346. </p></div></dd><dt id="GUC-LOG-TRANSACTION-SAMPLE-RATE"><span class="term"><code class="varname">log_transaction_sample_rate</code> (<code class="type">real</code>)
  347. <a id="id-1.6.6.11.4.2.4.1.3" class="indexterm"></a>
  348. </span></dt><dd><p>
  349. Set the fraction of transactions whose statements are all logged,
  350. in addition to statements logged for other reasons. It applies to
  351. each new transaction regardless of its statements' durations.
  352. The default is <code class="literal">0</code>, meaning not to log statements
  353. from any additional transaction. Setting this to <code class="literal">1</code>
  354. logs all statements for all transactions.
  355. <code class="varname">log_transaction_sample_rate</code> is helpful to track a
  356. sample of transaction.
  357. Only superusers can change this setting.
  358. </p><div class="note"><h3 class="title">Note</h3><p>
  359. Like all statement-logging options, this option can add significant
  360. overhead.
  361. </p></div></dd></dl></div><p>
  362. <a class="xref" href="runtime-config-logging.html#RUNTIME-CONFIG-SEVERITY-LEVELS" title="Table 19.1. Message Severity Levels">Table 19.1</a> explains the message
  363. severity levels used by <span class="productname">PostgreSQL</span>. If logging output
  364. is sent to <span class="systemitem">syslog</span> or Windows'
  365. <span class="systemitem">eventlog</span>, the severity levels are translated
  366. as shown in the table.
  367. </p><div class="table" id="RUNTIME-CONFIG-SEVERITY-LEVELS"><p class="title"><strong>Table 19.1. Message Severity Levels</strong></p><div class="table-contents"><table class="table" summary="Message Severity Levels" border="1"><colgroup><col /><col /><col /><col /></colgroup><thead><tr><th>Severity</th><th>Usage</th><th><span class="systemitem">syslog</span></th><th><span class="systemitem">eventlog</span></th></tr></thead><tbody><tr><td><code class="literal">DEBUG1..DEBUG5</code></td><td>Provides successively-more-detailed information for use by
  368. developers.</td><td><code class="literal">DEBUG</code></td><td><code class="literal">INFORMATION</code></td></tr><tr><td><code class="literal">INFO</code></td><td>Provides information implicitly requested by the user,
  369. e.g., output from <code class="command">VACUUM VERBOSE</code>.</td><td><code class="literal">INFO</code></td><td><code class="literal">INFORMATION</code></td></tr><tr><td><code class="literal">NOTICE</code></td><td>Provides information that might be helpful to users, e.g.,
  370. notice of truncation of long identifiers.</td><td><code class="literal">NOTICE</code></td><td><code class="literal">INFORMATION</code></td></tr><tr><td><code class="literal">WARNING</code></td><td>Provides warnings of likely problems, e.g., <code class="command">COMMIT</code>
  371. outside a transaction block.</td><td><code class="literal">NOTICE</code></td><td><code class="literal">WARNING</code></td></tr><tr><td><code class="literal">ERROR</code></td><td>Reports an error that caused the current command to
  372. abort.</td><td><code class="literal">WARNING</code></td><td><code class="literal">ERROR</code></td></tr><tr><td><code class="literal">LOG</code></td><td>Reports information of interest to administrators, e.g.,
  373. checkpoint activity.</td><td><code class="literal">INFO</code></td><td><code class="literal">INFORMATION</code></td></tr><tr><td><code class="literal">FATAL</code></td><td>Reports an error that caused the current session to
  374. abort.</td><td><code class="literal">ERR</code></td><td><code class="literal">ERROR</code></td></tr><tr><td><code class="literal">PANIC</code></td><td>Reports an error that caused all database sessions to abort.</td><td><code class="literal">CRIT</code></td><td><code class="literal">ERROR</code></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-WHAT"><div class="titlepage"><div><div><h3 class="title">19.8.3. What to Log</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt id="GUC-APPLICATION-NAME"><span class="term"><code class="varname">application_name</code> (<code class="type">string</code>)
  375. <a id="id-1.6.6.11.5.2.1.1.3" class="indexterm"></a>
  376. </span></dt><dd><p>
  377. The <code class="varname">application_name</code> can be any string of less than
  378. <code class="symbol">NAMEDATALEN</code> characters (64 characters in a standard build).
  379. It is typically set by an application upon connection to the server.
  380. The name will be displayed in the <code class="structname">pg_stat_activity</code> view
  381. and included in CSV log entries. It can also be included in regular
  382. log entries via the <a class="xref" href="runtime-config-logging.html#GUC-LOG-LINE-PREFIX">log_line_prefix</a> parameter.
  383. Only printable ASCII characters may be used in the
  384. <code class="varname">application_name</code> value. Other characters will be
  385. replaced with question marks (<code class="literal">?</code>).
  386. </p></dd><dt><span class="term"><code class="varname">debug_print_parse</code> (<code class="type">boolean</code>)
  387. <a id="id-1.6.6.11.5.2.2.1.3" class="indexterm"></a>
  388. <br /></span><span class="term"><code class="varname">debug_print_rewritten</code> (<code class="type">boolean</code>)
  389. <a id="id-1.6.6.11.5.2.2.2.3" class="indexterm"></a>
  390. <br /></span><span class="term"><code class="varname">debug_print_plan</code> (<code class="type">boolean</code>)
  391. <a id="id-1.6.6.11.5.2.2.3.3" class="indexterm"></a>
  392. </span></dt><dd><p>
  393. These parameters enable various debugging output to be emitted.
  394. When set, they print the resulting parse tree, the query rewriter
  395. output, or the execution plan for each executed query.
  396. These messages are emitted at <code class="literal">LOG</code> message level, so by
  397. default they will appear in the server log but will not be sent to the
  398. client. You can change that by adjusting
  399. <a class="xref" href="runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES">client_min_messages</a> and/or
  400. <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-MESSAGES">log_min_messages</a>.
  401. These parameters are off by default.
  402. </p></dd><dt><span class="term"><code class="varname">debug_pretty_print</code> (<code class="type">boolean</code>)
  403. <a id="id-1.6.6.11.5.2.3.1.3" class="indexterm"></a>
  404. </span></dt><dd><p>
  405. When set, <code class="varname">debug_pretty_print</code> indents the messages
  406. produced by <code class="varname">debug_print_parse</code>,
  407. <code class="varname">debug_print_rewritten</code>, or
  408. <code class="varname">debug_print_plan</code>. This results in more readable
  409. but much longer output than the <span class="quote">“<span class="quote">compact</span>”</span> format used when
  410. it is off. It is on by default.
  411. </p></dd><dt id="GUC-LOG-CHECKPOINTS"><span class="term"><code class="varname">log_checkpoints</code> (<code class="type">boolean</code>)
  412. <a id="id-1.6.6.11.5.2.4.1.3" class="indexterm"></a>
  413. </span></dt><dd><p>
  414. Causes checkpoints and restartpoints to be logged in the server log.
  415. Some statistics are included in the log messages, including the number
  416. of buffers written and the time spent writing them.
  417. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  418. file or on the server command line. The default is off.
  419. </p></dd><dt id="GUC-LOG-CONNECTIONS"><span class="term"><code class="varname">log_connections</code> (<code class="type">boolean</code>)
  420. <a id="id-1.6.6.11.5.2.5.1.3" class="indexterm"></a>
  421. </span></dt><dd><p>
  422. Causes each attempted connection to the server to be logged,
  423. as well as successful completion of client authentication.
  424. Only superusers can change this parameter at session start,
  425. and it cannot be changed at all within a session.
  426. The default is <code class="literal">off</code>.
  427. </p><div class="note"><h3 class="title">Note</h3><p>
  428. Some client programs, like <span class="application">psql</span>, attempt
  429. to connect twice while determining if a password is required, so
  430. duplicate <span class="quote">“<span class="quote">connection received</span>”</span> messages do not
  431. necessarily indicate a problem.
  432. </p></div></dd><dt id="GUC-LOG-DISCONNECTIONS"><span class="term"><code class="varname">log_disconnections</code> (<code class="type">boolean</code>)
  433. <a id="id-1.6.6.11.5.2.6.1.3" class="indexterm"></a>
  434. </span></dt><dd><p>
  435. Causes session terminations to be logged. The log output
  436. provides information similar to <code class="varname">log_connections</code>,
  437. plus the duration of the session.
  438. Only superusers can change this parameter at session start,
  439. and it cannot be changed at all within a session.
  440. The default is <code class="literal">off</code>.
  441. </p></dd><dt id="GUC-LOG-DURATION"><span class="term"><code class="varname">log_duration</code> (<code class="type">boolean</code>)
  442. <a id="id-1.6.6.11.5.2.7.1.3" class="indexterm"></a>
  443. </span></dt><dd><p>
  444. Causes the duration of every completed statement to be logged.
  445. The default is <code class="literal">off</code>.
  446. Only superusers can change this setting.
  447. </p><p>
  448. For clients using extended query protocol, durations of the Parse,
  449. Bind, and Execute steps are logged independently.
  450. </p><div class="note"><h3 class="title">Note</h3><p>
  451. The difference between enabling <code class="varname">log_duration</code> and setting
  452. <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT">log_min_duration_statement</a> to zero is that
  453. exceeding <code class="varname">log_min_duration_statement</code> forces the text of
  454. the query to be logged, but this option doesn't. Thus, if
  455. <code class="varname">log_duration</code> is <code class="literal">on</code> and
  456. <code class="varname">log_min_duration_statement</code> has a positive value, all
  457. durations are logged but the query text is included only for
  458. statements exceeding the threshold. This behavior can be useful for
  459. gathering statistics in high-load installations.
  460. </p></div></dd><dt id="GUC-LOG-ERROR-VERBOSITY"><span class="term"><code class="varname">log_error_verbosity</code> (<code class="type">enum</code>)
  461. <a id="id-1.6.6.11.5.2.8.1.3" class="indexterm"></a>
  462. </span></dt><dd><p>
  463. Controls the amount of detail written in the server log for each
  464. message that is logged. Valid values are <code class="literal">TERSE</code>,
  465. <code class="literal">DEFAULT</code>, and <code class="literal">VERBOSE</code>, each adding more
  466. fields to displayed messages. <code class="literal">TERSE</code> excludes
  467. the logging of <code class="literal">DETAIL</code>, <code class="literal">HINT</code>,
  468. <code class="literal">QUERY</code>, and <code class="literal">CONTEXT</code> error information.
  469. <code class="literal">VERBOSE</code> output includes the <code class="symbol">SQLSTATE</code> error
  470. code (see also <a class="xref" href="errcodes-appendix.html" title="Appendix A. PostgreSQL Error Codes">Appendix A</a>) and the source code file name, function name,
  471. and line number that generated the error.
  472. Only superusers can change this setting.
  473. </p></dd><dt id="GUC-LOG-HOSTNAME"><span class="term"><code class="varname">log_hostname</code> (<code class="type">boolean</code>)
  474. <a id="id-1.6.6.11.5.2.9.1.3" class="indexterm"></a>
  475. </span></dt><dd><p>
  476. By default, connection log messages only show the IP address of the
  477. connecting host. Turning this parameter on causes logging of the
  478. host name as well. Note that depending on your host name resolution
  479. setup this might impose a non-negligible performance penalty.
  480. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  481. file or on the server command line.
  482. </p></dd><dt id="GUC-LOG-LINE-PREFIX"><span class="term"><code class="varname">log_line_prefix</code> (<code class="type">string</code>)
  483. <a id="id-1.6.6.11.5.2.10.1.3" class="indexterm"></a>
  484. </span></dt><dd><p>
  485. This is a <code class="function">printf</code>-style string that is output at the
  486. beginning of each log line.
  487. <code class="literal">%</code> characters begin <span class="quote">“<span class="quote">escape sequences</span>”</span>
  488. that are replaced with status information as outlined below.
  489. Unrecognized escapes are ignored. Other
  490. characters are copied straight to the log line. Some escapes are
  491. only recognized by session processes, and will be treated as empty by
  492. background processes such as the main server process. Status
  493. information may be aligned either left or right by specifying a
  494. numeric literal after the % and before the option. A negative
  495. value will cause the status information to be padded on the
  496. right with spaces to give it a minimum width, whereas a positive
  497. value will pad on the left. Padding can be useful to aid human
  498. readability in log files.
  499. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  500. file or on the server command line. The default is
  501. <code class="literal">'%m [%p] '</code> which logs a time stamp and the process ID.
  502. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Escape</th><th>Effect</th><th>Session only</th></tr></thead><tbody><tr><td><code class="literal">%a</code></td><td>Application name</td><td>yes</td></tr><tr><td><code class="literal">%u</code></td><td>User name</td><td>yes</td></tr><tr><td><code class="literal">%d</code></td><td>Database name</td><td>yes</td></tr><tr><td><code class="literal">%r</code></td><td>Remote host name or IP address, and remote port</td><td>yes</td></tr><tr><td><code class="literal">%h</code></td><td>Remote host name or IP address</td><td>yes</td></tr><tr><td><code class="literal">%p</code></td><td>Process ID</td><td>no</td></tr><tr><td><code class="literal">%t</code></td><td>Time stamp without milliseconds</td><td>no</td></tr><tr><td><code class="literal">%m</code></td><td>Time stamp with milliseconds</td><td>no</td></tr><tr><td><code class="literal">%n</code></td><td>Time stamp with milliseconds (as a Unix epoch)</td><td>no</td></tr><tr><td><code class="literal">%i</code></td><td>Command tag: type of session's current command</td><td>yes</td></tr><tr><td><code class="literal">%e</code></td><td>SQLSTATE error code</td><td>no</td></tr><tr><td><code class="literal">%c</code></td><td>Session ID: see below</td><td>no</td></tr><tr><td><code class="literal">%l</code></td><td>Number of the log line for each session or process, starting at 1</td><td>no</td></tr><tr><td><code class="literal">%s</code></td><td>Process start time stamp</td><td>no</td></tr><tr><td><code class="literal">%v</code></td><td>Virtual transaction ID (backendID/localXID)</td><td>no</td></tr><tr><td><code class="literal">%x</code></td><td>Transaction ID (0 if none is assigned)</td><td>no</td></tr><tr><td><code class="literal">%q</code></td><td>Produces no output, but tells non-session
  503. processes to stop at this point in the string; ignored by
  504. session processes</td><td>no</td></tr><tr><td><code class="literal">%%</code></td><td>Literal <code class="literal">%</code></td><td>no</td></tr></tbody></table></div><p>
  505. The <code class="literal">%c</code> escape prints a quasi-unique session identifier,
  506. consisting of two 4-byte hexadecimal numbers (without leading zeros)
  507. separated by a dot. The numbers are the process start time and the
  508. process ID, so <code class="literal">%c</code> can also be used as a space saving way
  509. of printing those items. For example, to generate the session
  510. identifier from <code class="literal">pg_stat_activity</code>, use this query:
  511. </p><pre class="programlisting">
  512. SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||
  513. to_hex(pid)
  514. FROM pg_stat_activity;
  515. </pre><p>
  516. </p><div class="tip"><h3 class="title">Tip</h3><p>
  517. If you set a nonempty value for <code class="varname">log_line_prefix</code>,
  518. you should usually make its last character be a space, to provide
  519. visual separation from the rest of the log line. A punctuation
  520. character can be used too.
  521. </p></div><div class="tip"><h3 class="title">Tip</h3><p>
  522. <span class="application">Syslog</span> produces its own
  523. time stamp and process ID information, so you probably do not want to
  524. include those escapes if you are logging to <span class="application">syslog</span>.
  525. </p></div><div class="tip"><h3 class="title">Tip</h3><p>
  526. The <code class="literal">%q</code> escape is useful when including information that is
  527. only available in session (backend) context like user or database
  528. name. For example:
  529. </p><pre class="programlisting">
  530. log_line_prefix = '%m [%p] %q%u@%d/%a '
  531. </pre><p>
  532. </p></div></dd><dt id="GUC-LOG-LOCK-WAITS"><span class="term"><code class="varname">log_lock_waits</code> (<code class="type">boolean</code>)
  533. <a id="id-1.6.6.11.5.2.11.1.3" class="indexterm"></a>
  534. </span></dt><dd><p>
  535. Controls whether a log message is produced when a session waits
  536. longer than <a class="xref" href="runtime-config-locks.html#GUC-DEADLOCK-TIMEOUT">deadlock_timeout</a> to acquire a
  537. lock. This is useful in determining if lock waits are causing
  538. poor performance. The default is <code class="literal">off</code>.
  539. Only superusers can change this setting.
  540. </p></dd><dt id="GUC-LOG-STATEMENT"><span class="term"><code class="varname">log_statement</code> (<code class="type">enum</code>)
  541. <a id="id-1.6.6.11.5.2.12.1.3" class="indexterm"></a>
  542. </span></dt><dd><p>
  543. Controls which SQL statements are logged. Valid values are
  544. <code class="literal">none</code> (off), <code class="literal">ddl</code>, <code class="literal">mod</code>, and
  545. <code class="literal">all</code> (all statements). <code class="literal">ddl</code> logs all data definition
  546. statements, such as <code class="command">CREATE</code>, <code class="command">ALTER</code>, and
  547. <code class="command">DROP</code> statements. <code class="literal">mod</code> logs all
  548. <code class="literal">ddl</code> statements, plus data-modifying statements
  549. such as <code class="command">INSERT</code>,
  550. <code class="command">UPDATE</code>, <code class="command">DELETE</code>, <code class="command">TRUNCATE</code>,
  551. and <code class="command">COPY FROM</code>.
  552. <code class="command">PREPARE</code>, <code class="command">EXECUTE</code>, and
  553. <code class="command">EXPLAIN ANALYZE</code> statements are also logged if their
  554. contained command is of an appropriate type. For clients using
  555. extended query protocol, logging occurs when an Execute message
  556. is received, and values of the Bind parameters are included
  557. (with any embedded single-quote marks doubled).
  558. </p><p>
  559. The default is <code class="literal">none</code>. Only superusers can change this
  560. setting.
  561. </p><div class="note"><h3 class="title">Note</h3><p>
  562. Statements that contain simple syntax errors are not logged
  563. even by the <code class="varname">log_statement</code> = <code class="literal">all</code> setting,
  564. because the log message is emitted only after basic parsing has
  565. been done to determine the statement type. In the case of extended
  566. query protocol, this setting likewise does not log statements that
  567. fail before the Execute phase (i.e., during parse analysis or
  568. planning). Set <code class="varname">log_min_error_statement</code> to
  569. <code class="literal">ERROR</code> (or lower) to log such statements.
  570. </p></div></dd><dt id="GUC-LOG-REPLICATION-COMMANDS"><span class="term"><code class="varname">log_replication_commands</code> (<code class="type">boolean</code>)
  571. <a id="id-1.6.6.11.5.2.13.1.3" class="indexterm"></a>
  572. </span></dt><dd><p>
  573. Causes each replication command to be logged in the server log.
  574. See <a class="xref" href="protocol-replication.html" title="52.4. Streaming Replication Protocol">Section 52.4</a> for more information about
  575. replication command. The default value is <code class="literal">off</code>.
  576. Only superusers can change this setting.
  577. </p></dd><dt id="GUC-LOG-TEMP-FILES"><span class="term"><code class="varname">log_temp_files</code> (<code class="type">integer</code>)
  578. <a id="id-1.6.6.11.5.2.14.1.3" class="indexterm"></a>
  579. </span></dt><dd><p>
  580. Controls logging of temporary file names and sizes.
  581. Temporary files can be
  582. created for sorts, hashes, and temporary query results.
  583. If enabled by this setting, a log entry is emitted for each
  584. temporary file when it is deleted.
  585. A value of zero logs all temporary file information, while positive
  586. values log only files whose size is greater than or equal to
  587. the specified amount of data.
  588. If this value is specified without units, it is taken as kilobytes.
  589. The default setting is -1, which disables such logging.
  590. Only superusers can change this setting.
  591. </p></dd><dt id="GUC-LOG-TIMEZONE"><span class="term"><code class="varname">log_timezone</code> (<code class="type">string</code>)
  592. <a id="id-1.6.6.11.5.2.15.1.3" class="indexterm"></a>
  593. </span></dt><dd><p>
  594. Sets the time zone used for timestamps written in the server log.
  595. Unlike <a class="xref" href="runtime-config-client.html#GUC-TIMEZONE">TimeZone</a>, this value is cluster-wide,
  596. so that all sessions will report timestamps consistently.
  597. The built-in default is <code class="literal">GMT</code>, but that is typically
  598. overridden in <code class="filename">postgresql.conf</code>; <span class="application">initdb</span>
  599. will install a setting there corresponding to its system environment.
  600. See <a class="xref" href="datatype-datetime.html#DATATYPE-TIMEZONES" title="8.5.3. Time Zones">Section 8.5.3</a> for more information.
  601. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  602. file or on the server command line.
  603. </p></dd></dl></div></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-CSVLOG"><div class="titlepage"><div><div><h3 class="title">19.8.4. Using CSV-Format Log Output</h3></div></div></div><p>
  604. Including <code class="literal">csvlog</code> in the <code class="varname">log_destination</code> list
  605. provides a convenient way to import log files into a database table.
  606. This option emits log lines in comma-separated-values
  607. (<acronym class="acronym">CSV</acronym>) format,
  608. with these columns:
  609. time stamp with milliseconds,
  610. user name,
  611. database name,
  612. process ID,
  613. client host:port number,
  614. session ID,
  615. per-session line number,
  616. command tag,
  617. session start time,
  618. virtual transaction ID,
  619. regular transaction ID,
  620. error severity,
  621. SQLSTATE code,
  622. error message,
  623. error message detail,
  624. hint,
  625. internal query that led to the error (if any),
  626. character count of the error position therein,
  627. error context,
  628. user query that led to the error (if any and enabled by
  629. <code class="varname">log_min_error_statement</code>),
  630. character count of the error position therein,
  631. location of the error in the PostgreSQL source code
  632. (if <code class="varname">log_error_verbosity</code> is set to <code class="literal">verbose</code>),
  633. and application name.
  634. Here is a sample table definition for storing CSV-format log output:
  635. </p><pre class="programlisting">
  636. CREATE TABLE postgres_log
  637. (
  638. log_time timestamp(3) with time zone,
  639. user_name text,
  640. database_name text,
  641. process_id integer,
  642. connection_from text,
  643. session_id text,
  644. session_line_num bigint,
  645. command_tag text,
  646. session_start_time timestamp with time zone,
  647. virtual_transaction_id text,
  648. transaction_id bigint,
  649. error_severity text,
  650. sql_state_code text,
  651. message text,
  652. detail text,
  653. hint text,
  654. internal_query text,
  655. internal_query_pos integer,
  656. context text,
  657. query text,
  658. query_pos integer,
  659. location text,
  660. application_name text,
  661. PRIMARY KEY (session_id, session_line_num)
  662. );
  663. </pre><p>
  664. </p><p>
  665. To import a log file into this table, use the <code class="command">COPY FROM</code>
  666. command:
  667. </p><pre class="programlisting">
  668. COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
  669. </pre><p>
  670. </p><p>
  671. There are a few things you need to do to simplify importing CSV log
  672. files:
  673. </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
  674. Set <code class="varname">log_filename</code> and
  675. <code class="varname">log_rotation_age</code> to provide a consistent,
  676. predictable naming scheme for your log files. This lets you
  677. predict what the file name will be and know when an individual log
  678. file is complete and therefore ready to be imported.
  679. </p></li><li class="listitem"><p>
  680. Set <code class="varname">log_rotation_size</code> to 0 to disable
  681. size-based log rotation, as it makes the log file name difficult
  682. to predict.
  683. </p></li><li class="listitem"><p>
  684. Set <code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code> so
  685. that old log data isn't mixed with the new in the same file.
  686. </p></li><li class="listitem"><p>
  687. The table definition above includes a primary key specification.
  688. This is useful to protect against accidentally importing the same
  689. information twice. The <code class="command">COPY</code> command commits all of the
  690. data it imports at one time, so any error will cause the entire
  691. import to fail. If you import a partial log file and later import
  692. the file again when it is complete, the primary key violation will
  693. cause the import to fail. Wait until the log is complete and
  694. closed before importing. This procedure will also protect against
  695. accidentally importing a partial line that hasn't been completely
  696. written, which would also cause <code class="command">COPY</code> to fail.
  697. </p></li></ol></div><p>
  698. </p></div><div class="sect2" id="id-1.6.6.11.7"><div class="titlepage"><div><div><h3 class="title">19.8.5. Process Title</h3></div></div></div><p>
  699. These settings control how process titles of server processes are
  700. modified. Process titles are typically viewed using programs like
  701. <span class="application">ps</span> or, on Windows, <span class="application">Process Explorer</span>.
  702. See <a class="xref" href="monitoring-ps.html" title="27.1. Standard Unix Tools">Section 27.1</a> for details.
  703. </p><div class="variablelist"><dl class="variablelist"><dt id="GUC-CLUSTER-NAME"><span class="term"><code class="varname">cluster_name</code> (<code class="type">string</code>)
  704. <a id="id-1.6.6.11.7.3.1.1.3" class="indexterm"></a>
  705. </span></dt><dd><p>
  706. Sets a name that identifies this database cluster (instance) for
  707. various purposes. The cluster name appears in the process title for
  708. all server processes in this cluster. Moreover, it is the default
  709. application name for a standby connection (see <a class="xref" href="runtime-config-replication.html#GUC-SYNCHRONOUS-STANDBY-NAMES">synchronous_standby_names</a>.)
  710. </p><p>
  711. The name can be any string of less
  712. than <code class="symbol">NAMEDATALEN</code> characters (64 characters in a standard
  713. build). Only printable ASCII characters may be used in the
  714. <code class="varname">cluster_name</code> value. Other characters will be
  715. replaced with question marks (<code class="literal">?</code>). No name is shown
  716. if this parameter is set to the empty string <code class="literal">''</code> (which is
  717. the default). This parameter can only be set at server start.
  718. </p></dd><dt id="GUC-UPDATE-PROCESS-TITLE"><span class="term"><code class="varname">update_process_title</code> (<code class="type">boolean</code>)
  719. <a id="id-1.6.6.11.7.3.2.1.3" class="indexterm"></a>
  720. </span></dt><dd><p>
  721. Enables updating of the process title every time a new SQL command
  722. is received by the server.
  723. This setting defaults to <code class="literal">on</code> on most platforms, but it
  724. defaults to <code class="literal">off</code> on Windows due to that platform's larger
  725. overhead for updating the process title.
  726. Only superusers can change this setting.
  727. </p></dd></dl></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="runtime-config-query.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-statistics.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">19.7. Query Planning </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 19.9. Run-time Statistics</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1