# Self-host n8n with Postgres

What a stable self-hosted n8n needs: Postgres instead of SQLite, a fixed encryption key, a public webhook URL, and a backup you have restored.

Canonical URL: https://unbroker.cloud/blog/self-host-n8n
Published: 2026-11-01
Reviewed: 2026-11-01
Author: Timoteo Borgobello

## What you need to self-host n8n

A stable self-hosted n8n is five things: the n8n container, Postgres instead of the default SQLite file, a persistent volume for the n8n user folder, an encryption key you set once and keep, and a public URL for webhooks.

n8n listens on port 5678. n8n's Docker install runs the `n8nio/n8n` image and maps that port. The template on this page runs on Cloud Apps. A [Linux cloud server](https://unbroker.cloud/cloud-servers) is the other shape, when you want to operate the host yourself. If that host runs a PaaS panel, what stays with you is [self-hosted PaaS](https://unbroker.cloud/blog/self-hosted-paas). The [n8n template](https://unbroker.cloud/templates/n8n) on Unbroker runs `n8nio/n8n:2.44.1` on the same port, with a private Postgres 16 service, a 1 GiB volume for n8n data, and a 1 GiB volume for Postgres. This note is the settings that keep that layout stable. Connecting an app to Postgres, and restoring it, is the separate note [Postgres in production](https://unbroker.cloud/blog/postgres-in-production). A multi-service stack such as Supabase is a different inventory: [Self-host Supabase](https://unbroker.cloud/blog/self-host-supabase).

## Why Postgres instead of SQLite

By default, n8n uses SQLite to save credentials, past executions, and workflows. The file is `~/.n8n/database.sqlite` when you have not configured a database. n8n also supports PostgreSQL. You select it with `DB_TYPE=postgresdb`, then set `DB_POSTGRESDB_HOST`, `DB_POSTGRESDB_PORT`, `DB_POSTGRESDB_DATABASE`, `DB_POSTGRESDB_USER`, and `DB_POSTGRESDB_PASSWORD`. The database name defaults to `n8n`. The user defaults to `postgres`. The host defaults to `localhost` and the port to `5432`.

n8n's database page lists PostgreSQL 16 as the extra compatibility major, beside 17 and 18, in a note dated July 2026. The same page says that range moves each November, so read it again before you pick a different major. Queue mode on SQLite is not recommended, and a distributed queue over SQLite is not supported. The template does not enable queue mode. It sets `DB_TYPE=postgresdb` and points the Postgres variables at a private Postgres 16 service. Workflows, executions, and users live in that database.

