Sets the fraction of transactions whose statements are all logged, in addition to statements logged for other reasons.
At a glance
| Property | Value |
|---|---|
| Parameter | log_transaction_sample_rate |
| Category | Error Reporting and Logging |
| Default | 0 |
| Value type | floating point |
| Change scope | Per-session (SET) |
| Available in | PostgreSQL 12, 13, 14, 15, 16, 17, 18, 19 (added in 12) |
What it does
Sets the fraction of transactions whose statements are all logged, in addition to statements logged for other reasons. It applies to each new transaction regardless of its statements’ durations. Sampling is stochastic, for example 0.1 means there is statistically one chance in ten that any given transaction will be logged. log_transaction_sample_rate can be helpful to construct a sample of transactions. The default is 0, meaning not to log statements from any additional transactions. Setting this to 1 logs all statements of all transactions. Only superusers and users with the appropriate SET privilege can change this setting.
Like all statement-logging options, this option can add significant overhead.
(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_transaction_sample_rate; or SELECT name, setting, unit, context, source FROM pg_settings WHERE name = 'log_transaction_sample_rate';.
Tuning guidance
Logs all statements of a sampled fraction of transactions; keep it small (e.g. 0.01) in production since it can generate a lot of output. Useful for tracing representative full transactions.