PostgreSQL: could not connect to server / connection refused — Is the server running on host and accepting TCP/IP connections?
The client reached no PostgreSQL listener at that host/port — the server is down, listening elsewhere, or not accepting remote connections.
could not connect to serverIs the server running on hostaccepting TCP/IP connectionsconnection to server atfailed: Connection refused Meaning
By default PostgreSQL listens only on localhost (listen_addresses = 'localhost') and port 5432. Remote clients also need a matching pg_hba.conf line and an open firewall port. In Docker, localhost means the app container itself.
Common causes
- PostgreSQL service stopped or crashed (disk full, bad config after edit)
listen_addresseslimited to localhost while connecting remotely- Different port (5433 when multiple versions are installed)
- Firewall / cloud security group blocking 5432
- Docker: using localhost instead of the service name
- Socket path mismatch: “could not connect to server: No such file or directory … /var/run/postgresql/.s.PGSQL.5432”
⚡ Quick fix
sudo systemctl status postgresqland read the log if it’s down- Check
SHOW listen_addresses;andSHOW port; - Set
listen_addresses = '*'+ a pg_hba.conf host line for remote access, then restart - In Docker Compose, connect to
db:5432
Detailed fix by platform
Linux
- Check service, port and listeners:bash
sudo systemctl status postgresql sudo ss -ltnp | grep postgres pg_lsclusters # Debian/Ubuntu: shows version, port, status sudo tail -n 50 /var/log/postgresql/postgresql-*-main.log
Docker
DATABASE_URL=postgres://app:secret@db:5432/app— use the compose service name; add a healthcheck so the app waits for the DB.
How to diagnose
- Service — Running?
- Listener — Which address/port does it listen on?
- Network — Firewall / container network?
- Auth — Next error after connecting: pg_hba.conf?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in PostgreSQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 14 Oct 2026