# 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`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

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

## Dead Ends

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