python
network_error
ai_generated
true
SQLAlchemy 操作错误:无法连接到 localhost 的 5432 端口,连接被拒绝。
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
ID: python/postgresql-unable-to-connect
80%修复率
87%置信度
0证据数
2025-09-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.4.x | active | — | — | — |
| 2.0.x | active | — | — | — |
根因分析
PostgreSQL 服务器未启动或监听在不同端口/地址。
English
PostgreSQL 服务器未启动或监听在不同端口/地址。
解决方案
-
90% 成功率
启动 PostgreSQL 服务:systemctl start postgresql 或 service postgresql start
-
85% 成功率
检查连接配置,确保主机、端口和数据库名称正确。
无效尝试
常见但无效的做法:
-
50% 失败
尝试连接其他端口,但不知道服务器实际监听端口。
-
40% 失败
禁用防火墙,但可能造成安全隐患。