diff --git a/homeassistant/components/recorder/purge.py b/homeassistant/components/recorder/purge.py index 90a69f8f2a1e0d..719f65abb4759e 100644 --- a/homeassistant/components/recorder/purge.py +++ b/homeassistant/components/recorder/purge.py @@ -28,5 +28,10 @@ def purge_old_data(instance, purge_days): # Execute sqlite vacuum command to free up space on disk _LOGGER.debug("DB engine driver: %s", instance.engine.driver) if instance.engine.driver == 'pysqlite': + from sqlalchemy import exc + _LOGGER.info("Vacuuming SQLite to free space") - instance.engine.execute("VACUUM") + try: + instance.engine.execute("VACUUM") + except exc.OperationalError as err: + _LOGGER.error("Error vacuuming SQLite: %s.", err)