PostgreSQL "Connection refused" — Server Down or Network Blocked?
Difference between connection refused, timeout, and no pg_hba entry; triage for listen_addresses, port conflicts, firewalls, and Docker container mappings.
Operational Verification & Reliability Metadata
The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.
▸Symptom
could not connect to server: Connection refused
Is the server running on that host and accepting TCP/IP connections?Target port has no active listener.
▸8-Step Triage Checklist
- 1
pg_isready -h [host] -p 5432 - 2Check process:
sudo systemctl status postgresql - 3Check socket binding:
sudo ss -ltnp | grep 5432 - 4Update binding:
ALTER SYSTEM SET listen_addresses = '*';(Requires service restart). - 5Verify cloud security group / host firewall ingress.
- 6Verify Docker container port mapping (
-p 5432:5432).
- •Validated versions: PostgreSQL 14 / 15 / 16 / 17
Other Database Error Triage Playbooks
Other battle-tested diagnostic guides for high-severity database errors.
PostgreSQL too many clients already: 6-Step Resolution
Three root causes of FATAL: sorry, too many clients already, single diagnostic query to identify the cause, and permanent mitigation via max_connections and PgBouncer.
PostgreSQL password authentication failed: Root Cause and Fix
Four root causes of psql password authentication failed: incorrect password, md5/SCRAM mismatch, pg_hba.conf rule ordering, and port/cluster confusion. Step-by-step triage.
PostgreSQL duplicate key Error: Sequence Sync Fix
Root cause of duplicate key violations after restore or bulk migration, one-line setval repair, and an automated schema-wide PL/pgSQL DO block.