That database is an Apps node you operate: a database image, a volume, and recovery of that volume. It is not a [managed Postgres](https://unbroker.cloud/managed-databases/postgres) cluster. Managed Postgres on Unbroker requires Pro. The smallest catalogue plan is 1 vCPU, 1 GB of RAM, and 10 GB of storage at $21.21 per month, separate from the Pro fee.

<aside class="plan-box">
<p><strong>On Unbroker.</strong> The template's database service is private Postgres 16 with a 1 GiB volume. You handle engine upgrades and recovery of that volume. A managed cluster is a different product. The plan list is on <a href="/managed-databases/postgres">managed Postgres</a>.</p>
</aside>

## The encryption key

n8n encrypts credentials before they are saved. If you do not set a key, n8n generates a random one on first launch and saves it in the user folder. `N8N_ENCRYPTION_KEY` is how you provide that key yourself, before it is written into the settings file. Without the key, a restored database or an encrypted credential export cannot be decrypted.

The template generates `N8N_ENCRYPTION_KEY` for you. Do not change or delete it. If you lose it, the stored credentials become unreadable. n8n's rotation notes say this instance key does not change: it protects the data encryption keys. Take a full database backup before you turn that rotation on.

`N8N_USER_FOLDER` is the path where n8n creates the `.n8n` folder. The template sets it to `/data` and mounts a 1 GiB volume there, for credential files and community nodes. With Postgres, the database is outside that folder. The folder still holds the n8n config, so it belongs in the backup.

## Webhook URL and custom domains

n8n builds a webhook URL from its protocol, host, and port. Behind a reverse proxy that combination is the internal address, not the public one. Set the webhook base URL so the editor shows the URL you registered with other services.

n8n's docs name `N8N_WEBHOOK_URL` for that base URL, covering both test and production webhooks. `WEBHOOK_URL` is a deprecated alias from n8n 2.35.0. It still works, and n8n logs a deprecation warning on startup. The template image is `n8nio/n8n:2.44.1`, and the template sets `WEBHOOK_URL` to the public service URL.

`N8N_EDITOR_BASE_URL` is the public URL of the editor. n8n also uses it in emails and as the redirect URL for SAML. The template sets it to the same public URL, and sets `N8N_PROXY_HOPS` to `1`, which is the hop count the reverse-proxy docs ask for. Those docs also list `X-Forwarded-For`, `X-Forwarded-Host`, and `X-Forwarded-Proto` on the last proxy when you run that proxy yourself.

If you add a custom domain, update `WEBHOOK_URL` and `N8N_EDITOR_BASE_URL` so both match that domain. The template does not rewrite them for you.

## Claim the owner account

The first time you open n8n, the app shows a signup screen. The account you create there is the instance owner. The password must be at least eight characters, including a number and a capital letter. The template says the first person to open the URL gets that signup. Open it yourself as soon as the service is up.

n8n recommends an SMTP server for invites and password resets, and says SMTP is optional from n8n 0.210.1. If you skip it, users cannot reset passwords. The template does not configure SMTP.

## Keep executions from filling the database

Finished executions, and the data saved with them, are what grow the database. n8n deletes that history on a rolling basis, and pruning is on by default.

`EXECUTIONS_DATA_PRUNE` defaults to `true`. A finished execution qualifies when it is older than `EXECUTIONS_DATA_MAX_AGE` hours, or when the stored count passes `EXECUTIONS_DATA_PRUNE_MAX_COUNT`. The age default is 336 hours, which is 14 days. The count default is 10,000. Set the count to `0` for no count limit. When the count is what triggers pruning, n8n deletes from oldest to newest. Executions in `new`, `running`, or `waiting` are not eligible. Annotated executions, such as ones with tags or ratings, are never pruned.

The template does not set these variables, so those defaults apply. Change `EXECUTIONS_DATA_MAX_AGE` when 14 days is the wrong window. On the default SQLite database, pruned rows do not free disk until a vacuum. The template uses Postgres, so that SQLite limit does not apply to it.

## Timezone, schedule triggers, and memory

The Schedule Trigger uses the workflow timezone if that workflow sets one. Otherwise it uses the instance timezone. n8n's default instance timezone is `America/New_York`. `GENERIC_TIMEZONE` changes it. The Schedule node reads that value to decide when a workflow starts.

The template exposes a `TIMEZONE` input. The default is `UTC`. The template writes that value to both `GENERIC_TIMEZONE` and `TZ`. A schedule on this template runs in UTC unless you set `TIMEZONE` at deploy, or set a timezone on the workflow.

The template notes that schedule and polling triggers run inside the n8n process, so the service has to stay running if you rely on them. The template is an image service with a persistent volume, and both of those stay at one replica. You raise memory in the service's Scale tab when a workflow needs more. You do not add a second replica. Image services and services with a persistent volume stay always-on. On-demand sleep is not available for them.

## Backups and upgrades

n8n's backup note asks for two copies: the user folder, and the external database when you use PostgreSQL. Credentials in the database are encrypted. A restore that does not include the encryption key cannot decrypt them. n8n recommends a full backup before an update. Load that backup once before you call it a plan. A file you have never restored is not a restore.

On Unbroker, n8n data is the 1 GiB volume mounted at `/data`. Postgres is its own 1 GiB volume. A volume survives a redeploy, a restart, and a rollback of the code. Reset, detach, and deleting the service remove the volume's data. Volume backups go to an S3-compatible bucket you control, on a schedule you set, and they require Pro. Images recognized as Postgres, including `pgvector/pgvector`, get `pg_dump` backups. The Apps Postgres preset runs `pgvector/pgvector:pg16`. The volume path is on [persistent storage](https://unbroker.cloud/solutions/persistent-files).

The template pins `n8nio/n8n:2.44.1`. Move off that tag only after a restore of both the volume and the database has worked.

## Running it on Unbroker

The [n8n template](https://unbroker.cloud/templates/n8n) deploys the container, the private Postgres service, the volumes, the generated encryption key, and the public webhook URL described above. You still operate that copy. It is not n8n's hosted product.

Containers, databases, and persistent volumes require Pro. Pro is $25 per month with $25 of usage credit. The credit resets each cycle and does not roll over. Usage past the credit is billed separately. Free does not include persistent volumes or container images, so this template is not a Free deploy. [Pricing](https://unbroker.cloud/pricing) is the plan page. The rest of the catalogue is on [templates](https://unbroker.cloud/templates).

<aside class="plan-box">
<p><strong>On Unbroker.</strong> Deploy from the template when you want this layout already wired. Keep the encryption key, point a custom domain at both URL variables, and restore a backup once before you treat it as production.</p>
</aside>

## FAQ

### What do I need to self-host n8n?

The n8n container, Postgres instead of the default SQLite file, a persistent volume for the n8n user folder, an encryption key you set once and keep, and a public URL for webhooks. The [n8n template](https://unbroker.cloud/templates/n8n) wires that layout on Unbroker.

### Why use Postgres instead of SQLite for n8n?

SQLite is the default. n8n stores credentials, past executions, and workflows in ~/.n8n/database.sqlite unless you set a database. PostgreSQL is the supported server database. Set DB_TYPE to postgresdb and the DB_POSTGRESDB_HOST, DB_POSTGRESDB_PORT, DB_POSTGRESDB_DATABASE, DB_POSTGRESDB_USER, and DB_POSTGRESDB_PASSWORD variables. n8n does not recommend queue mode on SQLite, and a distributed queue over SQLite is not supported.

### What happens if I lose the n8n encryption key?

Stored credentials become unreadable. n8n encrypts credentials before saving them. N8N_ENCRYPTION_KEY is the instance key. n8n generates a random one on first launch if you do not set it. A restored database cannot be decrypted without that same key. The Unbroker template generates the key. Do not change or delete it.

### Which variable sets the n8n webhook URL?

n8n's current docs name N8N_WEBHOOK_URL. It sets the base URL for test and production webhooks behind a reverse proxy. WEBHOOK_URL is a deprecated alias from n8n 2.35.0. It still works, and n8n logs a warning on startup. The Unbroker template sets WEBHOOK_URL and N8N_EDITOR_BASE_URL to the public service URL. Update both if you add a custom domain.

### Who becomes the owner of a self-hosted n8n?

The account created on the signup screen the first time you open n8n. That account is the instance owner. The password must be at least eight characters, with a number and a capital letter. On the Unbroker template, the first person to open the URL gets that signup, so open it yourself as soon as the service is up.

### How do I keep n8n executions from filling the database?

n8n prunes finished executions by default. EXECUTIONS_DATA_PRUNE defaults to true. EXECUTIONS_DATA_MAX_AGE defaults to 336 hours (14 days). EXECUTIONS_DATA_PRUNE_MAX_COUNT defaults to 10000, and 0 means no count limit. Executions that are new, running, or waiting are not pruned. Annotated executions are never pruned. The Unbroker template does not set these variables, so the defaults apply.

### What plan does self-hosted n8n need on Unbroker?

Pro. Template container services, databases, and persistent volumes require Pro. Pro is $25 per month with $25 of usage credit, and usage is billed separately. Free does not include persistent volumes or container images. The template's Postgres is an Apps service you operate, not managed Postgres. See [pricing](https://unbroker.cloud/pricing) and [managed Postgres](https://unbroker.cloud/managed-databases/postgres).

## Related reading

- [Deploy n8n](https://unbroker.cloud/templates/n8n)
- [Managed Postgres](https://unbroker.cloud/managed-databases/postgres)
- [Postgres in production](https://unbroker.cloud/blog/postgres-in-production)
- [Persistent storage](https://unbroker.cloud/solutions/persistent-files)
- [Pricing](https://unbroker.cloud/pricing)
- [Application templates](https://unbroker.cloud/templates)
