PostgreSQL “Connection refused”: start the server, then read its log
Check whether the server is running with pg_isready, then start it for your platform.
First check with pg_isready. If the server is down, start it: brew services start postgresql on macOS, sudo systemctl start postgresql on Linux, or pg_ctl start -D with your data directory. Then read the server log if it fails to start.
Try these fixes in order
Check server status
Ask the server directly whether it is accepting connections, instead of guessing from the client error.
pg_isreadyStart the server (macOS)
On macOS with Homebrew, start the service (replace with your installed version, e.g. postgresql@16).
brew services start postgresqlStart the server (Linux)
On systemd Linux distributions, start and enable the packaged PostgreSQL service.
sudo systemctl start postgresqlRead the log on startup failure
If the server refuses to start, read the log it names on failure; fix the reported problem (data directory permissions, port conflict, corrupt config) rather than deleting postmaster.pid.
pg_ctl start -D /usr/local/var/postgres -l server.logInterpret what you see
pg_isready reports no response
What it suggests: Nothing is listening on the port. The server was never started, crashed, or failed to start after a reboot.
Next check: Run pg_isready; if it reports no response, start the server.
The server is running but the port differs
What it suggests: The server runs but on a non-default port (common with multiple Homebrew versions or custom configs).
Next check: Check the port in postgresql.conf or with SHOW port; from a working connection.
The server fails to start after a crash
What it suggests: A stale postmaster.pid after a crash can block startup with a misleading state.
Next check: Check the server log for the real startup error before removing anything.
Why this happens
- The PostgreSQL server process is not running on the target host.
- The server is running but listening on a different port or only on a Unix socket.
Still not working?
Do not edit postgresql.conf listen settings until you have confirmed the server is actually running. Most connection-refused cases are a stopped server, not a listen-address problem.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.