log_min_duration_statement
Log every statement that runs at least this long; -1 disables, 0 logs everything.
- Default
-1 (disabled)- Range
- -1 to about 24 days, in ms
- Restart needed
- No
- Default checked on
- PostgreSQL 18
What it does
The simplest slow-query log. Combine with pg_stat_statements for aggregates and auto_explain for plans.
Default value
-1 (disabled). -1 (PostgreSQL 18).
Check the current value
SHOW log_min_duration_statement; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'log_min_duration_statement';
Change it
SET log_min_duration_statement = '500ms'; -- this session ALTER SYSTEM SET log_min_duration_statement = '500ms'; SELECT pg_reload_conf();
No restart. Superusers, or roles granted SET on the parameter (PostgreSQL 15 and later), can SET it per session; a server-wide ALTER SYSTEM change applies after a reload (context is superuser).
When to change it
Turn it on in production at a threshold that logs a manageable number of statements, often 250ms-1s.
What can go wrong
0 on a busy server floods the log and costs I/O. Logged statements include their parameter values, which can contain personal data.
The closest setting on other engines
| Engine | Setting | Default | Restart |
|---|---|---|---|
| PostgreSQL |
log_min_duration_statement this page
|
-1 (disabled) |
No |
| MySQL |
long_query_time
|
10 |
No |
| SQL Server |
QUERY_STORE
|
ON (READ_WRITE) |
No |
Questions about log_min_duration_statement
What is the default value of log_min_duration_statement in PostgreSQL?
-1 (disabled). -1 (PostgreSQL 18).
Does changing log_min_duration_statement require a restart?
No. No restart. Superusers, or roles granted SET on the parameter (PostgreSQL 15 and later), can SET it per session; a server-wide ALTER SYSTEM change applies after a reload (context is superuser).
When should I change log_min_duration_statement?
Turn it on in production at a threshold that logs a manageable number of statements, often 250ms-1s.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check log_min_duration_statement on your own server
SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.