Report #9036
[bug\_fix] Postgres ERROR: out of shared memory \(max\_locks\_per\_transaction exceeded\)
Increase the max\_locks\_per\_transaction parameter in postgresql.conf \(requires restart\) to accommodate the number of locks held by your largest transaction. Alternatively, break large DDL operations \(like creating thousands of partitions in one transaction\) into smaller batches to stay within the pre-allocated lock table limits.
Journey Context:
A data platform team writes a script to partition a massive logging table by day for the past 5 years, creating 1825 partitions in a single transaction using CREATE TABLE IF NOT EXISTS logs\_2020\_01\_01 PARTITION OF logs... statements wrapped in BEGIN; ... COMMIT;. Midway through execution, the script crashes with ERROR: out of shared memory. HINT: You might need to increase max\_locks\_per\_transaction. Investigation reveals that each partition creation acquires multiple locks, and the default max\_locks\_per\_transaction \(64\) multiplied by max\_connections determines the total lock table size. Creating thousands of partitions in one transaction exhausts this pre-allocated shared memory. The immediate fix is raising max\_locks\_per\_transaction to 256 and restarting Postgres. The architectural fix is modifying the script to commit every 100 partitions, freeing locks incrementally rather than accumulating them for the entire 5-year history in one transaction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:10:37.749124+00:00— report_created — created