database resource_error ai_generated true

ERROR: out of shared memory HINT: You might need to increase max_pred_locks_per_transaction.

ID: database/postgresql-max-pred-locks-per-transaction

Also available as: JSON · Markdown · 中文
85%Fix Rate
84%Confidence
1Evidence
2023-08-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
PostgreSQL 13.10 active
PostgreSQL 14.7 active
PostgreSQL 15.3 active

Root Cause

PostgreSQL 的谓词锁定(predicate locking)用于可重复读隔离级别下的序列化事务,当事务持有过多谓词锁时,共享内存耗尽,导致错误。

generic

中文

PostgreSQL 的谓词锁定(predicate locking)用于可重复读隔离级别下的序列化事务,当事务持有过多谓词锁时,共享内存耗尽,导致错误。

Official Documentation

https://www.postgresql.org/docs/current/runtime-config-locks.html

Workarounds

  1. 85% success 编辑 postgresql.conf,增加 max_pred_locks_per_transaction 值(例如从 64 增加到 128 或 256),然后重启 PostgreSQL 服务。
    编辑 postgresql.conf,增加 max_pred_locks_per_transaction 值(例如从 64 增加到 128 或 256),然后重启 PostgreSQL 服务。
  2. 70% success 降低事务隔离级别为 READ COMMITTED,避免使用谓词锁定:SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
    降低事务隔离级别为 READ COMMITTED,避免使用谓词锁定:SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

中文步骤

  1. 编辑 postgresql.conf,增加 max_pred_locks_per_transaction 值(例如从 64 增加到 128 或 256),然后重启 PostgreSQL 服务。
  2. 降低事务隔离级别为 READ COMMITTED,避免使用谓词锁定:SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

Dead Ends

Common approaches that don't work:

  1. 75% fail

    增加 max_locks_per_transaction 而不是 max_pred_locks_per_transaction,不解决谓词锁问题。

  2. 80% fail

    重启 PostgreSQL 而不调整配置,临时释放内存但问题会重复出现。