Skip to content
Learn › Get data in: open the docs menu

Delete old batches automatically with a retention policy

A retention policy deletes or suspends a dataset's batches for you, so the dataset doesn't keep growing. Open the dataset's panel in the Data Library, go to Settings & history, then Batches, and select Set up retention policy below the batch list. Each dataset can have one policy, and whether you can set one up depends on your plan.

Before you start

Create a retention policy

  1. Open the dataset's panel, then Settings & history, then Batches.
  2. Select Set up retention policy. The Retention policy window opens. At the top, What this rule does restates the rule in one sentence as you change it.
  3. Under What to remove, pick a rule type (see the table below) and set its values.
  4. Under When it runs, choose Ask for approval first or Run on its own.
  5. Add at least one project member to notify.
  6. Click Save Policy.
Retention Policy dialog with Time-based, Count-based, and Condition-based rule types, Run Mode set to Request Approval, a notification recipient, and a Policy Summary
Rule typeWhat it removesDefault
By ageDeletes or suspends batches older than a number of minutes, hours, days, weeks or monthsDelete batches older than 90 days
By countKeeps the latest batches and deletes or suspends the restKeep the latest 10
By conditionRows, across batches, that match something you describeNone

Remove rows that match a condition

  1. Choose By condition and describe the rows to remove in plain language, for example "Delete rows where date < 2024-01-01".
  2. Select Generate. Mammoth writes the condition and shows it as SQL.
  3. Select Test to see how many rows across how many batches match, for example "1,250 rows across 3 batches".

This rule permanently deletes matching rows and can't suspend. If your description doesn't say what to delete, Mammoth answers "Tell us what to delete."

Choose when the policy runs

OptionWhat it does
Ask for approval first (default)The policy flags batches for review. Nothing is deleted or suspended until someone approves.
Run on its ownThe policy deletes or suspends matching batches on schedule without approval

When the action is delete and you choose Run on its own, Mammoth asks Delete batches without approval? ("Deleted batches can't be recovered"). Confirm with Save and run automatically, or click Go back.

Choose who is notified

Recipients get an email for approval requests ("Notify on approval requests"), or each time the policy runs ("Notify when the policy runs"). In approval mode you can also select Also notify on every policy run. At least one recipient is required.

The policy runs daily.

Review and approve flagged batches

Once a policy exists, a banner at the top of the Batches section shows its status (Active, Suspended, or the number of batches pending), the rule summary, the last run and the next run.

ControlWhat it does
Run PolicyRuns the policy now. With approval required, it requests approval; with Run on its own, it runs immediately.
Approve All, or Delete 3 batches / Suspend 3 batchesApproves the pending batches. Pending rows show a Delete or Suspend button and the state Pending Delete.
Configure (the gear icon)Opens the policy to edit it, turn it off with This rule is on, or select Delete Policy

Deleting the policy leaves the dataset and its existing batches unchanged.

In Monitor, Pending Retentions lists policies waiting for a decision, with Review and Approve. Active Retentions shows policies that are currently deleting or suspending. The Activity Log records each Data Retention run. See Activity log.

Worked example: keep a 24-month rolling window

A finance team adds one month of transactions each cycle in Combine mode and wants two years of history. They set a By count policy that keeps the latest 24 batches and deletes the rest, with Ask for approval first. Each month, the oldest batch is flagged, and an approver clicks Approve All.

Troubleshooting retention policies

SymptomCauseFix
Set up retention policy is disabled or asks you to upgradeRetention depends on your plan, or you can't edit the datasetCheck your plan and your access to the dataset
Batches show Pending Delete and stayThe policy is set to Ask for approval firstApprove them with Approve All or the Delete button on each row
Historical batches are goneA policy deleted themCheck the policy's rule and the Activity Log. Deleted batches can't be recovered.
Saving fails with "At least one recipient is required."No one is set to be notifiedAdd a project member
Was this page helpful?

Something wrong? support@mammoth.io