{
  "id": "database/postgresql-cannot-connect-to-server-no-such-file",
  "signature": "psycopg2.OperationalError: could not connect to server: No such file or directory\n\tIs the server running locally and accepting connections on Unix socket \"/var/run/postgresql/.s.PGSQL.5432\"?",
  "signature_zh": "psycopg2.OperationalError: 无法连接到服务器：没有那个文件或目录\n\t服务器是否在本地运行并接受 Unix 套接字 \"/var/run/postgresql/.s.PGSQL.5432\" 上的连接？",
  "regex": "could not connect to server: No such file or directory\\n\\tIs the server running locally and accepting connections on Unix socket",
  "domain": "database",
  "category": "connection_error",
  "subcategory": null,
  "root_cause": "PostgreSQL is not running or the Unix socket file is missing, often because the postgres service is stopped, the socket directory is misconfigured, or the server was started with a different socket path.",
  "root_cause_type": "generic",
  "root_cause_zh": "PostgreSQL 未运行或 Unix 套接字文件丢失，通常是因为 postgres 服务已停止、套接字目录配置错误，或者服务器以不同的套接字路径启动。",
  "versions": [
    {
      "version": "PostgreSQL 16.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PostgreSQL 15.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PostgreSQL 14.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Changing the port in the connection string to a different port (e.g., from 5432 to 5433)",
      "why_fails": "The error is about the socket file, not the port; changing the port will only work if the server listens on that port via TCP, but the socket path remains the same.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Creating a symbolic link to the socket file manually (ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432)",
      "why_fails": "The socket file is created by PostgreSQL at startup; a manual symlink will not be valid if the server is not running, and it may cause permission issues.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Restarting only the application without checking PostgreSQL",
      "why_fails": "The application restart does not affect the database server; the connection will still fail if PostgreSQL is down.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check if PostgreSQL is running: systemctl status postgresql (or pg_isready). If not running, start it: systemctl start postgresql (or pg_ctl start -D /var/lib/postgresql/16/main).",
      "success_rate": 0.9,
      "how": "Check if PostgreSQL is running: systemctl status postgresql (or pg_isready). If not running, start it: systemctl start postgresql (or pg_ctl start -D /var/lib/postgresql/16/main).",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the socket path is misconfigured, update postgresql.conf to set unix_socket_directories to the correct path (e.g., /var/run/postgresql), then restart: sudo systemctl restart postgresql.",
      "success_rate": 0.85,
      "how": "If the socket path is misconfigured, update postgresql.conf to set unix_socket_directories to the correct path (e.g., /var/run/postgresql), then restart: sudo systemctl restart postgresql.",
      "condition": "",
      "sources": []
    },
    {
      "action": "As a workaround, connect via TCP instead of Unix socket by specifying host='localhost' in the connection string: psql -h localhost -U myuser mydb.",
      "success_rate": 0.8,
      "how": "As a workaround, connect via TCP instead of Unix socket by specifying host='localhost' in the connection string: psql -h localhost -U myuser mydb.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Check if PostgreSQL is running: systemctl status postgresql (or pg_isready). If not running, start it: systemctl start postgresql (or pg_ctl start -D /var/lib/postgresql/16/main).",
    "If the socket path is misconfigured, update postgresql.conf to set unix_socket_directories to the correct path (e.g., /var/run/postgresql), then restart: sudo systemctl restart postgresql.",
    "As a workaround, connect via TCP instead of Unix socket by specifying host='localhost' in the connection string: psql -h localhost -U myuser mydb."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.postgresql.org/docs/16/runtime-config-connection.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-01-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}