DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / What to Log

log_duration

Logs the duration of each completed SQL statement.

  • Default: off
  • Type: bool
  • Applies: Session (superuser)

In plain words

Writes how long every single statement took. On its own the line has no SQL text, just the time; combine it with log_statement to know which statement it belongs to.

For "find the slow queries" use log_min_duration_statement instead.

For DBAs and operators

Real lines with log_duration = on and nothing else (18.6):

LOG: duration: 0.018 ms LOG: duration: 0.041 ms

Difference from log_min_duration_statement = 0: that one prints duration and text in one line; log_duration prints only the time, relying on log_statement (which logs the text when the statement starts) and on %p/%c/%l in log_line_prefix to pair them. Older log analysers (pgBadger) support both styles; the single-line style is easier.

Overhead: one log line per statement, which on a busy OLTP system can be tens of thousands per second; logging is synchronous, so this measurably slows the server. Use it briefly, per session or per role (superuser).

How to change it

A superuser (or a role granted SET) can change it per session with SET.

See it in context

Life of a query Logger (logging collector)

Related parameters

log_min_duration_statement log_statement log_line_prefix

All Reporting and Logging parameters