---
title: "Indexes and retention"
description: "Configure index limits, retention periods and disk-size targets."
---

> Documentation Index
> Fetch the complete documentation index at: https://sandrinodm.github.io/logbrook/llms.txt
> Use this file to discover all available pages before exploring further.

# Indexes and retention

Every index inherits a global retention period and disk-size target, and `[indexes.<name>]` tables override them per index. [Archives, retention and backups](https://sandrinodm.github.io/logbrook/concepts/archives-and-retention/) explains how archival and expiry work.

## Index limits

`max_indexes` caps the number of indexes, including `default`. The default is 4 and the range is 1 to 64.

```toml title="logbrook.toml"
max_indexes = 8
```

Env: `LOGBROOK_MAX_INDEXES`. At startup, Logbrook counts the `default` index, every `[indexes.<name>]` table and `LOGBROOK_INDEXES` name, and the index directories already on disk. It refuses to start if the total exceeds the limit.

At the limit, a request that would create another index fails with `429` and `maximum index count reached; increase max_indexes and restart`. Raise the limit and restart, or delete an index.

### The limit also splits memory

DuckDB memory, DuckDB spill space and the ingestion queue byte budget are process-wide totals divided by `max_indexes`. Unused slots keep their share, so creating an index doesn't add memory.

| Setting | Default total | Per slot with `max_indexes = 4` |
| --- | --- | --- |
| `storage.memory_limit` | 512 MB | 128 MB |
| `storage.temp_limit` | 2 GB | 500 MB |
| `storage.queue_bytes` | 32 MiB | 8 MiB |

Thread settings apply per index, so each index adds threads and connections. For a single-index deployment, set `max_indexes = 1`. If you raise the limit, raise the totals too.

## Create indexes

An index can be created in four ways:

- **First authorized write.** An ingestion request to `POST /indexes/payments/logs/ingest` creates `payments` if the token is allowed to write there. Reads never create an index.
- **Explicit creation.** `logbrook indexes create payments` or `PUT /indexes/payments`, with an ingestion or admin token. It is idempotent.
- **TOML.** An `[indexes.payments]` table creates it at startup, even if the table is empty.
- **Environment.** `LOGBROOK_INDEXES=payments,audit` creates those indexes at startup. Existing tables keep their policies. Empty entries are ignored and whitespace is not trimmed.

Names have 1 to 63 lowercase ASCII letters, digits, hyphens or underscores, and start with a letter or digit.

> **First-write creation uses the global policy**
>
> An index created by its first write has no `[indexes.<name>]` table, so it gets the global retention and size target. Declare an index in TOML when it needs its own policy from the first event.

[`ingest_index_scopes`](https://sandrinodm.github.io/logbrook/configure/credentials/) restricts where a token may write. A token scoped to `payments` can't create `audit` by writing to it.

The `default` index and indexes declared in TOML or `LOGBROOK_INDEXES` can't be deleted. An admin token can delete the others:

```sh
logbrook indexes delete audit --yes
```

Deletion is permanent. Stop producers first, because the next ingestion request recreates the index.

## Retention

Retention is how long events are kept, measured against event time. Set the global default at the top level of the file.

```toml title="logbrook.toml"
retention_days = 30
archive_after_ms = 86400000
```

| Key | Env | Default |
| --- | --- | --- |
| `retention_days` | `LOGBROOK_RETENTION_DAYS` | unset |
| `retention_ms` | `LOGBROOK_RETENTION_MS` | `604800000` (7 days) |
| `archive_after_ms` | `LOGBROOK_ARCHIVE_AFTER_MS` | `86400000` (1 day) |

- Values must be positive integers.
- Retention must be longer than the archive age. For one-day retention, also lower `archive_after_ms`, for example to `3600000`.
- In the file, `retention_days` wins over `retention_ms` if both are set.
- Retention applies to each index separately.

The shipped container Compose file sets `LOGBROOK_RETENTION_DAYS` to 7 unless you override it.

## Disk-size targets

A disk-size target makes an index expire its oldest events before they reach the age limit. It is off by default.

```toml title="logbrook.toml"
max_size_gb = 20
```

| Key | Env | Default |
| --- | --- | --- |
| `max_size_gb` | `LOGBROOK_MAX_SIZE_GB` | disabled |
| `storage.max_size_bytes` | `LOGBROOK_MAX_SIZE_BYTES` | disabled |

- `max_size_gb` is decimal: 20 means 20,000,000,000 bytes.
- The smallest byte target is 16 MiB (16777216).
- In the file, `max_size_gb` wins over `storage.max_size_bytes` if both are set.
- In the environment, set only one of `LOGBROOK_MAX_SIZE_GB` and `LOGBROOK_MAX_SIZE_BYTES`.
- The target applies to each index: 20 GB means 20 GB for every index.
- The Compose file defaults to 20 GB. Running the binary without a file or variable gives no target.

The target counts the database, WAL, archives, spill files and other files Logbrook owns in the index directory. Over the target, maintenance expires the oldest events first, and ingestion returns `507` while the index stays at its target.

> **Not a hard quota**
>
> Writes in flight, compaction and query spill can briefly exceed the target, and DuckDB does not shrink its database file when it frees space. Use a filesystem or volume quota if you need a hard limit, and watch free disk space.

## Per-index overrides

An `[indexes.<name>]` table overrides the inherited values for one index. Omitted keys inherit the resolved global value.

```toml title="logbrook.toml"
retention_days = 30
max_size_gb = 20

[indexes.audit]
retention_days = 90
max_size_gb = 5

[indexes.payments]
retention_ms = 1209600000
archive_after_ms = 43200000
```

Per-index keys: `retention_days`, `retention_ms`, `archive_after_ms`, `max_size_gb`, `max_size_bytes` and `promoted_string_keys`.

- In one table, use `retention_days` or `retention_ms`, not both. Likewise `max_size_gb` or `max_size_bytes`.
- Per-index values override the global file values and the global environment variables. There are no per-index environment overrides.
- A per-index retention must still exceed that index's archive age, whether the archive age is its own or inherited.
- Changing a global value later doesn't change an index that overrides it.

Check what an index resolved to:

```sh
logbrook indexes show audit
```

The output shows the measured size, the size target, the retention and whether the index is ready. With `--json` it includes the raw `retention_ms` and `max_size_bytes`.

## Change retention

Policy changes apply on restart. Maintenance runs once at startup and then at each `maintenance_interval_secs`.

- Shortening retention can expire existing events on the first pass. This can't be undone.
- Lengthening retention doesn't bring back expired events. The stored expiry cutoff only moves forward, and ingestion keeps rejecting events older than it.
- Raising a disk-size target stops further size-based expiry but doesn't restore expired events.

Before you shorten retention, check what the new window removes, and take a [backup](https://sandrinodm.github.io/logbrook/operate/backup-and-upgrade/) if you may want the data.

Validate the file before restarting:

```sh
logbrook --config logbrook.toml check-config
```

## Next steps

- [Configuration file](https://sandrinodm.github.io/logbrook/configure/configuration-file/) — The full key reference.
- [Archives, retention and backups](https://sandrinodm.github.io/logbrook/concepts/archives-and-retention/) — How maintenance archives and expires events.
- [Run in production](https://sandrinodm.github.io/logbrook/operate/production/) — Monitor disk use and plan capacity.

Source: https://sandrinodm.github.io/logbrook/configure/indexes-and-retention/index.mdx
