mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Optimize recorder MySQL tables when repacking (#36762)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
16f1ef5a44
commit
ee816ed3dd
@ -33,10 +33,15 @@ def purge_old_data(instance, purge_days, repack):
|
||||
)
|
||||
_LOGGER.debug("Deleted %s events", deleted_rows)
|
||||
|
||||
# Execute sqlite vacuum command to free up space on disk
|
||||
if repack and instance.engine.driver in ("pysqlite", "postgresql"):
|
||||
_LOGGER.debug("Vacuuming SQL DB to free space")
|
||||
instance.engine.execute("VACUUM")
|
||||
if repack:
|
||||
# Execute sqlite or postgresql vacuum command to free up space on disk
|
||||
if instance.engine.driver in ("pysqlite", "postgresql"):
|
||||
_LOGGER.debug("Vacuuming SQL DB to free space")
|
||||
instance.engine.execute("VACUUM")
|
||||
# Optimize mysql / mariadb tables to free up space on disk
|
||||
elif instance.engine.driver == "mysqldb":
|
||||
_LOGGER.debug("Optimizing SQL DB to free space")
|
||||
instance.engine.execute("OPTIMIZE TABLE states, events")
|
||||
|
||||
except SQLAlchemyError as err:
|
||||
_LOGGER.warning("Error purging history: %s.", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user