# Self-host n8n (Postgres)

> n8n backed by Postgres instead of its default SQLite file, for production workflow volumes.

- Page: https://levelrail.com/templates/n8n-postgres/
- JSON: https://levelrail.com/templates/n8n-postgres.json
- Category: Automation
- Licence: LicenseRef-n8n-SUL (Source available)
- Source: https://github.com/n8n-io/n8n
- Upstream docs: https://docs.n8n.io/hosting/installation/server-setups/postgresql/

## Requirements
- Memory: about 1 GiB
- amd64: published, arm64: published
- Needs configuration before start: no
- Pinned image tag: 2.10.2

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| n8n | n8nio/n8n | 2.10.2 | 5678 | n8n_postgres_data -> /home/node/.n8n |
| postgres | postgres | 16-alpine | none | n8n_postgres_db_data -> /var/lib/postgresql/data |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| n8n | DB_POSTGRESDB_DATABASE | preset |
| n8n | DB_POSTGRESDB_HOST | preset |
| n8n | DB_POSTGRESDB_PASSWORD | generated |
| n8n | DB_POSTGRESDB_PORT | preset |
| n8n | DB_POSTGRESDB_USER | preset |
| n8n | DB_TYPE | preset |
| n8n | N8N_ENCRYPTION_KEY | generated |
| n8n | N8N_PORT | preset |
| n8n | N8N_PROTOCOL | preset |
| n8n | WEBHOOK_URL | preset |
| postgres | POSTGRES_DB | preset |
| postgres | POSTGRES_PASSWORD | generated |
| postgres | POSTGRES_USER | preset |

## Deploy

### CLI

```bash
levelrail-cli templates deploy n8n-postgres --name my-n8n-postgres
```

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" \
  https://levelrail.example.com/api/v1/service-templates/n8n-postgres/deploy
```

Create a token in the dashboard first. This one-click route deploys it as a trial app you can keep or remove.

## Questions

### Can I deploy n8n (Postgres) on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for n8n (Postgres), so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image n8nio/n8n:2.10.2, postgres:16-alpine is what you deploy there.

Self-host n8n (Postgres), n8n (Postgres) docker compose file, deploy n8n (Postgres) on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
