Configuration parameter

log_statement_sample_rate — PostgreSQL configuration parameter

Category Error Reporting and Logging Default 1

Determines the fraction of statements with duration exceeding log_min_duration_sample that will be logged.

At a glance

Property Value
Parameter log_statement_sample_rate
Category Error Reporting and Logging
Default 1.0
Value type floating point
Change scope Per-session (SET)
Available in PostgreSQL 13, 14, 15, 16, 17, 18, 19 (added in 13)

What it does

Determines the fraction of statements with duration exceeding log_min_duration_sample that will be logged. Sampling is stochastic, for example 0.5 means there is statistically one chance in two that any given statement will be logged. The default is 1.0, meaning to log all sampled statements. Setting this to zero disables sampled statement-duration logging, the same as setting log_min_duration_sample to -1. Only superusers and users with the appropriate SET privilege can change this setting.

(Description quoted from the official PostgreSQL documentation.)

How to apply a change

Can be set per session with SET, per role/database with ALTER ROLE/DATABASE ... SET, or globally in postgresql.conf.

Inspect the current value and source with SHOW log_statement_sample_rate; or SELECT name, setting, unit, context, source FROM pg_settings WHERE name = 'log_statement_sample_rate';.

Tuning guidance

Fraction (0-1) of statements over log_min_duration_sample that get logged; lower it on high-throughput systems to keep log volume sane while still sampling slow queries.

Reference

PostgreSQL documentation — log_statement_sample_rate.

Keep going

Related & next steps

Was this helpful?

← All configuration parameters