FluentDBFluentDB
PostgreSQL errors

PostgreSQL: out of shared memory

ERRORSQLSTATE 53200out_of_memory
ERROR: out of shared memory

A single transaction needed more locks than the shared lock table can hold, usually from touching a huge number of objects such as many partitions or tables at once. Increase max_locks_per_transaction, or break the work into smaller transactions.

What this error means

Postgres keeps a fixed-size shared lock table, sized by max_locks_per_transaction times max_connections. When one transaction acquires more object locks than that budget allows, it fails with this error and a HINT to raise max_locks_per_transaction.

It typically comes from operations that touch thousands of partitions or tables in a single transaction.

How to fix it

01

The transaction locks too many objects

Raise the lock budget and restart Postgres.

sql
ALTER SYSTEM SET max_locks_per_transaction = 256;
-- then restart Postgres
02

One transaction does too much

Split the work into smaller transactions so fewer locks are held at once.

03

You have very many partitions

Reduce how many partitions a single query or transaction touches, for example with better partition pruning.

How to avoid it next time

  • Keep the number of objects touched per transaction bounded.
  • Prune partitions so queries touch only what they need.
Varies by version

On Postgres 16+ the HINT quotes the setting name as "max_locks_per_transaction"; earlier versions print it unquoted.

Frequently asked questions

Is this the same as running out of RAM?

No. It is the shared lock table filling up, not system memory. Raising max_locks_per_transaction enlarges that table.

Why does a big TRUNCATE or partitioned query trigger it?

Each touched object takes a lock. Touch enough of them in one transaction and you exceed the lock table, hence the error.

Stop struggling with SQL

Use FluentDB, the AI database client for macOS.