N8n crashes with “Out of Memory”, slow UI, 502 Bad Gateway — SQLite + many active workflows (Traefik setup)

dHi everyone,

I’m running into a serious stability issue with my self-hosted n8n instance, and after spending days debugging, I still can’t get it stable.

Below is everything I’ve diagnosed so far, and I’d really appreciate feedback from the community to confirm whether my assumptions and planned fixes are correct.dd


Symptoms

  • n8n Editor takes minutes to load (“Loading… / Redirecting…”)
  • Sometimes returns 502 Bad Gateway
  • Container restarts frequently
  • Active workflows start, but UI becomes completely unusable
  • Server shows very low CPU/RAM usage (4 vCPU, 16 GB RAM, only 3–7% used)
  • Hosted on Hostinger VPS using Docker + Traefik reverse proxy

Log Output / Errors

1. Node.js Out Of Memory (main issue)

I repeatedly get:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory


And before that:

Mark-Compact … allocation failure; scavenge might not succeed


It looks like n8n is hitting the **~4GB Node.js heap limit**, even though my server still has 10+ GB RAM available.

---

### **2. Constant Traefik / Proxy Error**
Hundreds of log entries per minute:

ValidationError: The ‘X-Forwarded-For’ header is set but the Express ‘trust proxy’ setting is false


I’m using **Traefik**, but n8n is complaining because `trust proxy` is off.

---

### **3. Huge amount of active workflows loaded on startup**
During boot:

Start Active Workflows:
Activated workflow “…”
Activated workflow “…”
(about 15+ webhooks, cron workflows, tracking workflows, etc.)


Loading all active workflows takes very long.

---

### **4. SQLite warnings**
I get:

DB_SQLITE_POOL_SIZE → Running SQLite without a pool is deprecated


and performance seems extremely slow when SQLite is under load.

---

## **My Thoughts / Hypothesis**

I suspect the issue is a combination of:

- **SQLite** (not suited for production + many active workflows)  
- **High memory usage during workflow activation**  
- **Node.js heap limit (4GB) reached → crash**  
- **Traefik not trusted → rate-limit validation errors**  
- **Many webhooks + cron workflows → heavy boot-time load**

---

## **My Setup**

- Hostinger VPS  
  - 4 vCPUs  
  - 16 GB RAM  
- Ubuntu 24.04  
- Docker deployment  
- Traefik reverse proxy  
- n8n version: 1.121.3  
- Using **SQLite** database  
- Many active workflows (webhooks, cron jobs, scheduled tasks)

---

## **My Questions to the Community**

### **1. Should I migrate from SQLite to PostgreSQL?**  
Is SQLite the root cause of the crashes?  
(High memory usage + startup bottlenecks + concurrency issues)

### **2. Should I increase the Node.js memory limit?**  
For example:


NODE_OPTIONS=–max_old_space_size=8192


Is this safe / recommended?

### **3. Is this the correct fix for the Traefik proxy issue?**


N8N_TRUST_PROXY=true


### **4. Any known best practices for n8n + Traefik?**  
Especially regarding rate limiting and forwarded headers.

### **5. Should I set `DB_SQLITE_POOL_SIZE` or is that pointless if I'm moving to Postgres anyway?**

---

## **What I would appreciate guidance on**

- Should I **definitely** move to PostgreSQL?  
- Is increasing the Node.js heap the right short-term fix?  
- Is enabling `N8N_TRUST_PROXY` enough to stop the validation errors?  
- Are my issues typical for setups with many active workflows?  
- Any recommended Docker configuration changes?

---

Thanks in advance for any insights! I want to make sure my deployment is stable and configured according to best practices.


The issue seems to be a combination of Node.js memory limits and proxy configuration. First, try increasing Node.js heap size by setting `NODE_OPTIONS=–max-old-space-size=8192` in your Docker environment variables. For the Traefik proxy error, add `N8N_TRUST_PROXY=true` to enable `trust proxy` in Express. Also, consider switching from SQLite to Postgres if you’re running many active workflows, as SQLite can become a bottleneck under heavy load.