You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My usage implies some sensors to be requested every second. As a result - around 600MB data is collected every day. However, this data contains lot of dupes. Nonetheless it runs on ZFS with dedupe and compression, so storage is not a big problem, the HASS performance degrades anyway.
I created a script to remove state dupes and attribute dupes from pg base and later vacuuming. It would be great to have it in the default installation.
-- create mat view with dupes (non-changed states) and calculate old_state to fix later
create materialized view cleanup_dupes as (with d as (SELECT state_id,
FIRST_VALUE(STATE_ID) OVER (PARTITION BY ENTITY_ID,
LAST_CHANGED_TS
ORDER BY last_updated_ts) AS FST,
last_value(state_id) OVER (PARTITION BY ENTITY_ID,
LAST_CHANGED_TS
ORDER BY last_changed_ts) AS LST
FROMPUBLIC.STATESWHERE to_timestamp(last_changed_ts) < (NOW() - interval '12 hours'))
select*,
CASE when state_id != fst and state_id != lst then true else false end as to_delete
from d) with no data;
createindexdupes_state_idon cleanup_dupes (state_id);
createindexdupes_index_fston cleanup_dupes (fst);
-- maintenance -- refresh matview with dupes
refresh materialized view cleanup_dupes;
-- fixup old_state.UPDATEpublic.statesSET OLD_STATE_ID =cleanup_dupes.FSTFROM cleanup_dupes
WHEREcleanup_dupes.STATE_ID=STATES.STATE_IDANDcleanup_dupes.FST!=STATES.STATE_IDandstates.old_state_idis not NULL;
-- delete duped statesdeletefrompublic.stateswhere exists(select state_id
from cleanup_dupes
wherestates.state_id=cleanup_dupes.state_idandcleanup_dupes.to_delete= true);
-- delete unreferences attributes deletefrompublic.state_attributeswhere not exists (
select attributes_id frompublic.stateswherestates.attributes_id=state_attributes.attributes_id
) ;
-- free space
vacuum full analyze state_attributes, states;
The text was updated successfully, but these errors were encountered:
I only see a problem: to incorporate this into the addon, I have to be sure somebody uses this addon to store the homeassistant recorder database itself.
Most people do this, but not all.
I don't think I should sit on the users chair and proactively delete data from their tables.
What is your view on this?
Hello.
Thank you for such great extension.
My usage implies some sensors to be requested every second. As a result - around 600MB data is collected every day. However, this data contains lot of dupes. Nonetheless it runs on ZFS with dedupe and compression, so storage is not a big problem, the HASS performance degrades anyway.
I created a script to remove state dupes and attribute dupes from pg base and later vacuuming. It would be great to have it in the default installation.
The text was updated successfully, but these errors were encountered: