What This Workflow Does
This automation solves a critical maintenance challenge for n8n users - managing the growing execution history that accumulates in MySQL databases. As workflows run daily, the execution logs can quickly consume significant storage space and slow down database performance.
The workflow automatically purges older execution records based on customizable retention rules, helping maintain optimal database performance while preserving recent history for troubleshooting. It's particularly valuable for businesses running numerous automated workflows where manual cleanup would be impractical.
How It Works
1. Database Connection Setup
The workflow begins by establishing a secure connection to your MySQL database where n8n execution history is stored. It verifies credentials and checks table structures before proceeding.
2. Retention Policy Application
Based on your configured retention period (default 30 days), the workflow identifies all execution records older than the threshold. You can customize this period for different workflow types.
3. Batch Processing
To prevent database locks, records are deleted in manageable batches. The workflow includes error handling to pause if issues arise and can send notifications for manual review when needed.
Who This Is For
This solution benefits any team using n8n with MySQL database backend that:
- Runs numerous automated workflows daily
- Experiences slowing database performance over time
- Needs to maintain compliance with data retention policies
- Wants to reduce cloud database storage costs
Pro tip: Schedule this workflow to run during low-traffic periods to minimize impact on active workflows.
What You'll Need
- n8n instance with MySQL database backend
- Database credentials with appropriate delete permissions
- Basic understanding of your retention requirements
- Optional: Error notification channel (email, Slack, etc.)
Quick Setup Guide
- Download and import the JSON template into your n8n instance
- Configure the MySQL node with your database credentials
- Set your desired retention period in days
- Adjust batch size based on your database capacity
- Test with a small batch before full implementation
- Schedule to run weekly or monthly based on your volume
Key Benefits
Reduced storage costs: Automatically reclaim database space by removing obsolete records, potentially saving hundreds in cloud storage fees.
Improved performance: Smaller execution tables mean faster queries and more responsive workflow executions.
Compliance ready: Maintain consistent data retention policies across all workflows without manual intervention.
Scalable solution: Handles growing workflow volumes automatically as your automation needs expand.