n8n DevOps Automation Maintenance Database

Automatically Prune n8n Execution History

Keep your n8n instance clean and performant by automatically deleting old workflow executions. Set your retention period and let automation handle the cleanup.

Download Template JSON · n8n compatible · Free
n8n workflow diagram showing automatic execution pruning with schedule trigger and delete nodes

What This Workflow Does

As you run more automations in n8n, your execution history grows rapidly. Each successful run, failed attempt, and manual trigger creates a log entry that accumulates in your database. Over time, this can consume significant storage, slow down your instance, and make it harder to find recent, relevant executions when debugging.

This workflow solves that problem automatically. It periodically scans your n8n execution history and deletes entries older than your specified retention period (default: 10 days). Think of it as a digital janitor for your automation platform—working silently in the background to keep everything tidy and performant.

Instead of manually cleaning up through the UI or running database queries, this automation handles everything on a schedule. You maintain control over how much history to keep while ensuring your instance doesn't get bogged down by outdated data.

How It Works

The workflow uses a simple but effective three-step process to identify and remove old executions while preserving recent data.

1. Scheduled Trigger & Execution Retrieval

A Schedule Trigger node runs the workflow daily at your configured time (default: 4:44 AM). When triggered, the workflow uses n8n's native "List Executions" node to fetch all execution records from your instance. This includes both successful and failed executions across all workflows.

2. Age Evaluation & Filtering

An If node evaluates each execution's start date against your configured retention period. The default condition checks if an execution is older than 10 days (10 * 24 * 60 * 60 * 1000 milliseconds). You can easily adjust this threshold to match your compliance requirements or storage constraints.

3. Selective Deletion

Executions that meet the age criteria are passed to the "Delete Execution" node, which permanently removes them from your n8n database. Executions that don't meet the criteria (recent ones) flow to a "No Operation" node, meaning they're preserved. The workflow also includes a Manual Trigger for on-demand testing before committing to automated cleanup.

Pro tip: Start with a conservative retention period (like 30 days) and monitor the results. Once confident, you can shorten the period to optimize storage further.

Who This Is For

This template is essential for any team or individual running n8n in production. It's particularly valuable for:

DevOps teams managing self-hosted n8n instances who need to control database growth and maintain system performance. Business automation managers overseeing dozens of workflows that generate significant execution data daily. Agencies and consultants who manage n8n for multiple clients and need standardized maintenance procedures. Startups and scaling companies whose automation volume is increasing and who want to prevent performance degradation.

If you've noticed your n8n instance slowing down or your database growing unexpectedly large, this workflow provides an immediate solution.

What You'll Need

  1. A running n8n instance (Cloud or self-hosted)
  2. Administrator access or API credentials with execution read/delete permissions
  3. Basic understanding of n8n workflow import/export
  4. Knowledge of your compliance requirements for data retention

Quick Setup Guide

Getting started takes just a few minutes. Follow these steps to implement automated execution pruning in your n8n instance.

  1. Download the template using the button above and save the JSON file to your computer.
  2. Import into n8n by creating a new workflow and using the "Import from File" option in your n8n editor.
  3. Configure the retention period by editing the If node's condition. Adjust the milliseconds value to match your desired days.
  4. Test with Manual Trigger first to ensure the workflow identifies and processes executions correctly.
  5. Activate the Schedule Trigger once testing is complete, setting your preferred daily run time.
  6. Monitor initial runs to verify the correct number of executions are being pruned.

Important: Always test with the Manual Trigger first and review which executions would be deleted before enabling the schedule. Consider backing up important execution data if you have compliance requirements.

Key Benefits

Reduced database storage costs by automatically removing outdated execution logs that serve no operational purpose. For high-volume users, this can save gigabytes of storage monthly.

Improved n8n instance performance as smaller databases query faster. Execution lists load more quickly, and overall system responsiveness increases.

Simplified debugging and monitoring with less clutter in your execution history. When issues occur, you can focus on recent executions rather than sifting through months of old data.

Compliance-ready data retention with configurable policies that you can adjust based on regulatory requirements or internal policies.

Zero ongoing maintenance once configured. The workflow runs autonomously, handling cleanup without manual intervention or scheduled tasks on your calendar.

Frequently Asked Questions

Common questions about n8n execution management and automation maintenance

Old workflow executions accumulate over time, consuming valuable database storage and potentially slowing down your n8n instance. Regular pruning improves system performance, reduces clutter in the execution history, and helps you focus on recent, relevant logs.

For teams running hundreds of automations, this can save significant storage costs and maintain optimal instance speed. It also makes troubleshooting easier by eliminating noise from outdated executions.

The frequency depends on your workflow volume and storage constraints. For most businesses, pruning executions older than 7-30 days is sufficient. High-volume environments might need weekly cleanup, while lighter users can prune monthly.

This template runs daily by default, but you can adjust the schedule trigger to match your specific needs and retention policies. Consider your compliance requirements and how far back you typically need to investigate issues.

Yes, you can modify the workflow to target specific workflows or apply different retention periods based on workflow importance. By adding filtering logic before the deletion step, you can preserve critical execution logs while removing less important ones.

This allows you to maintain compliance logs while cleaning up routine automation data. For example, you might keep financial workflow executions for 90 days but prune marketing automations after 7 days.

The workflow includes a configurable retention period as a safety buffer. You can set it conservatively (like 90 days) initially and gradually reduce it. For critical systems, consider implementing a backup process before pruning or using n8n's execution data export feature.

Always test the workflow in a staging environment first to ensure it meets your requirements. The template includes a Manual Trigger specifically for safe testing before enabling automated deletion.

No, pruning only removes historical execution logs from the database. It doesn't affect active workflows, their configurations, or future executions. The workflow metadata, nodes, and settings remain intact.

This is purely a maintenance operation to optimize database performance and storage usage without impacting your automation's operation. Your workflows will continue running exactly as before, just with a cleaner execution history.

Yes, this workflow works with both n8n Cloud and self-hosted deployments. For self-hosted instances, ensure your database user has appropriate delete permissions. The workflow uses standard n8n nodes that are available across all deployment types.

This makes it universally applicable for any n8n installation. The process is identical whether you're using the managed cloud service or your own infrastructure, providing consistent maintenance across your automation platform.

Beyond execution pruning, consider automations for: backing up workflow configurations, monitoring failed executions, rotating credentials, cleaning up temporary files, and archiving important execution data to external storage.

Regular maintenance ensures your automation platform remains reliable, secure, and performs optimally as your usage scales. A comprehensive maintenance strategy prevents technical debt accumulation and keeps your automations running smoothly.

  • Backup workflows to version control weekly
  • Monitor and alert on consecutive failures
  • Archive critical execution data to cloud storage

Absolutely. GrowwStacks specializes in building tailored n8n maintenance and optimization systems. We can create custom solutions for execution pruning with advanced filtering, automated backups, performance monitoring, and integration with your existing DevOps tools.

Our team ensures your n8n instance remains clean, fast, and cost-effective as your automation needs grow. We design maintenance workflows that align with your specific compliance requirements, team workflows, and infrastructure constraints.

  • Custom retention policies per workflow type
  • Integration with monitoring tools like Datadog or New Relic
  • Automated backup and disaster recovery systems
  • Performance optimization and scaling consultations

Need a Custom n8n Maintenance Automation?

This free template is a starting point. Our team builds fully tailored automation systems for your specific business needs.