Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Connection Refused and Timeouts

Direct answer

Connection refused means nothing listens on that address/port (or it rejects); timeout means packets are dropped (firewall, routing) or the server is overloaded.

When to use this

Use it when applications cannot connect to the database.

First 30 seconds

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.

Operational verification

client → DNS → TCP to port → server accepts → auth

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it when applications cannot connect to the database.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Check listening address (localhost only?), port, firewall, and the server's connection limit. Then authentication.

Key checks
  • nc -vz <host> <port> — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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 errorLayerMost likely cause
could not translate host name / Unknown MySQL server hostDNSWrong name, resolver, split DNS
Connection refusedTCP, reached the hostNothing listens on that address/port (server down, listen_addresses/bind-address = localhost, wrong port)
Connection timed out / hangsNetwork pathFirewall, security group, routing silently dropping packets
no pg_hba.conf entry / Host '…' is not allowed to connectServer access rulesMissing allow rule for that client address
password authentication failed / Access denied for userAuthenticationWrong credentials or wrong account matched
too many clients / Too many connectionsCapacityConnection limit reached — pool problem
SSL connection is required / certificate errorsTLSClient 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Terminology layer

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.

Aliases that resolve here
connection refused and timeoutsdatabase connection refusedtoo many connections
Confirmation

Confirm action

Continue?