删除数据
使用influx CLI或InfluxDB API/api/v2/delete端点来删除InfluxDB存储桶中的数据。
InfluxDB Cloud 支持通过以下方式删除数据:
- 时间范围
- 测量 (
_measurement) - 标签
- 字段 (
_field)
在 InfluxDB Cloud 中,写入和删除是异步的,并且最终会一致。一旦 InfluxDB 验证了您的请求并排队了删除,它会发送一个 成功 响应(HTTP 204 状态码)作为确认。为了确保 InfluxDB 按照您请求的顺序处理写入和删除,在发送下一个请求之前,等待确认。一旦 InfluxDB 执行了排队的删除,已删除的数据将不再可查询,但将在磁盘上保留,直到压缩服务运行。
使用influx CLI删除数据
使用 InfluxDB CLI 连接配置 提供你的 InfluxDB 主机、组织和 API 令牌。
使用
influx delete命令从InfluxDB中删除数据点。使用
--bucket标志来指定要从哪个存储桶中删除数据。使用
--start和--stop标志来定义要删除数据的时间范围。使用 RFC3339 时间戳。(可选) 使用
-p,--predicate标志来包含一个 删除谓词,用于识别要删除的点。没有 删除谓词 的数据删除会删除指定桶中时间戳介于指定
start和stop时间之间的所有数据。
示例
删除具有特定标签值的特定测量中的点
influx delete --bucket example-bucket \
--start '1970-01-01T00:00:00Z' \
--stop $(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--predicate '_measurement="example-measurement" AND exampleTag="exampleTagValue"'
删除指定时间范围内的所有点
influx delete --bucket example-bucket \
--start 2020-03-01T00:00:00Z \
--stop 2020-11-14T00:00:00Z
在指定时间范围内删除特定字段的点
influx delete --bucket example-bucket \
--start 2022-01-01T00:00:00Z \
--stop 2022-02-01T00:00:00Z \
--predicate '_field="example-field"'
使用API删除数据
使用 InfluxDB API /api/v2/delete 端点 从 InfluxDB 删除点。
POST http://localhost:8086/api/v2/delete
包含以下内容:
- 请求方法:
POST - 标题:
- 授权:
Token模式,使用您的 InfluxDB API 令牌 - 内容类型:
application/json
- 授权:
- 查询参数:
- Request body: JSON object with the following fields:
* Required
示例
删除具有特定标签值的特定测量中的点
curl --request POST http://localhost:8086/api/v2/delete?org=example-org&bucket=example-bucket \
--header 'Authorization: Token YOUR_API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"start": "2020-03-01T00:00:00Z",
"stop": "2020-11-14T00:00:00Z",
"predicate": "_measurement=\"example-measurement\" AND exampleTag=\"exampleTagValue\""
}'
删除指定时间范围内的所有点
curl --request POST http://localhost:8086/api/v2/delete?org=example-org&bucket=example-bucket \
--header 'Authorization: Token YOUR_API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"start": "2020-03-01T00:00:00Z",
"stop": "2020-11-14T00:00:00Z"
}'
在指定时间范围内删除特定字段的点
curl --request POST http://localhost:8086/api/v2/delete?org=example-org&bucket=example-bucket \
--header 'Authorization: Token YOUR_API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"start": "2022-01-01T00:00:00Z",
"stop": "2022-02-01T00:00:00Z",
"predicate": "_field=\"example-field\""
}'
更多信息,请参见/api/v2/delete端点文档。
要删除一个存储桶,请参见 Delete a bucket。