Allow separate retention periods for states and short-term statistics #4616
Describe your core improvementHome Assistant Recorder should allow the retention period of short-term statistics to be configured independently from the retention period of regular state history. Currently, A configuration such as the following would solve this cleanly: recorder:
purge_keep_days: 730
statistics_short_term_keep_days: 90The exact configuration/API is only illustrative. This would allow users to independently decide how long they want to retain:
The existing default behavior would not need to change. This could be an optional setting for installations that need different retention policies. Current limitationsThe current implementation makes it difficult to combine long state-history retention with shorter short-term-statistics retention. For example, my Recorder configuration intentionally keeps general state history for up to 730 days. Noisy entities are selectively reduced to 14, 31, 90, or 366 days using This works correctly for their state history, but their short-term statistics continue to follow the global retention period. In a real installation this has resulted in:
For comparison, the hourly long-term Reducing Using This behavior was previously reported in home-assistant/core#96254 ("statistics_short_term not deleted on recorder.purge_entities"). That issue was eventually closed as stale/not planned, without an apparent alternative mechanism for this use case. As a result, there currently appears to be no supported way to keep, for example, two years of selected state history while retaining only 90 days of 5-minute statistics. Technical benefitsSeparating these retention policies would give Recorder significantly better storage scalability without sacrificing long-term historical data. Short-term statistics have fundamentally different storage characteristics from raw states and hourly long-term statistics. A large installation can accumulate tens of millions of 5-minute statistic rows even though older data is primarily useful at the hourly long-term-statistics resolution. Benefits would include:
In the example above, a 90-day short-term-statistics retention would make approximately 84% of the current 85.6 million short-term-statistics rows eligible for removal, while hourly long-term statistics could remain available indefinitely. This also preserves flexibility: users who want the existing coupled retention behavior could simply leave the new option unset. Additional contextRelated previous issue: An alternative implementation could be to extend However, a separate configurable retention period for I am happy to provide additional database statistics or test behavior on my installation if that would help evaluate or implement this. |
Replies: 1 comment
|
Vote here https://github.com/orgs/home-assistant/discussions/380 |
Vote here https://github.com/orgs/home-assistant/discussions/380