{
  "id": "python/postgresql-unable-to-connect",
  "signature": "sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at \"localhost\" (127.0.0.1), port 5432 failed: Connection refused",
  "signature_zh": "SQLAlchemy 操作错误：无法连接到 localhost 的 5432 端口，连接被拒绝。",
  "regex": "sqlalchemy\\.exc\\.OperationalError:\\ \\(psycopg2\\.OperationalError\\)\\ connection\\ to\\ server\\ at\\ \"localhost\"\\ \\(127\\.0\\.0\\.1\\),\\ port\\ 5432\\ failed:\\ Connection\\ refused",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "PostgreSQL 服务器未启动或监听在不同端口/地址。",
  "root_cause_type": "generic",
  "root_cause_zh": "PostgreSQL 服务器未启动或监听在不同端口/地址。",
  "versions": [
    {
      "version": "1.4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.0.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "尝试连接其他端口，但不知道服务器实际监听端口。",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "禁用防火墙，但可能造成安全隐患。",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "启动 PostgreSQL 服务：systemctl start postgresql 或 service postgresql start",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "检查连接配置，确保主机、端口和数据库名称正确。",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-09-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}