====== Database Cleanup ====== ===== Work out usage ===== From ; https://community.home-assistant.io/t/how-to-keep-your-recorder-database-size-under-control/295795 SELECT COUNT(*) as cnt, SUM(LENGTH(event_data)) as bytes, event_type FROM events GROUP BY event_type ORDER BY cnt DESC and SELECT COUNT(*) AS cnt, COUNT(*) * 100 / (SELECT COUNT(*) FROM states) AS cnt_pct, SUM(LENGTH(attributes)) AS bytes, SUM(LENGTH(attributes)) * 100 / (SELECT SUM(LENGTH(attributes)) FROM states) AS bytes_pct, entity_id FROM states GROUP BY entity_id ORDER BY cnt DESC Delete enitities records; DELETE FROM states where entity_id IN ('sensor.temperature' , 'sensor.battery_temperature' , 'sensor.28_63e8d4122101_temperature', 'sensor.battery_voltage'); Backup the database; sudo rm -f /volume2/cctv/backups/1_backup.db sudo sqlite3 /volume3/sudo sqlite3 /volume3/docker-storage/home-assistant/config/home-assistant_v2.db ".backup /volume2/cctv/backups/1_backup.db"/home-assistant/config/home-assistant_v2.db ".backup /volume2/cctv/backups/1_backup.db"