How to delete data from InfluxDB?

InfluxDB is one of the most popular Timeseries data stores. It’s useful for recording system metrics, events, and performing analytics.As the data grows in the InfluxDB , we might need to delete old data which is irrelevant . In this article we will explain how to delete data from InfluxDB

First we will connect the InfluxDB server using “influx” client

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15   [root@test.test.com test]# influx Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. Connected to http://localhost:8086 version 0.13.0 InfluxDB shell version: 0.13.0 > use collectd Using database collectd > show series; key mysql_value,host=127.0.0.1,instance=test,type=mysql_commands,type_instance=admin_commands mysql_value,host=127.0.0.1,instance=test,type=mysql_commands,type_instance=change_db mysql_value,host=127.0.0.1,instance=test,type=mysql_commands,type_instance=delete mysql_value,host=127.0.0.1,instance=test,type=mysql_commands,type_instance=insert >  

Now let us see the data in the Series “mysql_value”

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17   > select * from mysql_value limit 10; name: mysql_value time host instance type type_instance value 1490104865000000000 127.0.0.1 test.test.com mysql_commands set_option 1 1490104865000000000 127.0.0.1 test.test.com mysql_locks waited 10597 1490104865000000000 127.0.0.1 test.test.com mysql_commands select 5.667256e+06 1490104865000000000 127.0.0.1 test.test.com mysql_commands replace 68120 1490104865000000000 127.0.0.1 test.test.com mysql_commands insert 81744 1490104865000000000 127.0.0.1 test.test.com mysql_commands grant 4 1490104865000000000 127.0.0.1 test.test.com mysql_commands delete 68118 1490104865000000000 127.0.0.1 test.test.com mysql_commands change_db 27248 1490104865000000000 127.0.0.1 test.test.com mysql_locks immediate 9.150236e+06 1490104865000000000 127.0.0.1 test.test.com mysql_commands admin_commands 216409 >  

We will delete series data which is older than 1000s

1 2 3 4   > delete from mysql_value where time > 1000s; > select * from mysql_value limit 10;  

You can see that above command deleted all data in the series “mysql_value” .

How to delete the data from InfluxDB referencing other columns?

Let us see how to delete the data for a particular host

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19   > select * from memory_value limit 10; name: memory_value time host type type_instance value 1490104631000000000 test.test.com memory buffered 5.62397184e+08 1490104631000000000 test.test.com memory used 1.3692878848e+10 1490104631000000000 test.test.com memory free 2.86810112e+08 1490104631000000000 test.test.com memory cached 2.053988352e+09 1490104641000000000 test.test.com memory used 1.3696299008e+10 1490104865000000000 test.test.com memory cached 2.055401472e+09 1490104865000000000 test.test.com memory used 1.369817088e+10 1490104865000000000 test.test.com memory buffered 5.62417664e+08 1490104865000000000 test.test.com memory free 2.8008448e+08 1490104875000000000 test.test.com memory buffered 5.62417664e+08   > drop series from memory_value where host=‘test.test.com’; > select * from memory_value limit 10;  

 

In the above example we deleted all series data where “host” matches “test.test.com” 

SUMMARY

In this article we explained how to delete data from influxdb using “where” clause. 

As always,please drop us a note if you have any questions or feedback using our comment form below.

Always Happy to Help ????

Author: , 0000-00-00