Skip to content

log_min_duration_statement

Logs every completed statement whose duration reaches a threshold. It is a deterministic slow-query capture control, distinct from sampling and from statement cancellation.
Note

Fact — official short description: “Sets the minimum execution time above which all statements will be logged.”

Identity

Type , Valueinteger
Upstream pg_settings type
Context , Valuesuperuser
Settable at runtime by a superuser
Unit , Valuems
Raw unit
Range , Value-12147483647
Raw limits in the last observed version
Enum values , Value
— for non-enum types
Category , ValueReporting and Logging / When to Log
Upstream classification
Latest boot value , Value-1
-1 ms

Lifecycle

Fact Value
First observed PG9.0 (research boundary)
Present in PG9.0–19 Beta 3
Removed in No
Introduction commit Not asserted: predates the PG9.0 research boundary
Commit date
Discussion

Default history

Measured PG9.0–19 Beta 3 boot defaults
Versions Raw boot_val Unit Human value
PG9.0–19 Beta 3 -1 ms -1 ms

How it works

The value is a duration in milliseconds when no unit is written. A value of -1 disables duration-based statement logging, zero logs every completed statement, and a positive value logs statements at or above the threshold.

Statements selected by this setting are always logged rather than sampled, so it takes priority over log_min_duration_sample. Under the extended query protocol, Parse, Bind, and Execute durations can appear separately.

This parameter observes and records completed work; it does not stop slow statements. statement_timeout is the separate execution-cancellation control.

Tuning advice

Tip

Advice. These are workload-specific starting points and must be validated with measurements.

Workload Guidance
OLTP Choose a threshold from the application’s latency objective and expected log volume. At high QPS, combine a meaningful hard threshold with sampled logging for the faster population.
OLAP Use a higher threshold so normal long analytical work does not flood logs. Pair logs with query identifiers and workload labels so repeated reports remain actionable.
Small nodes A low threshold can be useful while tuning, but watch disk use and rotation. Raise it or switch to sampling when logging becomes a measurable part of the workload.

Pigsty

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.

Template Effective value Versus upstream boot Source expression
OLTP 100 different 100
OLAP 1000 different 1000
CRIT 100 different 100
TINY 100 different 100
Caution

Advice — pending human review. Fact from the current Pigsty template projection: OLTP: PG9.0–19 Beta 3 = 100 (dcs); OLAP: PG9.0–19 Beta 3 = 1000 (dcs); CRIT: PG9.0–19 Beta 3 = 100 (dcs); TINY: PG9.0–19 Beta 3 = 100 (dcs). Advice, pending human review — Editorial hypothesis, pending maintainer review: Pigsty opts into deterministic slow-query evidence, while OLAP uses a looser threshold to accommodate naturally longer analytical statements.

Common pitfalls

  • Low thresholds on high-throughput systems can create extreme log volume and I/O.
  • SQL text can contain sensitive literals and must be protected like application data.
  • It logs slow statements but does not cancel them; use statement_timeout for that goal.
  • Extended-protocol phases may be logged separately and need session or PID correlation.
  • Interactions with log_statement, sampling, and log_line_prefix can confuse duplicate or fragmented entries.

log_min_duration_sample · log_statement_sample_rate · log_statement · log_duration · log_line_prefix · statement_timeout

References