Keep last N records

I want to keep last n records in a influxdb measurement and wanted to delete the remaning. This ordering is based on timestamp. How to do so?

I am using influxQL to do so.

@shashwat_007 From the post tag, I assume you’re using InfluxDB 1.x. InfluxDB 1.x doesn’t support these kinds of deletes. You can delete an entire database, measurement, or specific series.

Hi @scott!

Does it means that in InfluxDB2 is there a way to set the retention policy to number of points (records) instead of time? Or only that you can delete specific points?
I like the retention concept in influx.
I am trying to build an inventory/monitoring system based on the telegraf snmp plugin.
For inventory info I would like to have i.e. 10 points no matter how old.
For monitoring data the aging policy is great.


Retention periods are only time-based, not count based. When a timestamp of a point exceeds the retention period of a bucket, that point is marked for deletion and will be removed the next time data gets compacted.

You may need to store the inventory-specific information outside of InfluxDB. If you’re using a SQL database, you can use Flux to query the data with SQL and join it with your data stored in InfluxDB at query time.

Yes, I am considering that option, using Telegraf to send inventory data to a MySQL and monitoring data to InfluxDB.