Report #59023
[bug\_fix] Postgres out of shared memory \(lock exhaustion\)
Increase the max\_locks\_per\_transaction configuration parameter \(default 64\) to a higher value \(e.g., 256 or 512\) and restart PostgreSQL, or reduce the number of locks acquired by the application \(e.g., batching operations\).
Journey Context:
A background job performing bulk updates on millions of rows using PostgreSQL advisory locks for coordination suddenly fails with 'out of shared memory'. The error message suggests increasing max\_locks\_per\_transaction. Investigation reveals that PostgreSQL pre-allocates shared memory for locks based on max\_locks\_per\_transaction \* max\_connections. The application uses pg\_try\_advisory\_lock\(\) for rate limiting, creating thousands of advisory locks across many transactions. The default max\_locks\_per\_transaction \(64\) multiplied by max\_connections \(100\) only allows 6400 total locks, which is quickly exhausted. The solution requires editing postgresql.conf to set max\_locks\_per\_transaction = 256 \(or higher, depending on max\_connections and lock usage\), followed by a database restart to reallocate shared memory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:33:26.153132+00:00— report_created — created