This stack runs n8n with PostgreSQL as the workflow database backend.
It is suitable for more durable/self-hosted setups than SQLite-only deployments.
flowchart LR
User([User]) -->|:5678| N8N[n8n]
N8N --> PG[(PostgreSQL)]
N8N --> Webhooks[Webhooks]
postgresstarts and stores n8n data persistently.n8nconnects to PostgreSQL using the configured DB environment variables.- Workflows, credentials, and execution state are saved in Postgres.
- n8n editor/API is exposed on port
5678.
- n8n image:
docker.n8n.io/n8nio/n8n:latest - PostgreSQL image:
postgres:15 - n8n UI/API:
http://<host-ip>:5678 - Persistent data:
data:/root/.n8npostgres_data:/var/lib/postgresql/data
Copy .env.example to .env, then adjust values:
POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DBDB_POSTGRESDB_*settingsN8N_*runtime/security/URL settingsWEBHOOK_URL,TZ
From the repository root:
cd n8n+postgresql
cp .env.example .env
docker compose up -dOpen:
http://localhost:5678
Useful commands:
docker compose ps
docker compose logs -f
docker compose restart
docker compose down- Avoid committing real credentials/URLs in
.env. - If exposed behind reverse proxy, keep
N8N_HOST,N8N_PROTOCOL, and webhook URLs consistent.