Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
runtime-config-logging.html941 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>20.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 Vsnapshot" /><link rel="prev" href="runtime-config-query.html" title="20.7. Query Planning" /><link rel="next" href="runtime-config-statistics.html" title="20.9. Run-time Statistics" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">20.8. Error Reporting and Logging</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="runtime-config-query.html" title="20.7. Query Planning">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="runtime-config.html" title="Chapter 20. Server Configuration">Up</a></td><th width="60%" align="center">Chapter 20. Server Configuration</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="runtime-config-statistics.html" title="20.9. Run-time Statistics">Next</a></td></tr></table><hr /></div><div class="sect1" id="RUNTIME-CONFIG-LOGGING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">20.8. Error Reporting and Logging <a href="#RUNTIME-CONFIG-LOGGING" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHERE">20.8.1. Where to Log</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN">20.8.2. When to Log</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT">20.8.3. What to Log</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG">20.8.4. Using CSV-Format Log Output</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-JSONLOG">20.8.5. Using JSON-Format Log Output</a></span></dt><dt><span class="sect2"><a href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-PROC-TITLE">20.8.6. Process Title</a></span></dt></dl></div><a id="id-1.6.7.11.2" class="indexterm"></a><div class="sect2" id="RUNTIME-CONFIG-LOGGING-WHERE"><div class="titlepage"><div><div><h3 class="title">20.8.1. Where to Log <a href="#RUNTIME-CONFIG-LOGGING-WHERE" class="id_link">#</a></h3></div></div></div><a id="id-1.6.7.11.3.2" class="indexterm"></a><a id="id-1.6.7.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.7.11.3.4.1.1.3" class="indexterm"></a>4      </span> <a href="#GUC-LOG-DESTINATION" class="id_link">#</a></dt><dd><p>5        <span class="productname">PostgreSQL</span> supports several methods6         for logging server messages, including7         <span class="systemitem">stderr</span>, <span class="systemitem">csvlog</span>,8         <span class="systemitem">jsonlog</span>, and9         <span class="systemitem">syslog</span>. On Windows,10         <span class="systemitem">eventlog</span> is also supported. Set this11         parameter to a list of desired log destinations separated by12         commas. The default is to log to <span class="systemitem">stderr</span>13         only.14         This parameter can only be set in the <code class="filename">postgresql.conf</code>15         file or on the server command line.16       </p><p>17        If <span class="systemitem">csvlog</span> is included in <code class="varname">log_destination</code>,18        log entries are output in <span class="quote">“<span class="quote">comma separated19        value</span>”</span> (<acronym class="acronym">CSV</acronym>) format, which is convenient for20        loading logs into programs.21        See <a class="xref" href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG" title="20.8.4. Using CSV-Format Log Output">Section 20.8.4</a> for details.22        <a class="xref" href="runtime-config-logging.html#GUC-LOGGING-COLLECTOR">logging_collector</a> must be enabled to generate23        CSV-format log output.24       </p><p>25        If <span class="systemitem">jsonlog</span> is included in26        <code class="varname">log_destination</code>, log entries are output in27        <acronym class="acronym">JSON</acronym> format, which is convenient for loading logs28        into programs.29        See <a class="xref" href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-JSONLOG" title="20.8.5. Using JSON-Format Log Output">Section 20.8.5</a> for details.30        <a class="xref" href="runtime-config-logging.html#GUC-LOGGING-COLLECTOR">logging_collector</a> must be enabled to generate31        JSON-format log output.32       </p><p>33        When either <span class="systemitem">stderr</span>,34        <span class="systemitem">csvlog</span> or <span class="systemitem">jsonlog</span> are35        included, the file <code class="filename">current_logfiles</code> is created to36        record the location of the log file(s) currently in use by the logging37        collector and the associated logging destination. This provides a38        convenient way to find the logs currently in use by the instance. Here39        is an example of this file's content:40</p><pre class="programlisting">41stderr log/postgresql.log42csvlog log/postgresql.csv43jsonlog log/postgresql.json44</pre><p>45 46        <code class="filename">current_logfiles</code> is recreated when a new log file47        is created as an effect of rotation, and48        when <code class="varname">log_destination</code> is reloaded.  It is removed when49        none of <span class="systemitem">stderr</span>,50        <span class="systemitem">csvlog</span> or <span class="systemitem">jsonlog</span> are51        included in <code class="varname">log_destination</code>, and when the logging52        collector is disabled.53       </p><div class="note"><h3 class="title">Note</h3><p>54         On most Unix systems, you will need to alter the configuration of55         your system's <span class="application">syslog</span> daemon in order56         to make use of the <span class="systemitem">syslog</span> option for57         <code class="varname">log_destination</code>.  <span class="productname">PostgreSQL</span>58         can log to <span class="application">syslog</span> facilities59         <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 default60         <span class="application">syslog</span> configuration on most platforms61         will discard all such messages.  You will need to add something like:62</p><pre class="programlisting">63local0.*    /var/log/postgresql64</pre><p>65         to the  <span class="application">syslog</span> daemon's configuration file66         to make it work.67        </p><p>68         On Windows, when you use the <code class="literal">eventlog</code>69         option for <code class="varname">log_destination</code>, you should70         register an event source and its library with the operating71         system so that the Windows Event Viewer can display event72         log messages cleanly.73         See <a class="xref" href="event-log-registration.html" title="19.12. Registering Event Log on Windows">Section 19.12</a> for details.74        </p></div></dd><dt id="GUC-LOGGING-COLLECTOR"><span class="term"><code class="varname">logging_collector</code> (<code class="type">boolean</code>)75      <a id="id-1.6.7.11.3.4.2.1.3" class="indexterm"></a>76      </span> <a href="#GUC-LOGGING-COLLECTOR" class="id_link">#</a></dt><dd><p>77         This parameter enables the <em class="firstterm">logging collector</em>, which78         is a background process that captures log messages79         sent to <span class="systemitem">stderr</span> and redirects them into log files.80         This approach is often more useful than81         logging to <span class="application">syslog</span>, since some types of messages82         might not appear in <span class="application">syslog</span> output.  (One common83         example is dynamic-linker failure messages; another is error messages84         produced by scripts such as <code class="varname">archive_command</code>.)85         This parameter can only be set at server start.86       </p><div class="note"><h3 class="title">Note</h3><p>87         It is possible to log to <span class="systemitem">stderr</span> without using the88         logging collector; the log messages will just go to wherever the89         server's <span class="systemitem">stderr</span> is directed.  However, that method is90         only suitable for low log volumes, since it provides no convenient91         way to rotate log files.  Also, on some platforms not using the92         logging collector can result in lost or garbled log output, because93         multiple processes writing concurrently to the same log file can94         overwrite each other's output.95        </p></div><div class="note"><h3 class="title">Note</h3><p>96          The logging collector is designed to never lose messages.  This means97          that in case of extremely high load, server processes could be98          blocked while trying to send additional log messages when the99          collector has fallen behind.  In contrast, <span class="application">syslog</span>100          prefers to drop messages if it cannot write them, which means it101          may fail to log some messages in such cases but it will not block102          the rest of the system.103        </p></div></dd><dt id="GUC-LOG-DIRECTORY"><span class="term"><code class="varname">log_directory</code> (<code class="type">string</code>)104      <a id="id-1.6.7.11.3.4.3.1.3" class="indexterm"></a>105      </span> <a href="#GUC-LOG-DIRECTORY" class="id_link">#</a></dt><dd><p>106        When <code class="varname">logging_collector</code> is enabled,107        this parameter determines the directory in which log files will be created.108        It can be specified as an absolute path, or relative to the109        cluster data directory.110        This parameter can only be set in the <code class="filename">postgresql.conf</code>111        file or on the server command line.112        The default is <code class="literal">log</code>.113       </p></dd><dt id="GUC-LOG-FILENAME"><span class="term"><code class="varname">log_filename</code> (<code class="type">string</code>)114      <a id="id-1.6.7.11.3.4.4.1.3" class="indexterm"></a>115      </span> <a href="#GUC-LOG-FILENAME" class="id_link">#</a></dt><dd><p>116        When <code class="varname">logging_collector</code> is enabled,117        this parameter sets the file names of the created log files.  The value118        is treated as a <code class="function">strftime</code> pattern,119        so <code class="literal">%</code>-escapes can be used to specify time-varying120        file names.  (Note that if there are121        any time-zone-dependent <code class="literal">%</code>-escapes, the computation122        is done in the zone specified123        by <a class="xref" href="runtime-config-logging.html#GUC-LOG-TIMEZONE">log_timezone</a>.)124        The supported <code class="literal">%</code>-escapes are similar to those125        listed in the Open Group's <a class="ulink" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html" target="_top">strftime126        </a> specification.127        Note that the system's <code class="function">strftime</code> is not used128        directly, so platform-specific (nonstandard) extensions do not work.129        The default is <code class="literal">postgresql-%Y-%m-%d_%H%M%S.log</code>.130       </p><p>131        If you specify a file name without escapes, you should plan to132        use a log rotation utility to avoid eventually filling the133        entire disk.  In releases prior to 8.4, if134        no <code class="literal">%</code> escapes were135        present, <span class="productname">PostgreSQL</span> would append136        the epoch of the new log file's creation time, but this is no137        longer the case.138       </p><p>139        If CSV-format output is enabled in <code class="varname">log_destination</code>,140        <code class="literal">.csv</code> will be appended to the timestamped141        log file name to create the file name for CSV-format output.142        (If <code class="varname">log_filename</code> ends in <code class="literal">.log</code>, the suffix is143        replaced instead.)144       </p><p>145        If JSON-format output is enabled in <code class="varname">log_destination</code>,146        <code class="literal">.json</code> will be appended to the timestamped147        log file name to create the file name for JSON-format output.148        (If <code class="varname">log_filename</code> ends in <code class="literal">.log</code>, the suffix is149        replaced instead.)150       </p><p>151        This parameter can only be set in the <code class="filename">postgresql.conf</code>152        file or on the server command line.153       </p></dd><dt id="GUC-LOG-FILE-MODE"><span class="term"><code class="varname">log_file_mode</code> (<code class="type">integer</code>)154      <a id="id-1.6.7.11.3.4.5.1.3" class="indexterm"></a>155      </span> <a href="#GUC-LOG-FILE-MODE" class="id_link">#</a></dt><dd><p>156        On Unix systems this parameter sets the permissions for log files157        when <code class="varname">logging_collector</code> is enabled. (On Microsoft158        Windows this parameter is ignored.)159        The parameter value is expected to be a numeric mode160        specified in the format accepted by the161        <code class="function">chmod</code> and <code class="function">umask</code>162        system calls.  (To use the customary octal format the number163        must start with a <code class="literal">0</code> (zero).)164       </p><p>165        The default permissions are <code class="literal">0600</code>, meaning only the166        server owner can read or write the log files.  The other commonly167        useful setting is <code class="literal">0640</code>, allowing members of the owner's168        group to read the files.  Note however that to make use of such a169        setting, you'll need to alter <a class="xref" href="runtime-config-logging.html#GUC-LOG-DIRECTORY">log_directory</a> to170        store the files somewhere outside the cluster data directory.  In171        any case, it's unwise to make the log files world-readable, since172        they might contain sensitive data.173       </p><p>174        This parameter can only be set in the <code class="filename">postgresql.conf</code>175        file or on the server command line.176       </p></dd><dt id="GUC-LOG-ROTATION-AGE"><span class="term"><code class="varname">log_rotation_age</code> (<code class="type">integer</code>)177      <a id="id-1.6.7.11.3.4.6.1.3" class="indexterm"></a>178      </span> <a href="#GUC-LOG-ROTATION-AGE" class="id_link">#</a></dt><dd><p>179        When <code class="varname">logging_collector</code> is enabled,180        this parameter determines the maximum amount of time to use an181        individual log file, after which a new log file will be created.182        If this value is specified without units, it is taken as minutes.183        The default is 24 hours.184        Set to zero to disable time-based creation of new log files.185        This parameter can only be set in the <code class="filename">postgresql.conf</code>186        file or on the server command line.187       </p></dd><dt id="GUC-LOG-ROTATION-SIZE"><span class="term"><code class="varname">log_rotation_size</code> (<code class="type">integer</code>)188      <a id="id-1.6.7.11.3.4.7.1.3" class="indexterm"></a>189      </span> <a href="#GUC-LOG-ROTATION-SIZE" class="id_link">#</a></dt><dd><p>190        When <code class="varname">logging_collector</code> is enabled,191        this parameter determines the maximum size of an individual log file.192        After this amount of data has been emitted into a log file,193        a new log file will be created.194        If this value is specified without units, it is taken as kilobytes.195        The default is 10 megabytes.196        Set to zero to disable size-based creation of new log files.197        This parameter can only be set in the <code class="filename">postgresql.conf</code>198        file or on the server command line.199       </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>)200      <a id="id-1.6.7.11.3.4.8.1.3" class="indexterm"></a>201      </span> <a href="#GUC-LOG-TRUNCATE-ON-ROTATION" class="id_link">#</a></dt><dd><p>202        When <code class="varname">logging_collector</code> is enabled,203        this parameter will cause <span class="productname">PostgreSQL</span> to truncate (overwrite),204        rather than append to, any existing log file of the same name.205        However, truncation will occur only when a new file is being opened206        due to time-based rotation, not during server startup or size-based207        rotation.  When off, pre-existing files will be appended to in208        all cases.  For example, using this setting in combination with209        a <code class="varname">log_filename</code> like <code class="literal">postgresql-%H.log</code>210        would result in generating twenty-four hourly log files and then211        cyclically overwriting them.212        This parameter can only be set in the <code class="filename">postgresql.conf</code>213        file or on the server command line.214       </p><p>215        Example:  To keep 7 days of logs, one log file per day named216        <code class="literal">server_log.Mon</code>, <code class="literal">server_log.Tue</code>,217        etc., and automatically overwrite last week's log with this week's log,218        set <code class="varname">log_filename</code> to <code class="literal">server_log.%a</code>,219        <code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code>, and220        <code class="varname">log_rotation_age</code> to <code class="literal">1440</code>.221       </p><p>222        Example: To keep 24 hours of logs, one log file per hour, but223        also rotate sooner if the log file size exceeds 1GB, set224        <code class="varname">log_filename</code> to <code class="literal">server_log.%H%M</code>,225        <code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code>,226        <code class="varname">log_rotation_age</code> to <code class="literal">60</code>, and227        <code class="varname">log_rotation_size</code> to <code class="literal">1000000</code>.228        Including <code class="literal">%M</code> in <code class="varname">log_filename</code> allows229        any size-driven rotations that might occur to select a file name230        different from the hour's initial file name.231       </p></dd><dt id="GUC-SYSLOG-FACILITY"><span class="term"><code class="varname">syslog_facility</code> (<code class="type">enum</code>)232      <a id="id-1.6.7.11.3.4.9.1.3" class="indexterm"></a>233      </span> <a href="#GUC-SYSLOG-FACILITY" class="id_link">#</a></dt><dd><p>234        When logging to <span class="application">syslog</span> is enabled, this parameter235        determines the <span class="application">syslog</span>236        <span class="quote">“<span class="quote">facility</span>”</span> to be used.  You can choose237        from <code class="literal">LOCAL0</code>, <code class="literal">LOCAL1</code>,238        <code class="literal">LOCAL2</code>, <code class="literal">LOCAL3</code>, <code class="literal">LOCAL4</code>,239        <code class="literal">LOCAL5</code>, <code class="literal">LOCAL6</code>, <code class="literal">LOCAL7</code>;240        the default is <code class="literal">LOCAL0</code>. See also the241        documentation of your system's242        <span class="application">syslog</span> daemon.243        This parameter can only be set in the <code class="filename">postgresql.conf</code>244        file or on the server command line.245       </p></dd><dt id="GUC-SYSLOG-IDENT"><span class="term"><code class="varname">syslog_ident</code> (<code class="type">string</code>)246      <a id="id-1.6.7.11.3.4.10.1.3" class="indexterm"></a>247      </span> <a href="#GUC-SYSLOG-IDENT" class="id_link">#</a></dt><dd><p>248         When logging to <span class="application">syslog</span> is enabled, this parameter249         determines the program name used to identify250         <span class="productname">PostgreSQL</span> messages in251         <span class="application">syslog</span> logs. The default is252         <code class="literal">postgres</code>.253         This parameter can only be set in the <code class="filename">postgresql.conf</code>254         file or on the server command line.255        </p></dd><dt id="GUC-SYSLOG-SEQUENCE-NUMBERS"><span class="term"><code class="varname">syslog_sequence_numbers</code> (<code class="type">boolean</code>)256        <a id="id-1.6.7.11.3.4.11.1.3" class="indexterm"></a>257       </span> <a href="#GUC-SYSLOG-SEQUENCE-NUMBERS" class="id_link">#</a></dt><dd><p>258         When logging to <span class="application">syslog</span> and this is on (the259         default), then each message will be prefixed by an increasing260         sequence number (such as <code class="literal">[2]</code>).  This circumvents261         the <span class="quote">“<span class="quote">--- last message repeated N times ---</span>”</span> suppression262         that many syslog implementations perform by default.  In more modern263         syslog implementations, repeated message suppression can be configured264         (for example, <code class="literal">$RepeatedMsgReduction</code>265         in <span class="productname">rsyslog</span>), so this might not be266         necessary.  Also, you could turn this off if you actually want to267         suppress repeated messages.268        </p><p>269         This parameter can only be set in the <code class="filename">postgresql.conf</code>270         file or on the server command line.271        </p></dd><dt id="GUC-SYSLOG-SPLIT-MESSAGES"><span class="term"><code class="varname">syslog_split_messages</code> (<code class="type">boolean</code>)272      <a id="id-1.6.7.11.3.4.12.1.3" class="indexterm"></a>273      </span> <a href="#GUC-SYSLOG-SPLIT-MESSAGES" class="id_link">#</a></dt><dd><p>274        When logging to <span class="application">syslog</span> is enabled, this parameter275        determines how messages are delivered to syslog.  When on (the276        default), messages are split by lines, and long lines are split so277        that they will fit into 1024 bytes, which is a typical size limit for278        traditional syslog implementations.  When off, PostgreSQL server log279        messages are delivered to the syslog service as is, and it is up to280        the syslog service to cope with the potentially bulky messages.281       </p><p>282        If syslog is ultimately logging to a text file, then the effect will283        be the same either way, and it is best to leave the setting on, since284        most syslog implementations either cannot handle large messages or285        would need to be specially configured to handle them.  But if syslog286        is ultimately writing into some other medium, it might be necessary or287        more useful to keep messages logically together.288       </p><p>289        This parameter can only be set in the <code class="filename">postgresql.conf</code>290        file or on the server command line.291       </p></dd><dt id="GUC-EVENT-SOURCE"><span class="term"><code class="varname">event_source</code> (<code class="type">string</code>)292      <a id="id-1.6.7.11.3.4.13.1.3" class="indexterm"></a>293      </span> <a href="#GUC-EVENT-SOURCE" class="id_link">#</a></dt><dd><p>294        When logging to <span class="application">event log</span> is enabled, this parameter295        determines the program name used to identify296        <span class="productname">PostgreSQL</span> messages in297        the log. The default is <code class="literal">PostgreSQL</code>.298        This parameter can only be set in the <code class="filename">postgresql.conf</code>299        file or on the server command line.300       </p></dd></dl></div></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-WHEN"><div class="titlepage"><div><div><h3 class="title">20.8.2. When to Log <a href="#RUNTIME-CONFIG-LOGGING-WHEN" class="id_link">#</a></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>)301      <a id="id-1.6.7.11.4.2.1.1.3" class="indexterm"></a>302      </span> <a href="#GUC-LOG-MIN-MESSAGES" class="id_link">#</a></dt><dd><p>303        Controls which <a class="link" href="runtime-config-logging.html#RUNTIME-CONFIG-SEVERITY-LEVELS" title="Table 20.2. Message Severity Levels">message304        levels</a> are written to the server log.305        Valid values are <code class="literal">DEBUG5</code>, <code class="literal">DEBUG4</code>,306        <code class="literal">DEBUG3</code>, <code class="literal">DEBUG2</code>, <code class="literal">DEBUG1</code>,307        <code class="literal">INFO</code>, <code class="literal">NOTICE</code>, <code class="literal">WARNING</code>,308        <code class="literal">ERROR</code>, <code class="literal">LOG</code>, <code class="literal">FATAL</code>, and309        <code class="literal">PANIC</code>.  Each level includes all the levels that310        follow it.  The later the level, the fewer messages are sent311        to the log.  The default is <code class="literal">WARNING</code>.  Note that312        <code class="literal">LOG</code> has a different rank here than in313        <a class="xref" href="runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES">client_min_messages</a>.314        Only superusers and users with the appropriate <code class="literal">SET</code>315        privilege can change this setting.316       </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>)317      <a id="id-1.6.7.11.4.2.2.1.3" class="indexterm"></a>318      </span> <a href="#GUC-LOG-MIN-ERROR-STATEMENT" class="id_link">#</a></dt><dd><p>319        Controls which SQL statements that cause an error320        condition are recorded in the server log.  The current321        SQL statement is included in the log entry for any message of322        the specified323        <a class="link" href="runtime-config-logging.html#RUNTIME-CONFIG-SEVERITY-LEVELS" title="Table 20.2. Message Severity Levels">severity</a>324        or higher.325        Valid values are <code class="literal">DEBUG5</code>,326        <code class="literal">DEBUG4</code>, <code class="literal">DEBUG3</code>,327        <code class="literal">DEBUG2</code>, <code class="literal">DEBUG1</code>,328        <code class="literal">INFO</code>, <code class="literal">NOTICE</code>,329        <code class="literal">WARNING</code>, <code class="literal">ERROR</code>,330        <code class="literal">LOG</code>,331        <code class="literal">FATAL</code>, and <code class="literal">PANIC</code>.332        The default is <code class="literal">ERROR</code>, which means statements333        causing errors, log messages, fatal errors, or panics will be logged.334        To effectively turn off logging of failing statements,335        set this parameter to <code class="literal">PANIC</code>.336        Only superusers and users with the appropriate <code class="literal">SET</code>337        privilege can change this setting.338       </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>)339      <a id="id-1.6.7.11.4.2.3.1.3" class="indexterm"></a>340      </span> <a href="#GUC-LOG-MIN-DURATION-STATEMENT" class="id_link">#</a></dt><dd><p>341         Causes the duration of each completed statement to be logged342         if the statement ran for at least the specified amount of time.343         For example, if you set it to <code class="literal">250ms</code>344         then all SQL statements that run 250ms or longer will be345         logged.  Enabling this parameter can be helpful in tracking down346         unoptimized queries in your applications.347         If this value is specified without units, it is taken as milliseconds.348         Setting this to zero prints all statement durations.349         <code class="literal">-1</code> (the default) disables logging statement350         durations.351         Only superusers and users with the appropriate <code class="literal">SET</code>352         privilege can change this setting.353        </p><p>354         This overrides <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE">log_min_duration_sample</a>,355         meaning that queries with duration exceeding this setting are not356         subject to sampling and are always logged.357        </p><p>358         For clients using extended query protocol, durations of the Parse,359         Bind, and Execute steps are logged independently.360        </p><div class="note"><h3 class="title">Note</h3><p>361         When using this option together with362         <a class="xref" href="runtime-config-logging.html#GUC-LOG-STATEMENT">log_statement</a>,363         the text of statements that are logged because of364         <code class="varname">log_statement</code> will not be repeated in the365         duration log message.366         If you are not using <span class="application">syslog</span>, it is recommended367         that you log the PID or session ID using368         <a class="xref" href="runtime-config-logging.html#GUC-LOG-LINE-PREFIX">log_line_prefix</a>369         so that you can link the statement message to the later370         duration message using the process ID or session ID.371        </p></div></dd><dt id="GUC-LOG-MIN-DURATION-SAMPLE"><span class="term"><code class="varname">log_min_duration_sample</code> (<code class="type">integer</code>)372      <a id="id-1.6.7.11.4.2.4.1.3" class="indexterm"></a>373      </span> <a href="#GUC-LOG-MIN-DURATION-SAMPLE" class="id_link">#</a></dt><dd><p>374         Allows sampling the duration of completed statements that ran for375         at least the specified amount of time.  This produces the same376         kind of log entries as377         <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT">log_min_duration_statement</a>, but only for a378         subset of the executed statements, with sample rate controlled by379         <a class="xref" href="runtime-config-logging.html#GUC-LOG-STATEMENT-SAMPLE-RATE">log_statement_sample_rate</a>.380         For example, if you set it to <code class="literal">100ms</code> then all381         SQL statements that run 100ms or longer will be considered for382         sampling.  Enabling this parameter can be helpful when the383         traffic is too high to log all queries.384         If this value is specified without units, it is taken as milliseconds.385         Setting this to zero samples all statement durations.386         <code class="literal">-1</code> (the default) disables sampling statement387         durations.388         Only superusers and users with the appropriate <code class="literal">SET</code>389         privilege can change this setting.390        </p><p>391         This setting has lower priority392         than <code class="varname">log_min_duration_statement</code>, meaning that393         statements with durations394         exceeding <code class="varname">log_min_duration_statement</code> are not395         subject to sampling and are always logged.396        </p><p>397         Other notes for <code class="varname">log_min_duration_statement</code>398         apply also to this setting.399        </p></dd><dt id="GUC-LOG-STATEMENT-SAMPLE-RATE"><span class="term"><code class="varname">log_statement_sample_rate</code> (<code class="type">floating point</code>)400      <a id="id-1.6.7.11.4.2.5.1.3" class="indexterm"></a>401      </span> <a href="#GUC-LOG-STATEMENT-SAMPLE-RATE" class="id_link">#</a></dt><dd><p>402         Determines the fraction of statements with duration exceeding403         <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE">log_min_duration_sample</a> that will be logged.404         Sampling is stochastic, for example <code class="literal">0.5</code> means405         there is statistically one chance in two that any given statement406         will be logged.407         The default is <code class="literal">1.0</code>, meaning to log all sampled408         statements.409         Setting this to zero disables sampled statement-duration logging,410         the same as setting411         <code class="varname">log_min_duration_sample</code> to412         <code class="literal">-1</code>.413         Only superusers and users with the appropriate <code class="literal">SET</code>414         privilege can change this setting.415        </p></dd><dt id="GUC-LOG-TRANSACTION-SAMPLE-RATE"><span class="term"><code class="varname">log_transaction_sample_rate</code> (<code class="type">floating point</code>)416      <a id="id-1.6.7.11.4.2.6.1.3" class="indexterm"></a>417      </span> <a href="#GUC-LOG-TRANSACTION-SAMPLE-RATE" class="id_link">#</a></dt><dd><p>418         Sets the fraction of transactions whose statements are all logged,419         in addition to statements logged for other reasons.  It applies to420         each new transaction regardless of its statements' durations.421         Sampling is stochastic, for example <code class="literal">0.1</code> means422         there is statistically one chance in ten that any given transaction423         will be logged.424         <code class="varname">log_transaction_sample_rate</code> can be helpful to425         construct a sample of transactions.426         The default is <code class="literal">0</code>, meaning not to log427         statements from any additional transactions.  Setting this428         to <code class="literal">1</code> logs all statements of all transactions.429         Only superusers and users with the appropriate <code class="literal">SET</code>430         privilege can change this setting.431        </p><div class="note"><h3 class="title">Note</h3><p>432         Like all statement-logging options, this option can add significant433         overhead.434        </p></div></dd><dt id="GUC-LOG-STARTUP-PROGRESS-INTERVAL"><span class="term"><code class="varname">log_startup_progress_interval</code> (<code class="type">integer</code>)435      <a id="id-1.6.7.11.4.2.7.1.3" class="indexterm"></a>436      </span> <a href="#GUC-LOG-STARTUP-PROGRESS-INTERVAL" class="id_link">#</a></dt><dd><p>437         Sets the amount of time after which the startup process will log438         a message about a long-running operation that is still in progress,439         as well as the interval between further progress messages for that440         operation. The default is 10 seconds. A setting of <code class="literal">0</code>441         disables the feature.  If this value is specified without units,442         it is taken as milliseconds.  This setting is applied separately to443         each operation.444         This parameter can only be set in the <code class="filename">postgresql.conf</code>445         file or on the server command line.446        </p><p>447         For example, if syncing the data directory takes 25 seconds and448         thereafter resetting unlogged relations takes 8 seconds, and if this449         setting has the default value of 10 seconds, then a messages will be450         logged for syncing the data directory after it has been in progress451         for 10 seconds and again after it has been in progress for 20 seconds,452         but nothing will be logged for resetting unlogged relations.453        </p></dd></dl></div><p>454     <a class="xref" href="runtime-config-logging.html#RUNTIME-CONFIG-SEVERITY-LEVELS" title="Table 20.2. Message Severity Levels">Table 20.2</a> explains the message455     severity levels used by <span class="productname">PostgreSQL</span>.  If logging output456     is sent to <span class="systemitem">syslog</span> or Windows'457     <span class="systemitem">eventlog</span>, the severity levels are translated458     as shown in the table.459    </p><div class="table" id="RUNTIME-CONFIG-SEVERITY-LEVELS"><p class="title"><strong>Table 20.2. Message Severity Levels</strong></p><div class="table-contents"><table class="table" summary="Message Severity Levels" border="1"><colgroup><col class="col1" /><col class="col2" /><col class="col3" /><col class="col4" /></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 by460         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,461         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.,462         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>463         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 to464         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.,465         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 to466         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">20.8.3. What to Log <a href="#RUNTIME-CONFIG-LOGGING-WHAT" class="id_link">#</a></h3></div></div></div><div class="note"><h3 class="title">Note</h3><p>467       What you choose to log can have security implications;  see468       <a class="xref" href="logfile-maintenance.html" title="25.3. Log File Maintenance">Section 25.3</a>.469      </p></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>)470      <a id="id-1.6.7.11.5.3.1.1.3" class="indexterm"></a>471      </span> <a href="#GUC-APPLICATION-NAME" class="id_link">#</a></dt><dd><p>472        The <code class="varname">application_name</code> can be any string of less than473        <code class="symbol">NAMEDATALEN</code> characters (64 characters in a standard build).474        It is typically set by an application upon connection to the server.475        The name will be displayed in the <code class="structname">pg_stat_activity</code> view476        and included in CSV log entries.  It can also be included in regular477        log entries via the <a class="xref" href="runtime-config-logging.html#GUC-LOG-LINE-PREFIX">log_line_prefix</a> parameter.478        Only printable ASCII characters may be used in the479        <code class="varname">application_name</code> value.480        Other characters are replaced with <a class="link" href="sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE" title="4.1.2.2. String Constants with C-Style Escapes">C-style hexadecimal escapes</a>.481       </p></dd><dt id="GUC-DEBUG-PRINT-PARSE"><span class="term"><code class="varname">debug_print_parse</code> (<code class="type">boolean</code>)482      <a id="id-1.6.7.11.5.3.2.1.3" class="indexterm"></a>483      <br /></span><span class="term"><code class="varname">debug_print_rewritten</code> (<code class="type">boolean</code>)484      <a id="id-1.6.7.11.5.3.2.2.3" class="indexterm"></a>485      <br /></span><span class="term"><code class="varname">debug_print_plan</code> (<code class="type">boolean</code>)486      <a id="id-1.6.7.11.5.3.2.3.3" class="indexterm"></a>487      </span> <a href="#GUC-DEBUG-PRINT-PARSE" class="id_link">#</a></dt><dd><p>488        These parameters enable various debugging output to be emitted.489        When set, they print the resulting parse tree, the query rewriter490        output, or the execution plan for each executed query.491        These messages are emitted at <code class="literal">LOG</code> message level, so by492        default they will appear in the server log but will not be sent to the493        client.  You can change that by adjusting494        <a class="xref" href="runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES">client_min_messages</a> and/or495        <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-MESSAGES">log_min_messages</a>.496        These parameters are off by default.497       </p></dd><dt id="GUC-DEBUG-PRETTY-PRINT"><span class="term"><code class="varname">debug_pretty_print</code> (<code class="type">boolean</code>)498      <a id="id-1.6.7.11.5.3.3.1.3" class="indexterm"></a>499      </span> <a href="#GUC-DEBUG-PRETTY-PRINT" class="id_link">#</a></dt><dd><p>500        When set, <code class="varname">debug_pretty_print</code> indents the messages501        produced by <code class="varname">debug_print_parse</code>,502        <code class="varname">debug_print_rewritten</code>, or503        <code class="varname">debug_print_plan</code>.  This results in more readable504        but much longer output than the <span class="quote">“<span class="quote">compact</span>”</span> format used when505        it is off.  It is on by default.506       </p></dd><dt id="GUC-LOG-AUTOVACUUM-MIN-DURATION"><span class="term"><code class="varname">log_autovacuum_min_duration</code> (<code class="type">integer</code>)507      <a id="id-1.6.7.11.5.3.4.1.3" class="indexterm"></a>508      </span> <a href="#GUC-LOG-AUTOVACUUM-MIN-DURATION" class="id_link">#</a></dt><dd><p>509        Causes each action executed by autovacuum to be logged if it ran for at510        least the specified amount of time.  Setting this to zero logs511        all autovacuum actions. <code class="literal">-1</code> disables logging autovacuum512        actions. If this value is specified without units, it is taken as milliseconds.513        For example, if you set this to514        <code class="literal">250ms</code> then all automatic vacuums and analyzes that run515        250ms or longer will be logged.  In addition, when this parameter is516        set to any value other than <code class="literal">-1</code>, a message will be517        logged if an autovacuum action is skipped due to a conflicting lock or a518        concurrently dropped relation. The default is <code class="literal">10min</code>.519        Enabling this parameter can be helpful in tracking autovacuum activity.520        This parameter can only be set in the <code class="filename">postgresql.conf</code>521        file or on the server command line; but the setting can be overridden for522        individual tables by changing table storage parameters.523       </p></dd><dt id="GUC-LOG-CHECKPOINTS"><span class="term"><code class="varname">log_checkpoints</code> (<code class="type">boolean</code>)524      <a id="id-1.6.7.11.5.3.5.1.3" class="indexterm"></a>525      </span> <a href="#GUC-LOG-CHECKPOINTS" class="id_link">#</a></dt><dd><p>526        Causes checkpoints and restartpoints to be logged in the server log.527        Some statistics are included in the log messages, including the number528        of buffers written and the time spent writing them.529        This parameter can only be set in the <code class="filename">postgresql.conf</code>530        file or on the server command line. The default is on.531       </p></dd><dt id="GUC-LOG-CONNECTIONS"><span class="term"><code class="varname">log_connections</code> (<code class="type">boolean</code>)532      <a id="id-1.6.7.11.5.3.6.1.3" class="indexterm"></a>533      </span> <a href="#GUC-LOG-CONNECTIONS" class="id_link">#</a></dt><dd><p>534        Causes each attempted connection to the server to be logged,535        as well as successful completion of both client authentication (if536        necessary) and authorization.537        Only superusers and users with the appropriate <code class="literal">SET</code>538        privilege can change this parameter at session start,539        and it cannot be changed at all within a session.540        The default is <code class="literal">off</code>.541       </p><div class="note"><h3 class="title">Note</h3><p>542         Some client programs, like <span class="application">psql</span>, attempt543         to connect twice while determining if a password is required, so544         duplicate <span class="quote">“<span class="quote">connection received</span>”</span> messages do not545         necessarily indicate a problem.546        </p></div></dd><dt id="GUC-LOG-DISCONNECTIONS"><span class="term"><code class="varname">log_disconnections</code> (<code class="type">boolean</code>)547      <a id="id-1.6.7.11.5.3.7.1.3" class="indexterm"></a>548      </span> <a href="#GUC-LOG-DISCONNECTIONS" class="id_link">#</a></dt><dd><p>549        Causes session terminations to be logged.  The log output550        provides information similar to <code class="varname">log_connections</code>,551        plus the duration of the session.552        Only superusers and users with the appropriate <code class="literal">SET</code>553        privilege can change this parameter at session start,554        and it cannot be changed at all within a session.555        The default is <code class="literal">off</code>.556       </p></dd><dt id="GUC-LOG-DURATION"><span class="term"><code class="varname">log_duration</code> (<code class="type">boolean</code>)557      <a id="id-1.6.7.11.5.3.8.1.3" class="indexterm"></a>558      </span> <a href="#GUC-LOG-DURATION" class="id_link">#</a></dt><dd><p>559        Causes the duration of every completed statement to be logged.560        The default is <code class="literal">off</code>.561        Only superusers and users with the appropriate <code class="literal">SET</code>562        privilege can change this setting.563       </p><p>564        For clients using extended query protocol, durations of the Parse,565        Bind, and Execute steps are logged independently.566       </p><div class="note"><h3 class="title">Note</h3><p>567         The difference between enabling <code class="varname">log_duration</code> and setting568         <a class="xref" href="runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT">log_min_duration_statement</a> to zero is that569         exceeding <code class="varname">log_min_duration_statement</code> forces the text of570         the query to be logged, but this option doesn't.  Thus, if571         <code class="varname">log_duration</code> is <code class="literal">on</code> and572         <code class="varname">log_min_duration_statement</code> has a positive value, all573         durations are logged but the query text is included only for574         statements exceeding the threshold.  This behavior can be useful for575         gathering statistics in high-load installations.576        </p></div></dd><dt id="GUC-LOG-ERROR-VERBOSITY"><span class="term"><code class="varname">log_error_verbosity</code> (<code class="type">enum</code>)577      <a id="id-1.6.7.11.5.3.9.1.3" class="indexterm"></a>578      </span> <a href="#GUC-LOG-ERROR-VERBOSITY" class="id_link">#</a></dt><dd><p>579        Controls the amount of detail written in the server log for each580        message that is logged.  Valid values are <code class="literal">TERSE</code>,581        <code class="literal">DEFAULT</code>, and <code class="literal">VERBOSE</code>, each adding more582        fields to displayed messages.  <code class="literal">TERSE</code> excludes583        the logging of <code class="literal">DETAIL</code>, <code class="literal">HINT</code>,584        <code class="literal">QUERY</code>, and <code class="literal">CONTEXT</code> error information.585        <code class="literal">VERBOSE</code> output includes the <code class="symbol">SQLSTATE</code> error586        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,587        and line number that generated the error.588        Only superusers and users with the appropriate <code class="literal">SET</code>589        privilege can change this setting.590       </p></dd><dt id="GUC-LOG-HOSTNAME"><span class="term"><code class="varname">log_hostname</code> (<code class="type">boolean</code>)591      <a id="id-1.6.7.11.5.3.10.1.3" class="indexterm"></a>592      </span> <a href="#GUC-LOG-HOSTNAME" class="id_link">#</a></dt><dd><p>593        By default, connection log messages only show the IP address of the594        connecting host. Turning this parameter on causes logging of the595        host name as well.  Note that depending on your host name resolution596        setup this might impose a non-negligible performance penalty.597        This parameter can only be set in the <code class="filename">postgresql.conf</code>598        file or on the server command line.599       </p></dd><dt id="GUC-LOG-LINE-PREFIX"><span class="term"><code class="varname">log_line_prefix</code> (<code class="type">string</code>)600      <a id="id-1.6.7.11.5.3.11.1.3" class="indexterm"></a>601      </span> <a href="#GUC-LOG-LINE-PREFIX" class="id_link">#</a></dt><dd><p>602         This is a <code class="function">printf</code>-style string that is output at the603         beginning of each log line.604         <code class="literal">%</code> characters begin <span class="quote">“<span class="quote">escape sequences</span>”</span>605         that are replaced with status information as outlined below.606         Unrecognized escapes are ignored. Other607         characters are copied straight to the log line. Some escapes are608         only recognized by session processes, and will be treated as empty by609         background processes such as the main server process. Status610         information may be aligned either left or right by specifying a611         numeric literal after the % and before the option. A negative612         value will cause the status information to be padded on the613         right with spaces to give it a minimum width, whereas a positive614         value will pad on the left. Padding can be useful to aid human615         readability in log files.616       </p><p>617         This parameter can only be set in the <code class="filename">postgresql.conf</code>618         file or on the server command line. The default is619         <code class="literal">'%m [%p] '</code> which logs a time stamp and the process ID.620       </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">%b</code></td><td>Backend type</td><td>no</td></tr><tr><td><code class="literal">%p</code></td><td>Process ID</td><td>no</td></tr><tr><td><code class="literal">%P</code></td><td>Process ID of the parallel group leader, if this process621              is a parallel query worker</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);  see622             <a class="xref" href="transaction-id.html" title="74.1. Transactions and Identifiers">Section 74.1</a></td><td>no</td></tr><tr><td><code class="literal">%x</code></td><td>Transaction ID (0 if none is assigned);  see623             <a class="xref" href="transaction-id.html" title="74.1. Transactions and Identifiers">Section 74.1</a></td><td>no</td></tr><tr><td><code class="literal">%q</code></td><td>Produces no output, but tells non-session624             processes to stop at this point in the string; ignored by625             session processes</td><td>no</td></tr><tr><td><code class="literal">%Q</code></td><td>Query identifier of the current query.  Query626             identifiers are not computed by default, so this field627             will be zero unless <a class="xref" href="runtime-config-statistics.html#GUC-COMPUTE-QUERY-ID">compute_query_id</a>628             parameter is enabled or a third-party module that computes629             query identifiers is configured.</td><td>yes</td></tr><tr><td><code class="literal">%%</code></td><td>Literal <code class="literal">%</code></td><td>no</td></tr></tbody></table></div><p>630          The backend type corresponds to the column631          <code class="structfield">backend_type</code> in the view632          <a class="link" href="monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW" title="28.2.3. pg_stat_activity">633          <code class="structname">pg_stat_activity</code></a>,634          but additional types can appear635          in the log that don't show in that view.636         </p><p>637         The <code class="literal">%c</code> escape prints a quasi-unique session identifier,638         consisting of two 4-byte hexadecimal numbers (without leading zeros)639         separated by a dot.  The numbers are the process start time and the640         process ID, so <code class="literal">%c</code> can also be used as a space saving way641         of printing those items.  For example, to generate the session642         identifier from <code class="literal">pg_stat_activity</code>, use this query:643</p><pre class="programlisting">644SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||645       to_hex(pid)646FROM pg_stat_activity;647</pre><p>648 649       </p><div class="tip"><h3 class="title">Tip</h3><p>650         If you set a nonempty value for <code class="varname">log_line_prefix</code>,651         you should usually make its last character be a space, to provide652         visual separation from the rest of the log line.  A punctuation653         character can be used too.654        </p></div><div class="tip"><h3 class="title">Tip</h3><p>655         <span class="application">Syslog</span> produces its own656         time stamp and process ID information, so you probably do not want to657         include those escapes if you are logging to <span class="application">syslog</span>.658        </p></div><div class="tip"><h3 class="title">Tip</h3><p>659         The <code class="literal">%q</code> escape is useful when including information that is660         only available in session (backend) context like user or database661         name.  For example:662</p><pre class="programlisting">663log_line_prefix = '%m [%p] %q%u@%d/%a '664</pre><p>665        </p></div><div class="note"><h3 class="title">Note</h3><p>666         The <code class="literal">%Q</code> escape always reports a zero identifier667         for lines output by <a class="xref" href="runtime-config-logging.html#GUC-LOG-STATEMENT">log_statement</a> because668         <code class="varname">log_statement</code> generates output before an669         identifier can be calculated, including invalid statements for670         which an identifier cannot be calculated.671        </p></div></dd><dt id="GUC-LOG-LOCK-WAITS"><span class="term"><code class="varname">log_lock_waits</code> (<code class="type">boolean</code>)672      <a id="id-1.6.7.11.5.3.12.1.3" class="indexterm"></a>673      </span> <a href="#GUC-LOG-LOCK-WAITS" class="id_link">#</a></dt><dd><p>674        Controls whether a log message is produced when a session waits675        longer than <a class="xref" href="runtime-config-locks.html#GUC-DEADLOCK-TIMEOUT">deadlock_timeout</a> to acquire a676        lock.  This is useful in determining if lock waits are causing677        poor performance.  The default is <code class="literal">off</code>.678        Only superusers and users with the appropriate <code class="literal">SET</code>679        privilege can change this setting.680       </p></dd><dt id="GUC-LOG-RECOVERY-CONFLICT-WAITS"><span class="term"><code class="varname">log_recovery_conflict_waits</code> (<code class="type">boolean</code>)681      <a id="id-1.6.7.11.5.3.13.1.3" class="indexterm"></a>682      </span> <a href="#GUC-LOG-RECOVERY-CONFLICT-WAITS" class="id_link">#</a></dt><dd><p>683        Controls whether a log message is produced when the startup process684        waits longer than <code class="varname">deadlock_timeout</code>685        for recovery conflicts.  This is useful in determining if recovery686        conflicts prevent the recovery from applying WAL.687       </p><p>688        The default is <code class="literal">off</code>.  This parameter can only be set689        in the <code class="filename">postgresql.conf</code> file or on the server690        command line.691       </p></dd><dt id="GUC-LOG-PARAMETER-MAX-LENGTH"><span class="term"><code class="varname">log_parameter_max_length</code> (<code class="type">integer</code>)692      <a id="id-1.6.7.11.5.3.14.1.3" class="indexterm"></a>693      </span> <a href="#GUC-LOG-PARAMETER-MAX-LENGTH" class="id_link">#</a></dt><dd><p>694        If greater than zero, each bind parameter value logged with a695        non-error statement-logging message is trimmed to this many bytes.696        Zero disables logging of bind parameters for non-error statement logs.697        <code class="literal">-1</code> (the default) allows bind parameters to be698        logged in full.699        If this value is specified without units, it is taken as bytes.700        Only superusers and users with the appropriate <code class="literal">SET</code>701        privilege can change this setting.702       </p><p>703        This setting only affects log messages printed as a result of704        <a class="xref" href="runtime-config-logging.html#GUC-LOG-STATEMENT">log_statement</a>,705        <a class="xref" href="runtime-config-logging.html#GUC-LOG-DURATION">log_duration</a>, and related settings.  Non-zero706        values of this setting add some overhead, particularly if parameters707        are sent in binary form, since then conversion to text is required.708       </p></dd><dt id="GUC-LOG-PARAMETER-MAX-LENGTH-ON-ERROR"><span class="term"><code class="varname">log_parameter_max_length_on_error</code> (<code class="type">integer</code>)709      <a id="id-1.6.7.11.5.3.15.1.3" class="indexterm"></a>710      </span> <a href="#GUC-LOG-PARAMETER-MAX-LENGTH-ON-ERROR" class="id_link">#</a></dt><dd><p>711        If greater than zero, each bind parameter value reported in error712        messages is trimmed to this many bytes.713        Zero (the default) disables including bind parameters in error714        messages.715        <code class="literal">-1</code> allows bind parameters to be printed in full.716        If this value is specified without units, it is taken as bytes.717       </p><p>718        Non-zero values of this setting add overhead, as719        <span class="productname">PostgreSQL</span> will need to store textual720        representations of parameter values in memory at the start of each721        statement, whether or not an error eventually occurs.  The overhead722        is greater when bind parameters are sent in binary form than when723        they are sent as text, since the former case requires data724        conversion while the latter only requires copying the string.725       </p></dd><dt id="GUC-LOG-STATEMENT"><span class="term"><code class="varname">log_statement</code> (<code class="type">enum</code>)726      <a id="id-1.6.7.11.5.3.16.1.3" class="indexterm"></a>727      </span> <a href="#GUC-LOG-STATEMENT" class="id_link">#</a></dt><dd><p>728        Controls which SQL statements are logged. Valid values are729        <code class="literal">none</code> (off), <code class="literal">ddl</code>, <code class="literal">mod</code>, and730        <code class="literal">all</code> (all statements). <code class="literal">ddl</code> logs all data definition731        statements, such as <code class="command">CREATE</code>, <code class="command">ALTER</code>, and732        <code class="command">DROP</code> statements. <code class="literal">mod</code> logs all733        <code class="literal">ddl</code> statements, plus data-modifying statements734        such as <code class="command">INSERT</code>,735        <code class="command">UPDATE</code>, <code class="command">DELETE</code>, <code class="command">TRUNCATE</code>,736        and <code class="command">COPY FROM</code>.737        <code class="command">PREPARE</code>, <code class="command">EXECUTE</code>, and738        <code class="command">EXPLAIN ANALYZE</code> statements are also logged if their739        contained command is of an appropriate type.  For clients using740        extended query protocol, logging occurs when an Execute message741        is received, and values of the Bind parameters are included742        (with any embedded single-quote marks doubled).743       </p><p>744        The default is <code class="literal">none</code>.745        Only superusers and users with the appropriate <code class="literal">SET</code>746        privilege can change this setting.747       </p><div class="note"><h3 class="title">Note</h3><p>748         Statements that contain simple syntax errors are not logged749         even by the <code class="varname">log_statement</code> = <code class="literal">all</code> setting,750         because the log message is emitted only after basic parsing has751         been done to determine the statement type.  In the case of extended752         query protocol, this setting likewise does not log statements that753         fail before the Execute phase (i.e., during parse analysis or754         planning).  Set <code class="varname">log_min_error_statement</code> to755         <code class="literal">ERROR</code> (or lower) to log such statements.756        </p><p>757         Logged statements might reveal sensitive data and even contain758         plaintext passwords.759        </p></div></dd><dt id="GUC-LOG-REPLICATION-COMMANDS"><span class="term"><code class="varname">log_replication_commands</code> (<code class="type">boolean</code>)760      <a id="id-1.6.7.11.5.3.17.1.3" class="indexterm"></a>761      </span> <a href="#GUC-LOG-REPLICATION-COMMANDS" class="id_link">#</a></dt><dd><p>762        Causes each replication command to be logged in the server log.763        See <a class="xref" href="protocol-replication.html" title="55.4. Streaming Replication Protocol">Section 55.4</a> for more information about764        replication command. The default value is <code class="literal">off</code>.765        Only superusers and users with the appropriate <code class="literal">SET</code>766        privilege can change this setting.767       </p></dd><dt id="GUC-LOG-TEMP-FILES"><span class="term"><code class="varname">log_temp_files</code> (<code class="type">integer</code>)768      <a id="id-1.6.7.11.5.3.18.1.3" class="indexterm"></a>769      </span> <a href="#GUC-LOG-TEMP-FILES" class="id_link">#</a></dt><dd><p>770        Controls logging of temporary file names and sizes.771        Temporary files can be772        created for sorts, hashes, and temporary query results.773        If enabled by this setting, a log entry is emitted for each774        temporary file, with the file size specified in bytes, when it is deleted.775        A value of zero logs all temporary file information, while positive776        values log only files whose size is greater than or equal to777        the specified amount of data.778        If this value is specified without units, it is taken as kilobytes.779        The default setting is -1, which disables such logging.780        Only superusers and users with the appropriate <code class="literal">SET</code>781        privilege can change this setting.782       </p></dd><dt id="GUC-LOG-TIMEZONE"><span class="term"><code class="varname">log_timezone</code> (<code class="type">string</code>)783      <a id="id-1.6.7.11.5.3.19.1.3" class="indexterm"></a>784      </span> <a href="#GUC-LOG-TIMEZONE" class="id_link">#</a></dt><dd><p>785        Sets the time zone used for timestamps written in the server log.786        Unlike <a class="xref" href="runtime-config-client.html#GUC-TIMEZONE">TimeZone</a>, this value is cluster-wide,787        so that all sessions will report timestamps consistently.788        The built-in default is <code class="literal">GMT</code>, but that is typically789        overridden in <code class="filename">postgresql.conf</code>; <span class="application">initdb</span>790        will install a setting there corresponding to its system environment.791        See <a class="xref" href="datatype-datetime.html#DATATYPE-TIMEZONES" title="8.5.3. Time Zones">Section 8.5.3</a> for more information.792        This parameter can only be set in the <code class="filename">postgresql.conf</code>793        file or on the server command line.794       </p></dd></dl></div></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-CSVLOG"><div class="titlepage"><div><div><h3 class="title">20.8.4. Using CSV-Format Log Output <a href="#RUNTIME-CONFIG-LOGGING-CSVLOG" class="id_link">#</a></h3></div></div></div><p>795        Including <code class="literal">csvlog</code> in the <code class="varname">log_destination</code> list796        provides a convenient way to import log files into a database table.797        This option emits log lines in comma-separated-values798        (<acronym class="acronym">CSV</acronym>) format,799        with these columns:800        time stamp with milliseconds,801        user name,802        database name,803        process ID,804        client host:port number,805        session ID,806        per-session line number,807        command tag,808        session start time,809        virtual transaction ID,810        regular transaction ID,811        error severity,812        SQLSTATE code,813        error message,814        error message detail,815        hint,816        internal query that led to the error (if any),817        character count of the error position therein,818        error context,819        user query that led to the error (if any and enabled by820        <code class="varname">log_min_error_statement</code>),821        character count of the error position therein,822        location of the error in the PostgreSQL source code823        (if <code class="varname">log_error_verbosity</code> is set to <code class="literal">verbose</code>),824        application name, backend type, process ID of parallel group leader,825        and query id.826        Here is a sample table definition for storing CSV-format log output:827 828</p><pre class="programlisting">829CREATE TABLE postgres_log830(831  log_time timestamp(3) with time zone,832  user_name text,833  database_name text,834  process_id integer,835  connection_from text,836  session_id text,837  session_line_num bigint,838  command_tag text,839  session_start_time timestamp with time zone,840  virtual_transaction_id text,841  transaction_id bigint,842  error_severity text,843  sql_state_code text,844  message text,845  detail text,846  hint text,847  internal_query text,848  internal_query_pos integer,849  context text,850  query text,851  query_pos integer,852  location text,853  application_name text,854  backend_type text,855  leader_pid integer,856  query_id bigint,857  PRIMARY KEY (session_id, session_line_num)858);859</pre><p>860       </p><p>861        To import a log file into this table, use the <code class="command">COPY FROM</code>862        command:863 864</p><pre class="programlisting">865COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;866</pre><p>867        It is also possible to access the file as a foreign table, using868        the supplied <a class="xref" href="file-fdw.html" title="F.16. file_fdw — access data files in the server's file system">file_fdw</a> module.869       </p><p>870       There are a few things you need to do to simplify importing CSV log871       files:872 873       </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>874            Set <code class="varname">log_filename</code> and875            <code class="varname">log_rotation_age</code> to provide a consistent,876            predictable naming scheme for your log files.  This lets you877            predict what the file name will be and know when an individual log878            file is complete and therefore ready to be imported.879         </p></li><li class="listitem"><p>880            Set <code class="varname">log_rotation_size</code> to 0 to disable881            size-based log rotation, as it makes the log file name difficult882            to predict.883           </p></li><li class="listitem"><p>884           Set <code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code> so885           that old log data isn't mixed with the new in the same file.886          </p></li><li class="listitem"><p>887           The table definition above includes a primary key specification.888           This is useful to protect against accidentally importing the same889           information twice.  The <code class="command">COPY</code> command commits all of the890           data it imports at one time, so any error will cause the entire891           import to fail.  If you import a partial log file and later import892           the file again when it is complete, the primary key violation will893           cause the import to fail.  Wait until the log is complete and894           closed before importing.  This procedure will also protect against895           accidentally importing a partial line that hasn't been completely896           written, which would also cause <code class="command">COPY</code> to fail.897          </p></li></ol></div><p>898      </p></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-JSONLOG"><div class="titlepage"><div><div><h3 class="title">20.8.5. Using JSON-Format Log Output <a href="#RUNTIME-CONFIG-LOGGING-JSONLOG" class="id_link">#</a></h3></div></div></div><p>899      Including <code class="literal">jsonlog</code> in the900      <code class="varname">log_destination</code> list provides a convenient way to901      import log files into many different programs. This option emits log902      lines in <acronym class="acronym">JSON</acronym> format.903     </p><p>904      String fields with null values are excluded from output.905      Additional fields may be added in the future. User applications that906      process <code class="literal">jsonlog</code> output should ignore unknown fields.907     </p><p>908      Each log line is serialized as a JSON object with the set of keys and909      their associated values shown in <a class="xref" href="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-JSONLOG-KEYS-VALUES" title="Table 20.3. Keys and Values of JSON Log Entries">Table 20.3</a>.910     </p><div class="table" id="RUNTIME-CONFIG-LOGGING-JSONLOG-KEYS-VALUES"><p class="title"><strong>Table 20.3. Keys and Values of JSON Log Entries</strong></p><div class="table-contents"><table class="table" summary="Keys and Values of JSON Log Entries" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Key name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal">timestamp</code></td><td>string</td><td>Time stamp with milliseconds</td></tr><tr><td><code class="literal">user</code></td><td>string</td><td>User name</td></tr><tr><td><code class="literal">dbname</code></td><td>string</td><td>Database name</td></tr><tr><td><code class="literal">pid</code></td><td>number</td><td>Process ID</td></tr><tr><td><code class="literal">remote_host</code></td><td>string</td><td>Client host</td></tr><tr><td><code class="literal">remote_port</code></td><td>number</td><td>Client port</td></tr><tr><td><code class="literal">session_id</code></td><td>string</td><td>Session ID</td></tr><tr><td><code class="literal">line_num</code></td><td>number</td><td>Per-session line number</td></tr><tr><td><code class="literal">ps</code></td><td>string</td><td>Current ps display</td></tr><tr><td><code class="literal">session_start</code></td><td>string</td><td>Session start time</td></tr><tr><td><code class="literal">vxid</code></td><td>string</td><td>Virtual transaction ID</td></tr><tr><td><code class="literal">txid</code></td><td>string</td><td>Regular transaction ID</td></tr><tr><td><code class="literal">error_severity</code></td><td>string</td><td>Error severity</td></tr><tr><td><code class="literal">state_code</code></td><td>string</td><td>SQLSTATE code</td></tr><tr><td><code class="literal">message</code></td><td>string</td><td>Error message</td></tr><tr><td><code class="literal">detail</code></td><td>string</td><td>Error message detail</td></tr><tr><td><code class="literal">hint</code></td><td>string</td><td>Error message hint</td></tr><tr><td><code class="literal">internal_query</code></td><td>string</td><td>Internal query that led to the error</td></tr><tr><td><code class="literal">internal_position</code></td><td>number</td><td>Cursor index into internal query</td></tr><tr><td><code class="literal">context</code></td><td>string</td><td>Error context</td></tr><tr><td><code class="literal">statement</code></td><td>string</td><td>Client-supplied query string</td></tr><tr><td><code class="literal">cursor_position</code></td><td>number</td><td>Cursor index into query string</td></tr><tr><td><code class="literal">func_name</code></td><td>string</td><td>Error location function name</td></tr><tr><td><code class="literal">file_name</code></td><td>string</td><td>File name of error location</td></tr><tr><td><code class="literal">file_line_num</code></td><td>number</td><td>File line number of the error location</td></tr><tr><td><code class="literal">application_name</code></td><td>string</td><td>Client application name</td></tr><tr><td><code class="literal">backend_type</code></td><td>string</td><td>Type of backend</td></tr><tr><td><code class="literal">leader_pid</code></td><td>number</td><td>Process ID of leader for active parallel workers</td></tr><tr><td><code class="literal">query_id</code></td><td>number</td><td>Query ID</td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="RUNTIME-CONFIG-LOGGING-PROC-TITLE"><div class="titlepage"><div><div><h3 class="title">20.8.6. Process Title <a href="#RUNTIME-CONFIG-LOGGING-PROC-TITLE" class="id_link">#</a></h3></div></div></div><p>911     These settings control how process titles of server processes are912     modified.  Process titles are typically viewed using programs like913     <span class="application">ps</span> or, on Windows, <span class="application">Process Explorer</span>.914     See <a class="xref" href="monitoring-ps.html" title="28.1. Standard Unix Tools">Section 28.1</a> for details.915    </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>)916      <a id="id-1.6.7.11.8.3.1.1.3" class="indexterm"></a>917      </span> <a href="#GUC-CLUSTER-NAME" class="id_link">#</a></dt><dd><p>918        Sets a name that identifies this database cluster (instance) for919        various purposes.  The cluster name appears in the process title for920        all server processes in this cluster.  Moreover, it is the default921        application name for a standby connection (see <a class="xref" href="runtime-config-replication.html#GUC-SYNCHRONOUS-STANDBY-NAMES">synchronous_standby_names</a>.)922       </p><p>923        The name can be any string of less924        than <code class="symbol">NAMEDATALEN</code> characters (64 characters in a standard925        build). Only printable ASCII characters may be used in the926        <code class="varname">cluster_name</code> value.927        Other characters are replaced with <a class="link" href="sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE" title="4.1.2.2. String Constants with C-Style Escapes">C-style hexadecimal escapes</a>.928        No name is shown if this parameter is set to the empty string929        <code class="literal">''</code> (which is the default).930        This parameter can only be set at server start.931       </p></dd><dt id="GUC-UPDATE-PROCESS-TITLE"><span class="term"><code class="varname">update_process_title</code> (<code class="type">boolean</code>)932      <a id="id-1.6.7.11.8.3.2.1.3" class="indexterm"></a>933      </span> <a href="#GUC-UPDATE-PROCESS-TITLE" class="id_link">#</a></dt><dd><p>934        Enables updating of the process title every time a new SQL command935        is received by the server.936        This setting defaults to <code class="literal">on</code> on most platforms, but it937        defaults to <code class="literal">off</code> on Windows due to that platform's larger938        overhead for updating the process title.939        Only superusers and users with the appropriate <code class="literal">SET</code>940        privilege can change this setting.941       </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" title="20.7. Query Planning">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="runtime-config.html" title="Chapter 20. Server Configuration">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="runtime-config-statistics.html" title="20.9. Run-time Statistics">Next</a></td></tr><tr><td width="40%" align="left" valign="top">20.7. Query Planning </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 20.9. Run-time Statistics</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai