---
title: "Delete old data automatically · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/personal-data/retention-jobs
updated: 2026-10-20
licence: "All rights reserved"
---

# Delete old data automatically

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Personal data](https://agentwranglers.se/playbook/data/personal-data)
- Rule: Give each kind of personal data a retention period, and let a scheduled job delete or anonymise rows when it ends.
- How: Store the date each row stops being needed, or compute it from a clear column such as `last_activity_at`. Erasure on request is a separate path, covered by the [data requests rule](https://agentwranglers.se/playbook/website/privacy/data-requests). Run the deletion job daily, in small batches. Remember copies in caches, search indexes, logs and analytics. Backups age out after the period in [backup retention](https://agentwranglers.se/playbook/operations/disaster-recovery/backup-retention). See also [keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule).
- Check: Insert a test row dated past its retention period and run the job. The row is gone, and so are its copies in the search index and cache.

Example:

```sql
DELETE FROM bookings
WHERE id IN (SELECT id FROM bookings WHERE ends_at < now() - interval '90 days' LIMIT 1000);
-- MySQL refuses LIMIT inside IN, so write it as
DELETE FROM bookings WHERE ends_at < now() - INTERVAL 90 DAY LIMIT 1000;
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/personal-data/retention-jobs`.

- Previous: [Store only the personal data you need](https://agentwranglers.se/playbook/data/personal-data/minimal-columns)
- Next: [Keep personal data out of test copies](https://agentwranglers.se/playbook/data/personal-data/masked-copies)
- [Personal data](https://agentwranglers.se/playbook/data/personal-data)
