Learn how to connect and automate your self-hosted databases with n8n using secure integrations and efficient workflows in this step-by-step guide.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
You use n8n with self‑hosted databases by giving n8n network access to the database host, creating proper n8n Database Credentials (Postgres, MySQL, Mongo, etc.), and then using the built‑in database nodes (like Postgres, MySQL, MongoDB) to run queries. In real production, the main things that matter are: networking, credentials, SSL, connection permissions, and keeping queries small and efficient so n8n doesn’t become your database engine.
n8n doesn’t magically “scan” your database — it simply acts like any normal app that connects to a database. It opens a connection, runs your SQL (or Mongo ops), returns the result as JSON, and passes that JSON to the next node.
To connect n8n to a self‑hosted DB, you only need:
Once that’s set, your workflow can run INSERT/UPDATE/SELECT queries directly from n8n, and the results become the JSON for the next node.
This is the typical pattern that works in Docker, bare‑metal servers, or cloud VMs.
This uses the Postgres node with Operation = “Execute Query”.
INSERT INTO users (email, name)
VALUES ({{$json.email}}, {{$json.name}});
n8n replaces {{$json.email}} with actual values from the previous node before running the SQL.
SELECT id, email, created_at
FROM users
WHERE created_at > NOW() - INTERVAL '1 day';
This returns an array of records as JSON items, perfect for loops, merges, or sending to APIs.
A very common setup is running n8n and the DB in the same Docker network.
// docker-compose.yml (simplified)
services:
n8n:
image: n8nio/n8n
depends_on:
- postgres
networks:
- internal
postgres:
image: postgres:15
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: n8npass
networks:
- internal
networks:
internal:
driver: bridge
Inside n8n, the host would simply be:
postgres
Because Docker resolves it by container name.
As long as n8n can reach your self‑hosted database and you provide valid credentials, you can query it like any normal application. n8n nodes simply turn query results into JSON and pass them along the workflow, making database operations easy to integrate with APIs, logic nodes, and automations.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.