log_transaction_sample_rate
Read PG 18 manual ↗Sets the fraction of transactions whose statements are all logged, in addition to statements logged for other reasons.
- Type
- real
- Context
- superuser
- Measured default
- 0
- Unit
- —
- Metadata snapshot
- 18
Definition PG 18 manual
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.
Measured default history
| Version interval | Default |
|---|---|
| 12 – 19 | 0 |
Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗
How it works
log_transaction_sample_rate sets the fraction of transactions from which to log all statements. Use a value between 0.0 (never log) and 1.0 (log all statements for all transactions). A sampled transaction logs every statement, preserving transaction context but potentially creating bursts from long or chatty transactions.
log_transaction_sample_rate is a SUPERUSER-context setting. Superuser or a role granted the appropriate SET privilege can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.
It changes emitted diagnostic data rather than query semantics, but volume, sensitive content, log_line_prefix, destinations, collector throughput, and retention determine operational cost and usefulness.
Operational considerations
Changing log_transaction_sample_rate in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.
Enabling richer logging without budgeting collector throughput, storage, retention, and downstream query cost.
Writing SQL text, bind values, identities, or host data without a redaction and access-control policy.
Underestimating bursts when one sampled, chatty transaction causes every statement to be logged.
Workload guidance
OLAP: Analytical jobs can justify richer log_transaction_sample_rate telemetry, but account for long statements, large bind values, and bursty completion patterns in the log pipeline.
OLTP: Tune log_transaction_sample_rate against an explicit observability question and a measured log-volume budget. Prefer selective thresholds, sampling, or role-level overrides over indiscriminate capture.
SMALL: Keep log_transaction_sample_rate useful but bounded: verify disk, collector, retention, and redaction capacity before increasing detail or frequency.
Version history 4
- PG 14 → 15changed
- PG 13 → 14changed
- PG 12 → 13changed
- PG 11 → 12added
Related entries
Further reading
Definition snapshot: english-manuals:17f1cb64b230c8b2192fc5e4994… · English manual source