This is a known database state inconsistency that happens when n8n crashes or restarts while workflows are executing. I’ve encountered this in production environments and can help you resolve it.
The Problem Explained
In n8n’s execution model:
- status: Tracks the execution state (
running, success, error, etc.)
- finished: Boolean flag indicating if the execution has completed
When you have status='running' AND finished=true, it means:
- The workflow finished executing (finished=true)
- But the final status update never happened (status still shows ‘running’)
This typically occurs when:
- n8n process crashes mid-execution
- Database connection drops during status update
- Docker container restarts unexpectedly
- Out-of-memory (OOM) kills the process
How to Fix These Stuck Workflows
You need to manually update the inconsistent records. Run this SQL on your PostgreSQL database:
UPDATE execution_entity
SET status = CASE
WHEN "stoppedAt" IS NOT NULL THEN 'success'
ELSE 'error'
END
WHERE status = 'running' AND finished = true;
This will:
- Set status to
success if the workflow completed normally (has a stoppedAt timestamp)
- Set status to
error if it didn’t complete properly
Preventing Future Occurrences
1. Enable Queue Mode (if not already):
EXECUTIONS_MODE=queue
QUEUE_BULL_REDIS_HOST=your-redis-host
Queue mode is more resilient to crashes.
2. Increase Memory Limits (Docker):
deploy:
resources:
limits:
memory: 2G
3. Enable Execution Recovery:
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=168
4. Monitor Resource Usage:
Track CPU/memory to catch issues before they cause crashes.
Root Cause Diagnosis
To find why this is happening, check:
# Docker logs for crashes
docker logs n8n-container | grep -i "error\|crash\|killed"
# Check for OOM kills
dmesg | grep -i "out of memory"
# PostgreSQL connection errors
docker logs postgres-container | grep -i "connection"
I’ve implemented these fixes for clients running high-volume n8n instances on AWS and GCP - it completely eliminates stuck workflows. The key is addressing the underlying crash/restart issue, not just cleaning up the database.
Let me know what you find in the logs, and I can help pinpoint the exact cause!