DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / When to Log

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).

  • Default: 0
  • Type: real
  • Range: 0 … 1
  • Applies: Session (superuser)

In plain words

Picks a random share of whole transactions and logs every statement in them, fast or slow. Good for getting a few complete, realistic examples of what the application does, without logging everything.

0 (default) turns it off.

For DBAs and operators

The decision is made once, at transaction start. Each statement of a sampled transaction is logged with its duration, exactly like log_min_duration_statement = 0 would (captured with rate 1):

LOG: duration: 0.005 ms statement: begin; LOG: duration: 0.005 ms statement: select 10; LOG: duration: 0.004 ms statement: select 11; LOG: duration: 0.003 ms statement: commit;

Independent of the duration thresholds: statements that are logged for another reason are not printed twice. Every statement outside an explicit transaction block is its own transaction, so with autocommit-heavy workloads this behaves like per-statement sampling.

Even 0.01 on a system doing 10,000 transactions per second logs about 100 transactions per second. Start very small (0.001) and set it per role or per session where possible: ALTER ROLE app_reporting SET log_transaction_sample_rate = 0.01 (superuser).

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) MVCC: row versions

Related parameters

log_min_duration_sample log_statement_sample_rate log_min_duration_statement log_statement

All Reporting and Logging parameters