Connected before n8n starts
The template sets DB_TYPE=postgresdb and the connection settings before the first boot. n8n builds its own tables the first time it starts. There is no database to create and no seed to run.
n8n 2.40.7, the workflow automation tool, deploys here with its own PostgreSQL 16 onto a dedicated server Selfhost.dev provisions, secures and runs, across six locations on three continents. A European 4 GB server is $0.02/hr, about $15 a month, with n8n connected to its database before it first starts.
See the monthly figure for your region before you sign up.
n8n, the open source automation tool, storing its workflows and execution history in PostgreSQL instead of a SQLite file. Not to be confused with the Postgres node, which queries your own databases from a workflow.
Teams whose workflows run all day, keep long execution history or will need queue mode later. Postgres takes many writers at once, where SQLite writes one at a time.
Pick it at deploy time when volume is already heavy or growing. For one person running a handful of workflows, the SQLite template does the same job with one fewer container.
Three containers on one project server, each pinned to a version and started together.
The template sets DB_TYPE=postgresdb and the connection settings before the first boot. n8n builds its own tables the first time it starts. There is no database to create and no seed to run.
Postgres holds your credential records, but the key that decrypts them sits in n8n's own volume. We pin that key as a platform secret, so every redeploy starts with the same key and your saved API keys keep working.
Every run n8n records goes into the database. n8n prunes old runs by default and keeps up to 10,000. Postgres reuses the space those deletions free, where a SQLite file keeps its size until it is vacuumed.
Webhooks, APIs, your browser
TLS and routing
n8n
Task runner
PostgreSQL 16
Encryption key
| Component | Version | What it does |
|---|---|---|
| n8n | n8nio/n8n:2.40.7 | Editor, workflow engine and webhook endpoints, behind HTTPS |
| Task runner | n8nio/runners:2.40.7 | Runs Code node JavaScript and Python, five at a time |
| PostgreSQL | postgres:16-alpine | Workflows, execution history and credential records |
| Volumes | n8n-data, postgresql-data | n8n's own files and the database files |
Every n8n and Postgres tutorial ends in the same compose file. Here it is already running, with the parts copied versions leave out already set.
| If you set it up yourself | On Selfhost.dev, already done |
|---|---|
| Write a compose file for n8n and Postgres | Three containers, declared and started together |
Set DB_TYPE and the DB_POSTGRESDB_* variables | Set before the first boot |
Point n8n at the database container, not localhost | Already wired to the database container |
| Choose a database password | Generated for this deployment |
Generate N8N_ENCRYPTION_KEY and never lose it | Pinned as a platform secret |
Swap :latest for a real version | n8n 2.40.7 and Postgres 16, pinned |
| Keep port 5432 off the internet | The server firewall opens only 22, 80 and 443 |
| Put HTTPS and a proxy in front | A Let's Encrypt certificate, with N8N_PROXY_HOPS=1 set |
| Make webhook URLs match your domain | WEBHOOK_URL, N8N_EDITOR_BASE_URL and N8N_HOST follow the live domain |
| Stop Code nodes reading server secrets | N8N_BLOCK_ENV_ACCESS_IN_NODE=true |
The example most guides copy publishes Postgres on port 5432 and sets no encryption key. On a server of your own, those are the first two things to fix.
Specifications current as of September 2026.
The whole template counts as one light workload. The task runner executes five Code steps at once. The server size, not a plan, sets the ceiling.
Need more room? An 8 GB server takes three heavy apps plus one light or any lighter mix.
Four steps. None of them is a compose file.
The Launch button opens the console on this exact template. Choose a server size and one of six locations.
The console shows each provisioning stage. The template deploys in about five minutes onto a generated HTTPS address.
Open the address and create the owner account straight away. That first account runs the instance.
Create your first workflow or import one as JSON. Every run it records from now on lands in Postgres.
You pay for the server by the hour. The rate depends on where it runs.
| Item | Cost |
|---|---|
| n8n, the task runner and the Postgres container | $0 |
| HTTPS and a custom domain | $0 |
| Users and seats | $0 |
| Bandwidth | $0, no traffic metering on a template project |
| Backups | Optional, +20% of the server rate |
| Server | RAM, cores, disk | Where | Rate | About a month |
|---|---|---|---|---|
cx23 (recommended) | 4 GB, 2 cores, 40 GB | Europe | $0.02/hr | $15 |
cpx21 (twice the disk) | 4 GB, 3 cores, 80 GB | Europe | $0.04/hr | $26 |
cpx21 | 4 GB, 3 cores, 80 GB | Singapore | $0.07/hr | $51 |
cpx21 | 4 GB, 3 cores, 80 GB | US | $0.12/hr | $88 |
cx33 (one size up) | 8 GB, 4 cores, 80 GB | Europe | $0.03/hr | $23 |
Monthly figures assume 730 hours. Hourly rates as displayed in the console, September 2026.
A server with a card on file or a past top-up is powered off first and held for 24 hours. Adding credit in that window starts it again. Welcome-credit-only servers are deleted at zero. Backups go with the server.
Price another size or region in the calculator, no signup.
For one person running a few workflows a day with short history, self hosted n8n on SQLite is the simpler machine: two containers, one volume, the same server price. Postgres earns its extra container when several workflows write at once, history runs long or queue mode is on the roadmap.
pg_dump copies, kept off the serverThe n8n Postgres template deploys in about five minutes. That is the platform's own budget, not an estimate.
None of these a dealbreaker? The template deploys in about five minutes.
Launch n8n with PostgresTwo ways to keep n8n and its database safe: a daily image of the whole server plus your own Postgres dumps over SSH.
| Method | What it covers | Where it lives |
|---|---|---|
| Daily server backup (optional, +20%) | n8n, Postgres and both volumes in one image, last 7 kept | With the server |
pg_dump over root SSH | Workflows, execution history and credential records | Wherever you copy it |
| n8n's CLI export | Workflows and credentials as files | Wherever you copy it |
Add your SSH key to the project, then run docker exec <db-container> pg_dump -U <user> <database> > n8n.sql on the server.
A dump restores cleanly into this deployment. Restored anywhere else, its credentials need this deployment's encryption key, so export credentials with n8n's CLI as well.
Start fresh on this template.
Export your workflows as JSON from the n8n editor.
Import them into the new instance.
Add your credentials again.
Credentials are encrypted with the old instance's key, which is why workflow files leave them behind.
Tell us how many executions you run a day and how long you keep history. We reply with the database we would pick, the server size and the monthly cost.
Self hosted n8n uses SQLite unless you configure Postgres. n8n Cloud runs SQLite on its Starter and Pro plans too, keeping Postgres for Enterprise Scaling. Our n8n pricing guide shows what each n8n Cloud plan costs. This template configures Postgres from the start, so workflows, executions and credential records go into PostgreSQL 16 rather than a single file on disk.
No. The Postgres node is a step inside a workflow that reads from or writes to a database you point it at. This page is about where n8n keeps its own data. The two work together: an instance running on Postgres can still use the node against any other Postgres database you own.
No. The Postgres container starts with n8n's database, user and password already in place, all generated for this deployment. On a server of your own, n8n's docs have you create the database, grant the user its privileges and write the password into n8n's settings before the first start.
n8n uses the public schema unless DB_POSTGRESDB_SCHEMA says otherwise; this template leaves it at public. You never create the tables yourself: n8n runs its migrations against that schema every time it starts, adding whatever tables and columns a new version needs.
The credential records sit in Postgres, encrypted. The key that decrypts them does not: n8n keeps it in its own data volume. We pin it as a platform secret on this template. That is why a redeploy keeps every saved API key and OAuth token working.
The disk holding n8n's SQLite file has run out of space, usually because execution history grew. n8n prunes old runs by default, but a SQLite file keeps its size until it is vacuumed. Clearing space fixes the error. On Postgres, the space pruned runs leave behind is reused for new ones.
The 4 GB server comes with 40 GB of fixed disk, shared by n8n, Postgres and anything else in the project. It does not grow, so if you keep long execution history, the 4 GB cpx21 with 80 GB is the better start. n8n's default pruning keeps the newest 10,000 runs.
Start fresh on this template: export your workflows as JSON from the n8n editor, import them into the new instance and add your credentials again. Credentials are encrypted with the old instance's key, which is why they do not travel inside workflow files. Delete the SQLite service once everything runs.
Selfhost.dev is a managed self hosting platform for developers and small teams. Open-source apps and databases on dedicated servers you control, billed by the hour with no subscription tiers.
Best for: n8n, Twenty CRM, Supabase and managed PostgreSQL, MySQL, Redis, ClickHouse, OpenSearch and Kafka.