Use it when applications cannot connect to the database.
Connection Refused and Timeouts
Connection refused means nothing listens on that address/port (or it rejects); timeout means packets are dropped (firewall, routing) or the server is overloaded.
1. nc -vz <host> <port> from the client host.
2. Server listening: ss -ltnp | grep <port>; listen_addresses/bind-address.
3. Firewall/security groups.
4. max_connections reached?
5. Then credentials and pg_hba/user@host.
client → DNS → TCP to port → server accepts → auth
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Test from the same host and network namespace as the application (for example inside the container). Compare with a test from the database host itself.
Step 2 Troubleshooting order Narrow the fault
1. Is the server listening? ss -ltnp | grep 5432 (or 3306, 1433); listen_addresses / bind-address.
2. Network: Test-NetConnection db -Port 5432 / nc -vz db 5432; firewalls and security groups.
3. Authentication: pg_hba.conf / user@host / login mapping.
4. Limits: max_connections reached?
5. DNS and TLS: name resolves? certificate valid?
"Connection refused" = nothing listening or firewall reject; timeout = packets dropped on the path.
Step 3 Common failures Narrow the fault
A server listening only on 127.0.0.1 refuses remote connections. Security groups or host firewalls cause timeouts. Pool misconfiguration exhausts max_connections.
Check listening address (localhost only?), port, firewall, and the server's connection limit. Then authentication.
nc -vz <host> <port>— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
Each layer gives a distinct error: name resolution failure, connection refused, timeout, too many connections, or authentication failed. Read the exact error before changing anything.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
The error text tells you the layer
| Client error | Layer | Most likely cause |
|---|---|---|
could not translate host name / Unknown MySQL server host | DNS | Wrong name, resolver, split DNS |
Connection refused | TCP, reached the host | Nothing listens on that address/port (server down, listen_addresses/bind-address = localhost, wrong port) |
Connection timed out / hangs | Network path | Firewall, security group, routing silently dropping packets |
no pg_hba.conf entry / Host '…' is not allowed to connect | Server access rules | Missing allow rule for that client address |
password authentication failed / Access denied for user | Authentication | Wrong credentials or wrong account matched |
too many clients / Too many connections | Capacity | Connection limit reached — pool problem |
SSL connection is required / certificate errors | TLS | Client TLS settings, CA trust, hostname |
Worked path from the application host
getent hosts db.example.com # 1. name resolves to the right address?
nc -vz db.example.com 5432 # 2. TCP: refused vs timeout
psql "host=db.example.com dbname=shop user=shop_app sslmode=verify-full" -c 'select 1' # 3. full login
Test-NetConnection db.example.com -Port 1433 # Windows / SQL Server
Run the tests from the same place as the application — inside the container or pod, through the same proxy — because a test from your workstation takes a different path.
On the server
ss -ltnp | grep -E '5432|3306|1433' # listening on 0.0.0.0 / the right IP?
SHOW listen_addresses; SHOW port; -- PostgreSQL (change needs restart)
SELECT @@bind_address, @@port; -- MySQL
Intermittent timeouts under load usually mean the pool is exhausted or the server's connection limit is reached, not the network.
Common mistakes
- Database listening only on localhost.
- Firewall blocking the port.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.