database resource_error ai_generated partial

psycopg2.OperationalError: 错误:内存不足 详细信息:请求大小为 123456 时失败。

psycopg2.OperationalError: ERROR: out of memory DETAIL: Failed on request of size 123456.

ID: database/postgresql-too-many-pins

其他格式: JSON · Markdown 中文 · English
82%修复率
84%置信度
1证据数
2024-03-05首次发现

版本兼容性

版本状态引入弃用备注
PostgreSQL 14 active
PostgreSQL 15 active
PostgreSQL 16 active

根因分析

PostgreSQL 服务器内存耗尽,通常是由于多个并发查询使用了过多的 work_mem,或单个查询需要非常大的内存(如排序、哈希操作)。

English

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

官方文档

https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM

解决方案

  1. 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.
  2. Identify and optimize the problematic query using EXPLAIN ANALYZE, then rewrite it to use less memory (e.g., add indexes, reduce sort operations).

无效尝试

常见但无效的做法:

  1. Increasing shared_buffers without adjusting work_mem 85% 失败

    shared_buffers is for caching, not for per-query memory; it does not prevent out-of-memory errors from work_mem.

  2. Restarting PostgreSQL without changing memory settings 90% 失败

    The memory is freed temporarily but the same query pattern will exhaust it again.