Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions homeassistant/components/recorder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@

CONFIG_SCHEMA = vol.Schema({
DOMAIN: FILTER_SCHEMA.extend({
vol.Inclusive(CONF_PURGE_KEEP_DAYS, 'purge'):
vol.Optional(CONF_PURGE_KEEP_DAYS):
vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Inclusive(CONF_PURGE_INTERVAL, 'purge'):
vol.Optional(CONF_PURGE_INTERVAL, default=1):
vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Optional(CONF_DB_URL): cv.string,
})
Expand Down Expand Up @@ -122,6 +122,12 @@ def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
keep_days = conf.get(CONF_PURGE_KEEP_DAYS)
purge_interval = conf.get(CONF_PURGE_INTERVAL)

if keep_days is None:
_LOGGER.warning(
"From version 0.64.0 the 'recorder' component will by default "
"purge data older than 10 days. To keep data longer you must "
"configure a 'purge_keep_days' value.")

db_url = conf.get(CONF_DB_URL, None)
if not db_url:
db_url = DEFAULT_URL.format(
Expand Down Expand Up @@ -162,6 +168,7 @@ def __init__(self, hass: HomeAssistant, keep_days: int,
self.hass = hass
self.keep_days = keep_days
self.purge_interval = purge_interval
self.did_vacuum = False
self.queue = queue.Queue() # type: Any
self.recording_start = dt_util.utcnow()
self.db_url = uri
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/recorder/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ 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':
if instance.engine.driver == 'pysqlite' and not instance.did_vacuum:
from sqlalchemy import exc

_LOGGER.info("Vacuuming SQLite to free space")
try:
instance.engine.execute("VACUUM")
instance.did_vacuum = True
except exc.OperationalError as err:
_LOGGER.error("Error vacuuming SQLite: %s.", err)