could not connect to server: Connection refused

The PostgreSQL server process isn't running, or isn't listening on the address/port you're connecting to.

Common causes

  • PostgreSQL service isn't started
  • Connecting to the wrong host or port

Diagnostic commands

bash
$ pg_isready

Solutions

  • Start the service: `sudo systemctl start postgresql` (Linux) or `brew services start postgresql@16` (macOS)
  • Double-check the host and port you're connecting with match where the server is actually listening

Related tutorials