// postgresql · logging & diagnostics

log_min_duration_statement

Log every statement that runs at least this long; -1 disables, 0 logs everything.

Standard
-1 (disabled)
Range
-1 to about 24 days, in ms
Restart needed
Nein
Default checked on
PostgreSQL 18

Was es bewirkt

The simplest slow-query log. Combine with pg_stat_statements for aggregates and auto_explain for plans.

Standardwert

-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

EngineEinstellungStandardRestart
PostgreSQL log_min_duration_statement this page -1 (disabled) Nein
MySQL long_query_time 10 Nein
SQL Server QUERY_STORE ON (READ_WRITE) Nein

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.

// one client for every engine

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.