Optimize Your Home Assistant Database
Home Assistant 默认的数据库是 sqlite,随着使用时间的增加,数据库文件越来越大,查看日志和历史的速度也变得越来越慢。
sqlite 数据库 内存模式 INMEMORY模式 文件内存中
曾经试着把这个 sqlite 数据库文件放到 /tmp 目录下,也就是内存中,响应速度快了很多,但是内存很快就塞满导致死机。
内存模式,sqlite3 支持内存模式,将数据库直接创建到内存中,打开地址传入”:memory:”即可,内存模式相比正常模式,可以省区IO的时间
关闭写同步,PRAGMA synchronous = OFF
在 sqlite3 中 synchronous 有三种模式,分别是 FULL,NORMAL 和 OFF,在系统意外终止的时候,安全性逐级减弱,FULL模式下,保证数据不会损坏,安全性最高,写入速度也最慢。OFF 模式会比 FULL 模式快50倍以上。
detail:https://www.cnblogs.com/sinpoo/p/15970396.html
https://community.home-assistant.io/t/speed-up-home-assistant-by-reducing-the-database-size/175094/24
solved 1 :
If you delete it and restart home assistant it will be recreated.
detail step by step
https://www.msly.cn/boards/topic/13373/optimize-your-home-assistant-database#17601
solved 2 :
Recoder
https://www.msly.cn/boards/topic/13373/optimize-your-home-assistant-database#17599
solved 3 :
change default database to mongdb etc.
https://www.msly.cn/boards/topic/13374/change-the-default-database-library-for-home-assistant
Home Assistant 默认的数据库是 sqlite,随着使用时间的增加,数据库文件越来越大,查看日志和历史的速度也变得越来越慢。
sqlite 数据库 内存模式 INMEMORY模式 文件内存中
曾经试着把这个 sqlite 数据库文件放到 /tmp 目录下,也就是内存中,响应速度快了很多,但是内存很快就塞满导致死机。
内存模式,sqlite3 支持内存模式,将数据库直接创建到内存中,打开地址传入”:memory:”即可,内存模式相比正常模式,可以省区IO的时间
关闭写同步,PRAGMA synchronous = OFF
在 sqlite3 中 synchronous 有三种模式,分别是 FULL,NORMAL 和 OFF,在系统意外终止的时候,安全性逐级减弱,FULL模式下,保证数据不会损坏,安全性最高,写入速度也最慢。OFF 模式会比 FULL 模式快50倍以上。
detail:https://www.cnblogs.com/sinpoo/p/15970396.html
Currently data is stored in JSON strings containing entity, states, attributes, etc. These could be several hundred bytes and are just stored as text blobs within the field.
The only way to reduce the database size is to change the way Home Assistant stores data.
Currently data is stored in JSON strings containing entity, states, attributes, etc. These could be several hundred bytes and are just stored as text blobs within the field.
This makes it extremely inefficient to store data as database native types are completely ignored, destroying all optimization the database engine may do. It also makes queries thousands of times slower than they should be because it causes a lot of string parsing during queries, limits what can be done in SQL, and pushes a lot of processing to the client.
Sort of like treating a relational database as a flat log file.
Entities should instead link to an other table holding attributes, states should like to the entity table, all attributes stored as their native data types, and indexes set up for all common queries.
https://community.home-assistant.io/t/speed-up-home-assistant-by-reducing-the-database-size/175094/24
solved 1 :
If you delete it and restart home assistant it will be recreated.
detail step by step
https://www.msly.cn/boards/topic/13373/optimize-your-home-assistant-database#17601
solved 2 :
Recoder
https://www.msly.cn/boards/topic/13373/optimize-your-home-assistant-database#17599
solved 3 :
change default database to mongdb etc.
https://www.msly.cn/boards/topic/13374/change-the-default-database-library-for-home-assistant
0