select open change scope Open full search

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

CONFIGURATION / REPORTING AND LOGGING

Causes the duration of every completed statement to be logged.

Type
bool
Context
superuser
Measured default
off
Unit
Metadata snapshot
18

Definition PG 18 manual

Causes the duration of every completed statement to be logged. The default is off. Only superusers and users with the appropriate SET privilege can change this setting.

For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently.

Note

The difference between enabling log_duration and setting log_min_duration_statement to zero is that exceeding log_min_duration_statement forces the text of the query to be logged, but this option doesn't. Thus, if log_duration is on and log_min_duration_statement has a positive value, all durations are logged but the query text is included only for statements exceeding the threshold. This behavior can be useful for gathering statistics in high-load installations.

Measured default history
Version intervalDefault
9.0 – 19off
Analysis & operational context

Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗

How it works

log_duration logs the duration of each completed SQL statement. It emits a duration for every completed statement but does not itself emit statement text; log_statement or a duration threshold supplies text when required.

log_duration is a SUPERUSER-context setting. Superuser or a role granted the appropriate SET privilege can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.

It changes emitted diagnostic data rather than query semantics, but volume, sensitive content, log_line_prefix, destinations, collector throughput, and retention determine operational cost and usefulness.

Operational considerations

Changing log_duration in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.

Enabling richer logging without budgeting collector throughput, storage, retention, and downstream query cost.

Writing SQL text, bind values, identities, or host data without a redaction and access-control policy.

Expecting duration records to contain SQL text when no statement-logging setting emits that text.

Workload guidance

OLAP: Analytical jobs can justify richer log_duration telemetry, but account for long statements, large bind values, and bursty completion patterns in the log pipeline.

OLTP: Tune log_duration against an explicit observability question and a measured log-volume budget. Prefer selective thresholds, sampling, or role-level overrides over indiscriminate capture.

SMALL: Keep log_duration useful but bounded: verify disk, collector, retention, and redaction capacity before increasing detail or frequency.

Version history 3
  1. PG 14 → 15changed
  2. PG 11 → 12changed
  3. PG 9.6 → 10changed

Related entries

Further reading

Definition snapshot: english-manuals:dff2e615c62b3de8a5579027da2… · English manual source