Error: connect ECONNREFUSED 127.0.0.1:5432

PostgreSQL·Sep 12, 2026·beginner·
Quick answer

Your app is trying to connect to a PostgreSQL server on localhost, but nothing is listening there — either your local Postgres isn't running, or `DATABASE_URL` still points at localhost when it should point at your actual hosted database (like Neon).

What causes this error

ECONNREFUSED means the connection attempt reached the target address but nothing accepted it — unlike a timeout, this is an immediate rejection, meaning no server process is listening on that port at all.

The Fix

Locally: confirm Postgres is actually running:

# macOS with Homebrew
brew services list
brew services start postgresql

# Or if using Docker
docker ps

In a deployed environment: this almost always means DATABASE_URL still has a local/placeholder value (localhost:5432) instead of your actual hosted database connection string — double-check your environment variables on your hosting platform.

Common causes / variations

  • Local Postgres service not started before running the dev server
  • A .env file with a leftover local connection string accidentally deployed to production
  • Docker Compose Postgres container not fully started yet when the app tries to connect (a startup race condition — add a retry or healthcheck)

Related errors

See also: password authentication failed, too many clients already.

Was this fix helpful?

Comments

Loading comments...