Home Assistant · Under the Hood
Home Assistant Recorder & Database Tuning
Every light that turns on, every temperature reading, every door that opens lands in one place: the recorder database. Left alone, it grows quietly until backups are enormous and the history graph takes seconds to draw. Managed deliberately, it stays small, fast, and useful for years. This guide explains how the recorder actually stores your history, what long-term statistics are (and why they are separate), when the built-in SQLite database is enough and when MariaDB earns its extra container, and the handful of settings that decide whether your database is a few hundred megabytes or a few dozen gigabytes.
Published Nov 21, 2026
What the recorder stores, and what it does not
The recorder integration writes state changes and events to a database. Two different kinds of history live there, and confusing them causes most of the bad decisions in this area. The first is the full state history: every state change with its attributes, the thing the history and logbook views draw. This is kept for a limited window — ten days by default — and then purged. The second is long-term statistics: hourly aggregates (mean, min, max, change, sum) for sensors that report statistics, above all energy sensors. Statistics are kept indefinitely, they are tiny compared to state history, and they are what the energy dashboard reads when you look at last year. Purging state history does not touch statistics; deleting statistics is a separate, deliberate act in the developer tools.
The practical consequence: the “keep everything forever” instinct is already satisfied for the numbers that matter long-term, by the statistics system, at almost no storage cost. What expires after ten days is the minute-by-minute detail — and for nearly every household question (“when did the door open last Tuesday?”), ten days is either enough or the question is really about statistics anyway. Extending the full-history window is the single most common way databases balloon, and it buys less than people expect. There is also a middle layer worth knowing about: short-term statistics, compiled every five minutes, are kept with the same retention as state history and then folded into the hourly figures. So a sensor’s story exists at three resolutions — raw changes for days, five-minute aggregates for the same window, and hourly aggregates effectively forever — and each resolution is the right one for a different question.
SQLite: the default, and usually the right answer
Out of the box, Home Assistant uses SQLite, stored in the configuration folder as home-assistant_v2.db. SQLite needs no extra container, no credentials, and no maintenance service, and it handles a typical household — hundreds of entities, normal event rates — without breaking a sweat. Its limits show up at the extremes: very large installs with thousands of entities changing constantly, heavy use of the history views over long ranges, or storage on slow media. It also shares a disk with your configuration, which on an SD card install is the real risk: constant small writes are what wear cards out, and the recorder is the largest writer in the system. On a mini PC or NAS with an SSD — the arrangement this site’s build uses — SQLite on the local disk is the sensible default and most readers should stop here.
If you stay on SQLite, three habits keep it healthy. Keep the database on the fastest local storage you have, not on a network share. Let the built-in nightly purge and the periodic repack do their work (the recorder vacuums and repacks on a schedule when auto-repack is on, which it is by default). And watch the file size in the system information; a database that grows week over week without the house changing is telling you a sensor is misbehaving — usually one chatty entity reporting every few seconds.
MariaDB: when the second container earns its place
MariaDB (or PostgreSQL, which the recorder also supports) moves the database into its own container with its own storage. The reasons to do it are specific: you want the database on a different disk or machine than Home Assistant itself; your install is large enough that history queries feel slow; or you already run a database container for other services and want the recorder in it. The setup is a database and user for Home Assistant, then a recorder configuration pointing at it with a connection URL. Moving is one-directional in practice — the recorder does not migrate old SQLite history into MariaDB for you; the new database starts fresh and the old file is your archive if you keep it.
The costs are equally specific. You now maintain a database: its updates, its backups, its disk. A database container that is down when Home Assistant starts means no history until it returns. And the performance gain on a normal household install is small, because SQLite was never the bottleneck — the bottleneck people feel is usually an unfiltered recorder writing thousands of useless state changes an hour, which MariaDB will faithfully store faster. Fix the firehose first; change databases only for placement or scale reasons.
The settings that actually matter
Purge keep days sets the full-history window; ten days is the default and a good default. Shortening it to seven is painless for most homes; lengthening it to thirty should be a decision, not a drift. Include and exclude filters are the highest-value settings in the whole integration: exclude the entities that change constantly and answer no question anyone asks — the classic offenders are sensors that report a new timestamp, a constantly jittering measurement, or a media player’s ever-changing attributes. Filtering at the recorder means those states never hit the disk at all. Commit interval trades a little immediacy for fewer, larger writes; on SD-card systems a longer interval reduces wear. And the purge_entities service lets you delete one misbehaving entity’s history without touching anything else — the right tool after you find the chatty sensor, so its backlog goes too.
A worked example of the filter mindset: a house with a weather station, a few energy plugs, and a solar inverter can generate a surprising share of its state changes from a handful of power and forecast entities updating every few seconds. Excluding the raw firehose entities while keeping their hourly statistics (statistics come from the sensor’s state class, and excluded-from-recorder entities need a moment’s thought — the clean pattern is to keep statistics-producing sensors recorded, and exclude the pure-noise ones) typically cuts database growth by more than half with no visible loss: the graphs people open still draw, and the energy history is untouched.
Measure your own database before changing anything
Tuning without numbers is folklore, so take three readings first. The database file size is shown in Settings → System → Repairs (and in the system information panel); write it down. The recorder’s own statistics — visible in the integration’s diagnostics and through the recorder services — tell you which entities produce the most events; in nearly every household the top ten entities are the majority of the writes, and they are rarely the ones the owner would have guessed. Finally, watch the file for a week after any change: the purge runs nightly, and the repack that actually returns space to the disk runs on its own schedule, so a filter change made on Monday shows its full effect the following week, not the next morning.
With those numbers, the decisions make themselves. A 400 MB database growing by a few megabytes a day is a healthy system that needs nothing. A 6 GB database growing by hundreds of megabytes a day has a firehose entity, and the fix is a filter, not a new backend. A database that is small but on a failing SD card is a storage problem wearing a database costume. The recorder is one of the few parts of Home Assistant that rewards measurement this directly — an hour with the actual numbers replaces every argument about database engines.
Backups, corruption, and the way out
The database is part of your configuration folder, so a normal Home Assistant backup includes it — which is exactly why an unmanaged database makes backups swell to gigabytes and restores take forever. The tuning above is therefore also backup tuning; the backups guide covers the wider strategy. If the database file corrupts — the classic cause is a power cut mid-write on marginal storage — Home Assistant renames the damaged file and starts a fresh one rather than refusing to boot; your statistics survive only if they were in the old file and you recover it, so the real fix is the boring one: reliable power, decent storage, and backups that exist. Treat the recorder as what it is — the house’s memory — and give it the same care as the rest of the system: a sensible retention window, a filter list you chose on purpose, and a size you check when you do the maintenance routine. Do those three things and the database stops being a topic at all, which is exactly where infrastructure belongs: underneath the house, working, unmentioned for months at a time.
Official documentation and references
- Home Assistant — Recorder — purge, filters, database URLs and the repack schedule
- Home Assistant — History — how the recorded states are presented
- Home Assistant — Database backends — SQLite, MariaDB and PostgreSQL notes
Frequently asked questions
How long does Home Assistant keep history?
Full state history is kept for ten days by default, then purged. Long-term statistics — hourly aggregates for energy and other statistics sensors — are kept indefinitely and are what the energy dashboard uses for long ranges.
Is SQLite good enough, or do I need MariaDB?
For most households, SQLite is enough and needs no maintenance. MariaDB earns its extra container when you want the database on separate storage, or on very large installs where history queries feel slow. Fix unfiltered chatty entities first — they are the usual cause of bloat on either backend.
Why is my database so large?
Almost always a small number of entities changing state constantly — jittering sensors, timestamp sensors, busy media players. Exclude them in the recorder filters, purge their stored history with the purge_entities service, and let the nightly repack reclaim the space.
Does purging delete my energy history?
No. The purge removes full state history older than the retention window. Long-term statistics are stored separately and survive purges; deleting them is a separate action in Developer Tools → Statistics.

