/n8n-tutorials

How to connect n8n to PostgreSQL?

Learn how to connect n8n to PostgreSQL with clear steps for credentials, nodes, and workflows to sync data easily and automate tasks effectively.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to connect n8n to PostgreSQL?

The direct way to connect n8n to PostgreSQL is to create a PostgreSQL Credential inside n8n, then use the built‑in Postgres node in your workflow and select that credential. Once the credential is saved, every Postgres node you add can run queries (SELECT, INSERT, UPDATE, etc.) using that connection.

 

How to Connect n8n to PostgreSQL (the practical, production‑safe way)

 

Connecting n8n to PostgreSQL is mostly about giving n8n the correct connection details and making sure your database accepts the connection. Here’s what matters in real setups:

  • You need a PostgreSQL server that n8n can reach (local container, remote server, cloud provider).
  • You need a PostgreSQL user with the correct permissions for whatever queries you’ll run.
  • In n8n, you create a Postgres Credential that stores the DB info securely.
  • You add a Postgres node in your workflow to run queries using that credential.

 

Step‑by‑Step Setup

 

Below is the cleanest path for someone new to n8n but building production‑grade workflows.

  • Open n8n → Credentials → New, then choose Postgres.
  • Fill the fields:
    • Host: the PostgreSQL hostname (for Docker, often the service name like “postgres”)
    • Port: normally 5432
    • Database: your DB name
    • User and Password: credential with enough permissions
    • SSL: set to “yes” only if required by your host (common with cloud DBs)
  • Save the credential.
  • In your workflow, drag in a Postgres node.
  • In the node’s settings, set:
    • Resource: usually “Query”
    • Operation: “Execute query”
    • Postgres credential: select the one you created
  • Write your SQL query.

 

A simple working example query

 

SELECT id, email 
FROM users 
WHERE active = true;  // This returns all active users

 

The Postgres node will output the rows as JSON so the next nodes can use them with expressions like {{$json.email}}.

 

Production Notes (things that matter when this runs 24/7)

 

  • Network access: n8n must be able to reach the DB host. In Docker, that usually means both containers on the same network. In cloud setups, check firewall rules.
  • Use a dedicated DB user: Don’t use the superuser. Give your n8n user only the tables it needs.
  • Long queries: n8n nodes have execution timeouts depending on hosting. Heavy ETL work belongs in the DB or a script, not inside n8n.
  • Parameterize when possible: You can use expressions for dynamic values:
    • Example: {{$json.customerId}} inside your SQL
  • Error handling: wrap Postgres nodes with an Error Workflow or use Continue On Fail if failures are acceptable.
  • Transactions: n8n’s Postgres node does not expose manual multi‑step transactions. If your use case requires it, keep that logic outside n8n.

 

Quick connection test example

 

SELECT NOW();  // A simple query to verify the connection works

 

That’s everything required to connect n8n to PostgreSQL in a way that works both in development and in real production environments.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022