# max_locks_per_transaction

> max_locks_per_transaction — Sets the maximum number of locks per transaction. Observed in PG9.0–19 Beta 3; its last measured boot default is 128 in PG19 Beta 3, with postmaster context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA.
---

> [!NOTE]
> **Fact — official short description:** “Sets the maximum number of locks per transaction.”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `integer` | Upstream pg_settings type |
| Context | `postmaster` | Requires a server restart |
| Unit | — | Raw unit |
| Range | `10` – `2147483647` | Raw limits in the last observed version |
| Enum values | — | — for non-enum types |
| Category | Lock Management | Upstream classification |
| Latest boot value | `128` | 128 |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG9.0 (research boundary) |
| Present in | PG9.0–19 Beta 3 |
| Removed in | No |
| Introduction commit | Not asserted: predates the PG9.0 research boundary |
| Commit date | — |
| Discussion | — |

## Default history {#default-history}

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

## How it works {#mechanism}

Sets the maximum number of locks per transaction. The value is fixed when the server starts, so changing it requires a restart.

The shared lock table is sized for this average number of distinct lockable objects per backend or prepared transaction. A single transaction may exceed the number if space remains; it does not limit row locks, and standbys need a value at least as large as the primary.

Monitor and change max_locks_per_transaction together with deadlock_timeout, log_lock_waits, lock_timeout. Validate on the relevant server role and real workload, then use its postmaster context to choose session change, reload, or restart; a historical boot default is not the current effective value.

## Tuning advice {#tuning-advice}

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

| Workload | Guidance |
| --- | --- |
| OLTP | Calibrate max_locks_per_transaction from lock-wait logs, objects touched, and the concurrency bound. Fix long transactions and access ordering before adding shared memory or changing detection granularity. |
| OLAP | Partitioned queries, bulk DDL, and SERIALIZABLE reports may touch many objects; test the worst plan, not only an average transaction. |
| Small nodes | Defaults are usually sufficient. If raising a startup lock-table setting, account for max_connections, prepared transactions, and standby consistency together. |
{.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 | `500` | different | `{{ pg_max_locks_per_transaction }}` |
| OLAP | `1000` | different | `{{ pg_max_locks_per_transaction }}` |
| CRIT | `500` | different | `{{ pg_max_locks_per_transaction }}` |
| TINY | `250` | different | `{{ pg_max_locks_per_transaction }}` |
{.full-width}

> [!CAUTION]
> **Advice — pending human review.** Fact from the current Pigsty template projection: OLTP: PG9.0–19 Beta 3 = 500 (dcs); OLAP: PG9.0–19 Beta 3 = 1000 (dcs); CRIT: PG9.0–19 Beta 3 = 500 (dcs); TINY: PG9.0–19 Beta 3 = 250 (dcs). Advice, pending human review — Editorial interpretation, pending human maintainer review: the override appears intended to reserve shared lock-table capacity for partition-heavy and schema-rich workloads; confirm it against the current Pigsty templates, hardware fixture, and operational guarantees before publication.

## Common pitfalls {#common-pitfalls}

- Reading it as a row-lock limit or a hard limit for one transaction.
- Raising it without accounting for max_connections and prepared transactions.
- Setting a standby below its primary and preventing standby queries.
- Reading an average shared-memory sizing value as a hard per-transaction limit.
- Raising it without the multiplier from connections and prepared transactions.

## Related parameters {#related-parameters}

[`deadlock_timeout`](/parameters/deadlock-timeout/) · [`log_lock_waits`](/parameters/log-lock-waits/) · [`lock_timeout`](/parameters/lock-timeout/) · [`max_pred_locks_per_transaction`](/parameters/max-pred-locks-per-transaction/) · [`max_pred_locks_per_relation`](/parameters/max-pred-locks-per-relation/) · [`max_pred_locks_per_page`](/parameters/max-pred-locks-per-page/)

## References {#references}

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