Fix pgAdmin Connection Error β Server Doesn't Listen
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.
Right β
# 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_addressesafter install or config restore. - Set
listen_addresses = '*'for multi-interface servers, then lock downpg_hba.confinstead. - Test with
psql -h <IP> -U postgres -d postgresbefore opening pgAdmin. - Keep
portmatching between<a href="/databases/postgresql/">postgresql</a>.confand your pgAdmin registration.
Common Mistakes with connect error
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - 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
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