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

- **ID:** `python/sqlalchemy-connection-refused`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

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

## 无效尝试

- **Changing the port number arbitrarily** — The database is not listening on that port either. (80% 失败率)
- **Disabling firewall completely** — This is a security risk and may not solve the issue if the server is not running. (60% 失败率)
