Parameter · Reporting and Logging / When to Log
log_min_duration_sample
Sets the minimum execution time above which a sample of statements will be logged. Sampling is determined by "log_statement_sample_rate". -1 disables sampling. 0 means sample all statements.
- Default:
-1 - Type: integer (ms)
- Range: -1 … max (2147483647)
- Applies: Session (superuser)
In plain words
Like the slow query log, but only a random sample of the qualifying statements is written. Useful when logging every statement above, say, 10 ms would be far too much: you still see a representative picture.
-1 (default) turns sampling off.
For DBAs and operators
Every statement whose duration is at least this value becomes a candidate; each candidate is logged with probability log_statement_sample_rate. Logged lines look exactly like the slow-query lines (LOG: duration: … ms statement: …), so you cannot tell from the line whether it came from sampling.
Designed to be combined with log_min_duration_statement as a two-tier setup (PostgreSQL 13+):
log_min_duration_statement = '1s' -- always log really slow ones
log_min_duration_sample = '50ms' -- candidates for sampling
log_statement_sample_rate = 0.05 -- keep 5% of themlog_min_duration_statement takes precedence: a statement above it is always logged, whatever the sample says. Setting log_min_duration_sample higher than log_min_duration_statement has no effect. Sampling is random per statement, so related statements of one transaction are not kept together; for that use log_transaction_sample_rate.
How to change it
A superuser (or a role granted SET) can change it per session with SET.
See it in context
Related parameters
log_statement_sample_rate log_min_duration_statement log_transaction_sample_rate