database
resource_error
ai_generated
partial
psycopg2.OperationalError: ERROR: out of memory DETAIL: Failed on request of size 123456.
ID: database/postgresql-too-many-pins
82%Fix Rate
84%Confidence
1Evidence
2024-03-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| PostgreSQL 14 | active | — | — | — |
| PostgreSQL 15 | active | — | — | — |
| PostgreSQL 16 | active | — | — | — |
Root Cause
PostgreSQL server ran out of memory, typically due to excessive work_mem usage from multiple concurrent queries, or a single query with very large memory needs (e.g., sorting, hashing).
generic中文
PostgreSQL 服务器内存耗尽,通常是由于多个并发查询使用了过多的 work_mem,或单个查询需要非常大的内存(如排序、哈希操作)。
Official Documentation
https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEMWorkarounds
-
85% success Reduce work_mem for the session or globally to limit per-operation memory usage: SET work_mem = '32MB'; Or in postgresql.conf: work_mem = 32MB Then restart or reload.
Reduce work_mem for the session or globally to limit per-operation memory usage: SET work_mem = '32MB'; Or in postgresql.conf: work_mem = 32MB Then restart or reload.
-
80% success Identify and optimize the problematic query using EXPLAIN ANALYZE, then rewrite it to use less memory (e.g., add indexes, reduce sort operations).
Identify and optimize the problematic query using EXPLAIN ANALYZE, then rewrite it to use less memory (e.g., add indexes, reduce sort operations).
中文步骤
Reduce work_mem for the session or globally to limit per-operation memory usage: SET work_mem = '32MB'; Or in postgresql.conf: work_mem = 32MB Then restart or reload.
Identify and optimize the problematic query using EXPLAIN ANALYZE, then rewrite it to use less memory (e.g., add indexes, reduce sort operations).
Dead Ends
Common approaches that don't work:
-
Increasing shared_buffers without adjusting work_mem
85% fail
shared_buffers is for caching, not for per-query memory; it does not prevent out-of-memory errors from work_mem.
-
Restarting PostgreSQL without changing memory settings
90% fail
The memory is freed temporarily but the same query pattern will exhaust it again.