SQL 你可以从influxdb中删除数据吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26268544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you delete data from influxdb?
提问by spuder
How do you delete data from influxdb?
你如何从influxdb中删除数据?
The documentation shows it should be as simple as:
文档显示它应该很简单:
delete from foo where time < now() -1h
For some reason, influxdb rejects my delete statements saying "Delete queries can't have where clause that doesn't reference time"
出于某种原因,influxdb 拒绝我的删除语句,说“删除查询不能有不引用时间的 where 子句”
select * from bootstrap where duration > 1000 and time > 14041409940s and time < now()
I want to delete these 5 entries whos duration > 1000 seconds
我想删除持续时间 > 1000 秒的这 5 个条目
This should be a valid sql statement, yet it fails
这应该是一个有效的 sql 语句,但它失败了
None of these delete statements work either
这些删除语句都不起作用
delete from bootstrap where duration > 3000000"
delete from bootstrap where duration > 300000"
delete from bootstrap where time = 1404140994043"
delete from bootstrap where duration > 300000 and time > 1404141054508 "
delete from bootstrap where duration > 300000 and time > 1404141054508s "
delete from bootstrap where time > 1404141054508s and duration > 300000 "
delete from bootstrap where duration > 30000 and time > 1s"
Documentation reference
文档参考
http://influxdb.com/docs/v0.8/api/query_language.html
http://influxdb.com/docs/v0.8/api/query_language.html
Update
更新
Additional queries
其他查询
delete from bootstrap where time > 1404141416824 and duration > 3000;
delete sequence_number from bootstrap where time > 1s and duration > 1000;
Maybe this is a bug?
也许这是一个错误?
https://github.com/influxdb/influxdb/issues/975
https://github.com/influxdb/influxdb/issues/84
https://github.com/influxdb/influxdb/issues/975
https://github.com/influxdb/influxdb/issues/84
采纳答案by John Clements
It appears that you can do this in influxdb 0.9. For instance, here's a query that just succeeded for me:
看来你可以在 influxdb 0.9 中做到这一点。例如,这是一个对我来说刚刚成功的查询:
DROP SERIES FROM temperature WHERE machine='zagbar'
(Per generous comment by @MuratCorlu, I'm reposting my earlier comment as an answer...)
(根据@MuratCorlu 的慷慨评论,我正在重新发布我之前的评论作为答案......)
回答by spuder
With influx, you can only delete by time
随着涌入,你只能按时间删除
For example, the following are invalid:
例如,以下是无效的:
#Wrong
DELETE FROM foo WHERE time < '2014-06-30' and duration > 1000 #Can't delete if where clause has non time entity
This is how I was able to delete the data
这就是我能够删除数据的方式
DELETE FROM foo WHERE time > '2014-06-30' and time < '2014-06-30 15:16:01'
Update: this worked on influx 8. Supposedly it doesn't work on influx 9
更新:这适用于涌入 8。据说它不适用于涌入 9
回答by Dan Esparza
I'm surprised that nobody has mentioned InfluxDB retention policiesfor automatic data removal. You can set a default retention policy and also set them on a per-database level.
我很惊讶没有人提到自动数据删除的InfluxDB 保留策略。您可以设置默认保留策略,也可以在每个数据库级别设置它们。
From the docs:
从文档:
CREATE RETENTION POLICY <retention_policy_name> ON <database_name> DURATION <duration> REPLICATION <n> [DEFAULT]
回答by Jason
Because InfluxDB is a bit painful about deletes, we use a schema that has a boolean field called "ForUse", which looks like this when posting via the line protocol (v0.9):
因为 InfluxDB 对删除有点痛苦,所以我们使用一个模式,它有一个名为“ForUse”的布尔字段,当通过线路协议(v0.9)发布时,它看起来像这样:
your_measurement,your_tag=foo ForUse=TRUE,value=123.5 1262304000000000000
You can overwrite the same measurement, tag key, and time with whatever field keys you send, so we do "deletes" by setting "ForUse" to false, and letting retention policy keep the database size under control.
您可以使用发送的任何字段键覆盖相同的度量、标签键和时间,因此我们通过将“ForUse”设置为 false 来“删除”,并让保留策略控制数据库大小。
Since the overwrite happens seamlessly, you can retroactively add the schema too. Noice.
由于覆盖无缝发生,您也可以追溯添加架构。诺斯。
回答by max pleaner
The accepted answer (DROP SERIES) will work for many cases, but will not work if the records you need to delete are distributed among many time ranges and tag sets.
接受的答案 (DROP SERIES) 将适用于许多情况,但如果您需要删除的记录分布在许多时间范围和标记集之间,则将不起作用。
A more general purpose approach (albeit a slower one) is to issue the delete queries one-by-one, with the use of another programming language.
一种更通用的方法(尽管速度较慢)是使用另一种编程语言逐个发出删除查询。
- Query for all the records you need to delete (or use some filtering logic in your script)
For each of the records you want to delete:
- Extract the time and the tag set (ignore the fields)
Format this into a query, e.g.
DELETE FROM "things" WHERE time=123123123 AND tag1='val' AND tag2='val'
Send each of the queries one at a time
- 查询需要删除的所有记录(或在脚本中使用一些过滤逻辑)
对于要删除的每条记录:
- 提取时间和标签集(忽略字段)
将其格式化为查询,例如
DELETE FROM "things" WHERE time=123123123 AND tag1='val' AND tag2='val'
一次发送一个查询
回答by Mahaveer Jangir
You can only delete with your time field, which is a number.
您只能使用您的时间字段进行删除,该字段是一个数字。
Delete from <measurement> where time=123456
will work. Remember not to give single quotes or double quotes. Its a number.
将工作。记住不要给出单引号或双引号。它的一个数字。
回答by Zaur
I am adding this commands as reference for altering retention inside of InfluxDB container in kubernetes k8s. wget is used so as container doesn't have curl and influx CLI
我正在添加此命令作为更改 kubernetes k8s 中 InfluxDB 容器内部保留的参考。使用 wget 是因为容器没有 curl 和 influx CLI
wget 'localhost:8086/query?pretty=true' --post-data="db=k8s;q=ALTER RETENTION POLICY \"default\" on \"k8s\" duration 5h shard duration 4h default" -O-
Verification
确认
wget 'localhost:8086/query?pretty=true' --post-data="db=k8s;q=SHOW RETENTION POLICIES" -O-