# Delete old data automatically

> Delete old OpenCTI knowledge, import files, workbenches and logs automatically with retention policies, and check what a policy will delete first.

- URL: https://filigran.io/docs/lts/7.260309-lts/opencti/configure/retention/
- Products: OpenCTI 7.260309.0-lts.8
- OpenCTI line: 7.260309 LTS · 7.260309.0-lts.8
- For: administrators, platform engineers
- Type: How-to guide

A retention policy deletes data that has not changed for a given time: old knowledge that matches your filters, imported files, workbenches, and, in recent versions, history and activity logs. It keeps the platform lean and enforces your data retention rules. This page shows how to set up a policy safely.

> **Warning**
>
> Retention deletes for good. What a policy deletes does not go to the [trash](https://filigran.io/docs/lts/7.260309-lts/opencti/use/delete-restore/) and cannot be restored. Always click **Verify** to see how many elements a policy would delete before you save it.

## Before you start {#before-you-start}

- Your role has the **Manage customization** capability.
- The retention manager is running. It is on by default (`retention_manager:enabled` in the [configuration reference](https://filigran.io/docs/lts/7.260309-lts/reference/opencti/configuration/)); when it is off, the page says so and no policy runs.

## What a policy can delete {#what-a-policy-can-delete}

The **Scope** of a policy says what it deletes. The **Apply on** column of the list shows the filters of a knowledge policy, or what a policy without filters covers: **Everything** for a knowledge policy, **Global files** (the **Files contained in** Data/Import), **All workbenches**, **Knowledge history logs** or **Activity logs**.

> **Warning**
>
> A knowledge policy that reads **Everything** has no filters: it deletes every entity and relationship of the platform, reports included, that has not been updated for its maximum retention. Check the **Apply on** column of every knowledge policy.

*(OpenCTI before 7.260811)*

| Scope | Deletes | Filters |
| --- | --- | --- |
| Knowledge | Entities and relationships that match the filters and have not been updated for the maximum retention | Yes |
| File | Files in **Data > Import** uploaded longer ago than the maximum retention, once their upload and every import from them are complete | No |
| Workbench | Workbenches not updated for the maximum retention, global ones and those attached to an entity | No |

Two policies come with the platform and run from the start: **Global files retention** and **All workbenches retention**, both set to 30 days. Change their duration if you keep imported files or workbenches longer.

The retention manager never deletes an individual that stands for a user, the platform main organization, or an organization that still has members or administrators: such objects are skipped and drop out of the **Remaining** count.

## Create a knowledge policy {#create-a-knowledge-policy}

1. Open **Settings > Customization > Retention policies** and click **Create Retention Policy**. The **Create a retention policy** panel opens.
2. Give the policy a **Name** that says what it deletes, for example "Indicators older than a year".
3. Choose the **Unit** (minutes, hours or days) and the **Maximum retention**: an object not updated for that long is deleted. The default is 31 days.
4. Add filters to target the objects to delete, for example an entity type and a label. Without filters, the policy applies to every entity and relationship of the platform and reads **Everything** in the list.
5. Click **Verify**. A message tells you how many elements the policy would delete now.
6. Adjust the filters until the count is what you expect, then click **Create**. **Create** stays disabled until you verify.

   ![The Create a retention policy panel with its Name, Unit, Maximum retention set to 31 and filters, and the Create button disabled next to Verify until the policy has been verified.](https://filigran.io/docs/shots/29e27a0a2e3a24f4b71bc95efc3ad308a94eb7ccd9292439a0cdabf6267a0084.webp)

![The Retention policies list showing a knowledge policy and the four built-in policies, with their maximum retention, last execution, remaining count, scope and status.](https://filigran.io/docs/shots/0f0a0f20149f714dc837ad94df8be3626c6c44900c7090b0d1b5d599b5a75b44.webp)

**Example: Purge scanner indicators after a year**

The Example Scanner Feed creates thousands of indicators a week, all labelled `scanner`. Decay revokes them within days, but revoked indicators still fill the search engine. Example CERT keeps them one year for investigations, then deletes them. Every other indicator, and every report, stays.

- **Name**: `Scanner indicators older than a year`
- **Unit**: `days`
- **Maximum retention**: `365`
- Filters, combined with AND:

```text
Entity type = Indicator
AND Label = scanner
```

Click **Verify** before **Create**: the message counts the scanner indicators not updated for a year. Compare it with the number of indicators labelled `scanner` in **Observations > Indicators**: a count above it means a filter is missing. Once created, the policy deletes in batches at each run, and the **Remaining** column falls to 0. An indicator that the feed sends again is updated, which restarts its year.

## Activate, pause or change a policy {#activate-pause-or-change-a-policy}

Open the menu of a policy in the list:

- **Update** changes its name, duration and filters. Click **Verify** again before **Update**, which stays disabled until you do.

*(OpenCTI before 7.260811)*

- **Delete** removes the policy.

The list shows, for each policy, the **Last execution** and the **Remaining** count of elements still to delete. The retention manager deletes in batches, so a policy that matches many elements catches up over several runs.

## Tune the retention manager {#tune-the-retention-manager}

The retention manager runs on one node of a cluster at a time. At each run, it takes every active policy in turn and deletes up to one batch of what the policy matches.

| Key | Environment variable | Default | Effect |
| --- | --- | --- | --- |
| `retention_manager:enabled` | `RETENTION_MANAGER__ENABLED` | `true` | Turns the retention manager on or off. Off, no policy runs |
| `retention_manager:interval` | `RETENTION_MANAGER__INTERVAL` | `30000` | Pause between the end of a run and the start of the next, in milliseconds |
| `retention_manager:batch_size` | `RETENTION_MANAGER__BATCH_SIZE` | `1500` | Maximum number of elements one policy deletes in one run |
| `retention_manager:max_deletion_concurrency` | `RETENTION_MANAGER__MAX_DELETION_CONCURRENCY` | `2` | Number of elements deleted in parallel |

A new policy on a large knowledge base can match millions of elements: with the defaults, it deletes at most 1,500 elements per run, with a 30-second pause between runs, so fewer than 180,000 an hour. Raise `batch_size` or `max_deletion_concurrency` to catch up faster, at the cost of more load on the search engine. The **Remaining** column shows how much is left.

## What's next {#what-s-next}

- [Delete and restore](https://filigran.io/docs/lts/7.260309-lts/opencti/use/delete-restore/), for deletions you can undo.
- [Audit who did what](https://filigran.io/docs/lts/7.260309-lts/opencti/configure/activity/), what the activity logs record.
- [Engines, Schedules and Managers](https://filigran.io/docs/lts/7.260309-lts/reference/opencti/configuration/#engines-schedules-and-managers) in the configuration reference, for every `retention_manager` key of your version.
