Timescale Cloud:性能、扩展、企业版
自托管产品
MST
删除时间范围完全在指定时间之前(或之后)的数据块。以与 `show_chunks` 函数 相同的样式显示已删除的数据块列表。
数据块受开始时间和结束时间限制,并且开始时间始终在结束时间之前。如果数据块的结束时间早于 `older_than` 时间戳,或者如果给定了 `newer_than`,其开始时间晚于 `newer_than` 时间戳,则该数据块将被删除。
请注意,由于数据块仅在其时间范围完全落在指定时间戳之前(或之后)时才会被删除,因此剩余数据可能仍包含早于(或晚于)指定时间戳的数据。
数据块只能根据其时间间隔进行删除。不能根据哈希分区进行删除。
名称 | 类型 | 描述 |
---|---|---|
relation | REGCLASS | 要删除数据块的超表或连续聚合。 |
名称 | 类型 | 描述 |
---|---|---|
older_than | ANY | 截止点规范,任何早于此时间戳的数据块都应被删除。 |
newer_than | ANY | 截止点规范,任何晚于此时间戳的数据块都应被删除。 |
verbose | BOOLEAN | 设置为 true 将显示有关重新排序命令进度的消息。默认为 false。 |
created_before | ANY | 截止点规范,任何在此时间戳之前创建的数据块都应被删除。 |
created_after | ANY | 截止点规范,任何在此时间戳之后创建的数据块都应被删除。 |
`older_than` 和 `newer_than` 参数可以通过两种方式指定
间隔类型: 截止点计算为 `now() - older_than`,类似地为 `now() - newer_than`。如果提供了 INTERVAL 且时间列不是 `TIMESTAMP`、`TIMESTAMPTZ` 或 `DATE` 之一,则返回错误。
时间戳、日期或整数类型: 截止点明确给出为 `TIMESTAMP` / `TIMESTAMPTZ` / `DATE` 或 `SMALLINT` / `INT` / `BIGINT`。时间戳或整数的选择必须与超表时间列的类型一致。
`created_before` 和 `created_after` 参数可以通过两种方式指定
间隔类型: 截止点计算为 `now() - created_before`,类似地为 `now() - created_after`。这使用相对于当前时间的数据块创建时间进行过滤。
时间戳、日期或整数类型: 截止点明确给出为 `TIMESTAMP` / `TIMESTAMPTZ` / `DATE` 或 `SMALLINT` / `INT` / `BIGINT`。整数值的选择必须与超表分区列的类型一致。否则,将使用数据块创建时间进行过滤。
警告
当只使用间隔类型时,函数会假定您正在删除*过去*的数据。如果您想删除未来的数据(例如,删除错误条目),请使用时间戳。
当同时使用 `older_than` 和 `newer_than` 参数时,函数返回由此产生的两个范围的交集。例如,指定 `newer_than` => 4 months` 和 `older_than` => 3 months` 会删除所有 3 到 4 个月之间的数据块。类似地,指定 `newer_than` => '2017-01-01'` 和 `older_than` => '2017-02-01'` 会删除 '2017-01-01' 和 '2017-02-01' 之间的所有数据块。指定导致两个范围之间没有重叠交集的参数将导致错误。
当同时使用 `created_before` 和 `created_after` 参数时,函数返回由此产生的两个范围的交集。例如,指定 `created_after` => 4 months` 和 `created_before` => 3 months` 会删除所有从现在起 3 到 4 个月之间创建的数据块。类似地,指定 `created_after` => '2017-01-01'` 和 `created_before` => '2017-02-01'` 会删除 '2017-01-01' 和 '2017-02-01' 之间创建的所有数据块。指定导致两个范围之间没有重叠交集的参数将导致错误。
注意
`created_before`/`created_after` 参数不能与 `older_than`/`newer_than` 参数一起使用。
删除超表 `conditions` 中所有早于 3 个月的数据块
SELECT drop_chunks('conditions', INTERVAL '3 months');
示例输出
drop_chunks----------------------------------------_timescaledb_internal._hyper_3_5_chunk_timescaledb_internal._hyper_3_6_chunk_timescaledb_internal._hyper_3_7_chunk_timescaledb_internal._hyper_3_8_chunk_timescaledb_internal._hyper_3_9_chunk(5 rows)
删除超表 `conditions` 中所有创建时间早于 3 个月的数据块
SELECT drop_chunks('conditions', created_before => now() - INTERVAL '3 months');
删除超表 `conditions` 中所有未来 3 个月以上的数据块。这对于纠正因时钟不正确而摄取的数据非常有用
SELECT drop_chunks('conditions', newer_than => now() + interval '3 months');
删除超表 `conditions` 中 2017 年之前的所有数据块
SELECT drop_chunks('conditions', '2017-01-01'::date);
删除超表 `conditions` 中 2017 年之前的所有数据块,其中时间列以 UNIX 纪元以来的毫秒数给出
SELECT drop_chunks('conditions', 1483228800000);
删除超表 `conditions` 中所有早于 3 个月且晚于 4 个月的数据块
SELECT drop_chunks('conditions', older_than => INTERVAL '3 months', newer_than => INTERVAL '4 months')
删除超表 `conditions` 中所有在 3 到 4 个月前创建的数据块
SELECT drop_chunks('conditions', created_before => INTERVAL '3 months', created_after => INTERVAL '4 months')
删除所有超表中所有早于 3 个月的数据块
SELECT drop_chunks(format('%I.%I', hypertable_schema, hypertable_name)::regclass, INTERVAL '3 months')FROM timescaledb_information.hypertables;
关键词