↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Configuration Parameters

log_line_prefix

This is a printf-style string that is output at the beginning of each log entry that is sent to stderr, syslog, or eventlog. % characters begin “escape sequences” that are replaced with status information as outlined below. Unrecognized escapes are ignored. Other characters are copied straight to the log line. Some escapes are only recognized by session processes, and will be treated as empty by background processes such as the main server process. Status information may be aligned either left or right by specifying a numeric literal after the % and before the option. A negative value will cause the status information to be padded on the right with spaces to give it a minimum width, whereas a positive value will pad on the left. Padding can be useful to aid human readability in log files. This parameter can only be set in the postgresql.conf file or on the server command line. The default is '%m [%p] ' which logs a time stamp and the process ID. EscapeEffectSession only%aApplication nameyes%uUser nameyes%dDatabase nameyes%rRemote host name or IP address, and remote portyes%hRemote host name or IP addressyes%LLocal address (the IP address on the server that the client connected to)yes%bBackend typeno%pProcess IDno%PProcess ID of the parallel group leader, if this process is a parallel query workerno%tTime stamp without millisecondsno%mTime stamp with millisecondsno%nTime stamp with milliseconds (as a Unix epoch)no%iCommand tag: type of session's current commandyes%eSQLSTATE error codeno%cSession ID: see belowno%lNumber of the log line for each session or process, starting at 1no%sProcess start time stampno%vVirtual transaction ID (procNumber/localXID); see Section 67.1no%xTransaction ID (0 if none is assigned); see Section 67.1no%qProduces no output, but tells non-session processes to stop at this point in the string; ignored by session processesno%QQuery identifier of the current query. Query identifiers are not computed by default, so this field will be zero unless compute_query_id parameter is enabled or a third-party module that computes query identifiers is configured.yes%%Literal %no The backend type corresponds to the column backend_type in the view pg_stat_activity, but additional types can appear in the log that don't show in that view. The %c escape prints a quasi-unique session identifier, consisting of two 4-byte hexadecimal numbers (without leading zeros) separated by a dot. The numbers are the process start time and the process ID, so %c can also be used as a space saving way of printing those items. For example, to generate the session identifier from pg_stat_activity, use this query: SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' || to_hex(pid) FROM pg_stat_activity; Tip If you set a nonempty value for log_line_prefix, you should usually make its last character be a space, to provide visual separation from the rest of the log line. A punctuation character can be used too. Tip Syslog produces its own time stamp and process ID information, so you probably do not want to include those escapes if you are logging to syslog. Tip The %q escape is useful when including information that is only available in session (backend) context like user or database name. For example: log_line_prefix = '%m [%p] %q%u@%d/%a ' Note The %Q escape always reports a zero identifier for lines output by log_statement because log_statement generates output before an identifier can be calculated, including invalid statements for which an identifier cannot be calculated.

English manual coverage begins with PostgreSQL 7.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

boot val
%m [%p]
category
Reporting and Logging / What to Log
context
sighup
doc same as
Unknown
documented
true
enumvals
Unknown
extra desc
An empty string means no prefix.
lang
en
max val
Unknown
metadata version
18
min val
Unknown
name
log_line_prefix
short desc
Controls information prefixed to each log line.
source
pg-settings-source-snapshot
unit
Unknown
vartype
string

Definition PG 18

This is a printf-style string that is output at the beginning of each log entry that is sent to stderr, syslog, or eventlog. % characters begin “escape sequences” that are replaced with status information as outlined below. Unrecognized escapes are ignored. Other characters are copied straight to the log line. Some escapes are only recognized by session processes, and will be treated as empty by background processes such as the main server process. Status information may be aligned either left or right by specifying a numeric literal after the % and before the option. A negative value will cause the status information to be padded on the right with spaces to give it a minimum width, whereas a positive value will pad on the left. Padding can be useful to aid human readability in log files.

This parameter can only be set in the postgresql.conf file or on the server command line. The default is '%m [%p] ' which logs a time stamp and the process ID.

EscapeEffectSession only
%aApplication nameyes
%uUser nameyes
%dDatabase nameyes
%rRemote host name or IP address, and remote portyes
%hRemote host name or IP addressyes
%LLocal address (the IP address on the server that the client connected to)yes
%bBackend typeno
%pProcess IDno
%PProcess ID of the parallel group leader, if this process is a parallel query workerno
%tTime stamp without millisecondsno
%mTime stamp with millisecondsno
%nTime stamp with milliseconds (as a Unix epoch)no
%iCommand tag: type of session's current commandyes
%eSQLSTATE error codeno
%cSession ID: see belowno
%lNumber of the log line for each session or process, starting at 1no
%sProcess start time stampno
%vVirtual transaction ID (procNumber/localXID); see Section 67.1no
%xTransaction ID (0 if none is assigned); see Section 67.1no
%qProduces no output, but tells non-session processes to stop at this point in the string; ignored by session processesno
%QQuery identifier of the current query. Query identifiers are not computed by default, so this field will be zero unless compute_query_id parameter is enabled or a third-party module that computes query identifiers is configured.yes
%%Literal %no

The backend type corresponds to the column backend_type in the view pg_stat_activity, but additional types can appear in the log that don't show in that view.

The %c escape prints a quasi-unique session identifier, consisting of two 4-byte hexadecimal numbers (without leading zeros) separated by a dot. The numbers are the process start time and the process ID, so %c can also be used as a space saving way of printing those items. For example, to generate the session identifier from pg_stat_activity, use this query:

SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||
       to_hex(pid)
FROM pg_stat_activity;

Tip

If you set a nonempty value for log_line_prefix, you should usually make its last character be a space, to provide visual separation from the rest of the log line. A punctuation character can be used too.

Tip

Syslog produces its own time stamp and process ID information, so you probably do not want to include those escapes if you are logging to syslog.

Tip

The %q escape is useful when including information that is only available in session (backend) context like user or database name. For example:

log_line_prefix = '%m [%p] %q%u@%d/%a '

Note

The %Q escape always reports a zero identifier for lines output by log_statement because log_statement generates output before an identifier can be calculated, including invalid statements for which an identifier cannot be calculated.

Compare versions

Complete source facts

doc html

<p>
         This is a <code class="function">printf</code>-style string that is output at the
         beginning of each log entry that is sent to <code class="literal">stderr</code>,
         <code class="literal">syslog</code>, or <code class="literal">eventlog</code>.
         <code class="literal">%</code> characters begin <span class="quote">“<span class="quote">escape sequences</span>”</span>
         that are replaced with status information as outlined below.
         Unrecognized escapes are ignored. Other
         characters are copied straight to the log line. Some escapes are
         only recognized by session processes, and will be treated as empty by
         background processes such as the main server process. Status
         information may be aligned either left or right by specifying a
         numeric literal after the % and before the option. A negative
         value will cause the status information to be padded on the
         right with spaces to give it a minimum width, whereas a positive
         value will pad on the left. Padding can be useful to aid human
         readability in log files.
       </p><p>
         This parameter can only be set in the <code class="filename">postgresql.conf</code>
         file or on the server command line. The default is
         <code class="literal">'%m [%p] '</code> which logs a time stamp and the process ID.
       </p><div class="informaltable"><table border="1" class="informaltable"><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">%L</code></td><td>Local address (the IP address on the server that the
             client connected to)</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 process
              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 (procNumber/localXID);  see
             <a class="xref" href="/docs/18/transaction-id.html" title="67.1. Transactions and Identifiers">Section 67.1</a></td><td>no</td></tr><tr><td><code class="literal">%x</code></td><td>Transaction ID (0 if none is assigned);  see
             <a class="xref" href="/docs/18/transaction-id.html" title="67.1. Transactions and Identifiers">Section 67.1</a></td><td>no</td></tr><tr><td><code class="literal">%q</code></td><td>Produces no output, but tells non-session
             processes to stop at this point in the string; ignored by
             session processes</td><td>no</td></tr><tr><td><code class="literal">%Q</code></td><td>Query identifier of the current query.  Query
             identifiers are not computed by default, so this field
             will be zero unless <a class="xref" href="/docs/18/runtime-config-statistics.html#GUC-COMPUTE-QUERY-ID">compute_query_id</a>
             parameter is enabled or a third-party module that computes
             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>
          The backend type corresponds to the column
          <code class="structfield">backend_type</code> in the view
          <a class="link" href="/docs/18/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW" title="27.2.3. pg_stat_activity">
<code class="structname">pg_stat_activity</code></a>,
          but additional types can appear
          in the log that don't show in that view.
         </p><p>
         The <code class="literal">%c</code> escape prints a quasi-unique session identifier,
         consisting of two 4-byte hexadecimal numbers (without leading zeros)
         separated by a dot.  The numbers are the process start time and the
         process ID, so <code class="literal">%c</code> can also be used as a space saving way
         of printing those items.  For example, to generate the session
         identifier from <code class="literal">pg_stat_activity</code>, use this query:
</p><pre class="programlisting">
SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||
       to_hex(pid)
FROM pg_stat_activity;
</pre><p>
</p><div class="tip"><h3 class="title">Tip</h3><p>
         If you set a nonempty value for <code class="varname">log_line_prefix</code>,
         you should usually make its last character be a space, to provide
         visual separation from the rest of the log line.  A punctuation
         character can be used too.
        </p></div><div class="tip"><h3 class="title">Tip</h3><p>
<span class="application">Syslog</span> produces its own
         time stamp and process ID information, so you probably do not want to
         include those escapes if you are logging to <span class="application">syslog</span>.
        </p></div><div class="tip"><h3 class="title">Tip</h3><p>
         The <code class="literal">%q</code> escape is useful when including information that is
         only available in session (backend) context like user or database
         name.  For example:
</p><pre class="programlisting">
log_line_prefix = '%m [%p] %q%u@%d/%a '
</pre><p>
</p></div><div class="note"><h3 class="title">Note</h3><p>
         The <code class="literal">%Q</code> escape always reports a zero identifier
         for lines output by <a class="xref" href="/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT">log_statement</a> because
         <code class="varname">log_statement</code> generates output before an
         identifier can be calculated, including invalid statements for
         which an identifier cannot be calculated.
        </p></div>

documentation revision

{"inputs":[{"file":"runtime-config-logging.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"278d913b9c0f735c5cd7b35fd7205826bbd9c449805370d2dbe54105c0ed1d88","version":"18.7"},{"file":"runtime-config-logging.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"68c010254e1859ec0b76f06a563babd51a6c38997f1242e35e4c6b649724b1cb","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:0592072223342af8a9ec0043313f2bc3af3afc3eb7a21d38286b248d9b1b8ee7

Text language: en · wiki-repair-20261023:0592072223342af8a9ec0043313f2bc3af3afc3eb7a21d38286b248d9b1b8ee7