| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| |
| --> |
| |
| ## 数据存活时间(TTL) |
| |
| IoTDB 支持对 database 级别设置数据存活时间(TTL),这使得 IoTDB 可以定期、自动地删除一定时间之前的数据。合理使用 TTL |
| 可以帮助您控制 IoTDB 占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, |
| 内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 |
| |
| TTL的默认单位为毫秒,如果配置文件中的时间精度修改为其他单位,设置ttl时仍然使用毫秒单位。 |
| |
| ### 设置 TTL |
| |
| 设置 TTL 的 SQL 语句如下所示: |
| ``` |
| IoTDB> set ttl to root.ln 3600000 |
| ``` |
| 这个例子表示在`root.ln`数据库中,只有3600000毫秒,即最近一个小时的数据将会保存,旧数据会被移除或不可见。 |
| ``` |
| IoTDB> set ttl to root.sgcc.** 3600000 |
| ``` |
| 支持给某一路径下的 database 设置TTL,这个例子表示`root.sgcc`路径下的所有 database 设置TTL。 |
| ``` |
| IoTDB> set ttl to root.** 3600000 |
| ``` |
| 表示给所有 database 设置TTL。 |
| |
| ### 取消 TTL |
| |
| 取消 TTL 的 SQL 语句如下所示: |
| |
| ``` |
| IoTDB> unset ttl to root.ln |
| ``` |
| |
| 取消设置 TTL 后, database `root.ln`中所有的数据都会被保存。 |
| ``` |
| IoTDB> unset ttl to root.sgcc.** |
| ``` |
| |
| 取消设置`root.sgcc`路径下的所有 database 的 TTL 。 |
| ``` |
| IoTDB> unset ttl to root.** |
| ``` |
| |
| 取消设置所有 database 的 TTL 。 |
| |
| ### 显示 TTL |
| |
| 显示 TTL 的 SQL 语句如下所示: |
| |
| ``` |
| IoTDB> SHOW ALL TTL |
| IoTDB> SHOW TTL ON StorageGroupNames |
| ``` |
| |
| SHOW ALL TTL 这个例子会给出所有 database 的 TTL。 |
| SHOW TTL ON root.ln,root.sgcc,root.DB 这个例子会显示指定的三个 database 的 TTL。 |
| 注意:没有设置 TTL 的 database 的 TTL 将显示为 null。 |
| |
| ``` |
| IoTDB> show all ttl |
| +-------------+-------+ |
| | database|ttl(ms)| |
| +-------------+-------+ |
| | root.ln|3600000| |
| | root.sgcc| null| |
| | root.DB|3600000| |
| +-------------+-------+ |
| ``` |
| |