# log_statement_sample_rate

> log_statement_sample_rate is the PostgreSQL setting that defines the fraction of statements exceeding "log_min_duration_sample" to be logged.
---

> [!NOTE]
> **Fact — official short description:** “Fraction of statements exceeding "log_min_duration_sample" to be logged.”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `real` | Upstream pg_settings type |
| Context | `superuser` | Settable at runtime by a superuser |
| Unit | — | Raw unit |
| Range | `0` – `1` | Raw limits in the last observed version |
| Enum values | — | — for non-enum types |
| Category | Reporting and Logging / When to Log | Upstream classification |
| Latest boot value | `1` | 1 |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG13 |
| Present in | PG13–19 Beta 3 |
| Removed in | No |
| Introduction commit | [`88bdbd3f7460`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=88bdbd3f746049834ae3cc972e6e650586ec3c9d) — Add log_statement_sample_rate parameter |
| Commit date | 2018-11-29 |
| Discussion | [thread 1](https://postgr.es/m/c30ee535-ee1e-db9f-fa97-146b9f62caed@anayrat.info) |

## Default history {#default-history}

| Versions | Raw `boot_val` | Unit | Human value |
| --- | --- | --- | --- |
| PG13–19 Beta 3 | `1` | — | 1 |
{.full-width caption="Measured PG9.0–19 Beta 3 boot defaults"}

## How it works {#mechanism}

log_statement_sample_rate sets the fraction of statements exceeding "log_min_duration_sample" to be logged. Use a value between 0.0 (never log) and 1.0 (always log). This probability is evaluated only for statements admitted by log_min_duration_sample; it does not sample log_statement or log_min_duration_statement output.

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

## Tuning advice {#tuning-advice}

> [!TIP]
> **Advice.** These are workload-specific starting points and must be validated with measurements.

| Workload | Guidance |
| --- | --- |
| OLTP | Tune log_statement_sample_rate against an explicit observability question and a measured log-volume budget. Prefer selective thresholds, sampling, or role-level overrides over indiscriminate capture. |
| OLAP | Analytical jobs can justify richer log_statement_sample_rate telemetry, but account for long statements, large bind values, and bursty completion patterns in the log pipeline. |
| Small nodes | Keep log_statement_sample_rate useful but bounded: verify disk, collector, retention, and redaction capacity before increasing detail or frequency. |
{.full-width}

## Pigsty {#pigsty}

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.

| Template | Effective value | Versus upstream boot | Source expression |
| --- | --- | --- | --- |
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
{.full-width}

> [!CAUTION]
> **Advice — pending human review.** Fact from the current Pigsty template projection: OLTP: PG13–19 Beta 3 unmodified; OLAP: PG13–19 Beta 3 unmodified; CRIT: PG13–19 Beta 3 unmodified; TINY: PG13–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.

## Common pitfalls {#common-pitfalls}

- Changing log_statement_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.
- Expecting it to sample all statement logging even though it only gates log_min_duration_sample.

## Related parameters {#related-parameters}

[`log_min_messages`](/parameters/log-min-messages/) · [`log_min_error_statement`](/parameters/log-min-error-statement/) · [`log_min_duration_statement`](/parameters/log-min-duration-statement/) · [`log_min_duration_sample`](/parameters/log-min-duration-sample/) · [`log_transaction_sample_rate`](/parameters/log-transaction-sample-rate/)

## References {#references}

- [PostgreSQL 19 Beta 3 — log_statement_sample_rate](https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-STATEMENT-SAMPLE-RATE)
- [PostgreSQL 19 release notes](https://www.postgresql.org/docs/19/release-19.html)
- [Machine-readable GUC export](/data/guc.jsonl)
