DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / When to Log

log_min_error_statement

Causes all statements generating error at or above this level to be logged. Each level includes all the levels that follow it. The later the level, the fewer messages are sent.

  • Default: error
  • Type: enum
  • Values: debug5 · debug4 · debug3 · debug2 · debug1 · info · notice · warning · error · log · fatal · panic
  • Applies: Session (superuser)

In plain words

An error message alone ("division by zero") rarely tells you which query failed. With this setting, PostgreSQL adds a STATEMENT: line with the SQL text for every message at or above the chosen severity. The default error does this for all errors.

For DBAs and operators

Uses the server-log order (… warning < error < log < fatal < panic). Because LOG ranks above ERROR, the default also attaches the statement to LOG messages that happen inside a query, such as temporary-file and lock-wait reports:

ERROR: division by zero STATEMENT: select 1/0; LOG: temporary file: path "base/pgsql_tmp/pgsql_tmp4621.0", size 2800000 STATEMENT: insert into t select g, md5(g::text) from generate_series(1,200000) g;

The STATEMENT line is only added if the message itself is logged (log_min_messages), and only when a statement is running (not for background processes). panic effectively turns the feature off. Lowering it to warning helps find which statements trigger warnings.

The statement text includes literal values, so failed ALTER ROLE … PASSWORD '…' or statements with personal data can appear in the log. For bind parameters, see log_parameter_max_length_on_error. Some sites set this to panic for compliance and rely on error codes instead.

How to change it

A superuser (or a role granted SET) can change it per session with SET.

See it in context

Logger (logging collector) Life of a query

Related parameters

log_min_messages log_parameter_max_length_on_error log_statement log_error_verbosity

All Reporting and Logging parameters