Klagio
(Klagio)
May 29, 2019, 10:31am
1
Hi, I have a DB that is GB large, and wish to reduce its size, how to check the inside (I don’t know much about DB)?
Overall my devices are around 100 (although with lots of sensors and components)
For the moment this is my configuration, any clue on how to reduce the size improving the config?
recorder:
# db_url: /backup
purge_interval: 2
purge_keep_days: 3
include:
domains:
- sensor
- switch
- light
- binary_sensor
entities:
- image_processing.living_room_person_detection
- image_processing.office_room_person_detection
- image_processing.kitchen_room_person_detection
- lock.home_door
exclude:
domains:
- automation
- weblink
- updater
- input_boolean
- input_number
entities:
- sensor.date
- sensor.time
- sensor.last_boot
- sun.sun
nickrout
(Nick Rout)
May 29, 2019, 11:56pm
2
Assuming you are running a standard sqlite database, any sqlite tool, google them.
jimz011
(Jim)
May 30, 2019, 12:14am
3
I use MariaDB as it is much faster for me then running the built-in recorder. However I have read that you can purge the database every x days or after every x days.
I haven’t used this before in my setup as I use an external DB which has plenty of space (however I might add this soon as it makes the DB slow and indeed extremely huge, over 20GB here already and that is from only a few months).
If you are interested in using MariaDB you can check it out here:
# Home Assistant Add-on: MariaDB
MariaDB database for Home Assistant.
![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] ![Supports i386 Architecture][i386-shield]
## About
You can use this add-on to install MariaDB, which is an open-source (GPLv2 licensed) database. MariaDB can be used as the database backend for Home Assistant. For more information, please see [MariaDB][mariadb]
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
[mariadb]: https://mariadb.com
[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg
123
(Taras)
May 30, 2019, 12:20am
4
You can also exclude event_types
:
Thanks, it seems to work great. Only state changes recorded. It would be nice to have an include filter as well so I can just include state_changes instead of excluding everything else.
recorder:
db_url: mysql+pymysql://hass:[email protected] /HOMEBASE
include:
domains:
- sensor
- switch
- shell_command
- binary_sensor
- input_text
- light
- script
# - device_tracker
exclude:
entities:
- sensor.time
event_types:
…
I provide examples of SQL statements to purge unwanted entries from the database in this post:
You can use a tool like DB Browser for SQLite to modify Home Assistant’s database file.
Before editing home-assistant_v2.db, I suggest you shutdown Home Assistant (so it doesn’t attempt to update the database while you’re tinkering with it) and make a backup copy just in case your modifications corrupt the database.
The table you want is called states. Select the Browse Data tab then select Table: states. Click the entity_id heading to sort on it.
The best way to select and delete records is …
3 Likes