Skip to main content

Automated execution cleanup system with n8n API and custom retention rules

Workflow preview

Workflow preview
100%
Automated execution cleanup system with n8n API and custom retention rules preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Make your n8n instance faster, cleaner, and more efficient by deleting old workflow executions — while keeping only the most recent ones you actually need. Whether you're using n8n Cloud or self ho...

Best for

  • DevOps automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.scheduletrigger, n8n-nodes-base.n8n, n8n-nodes-base.code, n8n-nodes-base.stickynote, n8n-nodes-base.set

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Arlin Perez.

Original n8n.io source

1.1 Workflow description

Title
Automated execution cleanup system with n8n API and custom retention rules
Workflow name
Automated execution cleanup system with n8n API and custom retention rules

Make your n8n instance faster, cleaner, and more efficient by deleting old workflow executions — while keeping only the most recent ones you actually need. Whether you're using n8n Cloud or self-hosted, this lightweight workflow helps reduce database/storage usage and improves UI responsiveness, using only official n8n nodes.

🔍 Description

Automatically clean up old executions in your n8n instance using only official nodes — no external database queries required. Whether you're on the Cloud version or running self-hosted, this workflow helps you optimize performance and keep your instance tidy by maintaining only the most recent executions per workflow.

Ideal for users managing dozens or hundreds of workflows, this solution reduces storage usage and improves the responsiveness of the n8n UI, especially in environments where execution logs can accumulate quickly.

✅ What It Does

  • Retrieves up to 250 recent executions across all workflows
  • Groups executions by workflow
  • Keeps only the most recent N executions per workflow (value is configurable)
  • Deletes all older executions (regardless of their status: success, error, etc.)
  • Works entirely with native n8n nodes — no external database access required
  • Optionally: set the number of executions to keep as 0 to delete all past executions from your instance in a single run

🛠️ How to Set Up

🔑 Create a Personal API Key in your n8n instance: Go to Settings → API Keys → Create a new key

🔧 Create a new n8n API Credential (used by both nodes): In your n8n credentials panel:

Name: anything you like (e.g., “Internal API Access”)

API Key: paste the Personal API Key you just created

Base URL: your full n8n instance URL with the /api/v1 path, e.g. https://your-n8n-instance.com/api/v1

✅ Use this credential in both:

The Get Many Executions node (to fetch recent executions)

The Delete Many Executions node (to remove outdated executions)

🧩 In the “Set Executions to Keep” node:

Edit the variable executionsToKeep and set the number of most recent executions to retain per workflow (e.g. 10)

Tip: Set it to 0 to delete all executions

📦 Note: The “Get Many Executions” node will retrieve up to 250 executions per run — this is the maximum allowed by the n8n API.

🧠 No further setup is required — the filtering and grouping logic is handled inside the Code Node automatically.

🧪 Included Nodes Overview

🕒 Schedule Trigger → Set to run daily, weekly, etc.

📥 Get Many Executions → Fetches past executions via n8n API

🛠️ Set Executions to Keep → Set how many recent ones to keep

🧠 Code Node → Filters out executions to delete per workflow

🗑️ Delete Executions → Deletes outdated executions

💡 Why Use This?

Reduce clutter and improve performance in your n8n instance

Maintain execution logs only when they’re useful

Avoid bloating your storage or database with obsolete data

Compatible with both n8n Cloud and self-hosted setups

Uses only official, supported n8n nodes — no SQL, no extra setup

🔒 This workflow modifies and deletes execution data. Always review and test it first on a staging instance or on a limited set of workflows before using it in production.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Schedule Trigger

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

Block 2 - Get many executions

Type / Role
n8n-nodes-base.n8n - n8n
Config choices
Version 1

Block 3 - Code

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 4 - Delete an execution

Type / Role
n8n-nodes-base.n8n - n8n
Config choices
Version 1

Block 5 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Set Executions to Keep

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 7 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Automated execution cleanup system with n8n API and custom retention rules
Complexity intermediate
Nodes 12
Categories DevOps
Author Arlin Perez
Published 02 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/6833/6833.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Automated execution cleanup system with n8n API and custom retention rules do?

Make your n8n instance faster, cleaner, and more efficient by deleting old workflow executions — while keeping only the most recent ones you actually need. Whether you're using n8n Cloud or self ho...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your DevOps use case.