Parameter · Reporting and Logging / When to Log
log_statement_sample_rate
Fraction of statements exceeding "log_min_duration_sample" to be logged. Use a value between 0.0 (never log) and 1.0 (always log).
- Default:
1 - Type: real
- Range: 0 … 1
- Applies: Session (superuser)
In plain words
The fraction of "sample candidates" (statements slower than log_min_duration_sample) that are written to the log. 1 keeps them all, 0.1 keeps about one in ten, 0 none.
For DBAs and operators
Each candidate statement gets an independent random draw; there is no guarantee of an exact count. Has no effect unless log_min_duration_sample is set (not -1), and never suppresses statements that qualify under log_min_duration_statement.
Sizing: estimate candidates per second from pg_stat_statements (calls with mean time above the threshold), multiply by the rate and by roughly 200 bytes per line, and check that against your log volume budget. A rate of 0.01–0.1 is typical on busy OLTP systems.
-- per session, as superuser, to sample one noisy application
SET log_min_duration_sample = '20ms';
SET log_statement_sample_rate = 0.1;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_min_duration_sample log_min_duration_statement log_transaction_sample_rate