content/shared/influxdb3-internals/data-retention.md
{{< product-name >}} enforces database{{% show-in "enterprise" %}} and table{{% /show-in %}} retention periods at query time. Any points with timestamps beyond a retention period are filtered out of query results, even though the data may still exist in storage.
A database retention period is the duration of time that a database retains data. Retention periods are designed to automatically delete expired data and optimize storage without any user intervention.
By default, data does not expire. When you create a database,
you can optionally set a retention period. Retention periods can be as short as an hour
or infinite (none).
Points in a database with timestamps beyond the defined retention period (relative to now) are not queryable, but may still exist in storage until {{% show-in "core" %}}fully deleted by the retention enforcement service{{% /show-in %}}{{% show-in "enterprise" %}}fully deleted{{% /show-in %}}.
{{% show-in "enterprise" %}} Database retention periods serve as the default retention period for all tables in the database, unless a table has its own retention period defined. {{% /show-in %}}
{{% show-in "enterprise" %}}
In addition to database-level retention periods, {{< product-name >}} supports table-level retention periods. A table retention period overrides the database retention period for that specific table.
This allows you to:
Retention periods are specified as duration values using a numeric value plus a duration unit. The retention period value cannot be negative or contain whitespace.
| Unit | Description |
|---|---|
h | hour |
d | day |
w | week |
mo | month (30 days) |
y | year (365 days) |
[!Note] Minute (
m) and second (s) units are not supported for retention periods.
[!Warning]
Retention period constraints
- Minimum for data retention: The practical minimum retention period is 1 hour (
1h).- Zero-duration periods: Setting a retention period to
0<unit>(for example,0dor0h) is allowed but marks all data for immediate deletion at query time. This differs from InfluxDB 1.x and 2.x where0dmeant infinite retention.- Infinite retention: Use
noneto set an infinite retention period.
| Value | Description |
|---|---|
1h | 1 hour |
24h | 24 hours (1 day) |
7d | 7 days |
4w | 4 weeks (28 days) |
1mo | 1 month (30 days) |
90d | 90 days |
1y | 1 year (365 days) |
none | Infinite - data never expires |
You can combine multiple duration units in a single value:
| Value | Description |
|---|---|
30d12h | 30 days and 12 hours (30.5 days) |
2w3d | 2 weeks and 3 days (17 days) |
1y6mo | 1 year and 6 months (545 days) |
Use the influxdb3 create database command or the /api/v3/configure/database HTTP API endpoint to create a database with a retention period:
{{< code-tabs-wrapper >}} {{% code-tabs %}} influxdb3 CLI HTTP API {{% /code-tabs %}} {{% code-tab-content %}}
# Create a database with a 30-day retention period
influxdb3 create database --retention-period 30d DATABASE_NAME
# Create a database with infinite retention
influxdb3 create database --retention-period none DATABASE_NAME
# Create a database with a 90-day retention period using authentication
influxdb3 create database \
--retention-period 90d \
--token AUTH_TOKEN \
DATABASE_NAME
{{% /code-tab-content %}} {{% code-tab-content %}}
# Create a database with a 30-day retention period
curl --request POST "{{< influxdb/host >}}/api/v3/configure/database" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"db": "DATABASE_NAME",
"retention_period": "30d"
}'
# Create a database with infinite retention
curl --request POST "{{< influxdb/host >}}/api/v3/configure/database" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"db": "DATABASE_NAME",
"retention_period": "none"
}'
# Create a database with a 90-day retention period
curl --request POST "{{< influxdb/host >}}/api/v3/configure/database" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"db": "DATABASE_NAME",
"retention_period": "90d"
}'
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: the name of the databaseAUTH_TOKEN{{% /code-placeholder-key %}}: your {{% token-link "admin" %}}{{% show-in "core" %}}
[!Note]
Retention periods are immutable in Core
In {{< product-name >}}, retention periods can only be set when creating a database and cannot be changed afterward. If you need to change a retention period, you must create a new database with the desired retention period and migrate your data.
Upgrade to InfluxDB 3 Enterprise for advanced retention features
With InfluxDB 3 Enterprise, you can set table-level retention policies and update retention periods after creation. For more information, see InfluxDB 3 Enterprise data retention. {{% /show-in %}}
{{% show-in "enterprise" %}}
Use the influxdb3 create table command or the /api/v3/configure/table HTTP API endpoint to create a table with a retention period:
{{< code-tabs-wrapper >}} {{% code-tabs %}} influxdb3 CLI HTTP API {{% /code-tabs %}} {{% code-tab-content %}}
# Create a table with a 7-day retention period
influxdb3 create table \
--tags sensor_id,location \
--retention-period 7d \
--database DATABASE_NAME \
--token AUTH_TOKEN \
TABLE_NAME
# Create a table with field definitions and retention period
influxdb3 create table \
--tags room,sensor_id \
--fields temp:float64,hum:float64 \
--retention-period 30d \
--database DATABASE_NAME \
--token AUTH_TOKEN \
TABLE_NAME
{{% /code-tab-content %}} {{% code-tab-content %}}
# Create a table with a 7-day retention period
curl --request POST "{{< influxdb/host >}}/api/v3/configure/table" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"db": "DATABASE_NAME",
"table": "TABLE_NAME",
"tags": ["sensor_id", "location"],
"retention_period": "7d"
}'
# Create a table with field definitions and retention period
curl --request POST "{{< influxdb/host >}}/api/v3/configure/table" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"db": "DATABASE_NAME",
"table": "TABLE_NAME",
"tags": ["room", "sensor_id"],
"fields": [
{"name": "temp", "type": "float64"},
{"name": "hum", "type": "float64"}
],
"retention_period": "30d"
}'
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: the name of the database
{{% show-in "enterprise" %}}TABLE_NAME{{% /code-placeholder-key %}}: the name of the table to create
{{% /show-in %}}AUTH_TOKEN{{% /code-placeholder-key %}}: your {{% token-link "admin" %}}{{< product-name >}} allows you to update database retention
periods after creation using the
influxdb3 update database command.
{{< code-tabs-wrapper >}} {{% code-tabs %}} influxdb3 CLI HTTP API {{% /code-tabs %}} {{% code-tab-content %}}
# Update a database retention period to 60 days
influxdb3 update database --retention-period 60d DATABASE_NAME
# Clear a database retention period (set to infinite)
influxdb3 update database --retention-period none DATABASE_NAME
# Update with authentication
influxdb3 update database \
--retention-period 90d \
--token AUTH_TOKEN \
DATABASE_NAME
{{% /code-tab-content %}} {{% code-tab-content %}}
# Update a database retention period to 60 days
curl --request PATCH "{{< influxdb/host >}}/api/v3/configure/database/DATABASE_NAME" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"retention_period": "60d"
}'
# Clear a database retention period (set to infinite)
curl --request PATCH "{{< influxdb/host >}}/api/v3/configure/database/DATABASE_NAME" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"retention_period": "none"
}'
# Update a database retention period to 90 days
curl --request PATCH "{{< influxdb/host >}}/api/v3/configure/database/DATABASE_NAME" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer AUTH_TOKEN" \
--data '{
"retention_period": "90d"
}'
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: the name of the databaseAUTH_TOKEN{{% /code-placeholder-key %}}: your {{% token-link "admin" %}}[!Note] {{< product-name >}} does not currently support updating table retention periods after creation. Table retention periods can only be set when creating the table.
When both database and table retention periods are defined, the table retention period takes precedence for that specific table. This allows fine-grained control over data retention within a database.
# Database with 90-day retention
influxdb3 create database --retention-period 90d mydb
# Table with 7-day retention (overrides database retention)
influxdb3 create table \
--tags sensor_id \
--retention-period 7d \
--database mydb \
metrics
In this example:
metrics table expires after 7 daysmydb expires after 90 days# Database with 30-day retention
influxdb3 create database --retention-period 30d mydb
# Table with 1-year retention (overrides database retention)
influxdb3 create table \
--tags device_id \
--retention-period 1y \
--database mydb \
audit_logs
In this example:
audit_logs table expires after 1 yearmydb expires after 30 days# Original database with 30-day retention
influxdb3 create database --retention-period 30d mydb
# Table with 7-day retention
influxdb3 create table \
--tags sensor_id \
--retention-period 7d \
--database mydb \
metrics
# Update database retention to 90 days
influxdb3 update database --retention-period 90d mydb
After the update:
metrics table still expires after 7 days (table retention unchanged)mydb now expires after 90 days (affected by database update){{< product-name >}} routinely deletes expired data to optimize storage. The retention enforcement service runs periodically and:
The timing of physical deletion depends on:
[!Important] Even though expired data may still exist in storage temporarily, it will never appear in query results. Retention period enforcement at query time ensures expired data is always filtered out. {{% /show-in %}}