InfluxDB 2.x - Delete Measurement Using API or Docker Container Shell
I regularly delete a ‘sandbox’ measurement with test data. It is not very complicated to delete a measurement, but it is worth noting. You can do this via the InfluxDB v2 API or via the shell of the InfluxDB 2.x Docker container. Both options are described here.
InfluxDB v2 API
The InfluxDB v2 API makes it very easy to remove a measurement from the docker host’s CLI with cURL. And of course it is also possible to use tools like Node-RED or Pentaho to make an HTTP call to the API.
Run the following command on the CLI of the Docker host:
curl --request POST "http://IP:PORT/api/v2/delete?org=ORG&bucket=BUCKET" \
--header 'Authorization: Token YOUR-TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"start": "1970-01-01T00:00:00Z",
"stop": "2025-12-31T23:59:00Z",
"predicate": "_measurement=\"MEASUREMENT\""
}'
Adjust the following:
IP
Replace with the IP address of InfluxDB. In my case this was the IP address of the Docker host
PORT
Replace with the port used for InfluxDB. Usually this is port8086
. My own InfluxDB container runs on port3004
ORG
Replace with the name of your InfluxDB Organization. In my case this wasubuntuvm
BUCKET
Replace with the name of your InfluxDB Bucket. In my case this wasstock
YOUR-TOKEN
Replace with your token. In my case this was the token with access to thestock
Bucket
MEASUREMENT
Replace with the name of the measurement you want to delete. In my case this wassandbox_added_symbols
Docker Container Shell
Another method to remove a measurement is via the shell of the InfluxDB container using the influx CLI.
Open a shell in the container:
docker exec -it influxdb /bin/bash
Now run the following command:
influx delete --bucket "BUCKET" --org "ORG" --predicate '_measurement="MEASUREMENT"' --start "1970-01-01T00:00:00Z" --stop "2025-12-31T23:59:00Z" --token "TOKEN"
Adjust the following:
BUCKET
Replace with the name of your InfluxDB Bucket. In my case this wasstock
ORG
Replace with the name of your InfluxDB Organization. In my case this wasubuntuvm
MEASUREMENT
Replace with the name of the measurement you want to delete. In my case this wassandbox_added_symbols
TOKEN
Replace with your token. In my case this was the token with access to thestock
Bucket
If everything went well, the entire measurement has been deleted. Now you can exit the container shell and go back to the docker host CLI:
exit
Read other notes
Tags
Notes mentioning this note
- Node-RED - Access the InfluxDB API Using the HTTP Request Node
Within Node-RED you can use the InfluxDB nodes. But it is also possible to query the InfluxDB v2 API via...
- Docker - InfluxDB 2.x Container Setup
InfluxDB is a time series database.
Comments
No comments found for this note.
Join the discussion for this note on this ticket. Comments appear on this page instantly.