Parameter · Reporting and Logging / When to Log
log_min_duration_statement
Sets the minimum execution time above which all statements will be logged. -1 disables logging statement durations. 0 means log all statement durations.
- Default:
-1 - Type: integer (ms)
- Range: -1 … max (2147483647)
- Applies: Session (superuser)
In plain words
The classic "slow query log". Any statement that takes at least this long is written to the log with its duration and text. With -1 (default) nothing is logged; 0 logs every statement.
A value like 250ms to 1s on production is common: you catch the slow queries without flooding the log.
For DBAs and operators
Duration is measured inside the server, from the start of processing until the statement completes. Result rows are sent to the client while the statement runs, so a slow client or network can make a statement look slow. Real lines (18.6):
LOG: duration: 17.187 ms statement: select count(*) from t;With the extended query protocol (most drivers), parse, bind and execute are timed separately, and bind parameters are shown in a DETAIL line:
LOG: duration: 0.107 ms bind <unnamed>: select $1::text, $2::int DETAIL: Parameters: $1 = 'abcdefghij...', $2 = '42' LOG: duration: 0.006 ms execute <unnamed>: select $1::text, $2::intInteractions: it takes precedence over sampling (log_min_duration_sample); if the statement was already printed by log_statement, the duration line omits the text. Superusers can set it per role or database: ALTER ROLE batch SET log_min_duration_statement = '5s'. Units: ms by default, '500ms', '2s' work.
For "what are my top queries" use pg_stat_statements; for "show me the slow ones with exact parameters at the time" use this log. auto_explain.log_min_duration adds the plan.
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_statement log_duration log_parameter_max_length log_transaction_sample_rate