N8n PostgreSQL “Connection refused 127.0.0.1:5432” despite pgAdmin working

Body:
Hi everyone,

I’m trying to connect PostgreSQL to n8n using the “Postgres” credential, but I’m getting the following error:

Couldn't connect with these settings  
Connection refused 127.0.0.1:5432

Here are my details:

  • Host: 127.0.0.1

  • Port: 5432

  • Database: rent_mgmt

  • User: postgres

  • Password: (correct, same as pgAdmin)

PostgreSQL is installed locally, and I can access the database successfully through pgAdmin. I’ve also confirmed that the service is running.

However, n8n still fails to connect.

Things I’ve tried:

  • Restarting PostgreSQL service

  • Switching host between 127.0.0.1 and localhost

  • Rechecking credentials

Still getting the same error.

Is there something I might be missing (like configuration, permissions, or network settings)?

Thanks in advance!

if n8n is running in docker, 127.0.0.1:5432 won’t work — postgres is on your host. try host.docker.internal:5432 instead (or the actual hostname if you’re on linux). otherwise make sure postgres is listening on all interfaces, not just 127.0.0.1

1 Like

welcome to the n8n community @Rishika_Das
I’d like to add another angle to this, a “connection refused” error usually means PostgreSQL is not accepting connections from that source. I would check your PostgreSQL config and make sure it’s listening on the correct interfaces (not only localhost) and allowing connections from where n8n is running.

1 Like

The answers above cover the main cases well. One more thing to check if you’re running n8n locally (not Docker): your PostgreSQL pg_hba.conf file.

Even if PostgreSQL is running and listening on 127.0.0.1, it might not allow connections with password authentication from that IP. In pg_hba.conf, look for a line like:

host all all 127.0.0.1/32 md5

If it says “ident” or “peer” instead of “md5” (or “scram-sha-256”), password-based connections will be rejected even with the correct credentials.

To fix it, change the auth method to “md5” or “scram-sha-256” and then restart PostgreSQL service.

I hit this exact issue when first connecting n8n to a local PostgreSQL for my RAG workflow. Took me a while to spot. pgAdmin worked because it uses a different connection method internally.

1 Like