# Retention and clean-up

> What the realm clears on its own as it expires, what it keeps for the life of the realm, and what happens to a deleted realm's data.

The realm clears what has run its course without anyone asking: ended sessions, lapsed lockouts, spent one-time codes
and expired shares. It keeps what is a record: your objects, until you delete them, and the audit trail, for as long
as the realm exists. This page says which is which, so you can answer an auditor's *how long do you keep it?*

## Before you begin

Nothing to set: clean-up runs in every active realm, and no setting changes what is kept. To have a deleted realm
purged, you need to have deleted it, as an administrator of its parent; see
[Realms and sub-realms](/platform/realms/sub-realms/#deleting-a-realm).

## How it works

Every five minutes, the realm clears what has expired in each active realm:

| What is cleared | When |
|---|---|
| Sessions | Once signed out, or past their maximum lifetime or idle window. An idled-out session is revoked as it goes |
| Lockouts | Once both the counting window and the lockout itself have lapsed |
| One-time codes, revocations, unfinished sign-ins, recorded credential changes | Once past their expiry |
| One-time shares of secrets | Once past their expiry |

Everything else stays until it is deleted:

| What is kept | For how long |
|---|---|
| Users, groups, apps, policies and settings | Until you delete them |
| The audit trail | For the life of the realm. Nothing expires it |
| A deleted realm's data and keys | Until the realm is purged, which happens only when you ask |
| A deleted realm's audit trail | Until the realm is purged, and after it unless you ask for the trail to go too |

### A deleted realm

Deleting a realm takes it out of service and frees its host names; it doesn't erase it, and it can't be brought back.
Its data and keys are kept, unreadable to anyone, until Cvyūh **purges** the realm. Nothing purges a realm on a
timer: ask your Cvyūh support contact, naming the realm. A purge destroys the realm's records and keys together, and
every realm beneath it first.

**By default a purge keeps the realm's audit trail**, so what happened in the realm can still be answered for. Ask
for the audit trail to be purged too if you want nothing kept.

## Limits and defaults

| What | Default | Can it change |
|---|---|---|
| How often expired records are cleared | Every five minutes | No |
| How long the audit trail is kept | The life of the realm | No |
| How long a deleted realm is kept before purge | Until you ask | Ask for a purge at any time |
| A purge's audit trail | Kept | Ask for it to be purged too |

## Troubleshooting

- **An expired session still shows in a list.** Expiry is enforced at once, and the record is cleared within about
  five minutes. It gives no access meanwhile.
- **A suspended realm's expired records aren't cleared.** Only active realms are cleared. They're cleared once it's
  active again, and give no access meanwhile.

## Audit record

Clean-up of expired sessions writes a `SESSIONS_REAPED` record; see
[What is recorded](/audit-reports/audit-trail/what-is-recorded/). A realm's deletion is recorded as `DELETED`; see
[Realms and sub-realms](/platform/realms/sub-realms/#audit-record).

## Good to know

- **No setting shortens the audit trail yet.** Every record is kept, and no call edits or deletes one. A retention
  period you set is planned: see
  [What's next for audit and reports](/audit-reports/audit-trail/whats-next/#set-how-long-the-trail-is-kept).
- **No backups yet.** A realm served from more than one site is kept whole at each, but nothing keeps a copy you can
  restore to a moment before a change. See [Backups](/platform/data/whats-next/#backups).

## Coming next

- **[Backups](/platform/data/whats-next/#backups):** point-in-time copies of a realm's data you can restore from.

## Related

- [What is recorded](/audit-reports/audit-trail/what-is-recorded/): what the audit trail records.
- [Encryption of stored data](/platform/data/encryption/): how what is kept is protected.
- [Realms and sub-realms](/platform/realms/sub-realms/#deleting-a-realm): deleting a realm.
