n8n + PostgreSQL 16 Production Hardening: Prevent OOM Kills, Disk Full & Webhook 502 (2026)
90% of self-hosted n8n outages come from three misconfigurations: unbounded execution logs filling the disk, missing 2 GB swap causing Linux OOM kills, and mismatched WEBHOOK_URL headers causing 502/OAuth failures. Apply the 4-step hardening block below to keep n8n + PostgreSQL 16 running for months unattended.
| Symptom / Log Error | Root Cause | Verified Fix | Prevention Metric |
|---|---|---|---|
| Container exits with code 137 | Linux OOM Killer (RAM spike > limit) | Add 2 GB swap + NODE_OPTIONS=--max-old-space-size=2048 | Keep peak RSS < 70% of node RAM |
| SQLITE_BUSY / database is locked | Concurrent webhooks hitting SQLite | Migrate to PostgreSQL 16 (31 MB idle RSS) | Zero write-lock retries |
| No space left on device (ENOSPC) | Unpruned binary/JSON execution logs | EXECUTIONS_DATA_PRUNE=true + MAX_AGE=168 | Disk usage flat < 55% |
| Secure cookie / OAuth redirect_uri_mismatch | HTTP mismatch or missing WEBHOOK_URL | Caddy 443 TLS + WEBHOOK_URL=https://domain/ | HTTP 200 on /healthz |
1. Why Default n8n Docker Tutorials Break in Week 3
Most quickstart posts run n8n on SQLite with default log retention. Once an AI agent runs every 5 minutes storing JSON tool responses, the SQLite database balloons past 15 GB, causing sluggish UI loads and sudden ENOSPC crashes.
Switching to PostgreSQL 16 adds only ~31 MB idle RSS (confirmed on our live Linux 6.8 host) while enabling safe concurrent writes and instant pg_dump snapshots without stopping n8n.
2. Backing Up N8N_ENCRYPTION_KEY Alongside PostgreSQL
A PostgreSQL dump is useless without your N8N_ENCRYPTION_KEY because stored OAuth tokens and API keys are encrypted at rest. Store your .env encryption key inside your password manager separately from the database dumps.
3. Fast Triage for Webhook 502 & TLS Certificate Errors
When Caddy logs ACME HTTP-01 errors, verify your DNS A record points directly to the server IP (or use Cloudflare DNS-01 / Tunnel) and confirm `ss -tulpn | grep -E ":80|:443"` shows no leftover Apache or Nginx process competing for port 80.
Verified Production Commands
# 1. Verify swap & container health
swapon --show && docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}\t{{.CPUPerc}}"
# 2. Automated nightly PostgreSQL 16 backup (add via crontab -e)
0 3 * * * docker exec nodebudget-postgres pg_dump -U n8n n8n | gzip > /root/backups/n8n-$(date +\%F).sql.gz && find /root/backups -name "n8n-*.sql.gz" -mtime +14 -delete