]> begriffs open source - ai-pg/blob - full-docs/txt/runtime-config-logging.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / runtime-config-logging.txt
1
2 19.8. Error Reporting and Logging #
3
4    19.8.1. Where to Log
5    19.8.2. When to Log
6    19.8.3. What to Log
7    19.8.4. Using CSV-Format Log Output
8    19.8.5. Using JSON-Format Log Output
9    19.8.6. Process Title
10
11 19.8.1. Where to Log #
12
13    log_destination (string) #
14           PostgreSQL supports several methods for logging server messages,
15           including stderr, csvlog, jsonlog, and syslog. On Windows,
16           eventlog is also supported. Set this parameter to a list of
17           desired log destinations separated by commas. The default is to
18           log to stderr only. This parameter can only be set in the
19           postgresql.conf file or on the server command line.
20
21           If csvlog is included in log_destination, log entries are output
22           in “comma-separated value” (CSV) format, which is convenient for
23           loading logs into programs. See Section 19.8.4 for details.
24           logging_collector must be enabled to generate CSV-format log
25           output.
26
27           If jsonlog is included in log_destination, log entries are
28           output in JSON format, which is convenient for loading logs into
29           programs. See Section 19.8.5 for details. logging_collector must
30           be enabled to generate JSON-format log output.
31
32           When either stderr, csvlog or jsonlog are included, the file
33           current_logfiles is created to record the location of the log
34           file(s) currently in use by the logging collector and the
35           associated logging destination. This provides a convenient way
36           to find the logs currently in use by the instance. Here is an
37           example of this file's content:
38
39 stderr log/postgresql.log
40 csvlog log/postgresql.csv
41 jsonlog log/postgresql.json
42
43           current_logfiles is recreated when a new log file is created as
44           an effect of rotation, and when log_destination is reloaded. It
45           is removed when none of stderr, csvlog or jsonlog are included
46           in log_destination, and when the logging collector is disabled.
47
48 Note
49
50           On most Unix systems, you will need to alter the configuration
51           of your system's syslog daemon in order to make use of the
52           syslog option for log_destination. PostgreSQL can log to syslog
53           facilities LOCAL0 through LOCAL7 (see syslog_facility), but the
54           default syslog configuration on most platforms will discard all
55           such messages. You will need to add something like:
56
57 local0.*    /var/log/postgresql
58
59           to the syslog daemon's configuration file to make it work.
60
61           On Windows, when you use the eventlog option for
62           log_destination, you should register an event source and its
63           library with the operating system so that the Windows Event
64           Viewer can display event log messages cleanly. See Section 18.12
65           for details.
66
67    logging_collector (boolean) #
68           This parameter enables the logging collector, which is a
69           background process that captures log messages sent to stderr and
70           redirects them into log files. This approach is often more
71           useful than logging to syslog, since some types of messages
72           might not appear in syslog output. (One common example is
73           dynamic-linker failure messages; another is error messages
74           produced by scripts such as archive_command.) This parameter can
75           only be set at server start.
76
77 Note
78
79           It is possible to log to stderr without using the logging
80           collector; the log messages will just go to wherever the
81           server's stderr is directed. However, that method is only
82           suitable for low log volumes, since it provides no convenient
83           way to rotate log files. Also, on some platforms not using the
84           logging collector can result in lost or garbled log output,
85           because multiple processes writing concurrently to the same log
86           file can overwrite each other's output.
87
88 Note
89
90           The logging collector is designed to never lose messages. This
91           means that in case of extremely high load, server processes
92           could be blocked while trying to send additional log messages
93           when the collector has fallen behind. In contrast, syslog
94           prefers to drop messages if it cannot write them, which means it
95           may fail to log some messages in such cases but it will not
96           block the rest of the system.
97
98    log_directory (string) #
99           When logging_collector is enabled, this parameter determines the
100           directory in which log files will be created. It can be
101           specified as an absolute path, or relative to the cluster data
102           directory. This parameter can only be set in the postgresql.conf
103           file or on the server command line. The default is log.
104
105    log_filename (string) #
106           When logging_collector is enabled, this parameter sets the file
107           names of the created log files. The value is treated as a
108           strftime pattern, so %-escapes can be used to specify
109           time-varying file names. (Note that if there are any
110           time-zone-dependent %-escapes, the computation is done in the
111           zone specified by log_timezone.) The supported %-escapes are
112           similar to those listed in the Open Group's strftime
113           specification. Note that the system's strftime is not used
114           directly, so platform-specific (nonstandard) extensions do not
115           work. The default is postgresql-%Y-%m-%d_%H%M%S.log.
116
117           If you specify a file name without escapes, you should plan to
118           use a log rotation utility to avoid eventually filling the
119           entire disk. In releases prior to 8.4, if no % escapes were
120           present, PostgreSQL would append the epoch of the new log file's
121           creation time, but this is no longer the case.
122
123           If CSV-format output is enabled in log_destination, .csv will be
124           appended to the timestamped log file name to create the file
125           name for CSV-format output. (If log_filename ends in .log, the
126           suffix is replaced instead.)
127
128           If JSON-format output is enabled in log_destination, .json will
129           be appended to the timestamped log file name to create the file
130           name for JSON-format output. (If log_filename ends in .log, the
131           suffix is replaced instead.)
132
133           This parameter can only be set in the postgresql.conf file or on
134           the server command line.
135
136    log_file_mode (integer) #
137           On Unix systems this parameter sets the permissions for log
138           files when logging_collector is enabled. (On Microsoft Windows
139           this parameter is ignored.) The parameter value is expected to
140           be a numeric mode specified in the format accepted by the chmod
141           and umask system calls. (To use the customary octal format the
142           number must start with a 0 (zero).)
143
144           The default permissions are 0600, meaning only the server owner
145           can read or write the log files. The other commonly useful
146           setting is 0640, allowing members of the owner's group to read
147           the files. Note however that to make use of such a setting,
148           you'll need to alter log_directory to store the files somewhere
149           outside the cluster data directory. In any case, it's unwise to
150           make the log files world-readable, since they might contain
151           sensitive data.
152
153           This parameter can only be set in the postgresql.conf file or on
154           the server command line.
155
156    log_rotation_age (integer) #
157           When logging_collector is enabled, this parameter determines the
158           maximum amount of time to use an individual log file, after
159           which a new log file will be created. If this value is specified
160           without units, it is taken as minutes. The default is 24 hours.
161           Set to zero to disable time-based creation of new log files.
162           This parameter can only be set in the postgresql.conf file or on
163           the server command line.
164
165    log_rotation_size (integer) #
166           When logging_collector is enabled, this parameter determines the
167           maximum size of an individual log file. After this amount of
168           data has been emitted into a log file, a new log file will be
169           created. If this value is specified without units, it is taken
170           as kilobytes. The default is 10 megabytes. Set to zero to
171           disable size-based creation of new log files. This parameter can
172           only be set in the postgresql.conf file or on the server command
173           line.
174
175    log_truncate_on_rotation (boolean) #
176           When logging_collector is enabled, this parameter will cause
177           PostgreSQL to truncate (overwrite), rather than append to, any
178           existing log file of the same name. However, truncation will
179           occur only when a new file is being opened due to time-based
180           rotation, not during server startup or size-based rotation. When
181           off, pre-existing files will be appended to in all cases. For
182           example, using this setting in combination with a log_filename
183           like postgresql-%H.log would result in generating twenty-four
184           hourly log files and then cyclically overwriting them. This
185           parameter can only be set in the postgresql.conf file or on the
186           server command line.
187
188           Example: To keep 7 days of logs, one log file per day named
189           server_log.Mon, server_log.Tue, etc., and automatically
190           overwrite last week's log with this week's log, set log_filename
191           to server_log.%a, log_truncate_on_rotation to on, and
192           log_rotation_age to 1440.
193
194           Example: To keep 24 hours of logs, one log file per hour, but
195           also rotate sooner if the log file size exceeds 1GB, set
196           log_filename to server_log.%H%M, log_truncate_on_rotation to on,
197           log_rotation_age to 60, and log_rotation_size to 1000000.
198           Including %M in log_filename allows any size-driven rotations
199           that might occur to select a file name different from the hour's
200           initial file name.
201
202    syslog_facility (enum) #
203           When logging to syslog is enabled, this parameter determines the
204           syslog “facility” to be used. You can choose from LOCAL0,
205           LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7; the
206           default is LOCAL0. See also the documentation of your system's
207           syslog daemon. This parameter can only be set in the
208           postgresql.conf file or on the server command line.
209
210    syslog_ident (string) #
211           When logging to syslog is enabled, this parameter determines the
212           program name used to identify PostgreSQL messages in syslog
213           logs. The default is postgres. This parameter can only be set in
214           the postgresql.conf file or on the server command line.
215
216    syslog_sequence_numbers (boolean) #
217           When logging to syslog and this is on (the default), then each
218           message will be prefixed by an increasing sequence number (such
219           as [2]). This circumvents the “--- last message repeated N times
220           ---” suppression that many syslog implementations perform by
221           default. In more modern syslog implementations, repeated message
222           suppression can be configured (for example,
223           $RepeatedMsgReduction in rsyslog), so this might not be
224           necessary. Also, you could turn this off if you actually want to
225           suppress repeated messages.
226
227           This parameter can only be set in the postgresql.conf file or on
228           the server command line.
229
230    syslog_split_messages (boolean) #
231           When logging to syslog is enabled, this parameter determines how
232           messages are delivered to syslog. When on (the default),
233           messages are split by lines, and long lines are split so that
234           they will fit into 1024 bytes, which is a typical size limit for
235           traditional syslog implementations. When off, PostgreSQL server
236           log messages are delivered to the syslog service as is, and it
237           is up to the syslog service to cope with the potentially bulky
238           messages.
239
240           If syslog is ultimately logging to a text file, then the effect
241           will be the same either way, and it is best to leave the setting
242           on, since most syslog implementations either cannot handle large
243           messages or would need to be specially configured to handle
244           them. But if syslog is ultimately writing into some other
245           medium, it might be necessary or more useful to keep messages
246           logically together.
247
248           This parameter can only be set in the postgresql.conf file or on
249           the server command line.
250
251    event_source (string) #
252           When logging to event log is enabled, this parameter determines
253           the program name used to identify PostgreSQL messages in the
254           log. The default is PostgreSQL. This parameter can only be set
255           in the postgresql.conf file or on the server command line.
256
257 19.8.2. When to Log #
258
259    log_min_messages (enum) #
260           Controls which message levels are written to the server log.
261           Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO,
262           NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level
263           includes all the levels that follow it. The later the level, the
264           fewer messages are sent to the log. The default is WARNING. Note
265           that LOG has a different rank here than in client_min_messages.
266           Only superusers and users with the appropriate SET privilege can
267           change this setting.
268
269    log_min_error_statement (enum) #
270           Controls which SQL statements that cause an error condition are
271           recorded in the server log. The current SQL statement is
272           included in the log entry for any message of the specified
273           severity or higher. Valid values are DEBUG5, DEBUG4, DEBUG3,
274           DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and
275           PANIC. The default is ERROR, which means statements causing
276           errors, log messages, fatal errors, or panics will be logged. To
277           effectively turn off logging of failing statements, set this
278           parameter to PANIC. Only superusers and users with the
279           appropriate SET privilege can change this setting.
280
281    log_min_duration_statement (integer) #
282           Causes the duration of each completed statement to be logged if
283           the statement ran for at least the specified amount of time. For
284           example, if you set it to 250ms then all SQL statements that run
285           250ms or longer will be logged. Enabling this parameter can be
286           helpful in tracking down unoptimized queries in your
287           applications. If this value is specified without units, it is
288           taken as milliseconds. Setting this to zero prints all statement
289           durations. -1 (the default) disables logging statement
290           durations. Only superusers and users with the appropriate SET
291           privilege can change this setting.
292
293           This overrides log_min_duration_sample, meaning that queries
294           with duration exceeding this setting are not subject to sampling
295           and are always logged.
296
297           For clients using extended query protocol, durations of the
298           Parse, Bind, and Execute steps are logged independently.
299
300 Note
301
302           When using this option together with log_statement, the text of
303           statements that are logged because of log_statement will not be
304           repeated in the duration log message. If you are not using
305           syslog, it is recommended that you log the PID or session ID
306           using log_line_prefix so that you can link the statement message
307           to the later duration message using the process ID or session
308           ID.
309
310    log_min_duration_sample (integer) #
311           Allows sampling the duration of completed statements that ran
312           for at least the specified amount of time. This produces the
313           same kind of log entries as log_min_duration_statement, but only
314           for a subset of the executed statements, with sample rate
315           controlled by log_statement_sample_rate. For example, if you set
316           it to 100ms then all SQL statements that run 100ms or longer
317           will be considered for sampling. Enabling this parameter can be
318           helpful when the traffic is too high to log all queries. If this
319           value is specified without units, it is taken as milliseconds.
320           Setting this to zero samples all statement durations. -1 (the
321           default) disables sampling statement durations. Only superusers
322           and users with the appropriate SET privilege can change this
323           setting.
324
325           This setting has lower priority than log_min_duration_statement,
326           meaning that statements with durations exceeding
327           log_min_duration_statement are not subject to sampling and are
328           always logged.
329
330           Other notes for log_min_duration_statement apply also to this
331           setting.
332
333    log_statement_sample_rate (floating point) #
334           Determines the fraction of statements with duration exceeding
335           log_min_duration_sample that will be logged. Sampling is
336           stochastic, for example 0.5 means there is statistically one
337           chance in two that any given statement will be logged. The
338           default is 1.0, meaning to log all sampled statements. Setting
339           this to zero disables sampled statement-duration logging, the
340           same as setting log_min_duration_sample to -1. Only superusers
341           and users with the appropriate SET privilege can change this
342           setting.
343
344    log_transaction_sample_rate (floating point) #
345           Sets the fraction of transactions whose statements are all
346           logged, in addition to statements logged for other reasons. It
347           applies to each new transaction regardless of its statements'
348           durations. Sampling is stochastic, for example 0.1 means there
349           is statistically one chance in ten that any given transaction
350           will be logged. log_transaction_sample_rate can be helpful to
351           construct a sample of transactions. The default is 0, meaning
352           not to log statements from any additional transactions. Setting
353           this to 1 logs all statements of all transactions. Only
354           superusers and users with the appropriate SET privilege can
355           change this setting.
356
357 Note
358
359           Like all statement-logging options, this option can add
360           significant overhead.
361
362    log_startup_progress_interval (integer) #
363           Sets the amount of time after which the startup process will log
364           a message about a long-running operation that is still in
365           progress, as well as the interval between further progress
366           messages for that operation. The default is 10 seconds. A
367           setting of 0 disables the feature. If this value is specified
368           without units, it is taken as milliseconds. This setting is
369           applied separately to each operation. This parameter can only be
370           set in the postgresql.conf file or on the server command line.
371
372           For example, if syncing the data directory takes 25 seconds and
373           thereafter resetting unlogged relations takes 8 seconds, and if
374           this setting has the default value of 10 seconds, then a
375           messages will be logged for syncing the data directory after it
376           has been in progress for 10 seconds and again after it has been
377           in progress for 20 seconds, but nothing will be logged for
378           resetting unlogged relations.
379
380    Table 19.2 explains the message severity levels used by PostgreSQL. If
381    logging output is sent to syslog or Windows' eventlog, the severity
382    levels are translated as shown in the table.
383
384    Table 19.2. Message Severity Levels
385    Severity Usage syslog eventlog
386    DEBUG1 .. DEBUG5 Provides successively-more-detailed information for
387    use by developers. DEBUG INFORMATION
388    INFO Provides information implicitly requested by the user, e.g.,
389    output from VACUUM VERBOSE. INFO INFORMATION
390    NOTICE Provides information that might be helpful to users, e.g.,
391    notice of truncation of long identifiers. NOTICE INFORMATION
392    WARNING Provides warnings of likely problems, e.g., COMMIT outside a
393    transaction block. NOTICE WARNING
394    ERROR Reports an error that caused the current command to abort.
395    WARNING ERROR
396    LOG Reports information of interest to administrators, e.g., checkpoint
397    activity. INFO INFORMATION
398    FATAL Reports an error that caused the current session to abort. ERR
399    ERROR
400    PANIC Reports an error that caused all database sessions to abort. CRIT
401    ERROR
402
403 19.8.3. What to Log #
404
405 Note
406
407    What you choose to log can have security implications; see
408    Section 24.3.
409
410    application_name (string) #
411           The application_name can be any string of less than NAMEDATALEN
412           characters (64 characters in a standard build). It is typically
413           set by an application upon connection to the server. The name
414           will be displayed in the pg_stat_activity view and included in
415           CSV log entries. It can also be included in regular log entries
416           via the log_line_prefix parameter. Only printable ASCII
417           characters may be used in the application_name value. Other
418           characters are replaced with C-style hexadecimal escapes.
419
420    debug_print_parse (boolean)
421           debug_print_rewritten (boolean)
422           debug_print_plan (boolean) #
423           These parameters enable various debugging output to be emitted.
424           When set, they print the resulting parse tree, the query
425           rewriter output, or the execution plan for each executed query.
426           These messages are emitted at LOG message level, so by default
427           they will appear in the server log but will not be sent to the
428           client. You can change that by adjusting client_min_messages
429           and/or log_min_messages. These parameters are off by default.
430
431    debug_pretty_print (boolean) #
432           When set, debug_pretty_print indents the messages produced by
433           debug_print_parse, debug_print_rewritten, or debug_print_plan.
434           This results in more readable but much longer output than the
435           “compact” format used when it is off. It is on by default.
436
437    log_autovacuum_min_duration (integer) #
438           Causes each action executed by autovacuum to be logged if it ran
439           for at least the specified amount of time. Setting this to zero
440           logs all autovacuum actions. -1 disables logging autovacuum
441           actions. If this value is specified without units, it is taken
442           as milliseconds. For example, if you set this to 250ms then all
443           automatic vacuums and analyzes that run 250ms or longer will be
444           logged. In addition, when this parameter is set to any value
445           other than -1, a message will be logged if an autovacuum action
446           is skipped due to a conflicting lock or a concurrently dropped
447           relation. The default is 10min. Enabling this parameter can be
448           helpful in tracking autovacuum activity. This parameter can only
449           be set in the postgresql.conf file or on the server command
450           line; but the setting can be overridden for individual tables by
451           changing table storage parameters.
452
453    log_checkpoints (boolean) #
454           Causes checkpoints and restartpoints to be logged in the server
455           log. Some statistics are included in the log messages, including
456           the number of buffers written and the time spent writing them.
457           This parameter can only be set in the postgresql.conf file or on
458           the server command line. The default is on.
459
460    log_connections (string) #
461           Causes aspects of each connection to the server to be logged.
462           The default is the empty string, '', which disables all
463           connection logging. The following options may be specified alone
464           or in a comma-separated list:
465
466           Table 19.3. Log Connection Options
467
468    Name Description
469    receipt Logs receipt of a connection.
470    authentication Logs the original identity used by an authentication
471    method to identify a user. In most cases, the identity string matches
472    the PostgreSQL username, but some third-party authentication methods
473    may alter the original user identifier before the server stores it.
474    Failed authentication is always logged regardless of the value of this
475    setting.
476    authorization Logs successful completion of authorization. At this
477    point the connection has been established but the backend is not yet
478    fully set up. The log message includes the authorized username as well
479    as the database name and application name, if applicable.
480    setup_durations Logs the time spent establishing the connection and
481    setting up the backend until the connection is ready to execute its
482    first query. The log message includes three durations: the total setup
483    duration (starting from the postmaster accepting the incoming
484    connection and ending when the connection is ready for query), the time
485    it took to fork the new backend, and the time it took to authenticate
486    the user.
487    all A convenience alias equivalent to specifying all options. If all is
488    specified in a list of other options, all connection aspects will be
489    logged.
490
491           Disconnection logging is separately controlled by
492           log_disconnections.
493
494           For the purposes of backwards compatibility, on, off, true,
495           false, yes, no, 1, and 0 are still supported. The positive
496           values are equivalent to specifying the receipt, authentication,
497           and authorization options.
498
499           Only superusers and users with the appropriate SET privilege can
500           change this parameter at session start, and it cannot be changed
501           at all within a session.
502
503 Note
504
505           Some client programs, like psql, attempt to connect twice while
506           determining if a password is required, so duplicate “connection
507           received” messages do not necessarily indicate a problem.
508
509    log_disconnections (boolean) #
510           Causes session terminations to be logged. The log output
511           provides information similar to log_connections, plus the
512           duration of the session. Only superusers and users with the
513           appropriate SET privilege can change this parameter at session
514           start, and it cannot be changed at all within a session. The
515           default is off.
516
517    log_duration (boolean) #
518           Causes the duration of every completed statement to be logged.
519           The default is off. Only superusers and users with the
520           appropriate SET privilege can change this setting.
521
522           For clients using extended query protocol, durations of the
523           Parse, Bind, and Execute steps are logged independently.
524
525 Note
526
527           The difference between enabling log_duration and setting
528           log_min_duration_statement to zero is that exceeding
529           log_min_duration_statement forces the text of the query to be
530           logged, but this option doesn't. Thus, if log_duration is on and
531           log_min_duration_statement has a positive value, all durations
532           are logged but the query text is included only for statements
533           exceeding the threshold. This behavior can be useful for
534           gathering statistics in high-load installations.
535
536    log_error_verbosity (enum) #
537           Controls the amount of detail written in the server log for each
538           message that is logged. Valid values are TERSE, DEFAULT, and
539           VERBOSE, each adding more fields to displayed messages. TERSE
540           excludes the logging of DETAIL, HINT, QUERY, and CONTEXT error
541           information. VERBOSE output includes the SQLSTATE error code
542           (see also Appendix A) and the source code file name, function
543           name, and line number that generated the error. Only superusers
544           and users with the appropriate SET privilege can change this
545           setting.
546
547    log_hostname (boolean) #
548           By default, connection log messages only show the IP address of
549           the connecting host. Turning this parameter on causes logging of
550           the host name as well. Note that depending on your host name
551           resolution setup this might impose a non-negligible performance
552           penalty. This parameter can only be set in the postgresql.conf
553           file or on the server command line.
554
555    log_line_prefix (string) #
556           This is a printf-style string that is output at the beginning of
557           each log line. % characters begin “escape sequences” that are
558           replaced with status information as outlined below. Unrecognized
559           escapes are ignored. Other characters are copied straight to the
560           log line. Some escapes are only recognized by session processes,
561           and will be treated as empty by background processes such as the
562           main server process. Status information may be aligned either
563           left or right by specifying a numeric literal after the % and
564           before the option. A negative value will cause the status
565           information to be padded on the right with spaces to give it a
566           minimum width, whereas a positive value will pad on the left.
567           Padding can be useful to aid human readability in log files.
568
569           This parameter can only be set in the postgresql.conf file or on
570           the server command line. The default is '%m [%p] ' which logs a
571           time stamp and the process ID.
572
573    Escape Effect Session only
574    %a Application name yes
575    %u User name yes
576    %d Database name yes
577    %r Remote host name or IP address, and remote port yes
578    %h Remote host name or IP address yes
579    %L Local address (the IP address on the server that the client
580    connected to) yes
581    %b Backend type no
582    %p Process ID no
583    %P Process ID of the parallel group leader, if this process is a
584    parallel query worker no
585    %t Time stamp without milliseconds no
586    %m Time stamp with milliseconds no
587    %n Time stamp with milliseconds (as a Unix epoch) no
588    %i Command tag: type of session's current command yes
589    %e SQLSTATE error code no
590    %c Session ID: see below no
591    %l Number of the log line for each session or process, starting at 1 no
592    %s Process start time stamp no
593    %v Virtual transaction ID (procNumber/localXID); see Section 67.1 no
594    %x Transaction ID (0 if none is assigned); see Section 67.1 no
595    %q Produces no output, but tells non-session processes to stop at this
596    point in the string; ignored by session processes no
597    %Q Query identifier of the current query. Query identifiers are not
598    computed by default, so this field will be zero unless compute_query_id
599    parameter is enabled or a third-party module that computes query
600    identifiers is configured. yes
601    %% Literal % no
602
603           The backend type corresponds to the column backend_type in the
604           view pg_stat_activity, but additional types can appear in the
605           log that don't show in that view.
606
607           The %c escape prints a quasi-unique session identifier,
608           consisting of two 4-byte hexadecimal numbers (without leading
609           zeros) separated by a dot. The numbers are the process start
610           time and the process ID, so %c can also be used as a space
611           saving way of printing those items. For example, to generate the
612           session identifier from pg_stat_activity, use this query:
613
614 SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||
615        to_hex(pid)
616 FROM pg_stat_activity;
617
618 Tip
619
620           If you set a nonempty value for log_line_prefix, you should
621           usually make its last character be a space, to provide visual
622           separation from the rest of the log line. A punctuation
623           character can be used too.
624
625 Tip
626
627           Syslog produces its own time stamp and process ID information,
628           so you probably do not want to include those escapes if you are
629           logging to syslog.
630
631 Tip
632
633           The %q escape is useful when including information that is only
634           available in session (backend) context like user or database
635           name. For example:
636
637 log_line_prefix = '%m [%p] %q%u@%d/%a '
638
639 Note
640
641           The %Q escape always reports a zero identifier for lines output
642           by log_statement because log_statement generates output before
643           an identifier can be calculated, including invalid statements
644           for which an identifier cannot be calculated.
645
646    log_lock_waits (boolean) #
647           Controls whether a log message is produced when a session waits
648           longer than deadlock_timeout to acquire a lock. This is useful
649           in determining if lock waits are causing poor performance. The
650           default is off. Only superusers and users with the appropriate
651           SET privilege can change this setting.
652
653    log_lock_failures (boolean) #
654           Controls whether a detailed log message is produced when a lock
655           acquisition fails. This is useful for analyzing the causes of
656           lock failures. Currently, only lock failures due to SELECT
657           NOWAIT is supported. The default is off. Only superusers and
658           users with the appropriate SET privilege can change this
659           setting.
660
661    log_recovery_conflict_waits (boolean) #
662           Controls whether a log message is produced when the startup
663           process waits longer than deadlock_timeout for recovery
664           conflicts. This is useful in determining if recovery conflicts
665           prevent the recovery from applying WAL.
666
667           The default is off. This parameter can only be set in the
668           postgresql.conf file or on the server command line.
669
670    log_parameter_max_length (integer) #
671           If greater than zero, each bind parameter value logged with a
672           non-error statement-logging message is trimmed to this many
673           bytes. Zero disables logging of bind parameters for non-error
674           statement logs. -1 (the default) allows bind parameters to be
675           logged in full. If this value is specified without units, it is
676           taken as bytes. Only superusers and users with the appropriate
677           SET privilege can change this setting.
678
679           This setting only affects log messages printed as a result of
680           log_statement, log_duration, and related settings. Non-zero
681           values of this setting add some overhead, particularly if
682           parameters are sent in binary form, since then conversion to
683           text is required.
684
685    log_parameter_max_length_on_error (integer) #
686           If greater than zero, each bind parameter value reported in
687           error messages is trimmed to this many bytes. Zero (the default)
688           disables including bind parameters in error messages. -1 allows
689           bind parameters to be printed in full. If this value is
690           specified without units, it is taken as bytes.
691
692           Non-zero values of this setting add overhead, as PostgreSQL will
693           need to store textual representations of parameter values in
694           memory at the start of each statement, whether or not an error
695           eventually occurs. The overhead is greater when bind parameters
696           are sent in binary form than when they are sent as text, since
697           the former case requires data conversion while the latter only
698           requires copying the string.
699
700    log_statement (enum) #
701           Controls which SQL statements are logged. Valid values are none
702           (off), ddl, mod, and all (all statements). ddl logs all data
703           definition statements, such as CREATE, ALTER, and DROP
704           statements. mod logs all ddl statements, plus data-modifying
705           statements such as INSERT, UPDATE, DELETE, TRUNCATE, and COPY
706           FROM. PREPARE, EXECUTE, and EXPLAIN ANALYZE statements are also
707           logged if their contained command is of an appropriate type. For
708           clients using extended query protocol, logging occurs when an
709           Execute message is received, and values of the Bind parameters
710           are included (with any embedded single-quote marks doubled).
711
712           The default is none. Only superusers and users with the
713           appropriate SET privilege can change this setting.
714
715 Note
716
717           Statements that contain simple syntax errors are not logged even
718           by the log_statement = all setting, because the log message is
719           emitted only after basic parsing has been done to determine the
720           statement type. In the case of extended query protocol, this
721           setting likewise does not log statements that fail before the
722           Execute phase (i.e., during parse analysis or planning). Set
723           log_min_error_statement to ERROR (or lower) to log such
724           statements.
725
726           Logged statements might reveal sensitive data and even contain
727           plaintext passwords.
728
729    log_replication_commands (boolean) #
730           Causes each replication command and walsender process's
731           replication slot acquisition/release to be logged in the server
732           log. See Section 54.4 for more information about replication
733           command. The default value is off. Only superusers and users
734           with the appropriate SET privilege can change this setting.
735
736    log_temp_files (integer) #
737           Controls logging of temporary file names and sizes. Temporary
738           files can be created for sorts, hashes, and temporary query
739           results. If enabled by this setting, a log entry is emitted for
740           each temporary file, with the file size specified in bytes, when
741           it is deleted. A value of zero logs all temporary file
742           information, while positive values log only files whose size is
743           greater than or equal to the specified amount of data. If this
744           value is specified without units, it is taken as kilobytes. The
745           default setting is -1, which disables such logging. Only
746           superusers and users with the appropriate SET privilege can
747           change this setting.
748
749    log_timezone (string) #
750           Sets the time zone used for timestamps written in the server
751           log. Unlike TimeZone, this value is cluster-wide, so that all
752           sessions will report timestamps consistently. The built-in
753           default is GMT, but that is typically overridden in
754           postgresql.conf; initdb will install a setting there
755           corresponding to its system environment. See Section 8.5.3 for
756           more information. This parameter can only be set in the
757           postgresql.conf file or on the server command line.
758
759 19.8.4. Using CSV-Format Log Output #
760
761    Including csvlog in the log_destination list provides a convenient way
762    to import log files into a database table. This option emits log lines
763    in comma-separated-values (CSV) format, with these columns: time stamp
764    with milliseconds, user name, database name, process ID, client
765    host:port number, session ID, per-session line number, command tag,
766    session start time, virtual transaction ID, regular transaction ID,
767    error severity, SQLSTATE code, error message, error message detail,
768    hint, internal query that led to the error (if any), character count of
769    the error position therein, error context, user query that led to the
770    error (if any and enabled by log_min_error_statement), character count
771    of the error position therein, location of the error in the PostgreSQL
772    source code (if log_error_verbosity is set to verbose), application
773    name, backend type, process ID of parallel group leader, and query id.
774    Here is a sample table definition for storing CSV-format log output:
775 CREATE TABLE postgres_log
776 (
777   log_time timestamp(3) with time zone,
778   user_name text,
779   database_name text,
780   process_id integer,
781   connection_from text,
782   session_id text,
783   session_line_num bigint,
784   command_tag text,
785   session_start_time timestamp with time zone,
786   virtual_transaction_id text,
787   transaction_id bigint,
788   error_severity text,
789   sql_state_code text,
790   message text,
791   detail text,
792   hint text,
793   internal_query text,
794   internal_query_pos integer,
795   context text,
796   query text,
797   query_pos integer,
798   location text,
799   application_name text,
800   backend_type text,
801   leader_pid integer,
802   query_id bigint,
803   PRIMARY KEY (session_id, session_line_num)
804 );
805
806    To import a log file into this table, use the COPY FROM command:
807 COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
808
809    It is also possible to access the file as a foreign table, using the
810    supplied file_fdw module.
811
812    There are a few things you need to do to simplify importing CSV log
813    files:
814     1. Set log_filename and log_rotation_age to provide a consistent,
815        predictable naming scheme for your log files. This lets you predict
816        what the file name will be and know when an individual log file is
817        complete and therefore ready to be imported.
818     2. Set log_rotation_size to 0 to disable size-based log rotation, as
819        it makes the log file name difficult to predict.
820     3. Set log_truncate_on_rotation to on so that old log data isn't mixed
821        with the new in the same file.
822     4. The table definition above includes a primary key specification.
823        This is useful to protect against accidentally importing the same
824        information twice. The COPY command commits all of the data it
825        imports at one time, so any error will cause the entire import to
826        fail. If you import a partial log file and later import the file
827        again when it is complete, the primary key violation will cause the
828        import to fail. Wait until the log is complete and closed before
829        importing. This procedure will also protect against accidentally
830        importing a partial line that hasn't been completely written, which
831        would also cause COPY to fail.
832
833 19.8.5. Using JSON-Format Log Output #
834
835    Including jsonlog in the log_destination list provides a convenient way
836    to import log files into many different programs. This option emits log
837    lines in JSON format.
838
839    String fields with null values are excluded from output. Additional
840    fields may be added in the future. User applications that process
841    jsonlog output should ignore unknown fields.
842
843    Each log line is serialized as a JSON object with the set of keys and
844    their associated values shown in Table 19.4.
845
846    Table 19.4. Keys and Values of JSON Log Entries
847        Key name       Type                    Description
848    timestamp         string Time stamp with milliseconds
849    user              string User name
850    dbname            string Database name
851    pid               number Process ID
852    remote_host       string Client host
853    remote_port       number Client port
854    session_id        string Session ID
855    line_num          number Per-session line number
856    ps                string Current ps display
857    session_start     string Session start time
858    vxid              string Virtual transaction ID
859    txid              string Regular transaction ID
860    error_severity    string Error severity
861    state_code        string SQLSTATE code
862    message           string Error message
863    detail            string Error message detail
864    hint              string Error message hint
865    internal_query    string Internal query that led to the error
866    internal_position number Cursor index into internal query
867    context           string Error context
868    statement         string Client-supplied query string
869    cursor_position   number Cursor index into query string
870    func_name         string Error location function name
871    file_name         string File name of error location
872    file_line_num     number File line number of the error location
873    application_name  string Client application name
874    backend_type      string Type of backend
875    leader_pid        number Process ID of leader for active parallel workers
876    query_id          number Query ID
877
878 19.8.6. Process Title #
879
880    These settings control how process titles of server processes are
881    modified. Process titles are typically viewed using programs like ps
882    or, on Windows, Process Explorer. See Section 27.1 for details.
883
884    cluster_name (string) #
885           Sets a name that identifies this database cluster (instance) for
886           various purposes. The cluster name appears in the process title
887           for all server processes in this cluster. Moreover, it is the
888           default application name for a standby connection (see
889           synchronous_standby_names).
890
891           The name can be any string of less than NAMEDATALEN characters
892           (64 characters in a standard build). Only printable ASCII
893           characters may be used in the cluster_name value. Other
894           characters are replaced with C-style hexadecimal escapes. No
895           name is shown if this parameter is set to the empty string ''
896           (which is the default). This parameter can only be set at server
897           start.
898
899    update_process_title (boolean) #
900           Enables updating of the process title every time a new SQL
901           command is received by the server. This setting defaults to on
902           on most platforms, but it defaults to off on Windows due to that
903           platform's larger overhead for updating the process title. Only
904           superusers and users with the appropriate SET privilege can
905           change this setting.