Automated Execution History Pruning for n8n Self-Hosted - n8n Workflow

Optimize your self-hosted n8n instance performance by automatically deleting old execution history. This essential n8n workflow uses the internal n8n node to manage database size.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • n8n administrators managing self-hosted instances.

  • DevOps teams focused on automation maintenance and resource management.

  • Users looking to maintain optimal long-term performance for their n8n installation.

  • Anyone utilizing n8n templates for robust infrastructure management.

Overview

For users running self-hosted instances of n8n, the execution history database can grow rapidly, potentially impacting overall performance and consuming unnecessary storage. This critical n8n workflow provides a set-and-forget solution for database hygiene. By leveraging the powerful internal n8n node, this automation lists all historical runs and deletes any record older than 10 days. This essential cleanup ensures system stability and keeps your resource consumption optimized. Deploying this n8n template is a key step toward sustainable, long-term n8n operation.

How it Works

This administrative n8n workflow operates on a scheduled basis, ensuring continuous maintenance without manual intervention.


  1. Trigger Initiation: The process is primarily initiated by the Schedule Trigger, set to run daily (e.g., at 4:44 AM). A manual n8n trigger is also available for testing purposes.

  2. List All Executions: The first internal n8n list execution n8n node connects to the instance's API to retrieve a comprehensive list of all past workflow executions (resource: execution). It utilizes the 'Return All' option to process the entire history.

  3. Date Filtering: The If n8n node evaluates each execution record individually. It checks if the execution's start time ($json.startedAt) is chronologically 'before' a dynamically calculated date—specifically, 10 days ago. This is the core logic of the retention policy.

  4. Pruning Action: If the condition is True (the record is older than 10 days), the execution is passed to the delete execution n8n node. This node uses the execution ID ($json.id) derived from the incoming item to delete the specific historical record.

  5. Retention: If the condition is False (the record is recent), the execution item is passed to the No Operation, do nothing n8n node, ensuring recent history is preserved. This continuous, automated cycle keeps your n8n execution log optimized.

Installation Guide

To deploy this n8n workflow template and begin pruning old data, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n canvas using the 'New' menu -> 'Import from JSON'.

  2. Internal API Credential Setup: This n8n workflow relies on the internal n8n node to manage the instance itself. You must configure an 'n8n Api' credential. This usually requires generating an API Key for your n8n instance, which serves as the authentication method for the internal n8n node.

  3. Connect Credential: Ensure the API credential is correctly selected for the n8n list execution and delete execution nodes.

  4. Activate: Set the Schedule Trigger to your desired maintenance time, and then activate the n8n workflow.

Node Details


  • Schedule Trigger: Acts as the primary n8n trigger for routine maintenance. It is configured to run automatically at a specified time (4:44 AM) to minimize impact during peak usage hours.

  • n8n list execution (n8n node): Connects to the local n8n API. Its function is to retrieve all execution records by setting Resource to execution and enabling Return All.

  • If (Core Logic Flow Control): This crucial n8n node implements the retention rule. It checks if startedAt is before Date.now() - 10 days. This condition controls which records are targeted for deletion.

  • delete execution (n8n node): This is the action node. If the If statement returns True, this n8n node takes the incoming execution ID ({{ $json.id }}) and performs a delete operation on the execution resource, removing the old log entry permanently.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Danger
Danger

Featured*