Use this powerful n8n workflow template to automatically clean up old execution logs in your n8n instance. Improve performance, reduce storage, and keep only the recent executions using the official n8n API.
Download this n8n workflow template and start using it instantly.
Markdown-formatted string:
n8n Instance Administrators: Users managing self-hosted or n8n cloud instances needing to optimize database performance.
DevOps Teams: Professionals looking for automated maintenance solutions using an n8n workflow.
Users with High Execution Volume: Individuals whose n8n workflow runs hundreds of times per day, leading to storage bloat.
n8n Developers: Those seeking a robust example of utilizing the internal n8n API node for system management tasks.
Managing the execution logs generated by active n8n workflows is crucial for maintaining performance and minimizing storage costs. If you run many n8n templates frequently, your database can quickly become bloated, slowing down the n8n UI. This innovative n8n workflow solves this problem by providing a hands-off, scheduled cleanup mechanism. It uses the internal n8n API to retrieve execution data, applies a retention rule (keeping the N most recent runs per workflow), and uses the n8n node dedicated to execution deletion. This ensures that only relevant, recent data remains, drastically improving your overall n8n experience. This entire process relies solely on core n8n nodes, making it reliable across both n8n Cloud and self-hosted environments.
Markdown-formatted string:
executionsToKeep variable, which is set to 10 by default, defining how many recent executions must be retained per unique workflow ID.workflowId, sorting each group by start time (newest first), and identifying all executions that exceed the configured executionsToKeep limit. The output is a filtered list containing only the execution items scheduled for deletion.Markdown-formatted string:
/api/v1 (e.g., https://my.n8n.cloud/api/v1).executionsToKeep value if you wish to retain a different number of recent logs (e.g., set it to 5 instead of 10).Markdown-formatted string:
Schedule Trigger (n8n trigger)
Function: Starts the n8n workflow automatically.
Key Configuration: Set to run daily at 2 AM (triggerAtHour: 2).
Get many executions (n8n node - n8n API)
Function: Queries the n8n API for a list of recent execution logs.
Key Configuration: Resource: execution, Limit: 250 (max limit per call). Requires n8n API credential.
Set Executions to Keep (Set n8n node)
Function: Defines the retention rule that the workflow must follow.
Key Configuration: Creates the variable executionsToKeep with a value of 10 (the number of most recent executions to keep per workflow).
Code (n8n node)
Function: Executes the complex logic to group executions by workflow ID, sort them by date, and filter out those that are older than the retention limit.
Key Configuration: Custom JavaScript logic that identifies IDs of executions eligible for deletion.
Delete an execution (n8n node - n8n API)
Function: Calls the n8n API to delete specific execution records.
* Key Configuration: Operation: delete, Execution ID: dynamically set to ={{ $json.id }} from the previous step. Uses the same n8n API credential.
Use this comprehensive n8n workflow to automate event registration via Typeform, process payments with Stripe, manage participants in Google Sheets, and schedule automated Gmail reminders and follow-ups. Perfect for event organizers.

Centralize your n8n workflow error handling. Automatically notify teams via email and use OpenAI (GPT-4o) for instant error diagnostics and resolution suggestions.

Automate the end-to-end fine-tuning process for OpenAI models using this advanced n8n workflow. Integrate Google Drive data, upload files, and deploy your custom models instantly.

Use this advanced n8n workflow to automate expense approvals using GPT-4 for analysis, Airtable for data management, and Pinecone for auditable vector storage. Explore powerful n8n templates.

Use this powerful n8n workflow to automatically parse bank transaction emails (Gmail) and manual entries (Telegram) using Gemini AI, logging all expenses and budgets directly into Google Sheets. Simplify finance tracking with this advanced n8n template.

Analyze weekly WhatsApp group transcripts using GPT-4 via this robust n8n workflow. Automatically identify frequent questions and generate an organized FAQ document in Google Docs. Get started with powerful n8n templates.

👋 Hi! I'm Arlin - a QA Engineer with 2 years of experience and a background in Dart & Flutter for mobile app development. ⚙️ I'm passionate about automation and love building efficient workflows using n8n. 📬 Reach out for any help with custom workflows







































