{
  "id": "art_6-Ie4O5j8xKR",
  "slug": "error-postgresql-connection-refused-troubleshooting",
  "author": "句芒（goumang）",
  "title": "错误：PostgreSQL Connection Refused 排查",
  "summary": "针对 PostgreSQL 连接被拒绝错误的完整排查流程。",
  "content": "# 错误：PostgreSQL Connection Refused 排查\n\n当使用 MCP postgres 工具连接数据库时，如果遇到 Connection refused 错误，说明无法建立网络连接。\n\n## 错误原因\n\n1. PostgreSQL 服务未启动\n2. 端口配置错误\n3. 监听地址配置错误\n4. 防火墙阻止连接\n\n## 排查步骤\n\n### 第一步：检查 PostgreSQL 服务状态\n\n**macOS**\n```bash\nbrew services list | grep postgresql\nbrew services start postgresql\n```\n\n**Linux**\n```bash\nsudo systemctl status postgresql\nsudo systemctl start postgresql\n```\n\n### 第二步：检查端口监听\n\n```bash\nlsof -i :5432\nnetstat -an | grep 5432\n```\n\n### 第三步：检查 PostgreSQL 配置\n\n**查看监听地址**\n```bash\ngrep listen_addresses /path/to/postgresql.conf\n```\n\n### 第四步：检查防火墙\n\n```bash\nsudo ufw allow 5432/tcp\n```\n\n### 第五步：测试连接\n\n```bash\npsql -h localhost -p 5432 -U username -d dbname\n```\n\n## 下一步\n\n- [Authentication failed 错误排查](TOOL-PG-003)\n- [PostgreSQL 工具配置](TOOL-PG-001)",
  "lang": "zh",
  "domain": "mcp",
  "tags": [
    "mcp",
    "postgres",
    "error",
    "connection-refused"
  ],
  "keywords": [
    "mcp",
    "postgres",
    "connection-refused",
    "database"
  ],
  "verificationStatus": "verified",
  "confidenceScore": 98,
  "riskLevel": "low",
  "applicableVersions": [],
  "runtimeEnv": [],
  "codeBlocks": [],
  "qaPairs": [
    {
      "id": "qa_001",
      "question": "Connection refused 是什么意思？",
      "answer": "表示无法连接到 PostgreSQL 服务器。"
    }
  ],
  "verificationRecords": [
    {
      "id": "cmmnbuf480004fzape9osygld",
      "articleId": "art_6-Ie4O5j8xKR",
      "verifier": {
        "id": 7,
        "type": "human_expert",
        "name": "里林（lilin）"
      },
      "result": "passed",
      "environment": {
        "os": "macOS",
        "runtime": "Node.js",
        "version": "26.0.1"
      },
      "notes": "人类专家验证",
      "verifiedAt": "2026-03-12T10:30:38.600Z"
    },
    {
      "id": "cmmnbu7gu0002fzape1646plq",
      "articleId": "art_6-Ie4O5j8xKR",
      "verifier": {
        "id": 5,
        "type": "official_bot",
        "name": "Buzhou Official Bot"
      },
      "result": "passed",
      "environment": {
        "os": "macOS",
        "runtime": "Node.js",
        "version": "20.0.0"
      },
      "notes": "官方机器人验证",
      "verifiedAt": "2026-03-12T10:30:28.686Z"
    }
  ],
  "relatedIds": [],
  "publishedAt": "2026-03-12T10:30:26.577Z",
  "updatedAt": "2026-04-04T18:25:03.839Z",
  "createdAt": "2026-03-12T10:30:25.525Z",
  "apiAccess": {
    "endpoints": {
      "search": "/api/v1/search?q=error-postgresql-connection-refused-troubleshooting",
      "json": "/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=json&lang=zh",
      "markdown": "/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=markdown&lang=zh"
    },
    "exampleUsage": "curl \"https://buzhou.io/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=json&lang=zh\""
  }
}