Troubleshooting guide
PostgreSQL connection refused: how to fix it
The client reached the host and nothing accepted on that port. Postgres is stopped, is listening on another address, or your client is pointed at the wrong place.
3 min read11 sectionsUpdated
On this page
Common causes
- The server is stopped, or failed to start, for example because the disk is full.
listen_addresses = 'localhost'blocks remote clients.- Docker or Compose: using
localhostinstead of the service name. - A different port configured, or two clusters on one machine.
- A firewall rejecting traffic.
# Is it listening, and on which address?
sudo ss -ltnp | grep 5432
# Status and recent logs
systemctl status postgresql --no-pager
sudo journalctl -u postgresql -n 40 --no-pager
# Readiness check, from the app host or container
pg_isready -h db.example.internal -p 5432
# Effective settings (once connected locally)
sudo -u postgres psql -c "SHOW listen_addresses; " -c "SHOW port;"
sudo -u postgres psql -c "SHOW hba_file;"Fixes
Start Postgres, and read the log if it will not start. For remote access, set listen_addresses to a private interface, and restart. Add a narrow pg_hba.conf line for your application's network, then reload. In Compose, connect to the service name. Open port 5432 only to the hosts that need it, using a firewall or security group.
Safely handling restarts
Applications should expect the database to disappear for a moment. A failover or restart gives a short period when connections are refused, so use a connection pool with retry and backoff, and make startup wait for the database with a pg_isready loop or an init container rather than crashing. A very frequent cause of startup failure is a full disk, particularly from WAL files retained by an abandoned replication slot, so if Postgres refuses to start, check df -h on its data volume before anything else.
Catch it automatically
A TCP check on port 5432 from your private network reports refused connections within a minute. PostgreSQL monitoring adds restarts and disk use, and an alert on retained WAL can prevent the disk filling up.
What is the difference between refused and no pg_hba.conf entry?
Refused means you never reached Postgres. No pg_hba.conf entry means you reached it and it rejected the host or user.
Do I need a restart to change listen_addresses?
Yes. pg_hba.conf only needs a reload.
Should Postgres be open to the internet?
No. Use private networks, or a VPN.
Check it now, free
- Open port checker: Is a TCP port open, closed or filtered from the internet?
Related reading
- Redis connection refused: how to fix it: Fix Redis connection refused on port 6379: server stopped, bind address, protected mode and Docker networking, with redis-cli and ss commands for each cause.
- SSH connection refused: how to fix it: Fix "ssh: connect to host port 22: Connection refused": sshd stopped, wrong port, firewalls and fail2ban, and how to get back in when you are locked out.
- ERR_CONNECTION_REFUSED: how to fix it: Fix ERR_CONNECTION_REFUSED in Chrome: nothing listening on the port, firewalls, wrong ports and localhost binding, with steps for visitors and for site owners.
- "DNS server not responding": how to fix it: Fix "DNS server not responding" on Windows and Mac: restart the router, flush DNS, switch to 1.1.1.1 or 8.8.8.8, and check adapters, VPNs and firewalls.
- ERR_NAME_NOT_RESOLVED: how to fix DNS lookup failures: Fix ERR_NAME_NOT_RESOLVED: missing records, expired domains, broken resolvers and DNSSEC failures, with dig commands that show exactly where lookup fails.
- EADDRINUSE: address already in use and how to fix it: Fix EADDRINUSE in Node.js and other servers: find which process holds the port, handle old processes after a crash and avoid race conditions in restarts.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.