# transaction_timeout

> transaction_timeout is the PostgreSQL setting that defines the maximum allowed duration of any transaction within a session (not a prepared transaction).
---

> [!NOTE]
> **Fact — official short description:** “Sets the maximum allowed duration of any transaction within a session (not a prepared transaction).”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `integer` | Upstream pg_settings type |
| Context | `user` | Settable by an ordinary user |
| Unit | `ms` | Raw unit |
| Range | `0` – `2147483647` | Raw limits in the last observed version |
| Enum values | — | — for non-enum types |
| Category | Client Connection Defaults / Statement Behavior | Upstream classification |
| Latest boot value | `0` | 0 ms |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG17 |
| Present in | PG17–19 Beta 3 |
| Removed in | No |
| Introduction commit | [`51efe38cb92f`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=51efe38cb92f4b15b68811bcce9ab878fbc71ea5) — Introduce transaction_timeout |
| Commit date | 2024-02-15 |
| Discussion | [thread 1](https://postgr.es/m/CAAhFRxiQsRs2Eq5kCo9nXE3HTugsAAJdSQSmxncivebAxdmBjQ%40mail.gmail.com) |

## Default history {#default-history}

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

## How it works {#mechanism}

transaction_timeout sets the maximum allowed duration of any transaction within a session (not a prepared transaction). 0 disables the timeout. It terminates the session rather than merely canceling one statement, excludes prepared transactions, and makes longer idle-in-transaction or statement timeouts ineffective when set lower.

transaction_timeout is a USER-context setting. An authorized role can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.

Timeouts overlap: the first applicable deadline wins, while client, pooler, TCP, and server cancellation behavior determines whether work is retried, canceled, or the session is closed.

## Tuning advice {#tuning-advice}

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

| Workload | Guidance |
| --- | --- |
| OLTP | Set transaction_timeout from the service latency and failure budget, preferably per role or application. Test retries and cancellation paths before enforcing a cluster-wide value. |
| OLAP | Analytical work usually needs a larger or job-specific transaction_timeout; preserve a finite guardrail for abandoned work without killing legitimate long scans. |
| Small nodes | Use a conservative finite transaction_timeout only when the client or operating system handles termination correctly; verify that maintenance still has a dedicated exception. |
{.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: PG17–19 Beta 3 unmodified; OLAP: PG17–19 Beta 3 unmodified; CRIT: PG17–19 Beta 3 unmodified; TINY: PG17–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.

## Common pitfalls {#common-pitfalls}

- Changing transaction_timeout in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.
- Forgetting that zero usually disables the timeout or delegates behavior to the operating system.
- Setting overlapping deadlines without deciding which layer owns retries, cancellation, and connection disposal.
- Expecting it to resolve prepared transactions, which are explicitly excluded.

## Related parameters {#related-parameters}

[`statement_timeout`](/parameters/statement-timeout/) · [`lock_timeout`](/parameters/lock-timeout/) · [`idle_in_transaction_session_timeout`](/parameters/idle-in-transaction-session-timeout/) · [`idle_session_timeout`](/parameters/idle-session-timeout/) · [`deadlock_timeout`](/parameters/deadlock-timeout/)

## References {#references}

- [PostgreSQL 19 Beta 3 — transaction_timeout](https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-TRANSACTION-TIMEOUT)
- [PostgreSQL 19 release notes](https://www.postgresql.org/docs/19/release-19.html)
- [Machine-readable GUC export](/data/guc.jsonl)
