# log_min_duration_sample

> log_min_duration_sample is the PostgreSQL setting that defines the minimum execution time above which a sample of statements will be logged. Sampling is determined by "log_statement_sample_rate".
---

> [!NOTE]
> **Fact — official short description:** “Sets the minimum execution time above which a sample of statements will be logged. Sampling is determined by "log_statement_sample_rate".”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `integer` | Upstream pg_settings type |
| Context | `superuser` | Settable at runtime by a superuser |
| Unit | `ms` | Raw unit |
| Range | `-1` – `2147483647` | 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 ms |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG13 |
| Present in | PG13–19 Beta 3 |
| Removed in | No |
| Introduction commit | [`6e3e6cc0e884`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=6e3e6cc0e884a6091e1094dff29db430af08fb93) — Allow sampling of statements depending on duration |
| Commit date | 2019-11-04 |
| Discussion | [thread 1](https://postgr.es/m/bbe0a1a8-a8f7-3be2-155a-888e661cc06c@anayrat.info) |

## Default history {#default-history}

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

## How it works {#mechanism}

log_min_duration_sample admits completed statements at or above its duration threshold into stochastic logging controlled by log_statement_sample_rate. -1 disables this path, zero admits every completed statement, and the sample rate then decides which admitted statements are emitted.

log_min_duration_statement has higher priority. A statement that reaches its threshold is always logged and is not sampled, even if it also exceeds log_min_duration_sample. Under the extended query protocol, Parse, Bind, and Execute durations are logged separately.

It is a SUPERUSER-context session setting. Sampled entries have the same statement-text, Bind-value, correlation, overhead, and security considerations as log_min_duration_statement, so log_line_prefix and log_parameter_max_length still determine usefulness and exposure.

## Tuning advice {#tuning-advice}

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

| Workload | Guidance |
| --- | --- |
| OLTP | Set an always-log threshold first with log_min_duration_statement, then use a lower sample threshold and measured rate for the high-volume middle band. Verify actual sample counts and sensitive-data handling under peak OLTP traffic. |
| OLAP | Long analytical queries often exceed the always-log threshold, so sampling may provide no reduction for them. Choose thresholds from the duration distribution rather than copying OLTP values. |
| Small nodes | Use a conservative rate and bounded statement text. A small node should avoid zero with rate 1 unless it intentionally wants every statement-duration entry. |
{.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}

- Expecting sampling to affect statements already captured by the higher-priority log_min_duration_statement threshold.
- Forgetting that Parse, Bind, and Execute are timed and logged separately with the extended query protocol.
- Setting zero with log_statement_sample_rate = 1 and unintentionally logging every completed statement duration.
- Sampling SQL and Bind values without correlation identifiers, redaction, access control, and a measured volume budget.

## 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_statement_sample_rate`](/parameters/log-statement-sample-rate/) · [`log_transaction_sample_rate`](/parameters/log-transaction-sample-rate/)

## References {#references}

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