Skip to content

Fix pgAdmin Connection Error – Server Doesn't Listen

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Fix pgAdmin Connection Error. We cover key concepts, practical examples, and best practices.

You fire up pgAdmin, fill in the server details, click Save β€” and get slapped with "could not connect to server: Connection refused". The postgres process is running, so what gives?

Wrong ❌

# pg_hba.conf
host all all 0.0.0.0/0 md5
listen_addresses = 'localhost'    # only listens on loopback
port = 5432

You try pinging the server from the client machine and it works, yet pgAdmin still can't connect.

# postgresql.conf
listen_addresses = '*'            # or the specific IP, e.g. '192.168.1.50'
port = 5432

# pg_hba.conf
host all all 0.0.0.0/0 scram-sha-256

After the change, restart PostgreSQL and verify:

sudo systemctl restart postgresql
ss -tlnp | grep 5432
# output: LISTEN  0  128  0.0.0.0:5432  0.0.0.0:*

Now pgAdmin connects without issues. The key difference: listen_addresses must include the network interface the client actually hits.

Root Cause

PostgreSQL binds only to localhost by default. If pgAdmin connects via the machine's public or private IP, the kernel refuses the connection because nothing is listening on that interface.

Prevention

  • Always audit listen_addresses after install or config restore.
  • Set listen_addresses = '*' for multi-interface servers, then lock down pg_hba.conf instead.
  • Test with psql -h <IP> -U postgres -d postgres before opening pgAdmin.
  • Keep port matching between <a href="/databases/postgresql/">postgresql</a>.conf and your pgAdmin registration.

Common Mistakes with connect error

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world PGADMIN code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

**Q: I still get "Connection refused" after changing listen_addresses β€” what now?**

A: Check the firewall: sudo ufw status or iptables -L. Port 5432 may be blocked.

**Q: Can I use a Unix socket instead of TCP?**

A: Yes β€” in pgAdmin, set the host to the socket directory path (e.g. /var/run/<a href="/databases/postgresql/">postgresql</a>). No TCP config needed.

**Q: Does pgAdmin cache connection info?**

A: No, but the server definition in pgAdmin stores host/port. Double‑click the server and verify the values.

**Q: What if I use Docker?**

A: Ensure the container publishes port 5432 (-p 5432:5432) and that listen_addresses inside the container is *.


Need a full step-by-step setup? Check the DodaTech pgAdmin course for guided labs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro