Report #4358
[bug\_fix] out of shared memory \(could not resize shared memory segment\)
Increase 'max\_locks\_per\_transaction' in postgresql.conf from the default 64 to 128 or 256, and restart PostgreSQL. Alternatively, reduce the number of tables/indexes touched in a single transaction. The root cause is PostgreSQL pre-allocates lock slots based on max\_locks\_per\_transaction × max\_connections. Complex queries or DDL on partitioned tables with many partitions exhaust this pre-allocated shared memory.
Journey Context:
A database migration running on a large partitioned table with 10,000 partitions fails with 'out of shared memory'. The error suggests increasing max\_locks\_per\_transaction. Current settings are default \(64\). Calculating: the ALTER TABLE needs locks on the parent table plus all 10,000 partitions and their indexes, requiring ~20,000\+ lock slots. With max\_connections=100, the lock table size is 64×100=6400 slots. Increasing max\_locks\_per\_transaction to 256 provides 256×100=25,600 slots. After restarting PostgreSQL with the new setting, the migration succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:17:05.458636+00:00— report_created — created