This workflow corresponds to n8n.io template #6833 — we link there as the canonical source.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "fc2eb1d2-8c2e-4956-a084-ef685652cdbd",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
320,
-32
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 2
}
]
}
},
"typeVersion": 1.2
},
{
"id": "f528c67c-0077-4d84-a756-5b9020b838d8",
"name": "Get many executions",
"type": "n8n-nodes-base.n8n",
"position": [
816,
-32
],
"parameters": {
"limit": 250,
"filters": {},
"options": {
"activeWorkflows": false
},
"resource": "execution",
"requestOptions": {}
},
"credentials": {
"n8nApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "9e3f98f2-f2f6-4d15-8858-1dacc46582a0",
"name": "Code",
"type": "n8n-nodes-base.code",
"position": [
1824,
-32
],
"parameters": {
"jsCode": "const executionsToKeep = $input.first().json.executionsToKeep ?? 10;\n\n// Filtrar ejecuciones v\u00e1lidas (con workflowId y startedAt)\nconst validExecutions = items.filter(item =>\n item.json.workflowId && item.json.startedAt\n);\n\n// Agrupar por workflowId\nconst grouped = {};\nfor (const item of validExecutions) {\n const wfId = item.json.workflowId;\n if (!grouped[wfId]) grouped[wfId] = [];\n grouped[wfId].push(item);\n}\n\n// Ordenar por startedAt descendente (m\u00e1s reciente primero)\nfor (const wfId in grouped) {\n grouped[wfId].sort((a, b) =>\n new Date(b.json.startedAt) - new Date(a.json.startedAt)\n );\n}\n\n// Obtener ejecuciones a eliminar\nlet toDelete = [];\nfor (const wfId in grouped) {\n const executions = grouped[wfId];\n if (executions.length > executionsToKeep) {\n toDelete = toDelete.concat(executions.slice(executionsToKeep));\n }\n}\n\nreturn toDelete;\n"
},
"typeVersion": 2
},
{
"id": "68e8939a-10f0-4a65-a56c-5f643d2dceec",
"name": "Delete an execution",
"type": "n8n-nodes-base.n8n",
"position": [
2304,
-32
],
"parameters": {
"resource": "execution",
"operation": "delete",
"executionId": "={{ $json.id }}",
"requestOptions": {}
},
"credentials": {
"n8nApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "c59692b1-8dc8-44f8-bd31-dcc3898a2978",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-800,
-880
],
"parameters": {
"width": 896,
"height": 1680,
"content": "# \ud83e\uddf9 Automatically Clean Up Old Executions in n8n (Keep Only the Most Recent Per Workflow)\nMake your n8n instance faster, cleaner, and more efficient by deleting old workflow executions \u2014 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.\n\n## \ud83d\udd0d Description\nAutomatically clean up old executions in your n8n instance using only official nodes \u2014 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.\n\nIdeal 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.\n\n\u2705 What It Does\n* Retrieves up to 250 recent executions across all workflows\n* Groups executions by workflow\n* Keeps only the most recent N executions per workflow (value is configurable)\n* Deletes all older executions (regardless of their status: success, error, etc.)\n* Works entirely with native n8n nodes \u2014 no external database access required\n* Optionally: set the number of executions to keep as 0 to delete all past executions from your instance in a single run\n\n## \ud83d\udee0\ufe0f How to Set Up\n\ud83d\udd11\u2002Create a Personal API Key in your n8n instance:\nGo to Settings \u2192 API Keys \u2192 Create a new key\n\n\ud83d\udd27\u2002Create a new n8n API Credential (used by both nodes):\nIn your n8n credentials panel:\n\nName: anything you like (e.g., \u201cInternal API Access\u201d)\n\nAPI Key: paste the Personal API Key you just created\n\nBase URL: your full n8n instance URL with the /api/v1 path, e.g.\nhttps://your-n8n-instance.com/api/v1\n\n\u2705\u2002Use this credential in both:\n\nThe Get Many Executions node (to fetch recent executions)\n\nThe Delete Many Executions node (to remove outdated executions)\n\n\ud83e\udde9\u2002In the \u201cSet Executions to Keep\u201d node:\n\nEdit the variable executionsToKeep and set the number of most recent executions to retain per workflow (e.g. 10)\n\nTip: Set it to 0 to delete all executions\n\n\ud83d\udce6\u2002Note: The \u201cGet Many Executions\u201d node will retrieve up to 250 executions per run \u2014 this is the maximum allowed by the n8n API.\n\n\ud83e\udde0\u2002No further setup is required \u2014 the filtering and grouping logic is handled inside the Code Node automatically.\n\n\n## \ud83e\uddea Included Nodes Overview\n\ud83d\udd52 Schedule Trigger \u2192 Set to run daily, weekly, etc.\n\n\ud83d\udce5 Get Many Executions \u2192 Fetches past executions via n8n API\n\n\ud83d\udee0\ufe0f Set Executions to Keep \u2192 Set how many recent ones to keep\n\n\ud83e\udde0 Code Node \u2192 Filters out executions to delete per workflow\n\n\ud83d\uddd1\ufe0f Delete Executions \u2192 Deletes outdated executions\n\n## \ud83d\udca1 Why Use This?\nReduce clutter and improve performance in your n8n instance\n\nMaintain execution logs only when they\u2019re useful\n\nAvoid bloating your storage or database with obsolete data\n\nCompatible with both n8n Cloud and self-hosted setups\n\nUses only official, supported n8n nodes \u2014 no SQL, no extra setup\n\n\ud83d\udd12 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.\n\n\n\n\n"
},
"typeVersion": 1
},
{
"id": "8ecf0fc5-9917-474c-b3f2-32d45ecf7059",
"name": "Set Executions to Keep",
"type": "n8n-nodes-base.set",
"position": [
1328,
-32
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "a7f3a2de-0606-434c-8a81-4bf64e766899",
"name": "executionsToKeep",
"type": "number",
"value": 10
}
]
},
"includeOtherFields": true
},
"typeVersion": 3.4
},
{
"id": "a249ad6e-6abc-42b8-a272-506c0f3f76a6",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
128,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# \ud83d\udd52 Schedule Trigger\nThis node defines how often the cleanup workflow should run. You can schedule it to execute daily, weekly, or at any custom interval.\n[to learn more about Schedule Trigger node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.scheduleTrigger)"
},
"typeVersion": 1
},
{
"id": "7f7c076d-2bb6-4cef-88c2-6fef8e22f4e1",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
624,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# \ud83d\udce5 Get Many Executions\nFetches up to 250 of the most recent executions from your n8n instance. It includes data like workflow ID, execution status, and timestamps.\n[to learn more about Get Many Executions node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.n8n/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.n8n#get-many-executions)"
},
"typeVersion": 1
},
{
"id": "b2be8559-6cbd-4778-8830-4fa467efe363",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1120,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# \ud83d\udee0\ufe0f Set Executions to Keep\nThis node defines how many of the most recent executions per workflow should be kept. You can easily adjust the executionsToKeep variable \u2014 set it to 10, 5, or 0 to delete all.\n[to learn more about Set node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.set/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.set)"
},
"typeVersion": 1
},
{
"id": "f31f51a1-70ba-46f5-adbb-4752b6c6d2c8",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1616,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# \ud83e\udde0 Code Node (Filter Executions to Delete)\nThis node processes the list of executions, groups them by workflow ID, sorts each group by most recent first, and filters out the oldest executions beyond the number you want to keep. Running executions are automatically excluded.\n[o learn more about Code node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.code)"
},
"typeVersion": 1
},
{
"id": "a7b5add2-eab2-4b79-b7d3-6e84fb4dc118",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
2112,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# \ud83d\uddd1\ufe0f Delete Many Executions\nDeletes the selected executions using the official n8n API. It works in bulk and uses the same API credential as the \"Get Many Executions\" node.\n[to learn more about Delete Executions node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.n8n/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.n8n#delete-execution)"
},
"typeVersion": 1
},
{
"id": "00e57fb6-961a-4e85-81c6-2de04f301a93",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
128,
-880
],
"parameters": {
"color": 3,
"width": 2432,
"height": 128,
"content": "# \u2757 This workflow deletes data. Always test in staging before enabling in production. "
},
"typeVersion": 1
}
],
"connections": {
"Code": {
"main": [
[
{
"node": "Delete an execution",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Get many executions",
"type": "main",
"index": 0
}
]
]
},
"Delete an execution": {
"main": [
[]
]
},
"Get many executions": {
"main": [
[
{
"node": "Set Executions to Keep",
"type": "main",
"index": 0
}
]
]
},
"Set Executions to Keep": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
n8nApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
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…
Source: https://n8n.io/workflows/6833/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Workflow 2469. Uses moveBinaryData, googleDrive, itemLists, n8n. Scheduled trigger; 33 nodes.
Perfect for content publishing with organic scheduling patterns, social media automation, API systems that need to avoid rate limiting, or any automation requiring randomised timing control across mul
Complete backup solution that saves both workflows and credentials to local/server disk with optional FTP upload for off-site redundancy.
Click here to access this Workflow for free.
This workflow will activate and deactivate a selected other workflow on schedule.