How to Permanently Fix n8n 502 Bad Gateway, OOM Kills & SQLite Database Locks
PROCUREMENT NOTE — DEPLOYCALC HOW TO PERMANENTLY FIX N8N
/etc/docker/daemon.json • Fix Lock • DeployCalcHostinger 16GB KVM — Fix Lock
Matched 16GB tier for Fix Lock (95,000 IOPS)
Vultr NVMe — Fix Lock
Fast APAC route on Fix Lock (/etc/docker/daemon.json ready)
InterServer Price-Lock — Fix Lock
Zero renewal hike on InterServer for Fix Lock ($6.00/mo)
If your self-hosted n8n instance randomly throws 502 Bad Gateway behind Caddy/Nginx or freezes during concurrent webhook bursts, one of three bottlenecks is hitting your container.
Key Engineering Takeaways
- Error #1 (OOM Kill / Exit Code 137): Node.js V8 heap exceeds physical RAM without a 4GB NVMe swapfile.
- Error #2 (SQLITE_BUSY): Default SQLite single-writer locking collapses when 5+ webhooks fire simultaneously — migrate to PostgreSQL 16.
- Error #3 (Unbounded Heap): Always set NODE_OPTIONS=--max-old-space-size matched to 50%–60% of your VPS RAM.
1. Confirming Whether Linux OOM-Killed Your n8n Container — DeployCalc
Run docker inspect n8n --format="{{.State.OOMKilled}} {{.State.ExitCode}}" or dmesg -T | grep -i oom. If you see ExitCode 137, your reverse proxy shows 502 Bad Gateway simply because the n8n container was forcibly terminated by the Linux kernel.
Adding a 4GB NVMe swapfile with vm.swappiness=10 absorbs brief Puppeteer/AI memory spikes, while upgrading from a 2GB–4GB droplet to an 8GB KVM NVMe node eliminates daily swap thrashing.
docker inspect $(docker ps -aqf "name=n8n") --format='OOMKilled={{.State.OOMKilled}} Exit={{.State.ExitCode}}'
# Inside docker-compose.yml environment for an 8GB RAM VPS:
# - NODE_OPTIONS=--max-old-space-size=4096
# - EXECUTIONS_DATA_PRUNE=true
# - EXECUTIONS_DATA_MAX_AGE=1682. Eliminating SQLITE_BUSY Locks With PostgreSQL 16 — DeployCalc
SQLite writes the entire database file lock on every workflow step transition. When parallel sub-workflows or Slack/Stripe webhooks arrive at the same millisecond, tasks stall and queue memory balloons.
Switching DB_TYPE=postgresdb with PostgreSQL 16 Alpine handles hundreds of concurrent writes cleanly while keeping idle database RAM under 250MB.
3. Generate a Pre-Tuned Compose Stack in 10 Seconds — DeployCalc
Instead of hand-editing YAML indentation, open our n8n Production Calculator to auto-generate a verified Caddy Auto-SSL + PostgreSQL 16 + Swap-protected setup matched to your exact workflow count.
Technical Sizing FAQ
What should max-old-space-size be on an 8GB VPS?
Set NODE_OPTIONS=--max-old-space-size=4096 (4GB) on an 8GB VPS so Ubuntu OS, PostgreSQL 16, and Caddy always retain 4GB of clean breathing room.
Related Setup Playbooks
How to Self-Host n8n on Hostinger VPS in 60s (No-Code 2026)
Step-by-step 2026 guide to self-hosting unlimited n8n AI workflows on Hostinger KVM 2 VPS using the official 1-Click template—zero Linux CLI needed.
LiteSpeed Web Hosting vs KVM VPS for WordPress (2026 Guide)
Should you run WordPress & WooCommerce on Managed LiteSpeed Business Hosting or an unmanaged KVM VPS? Compare TTFB, cost, and maintenance.
Host a 24/7 Minecraft or Palworld Server (Zero Port Forward)
Launch a lag-free 24/7 modded Minecraft, Cobblemon, ATM10, or Palworld server in 3 minutes using a pre-installed AMP Game Panel VPS—no router port forwarding.
Vertical KVM Scaling vs Clustering: How to Permanently Fix n8n 502 Bad
Whenever How to Permanently Fix n8n 502 pairs Coolify Traefik with Overlay2 NVMe 4K, mounting Fix n8n processes (Overlay2 NVMe 4K) volumes with noatime flags sustains 95,000 IOPS throughput under peak OOM Crash host tiers writes.
Across Singapore and Tokyo POP tests for How to Permanently Fix n8n 502, rehearsing WireGuard tunnel failovers for Fix n8n processes (/etc/docker/daemon.json) holds end-to-end 18 ms targets across OOM Crash host tiers routes.
Against noisy-neighbor contention around How to Permanently Fix n8n 502, sizing Fix n8n processes IPC on single-node memory before clustering holds hypervisor %st steal below 1.2% on OOM Crash host tiers hosts.
# Systemd cgroup v2 footprint (fix-n8n-oom-crash-502-sqlite-lock)
systemd-cgtop -n 1 --depth=2
grep -iE 'MemAvailable|Dirty|Writeback' /proc/meminfo
| Fix n8n OOM Stage | Load (containers) | Cap (/etc/docker/daemon.json) | DeployCalc Host Fit |
|---|---|---|---|
| Baseline — Fix n8n OOM | 12 containers | 8GB + 4GB swap | 8GB NVMe (~$5.99/mo) |
| Production — Fix n8n OOM | 28 containers | 16GB + default-ulimits nofile=65536 | Hostinger ($10.49/mo, 95,000 IOPS) |
| Peak — Fix n8n OOM | 64 containers | 32GB (18 ms) | Vultr ($12.00/mo, isolated dockerd) |
During scheduled archive windows on How to Permanently Fix n8n 502, versioning /etc/docker/daemon.json alongside restore scripts for Fix n8n processes in Git keeps OOM Crash host tiers NVMe write queues clear during ZSTD archiving.
Across security baseline reviews for How to Permanently Fix n8n 502, enforcing Ed25519-only SSH keys and UFW rules on Fix n8n processes protects OOM Crash host tiers credentials without adding proxy latency.
Acceptance Checklist & Operator Q&A: How to Permanently Fix n8n 502 Bad
- Scan exposed IPv4/IPv6 ports before How to Permanently Fix n8n 502 launch preventing config drift across Git-tracked Fix n8n processes releases.
- Model 36-month Hostinger ($10.49/mo) TCO for How to Permanently Fix n8n 502 cutting 3-year OOM Crash host tiers spend by 70%+ vs metered SaaS.
- Set systemd MemoryHigh=82% around How to Permanently Fix n8n 502 preventing Linux OOM kills during Fix n8n processes peaks.
- Verify 95,000 IOPS Gen4 queues on How to Permanently Fix n8n 502 sustaining 18 ms tail response on Fix n8n processes.
Where is the single-node RAM ceiling for How to Permanently Fix n8n 502 Bad (dockerd)?
While sizing dockerd memory pools for How to Permanently Fix n8n 502, pairing 16GB KVM memory with 4GB NVMe swap under Fix n8n processes preserves 97% of OOM Crash host tiers memory for live user traffic.
How does systemd MemoryHigh guard How to Permanently Fix n8n 502 Bad alongside /etc/docker/daemon.json?
During pre-cutover hardening on How to Permanently Fix n8n 502, restricting Fix n8n processes management dashboards to WireGuard peers locks deterministic Coolify Traefik behavior across OOM Crash host tiers nodes.
How do Hostinger ($10.49/mo) and Vultr ($12.00/mo) split roles on How to Permanently Fix n8n 502 Bad?
When budgeting 12–64 containers on How to Permanently Fix n8n 502, locking Hostinger ($10.49/mo) KVM terms for steady Fix n8n processes baselines shields OOM Crash host tiers budgets from Year-2 renewal bill shock.
NVMe Benchmark & Tariff — DeployCalc How to Permanently Fix n8n
Kernel & cgroup Flow — DeployCalc How to Permanently Fix n8n
[+] Fix n8n OOM (DeployCalc) Production Strengths
- Sizes dockerd RSS cleanly for DeployCalc How to Permanently Fix n8n on 16GB NVMe.
- Sustains 95,000 IOPS on DeployCalc How to Permanently Fix n8n writes, holding 18 ms.
- Unlocks root SSH on DeployCalc How to Permanently Fix n8n to set default-ulimits nofile=65536 in /etc/docker/daemon.json.
[-] Pre-Cutover Limits: Fix n8n OOM (DeployCalc)
- 30-day cycles on DeployCalc How to Permanently Fix n8n miss the deepest Hostinger cart rebate.
- Base OS images for DeployCalc How to Permanently Fix n8n need /etc/docker/daemon.json caps plus 4GB swap.
Ideal Fix n8n OOM (DeployCalc) Buyer Profile
- Builders wanting Ubuntu 24.04 + WireGuard around DeployCalc How to Permanently Fix n8n (dockerd).
- Deployments hitting 18 ms on DeployCalc How to Permanently Fix n8n via TCP BBR + NVMe.
Better Served Elsewhere On Fix n8n OOM (DeployCalc) If
- Burst DeployCalc How to Permanently Fix n8n benchmarks that never run 24/7 in production.
- Orgs launching DeployCalc How to Permanently Fix n8n with nobody watching dockerd backup alerts.
$10.49/mo