python network_error ai_generated true

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) 无法连接到服务器:连接被拒绝 服务器是否在主机 "localhost" (::1) 上运行并接受端口 5432 的 TCP/IP 连接?

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

ID: python/sqlalchemy-connection-refused

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-06-01首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

数据库服务器未运行或未在指定的主机和端口上接受连接。

English

The database server is not running or not accepting connections on the specified host and port.

generic

解决方案

  1. 95% 成功率 Start the database server
    # For PostgreSQL:
    sudo systemctl start postgresql
    # Or:
    pg_ctl start
  2. 90% 成功率 Check if the server is listening on the correct interface
    sudo netstat -tulpn | grep 5432
    # If not, edit postgresql.conf to listen on '*' or '0.0.0.0'

无效尝试

常见但无效的做法:

  1. Changing the port number arbitrarily 80% 失败

    The database is not listening on that port either.

  2. Disabling firewall completely 60% 失败

    This is a security risk and may not solve the issue if the server is not running.