Would be great to have this. Scenario:
- I disabled a lot of entities which produced many thousand rows in the database (including statistics and statistics_short_term tables) which I want to remove now.
- Note that I disabled them, they are not deleted. For reasons (e. g. to know the integration offers/offered this entity or maybe I decide to just re-enable the entity later).
- Additionally I ran the recorder service “purge_entities” for the affected entities, but that still does not allow to delete the statistics using “fix it” button in dev-tools statistics section.
- So all the corresponding statistics rows stay in the database, which are roughly
4.743
instatistics
and4.166
instatistics_short_term
- per entity.
Overview of current situation (scenarios and options as known to me after digging into this for six hours) when it comes to database hygiene and size reduction, where this feature request aims at scenario #4:
-
Delete the statistics of single deleted entities:
simply use the “fix” button in the dev-tools statistics section -
Delete the statistics of multiple deleted entities:
not easily possible currently, see this feature request Implement a "Fix All" button in "Developer Tools > Statistics" to remove orphaned IDs · Discussion #12644 · home-assistant/frontend · GitHub plus this feature request Removing statistics of deleted devices in one click
(it is possible by doing all of this in the backend which is quite risky: Statistics - Fix Issue - large amount of data - #3 by vinzcenzo) -
Delete the state and events of single entities:
use purge_entities service of Recorder - Home Assistant -
Delete the statistics of single or multiple disabled (not deleted!) entities:
not easily possible currently, see proposed solution for this below
(it is possible by doing all of this in the backend which is quite risky: Statistics - Fix Issue - large amount of data - #3 by vinzcenzo)
Proposed solution (depending on how easily this should be accessable to normal users):
-
Either add option in dev-tools statistics section similar to the existing one but enable it for ALL statistic entities, not only the deleted ones.
-
Or add a recorder service like the existing one Recorder - Home Assistant but for statistics tables instead of states and events, e. g. service
recorder.purge_statistics
.
I would be very happy with the service option in 2 already, even I would need to run that service for every single entity.