{
  "id": "database/postgresql-too-many-pins",
  "signature": "psycopg2.OperationalError: ERROR: out of memory\nDETAIL: Failed on request of size 123456.",
  "signature_zh": "psycopg2.OperationalError: 错误：内存不足\n详细信息：请求大小为 123456 时失败。",
  "regex": "psycopg2\\.OperationalError: ERROR: out of memory\nDETAIL: Failed on request of size \\d+\\.",
  "domain": "database",
  "category": "resource_error",
  "subcategory": null,
  "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).",
  "root_cause_type": "generic",
  "root_cause_zh": "PostgreSQL 服务器内存耗尽，通常是由于多个并发查询使用了过多的 work_mem，或单个查询需要非常大的内存（如排序、哈希操作）。",
  "versions": [
    {
      "version": "PostgreSQL 14",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PostgreSQL 15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PostgreSQL 16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing shared_buffers without adjusting work_mem",
      "why_fails": "shared_buffers is for caching, not for per-query memory; it does not prevent out-of-memory errors from work_mem.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Restarting PostgreSQL without changing memory settings",
      "why_fails": "The memory is freed temporarily but the same query pattern will exhaust it again.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Reduce work_mem for the session or globally to limit per-operation memory usage:\nSET work_mem = '32MB';\nOr in postgresql.conf:\nwork_mem = 32MB\nThen restart or reload.",
      "success_rate": 0.85,
      "how": "Reduce work_mem for the session or globally to limit per-operation memory usage:\nSET work_mem = '32MB';\nOr in postgresql.conf:\nwork_mem = 32MB\nThen restart or reload.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Identify and optimize the problematic query using EXPLAIN ANALYZE, then rewrite it to use less memory (e.g., add indexes, reduce sort operations).",
      "success_rate": 0.8,
      "how": "Identify and optimize the problematic query using EXPLAIN ANALYZE, then rewrite it to use less memory (e.g., add indexes, reduce sort operations).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Reduce work_mem for the session or globally to limit per-operation memory usage:\nSET work_mem = '32MB';\nOr in postgresql.conf:\nwork_mem = 32MB\nThen 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)."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.82,
  "resolvable": "partial",
  "first_seen": "2024-03-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}