Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: TTL policy #1159

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions docs/user-guide/concepts/features-that-you-concern.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@ Yes, it does. Please refer to the [delete data](/user-guide/manage-data/overview

## Can I set TTL or retention policy for different tables or measurements?

Of course, you can set TTL for every table when creating it:

```sql
CREATE TABLE IF NOT EXISTS temperatures(
ts TIMESTAMP TIME INDEX,
temperature DOUBLE DEFAULT 10,
) engine=mito with(ttl='7d');
```

The TTL of temperatures is set to be seven days.

Since 0.8, the database level `TTL` is supported too.

```sql
CREATE DATABASE test with(ttl='7d');
```

You can refer to the TTL option of the database and table create statement [here](/reference/sql/create.md).
Of course. Please refer to the document [on managing data retention with TTL policies](/user-guide/manage-data/overview.md#manage-data-retention-with-ttl-policies).

## What are the compression rates of GreptimeDB?

Expand Down
32 changes: 32 additions & 0 deletions docs/user-guide/manage-data/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,35 @@ TRUNCATE TABLE monitor;
```

For more information about the `TRUNCATE TABLE` statement, refer to the [SQL TRUNCATE TABLE](/reference/sql/truncate.md) documentation.

## Manage data retention with TTL policies

You can use Time to Live (TTL) policies to automatically remove stale data from your databases. TTL allows you to set policies to periodically delete data from tables. Setting TTL policies has the following benefits:

- Decrease storage costs by cleaning out obsolete data.
- Reduce the number of rows the database has to scan for some queries, potentially increasing query performance.

You can set TTL for every table when creating it. For example, the following SQL statement creates a table named `monitor` with a TTL policy of 7 days:

```sql
CREATE TABLE monitor (
host STRING,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP() TIME INDEX,
cpu FLOAT64,
memory FLOAT64,
PRIMARY KEY(host)
) WITH ('ttl'='7d');
```

You can also create a database-level TTL policy. For example, the following SQL statement creates a database named `test` with a TTL policy of 7 days:

```sql
CREATE DATABASE test WITH ('ttl'='7d');
```

You can set TTL policies at both the table level and the database level simultaneously.
If a table has its own TTL policy,
it will take precedence over the database TTL policy.
Otherwise, the database TTL policy will be applied to the table.

For more information about TTL policies, please refer to the [CREATE](/reference/sql/create.md) statement.
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@

## 我可以为不同的表或指标设置 TTL 或保留策略吗?

当然,你可以在创建表时为每个表设置 TTL:

```sql
CREATE TABLE IF NOT EXISTS temperatures(
ts TIMESTAMP TIME INDEX,
temperature DOUBLE DEFAULT 10,
) engine=mito with(ttl='7d');
```

在上述 SQL 中 `temperatures` 表的 TTL 被设置为 7 天。

从 0.8 版本开始,也支持数据库级别的 `TTL`。

```sql
CREATE DATABASE test WITH (ttl='7d');
```

你可以在[这里](/reference/sql/create.md)参考数据库和表创建语句的 TTL 选项。
当然。请参考[使用 TTL 策略保留数据](/user-guide/manage-data/overview.md#使用-ttl-策略保留数据)。

## GreptimeDB 的压缩率是多少?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,37 @@ TRUNCATE TABLE monitor;

有关 `TRUNCATE TABLE` 语句的更多信息,请参阅 [SQL TRUNCATE TABLE](/reference/sql/truncate.md) 文档。

## 使用 TTL 策略保留数据

Time to Live (TTL) 允许你设置定期删除表中数据的策略,
你可以使用 TTL 自动删除数据库中的过期数据。
设置 TTL 策略具有以下好处:

- 通过清理过期数据来降低存储成本。
- 减少数据库在某些查询中需要扫描的行数,从而提高查询性能。

你可以在创建每个表时设置 TTL。
例如,以下 SQL 语句创建了一个名为 `monitor` 的表,并设置了 7 天的 TTL 策略:

```sql
CREATE TABLE monitor (
host STRING,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP() TIME INDEX,
cpu FLOAT64,
memory FLOAT64,
PRIMARY KEY(host)
) WITH ('ttl'='7d');
```

你还可以创建数据库级别的 TTL 策略。
例如,以下 SQL 语句创建了一个名为 `test` 的数据库,并设置了 7 天的 TTL 策略:

```sql
CREATE DATABASE test WITH ('ttl'='7d');
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能需要加一些说明,设置了数据库的 ttl,还是可以继续设置表的 ttl,但是如果表没有明确设置,将在创建的时候继承数据库的设置。

你可以同时为 table 和 database 设置 TTL 策略。
如果 table 有自己的 TTL 策略,则该策略将优先于 database 的 TTL 策略,
否则 database 的 TTL 策略将被应用于 table。

有关 TTL 策略的更多信息,请参阅 [CREATE](/reference/sql/create.md) 语句。
Loading