Configuration parameter

log_min_duration_sample — PostgreSQL configuration parameter

Category Error Reporting and Logging

Allows sampling the duration of completed statements that ran for at least the specified amount of time.

At a glance

Property Value
Parameter log_min_duration_sample
Category Error Reporting and Logging
Default -1
Value type integer
Change scope Per-session (SET)
Available in PostgreSQL 13, 14, 15, 16, 17, 18, 19 (added in 13)

What it does

Allows sampling the duration of completed statements that ran for at least the specified amount of time. This produces the same kind of log entries as log_min_duration_statement, but only for a subset of the executed statements, with sample rate controlled by log_statement_sample_rate. For example, if you set it to 100ms then all SQL statements that run 100ms or longer will be considered for sampling. Enabling this parameter can be helpful when the traffic is too high to log all queries. If this value is specified without units, it is taken as milliseconds. Setting this to zero samples all statement durations. -1 (the default) disables sampling statement durations. Only superusers and users with the appropriate SET privilege can change this setting.

This setting has lower priority than log_min_duration_statement, meaning that statements with durations exceeding log_min_duration_statement are not subject to sampling and are always logged.

(Description quoted from the official PostgreSQL documentation.)

How to apply a change

Can be set per session with SET, per role/database with ALTER ROLE/DATABASE ... SET, or globally in postgresql.conf.

Inspect the current value and source with SHOW log_min_duration_sample; or SELECT name, setting, unit, context, source FROM pg_settings WHERE name = 'log_min_duration_sample';.

Tuning guidance

Set it with log_statement_sample_rate to log only a fraction of statements above a duration, capturing slow-query patterns without flooding logs on busy systems.

Reference

PostgreSQL documentation — log_min_duration_sample.

Keep going

Related & next steps

Was this helpful?

← All configuration parameters