max_locks_per_transaction
Fact — official short description: “Sets the maximum number of locks per transaction.”
Identity
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
| Versions | Raw boot_val |
Unit | Human value |
|---|---|---|---|
| PG9.0–18 | 64 |
— | 64 |
| PG19 Beta 3 | 128 |
— | 128 |
How it works
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
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. |
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 }} |
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
- 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
deadlock_timeout · log_lock_waits · lock_timeout · max_pred_locks_per_transaction · max_pred_locks_per_relation · max_pred_locks_per_page
References
- PostgreSQL 19 Beta 3 — max_locks_per_transaction
- PostgreSQL 19 release notes
- Machine-readable GUC export