Home assistant

Home Assistant Database Size and Data Retention: Recorder Guide (2026)

On this page
    TL;DR: Home Assistant keeps detailed history for 10 days by default and keeps hourly long-term statistics forever. To shrink the database, find the few entities that write the most, exclude them in the recorder: section of configuration.yaml, keep purge_keep_days short, then run the recorder.purge action with repack. Use InfluxDB if you really need years of raw data. The default SQLite database is the right choice for most homes.

    Updated November 2026 for Home Assistant 2026.10. The SQL in this guide uses the current database schema, where entity IDs live in the states_meta table.

    A big Home Assistant database is slow to back up, slow to load history, and on a Raspberry Pi with an SD card it wears the card out. The good news is that almost every bloated database has the same cause: a handful of sensors that update every second and get stored forever. Fix those and the rest takes care of itself.

    How Home Assistant stores history

    The part of Home Assistant that saves history is called the recorder. By default it writes everything into SQLite, a simple database that lives in a single file.

    • States and events (short-term history): every state change, stored for purge_keep_days, 10 days by default. This is what the History panel and logbook use, and it is where the size comes from.
    • Statistics (long-term): 5 minute and hourly mean, min and max for sensors with a state_class, plus energy totals. These are never purged automatically and stay small. The Energy dashboard and statistics graphs use them.

    This is the key point: you can cut detailed history to a few days and still keep years of hourly temperature and energy data, because those come from statistics.

    What you needRaspberry Pi 5 (8GB) starter kitPopular, quiet Home Assistant host. Get the official power supply and a case with a fan.Check price on AliExpressRaspberry Pi 5 NVMe HAT + small SSDBoot from NVMe instead of an SD card, which is what usually corrupts the database.Check price on AliExpressShelly Pro 3EM / EM energy meterWhole-house energy monitoring with CT clamps, local, and made for the Energy dashboard.Check price on AliExpressZigbee smart plug with energy monitoringLocal Zigbee plug that reports watts and kWh, and doubles as a mesh repeater.Check price on AliExpress

    Step 1: Check how big it is

    The default database is the file /config/home-assistant_v2.db. Check its size with the File editor app or the Terminal & SSH app:

    ls -lh /config/home-assistant_v2.db

    As a rough guide, under 1 GB is fine, 1 to 5 GB is worth a look, and above that you almost certainly have a few noisy entities.

    AliExpress deals

    Step 2: Find the entities that write the most

    Install the SQLite Web app, or use the SQL integration, and run:

    SELECT states_meta.entity_id, COUNT(*) AS rows_stored
    FROM states
    JOIN states_meta ON states.metadata_id = states_meta.metadata_id
    GROUP BY states_meta.entity_id
    ORDER BY rows_stored DESC
    LIMIT 20;

    The usual suspects at the top are power sensors that report every second, Wi-Fi signal and uptime sensors, CPU and memory sensors from system monitor, media players reporting playback position, and Bluetooth tracker RSSI values. In most homes the top ten entities make up more than half of the database.

    Step 3: Exclude the noise

    Add a recorder: section to configuration.yaml. Exclusion is YAML only, there is no UI for it:

    recorder:
      purge_keep_days: 7
      commit_interval: 5
      exclude:
        domains:
          - update
        entity_globs:
          - sensor.*_rssi
          - sensor.*_signal_strength
          - sensor.*_uptime
          - sensor.*_last_seen
        entities:
          - sensor.date_time
          - sensor.processor_use
          - sensor.memory_use_percent
        event_types:
          - call_service

    A few rules of thumb:

    • Do not exclude energy sensors you use in the Energy dashboard. Excluding an entity also stops its statistics.
    • Power sensors in watts: if a smart plug reports every second, keep the energy (kWh) sensor recorded and consider excluding the power (W) sensor, or lower its reporting rate in the device settings (Zigbee2MQTT, ESPHome and Shelly all allow this).
    • Prefer fixing the source. An ESPHome sensor with a throttle or delta filter writes far less without losing anything useful.

    Check the configuration under Developer tools > YAML > Check configuration before you restart. A typo in recorder: can stop history from recording entirely.

    Step 4: Purge and repack once

    New exclusions only stop new rows. Old ones stay until they age out. To clean up now, run this from Developer tools > Actions in YAML mode:

    action: recorder.purge_entities
    data:
      entity_globs:
        - sensor.*_rssi
        - sensor.*_uptime
      keep_days: 0

    Purge means deleting old rows. Then compact the file, which is called a repack:

    action: recorder.purge
    data:
      keep_days: 7
      repack: true

    Repacking rewrites the whole database and can take a while on a Pi. Run it when you do not need Home Assistant for half an hour, and make sure there is free disk space roughly equal to the database size.

    After that, the defaults keep things tidy: auto_purge runs every night and auto_repack once a month.

    Step 5: Keep long-term data the right way

    If you want years of data, there are three levels:

    • Statistics (built in): any sensor with a state_class keeps hourly data forever. Use the statistics graph card to view it. This covers temperature, humidity, energy and most numbers people care about.
    • Longer detailed history: raise purge_keep_days to 30 or 90 only for a small, clean database. Every extra day multiplies the size.
    • InfluxDB and Grafana: stream selected entities to InfluxDB for raw, long-term data and nice dashboards, while keeping the recorder small. See our InfluxDB and Grafana guide.

    SQLite, MariaDB or PostgreSQL

    For most homes, stay on the default SQLite. It is fast, needs no maintenance, and is included correctly in backups. Move to MariaDB or PostgreSQL only if you already run a database server you trust and back up, or have a very large install. A switch does not migrate old history, and a remote database that goes down takes your history with it.

    If you do switch, the MariaDB app is the easiest route on Home Assistant OS:

    recorder:
      db_url: !secret recorder_db_url

    with this in secrets.yaml:

    recorder_db_url: mysql://homeassistant:YOUR_PASSWORD@core-mariadb/homeassistant?charset=utf8mb4

    Storage hardware matters too

    On a Raspberry Pi, the database is the main reason SD cards die. If you are still on a card, moving to an SSD (for example a small USB 3 SSD, or NVMe on a Pi 5) helps more than any recorder setting. Our Raspberry Pi install guide explains how to move over with a backup and restore.

    It is not always the database

    When Home Assistant runs out of disk, check backups before you blame the recorder. On my own Home Assistant, an update failed with an HTTP 500 error in October 2026. The disk had 1.6 GB free out of 31 GB because 47 local backups of about 300 MB each had piled up. The database was fine. Moving the old backups to another computer freed about 14 GB and the update went through. Set a retention limit for automatic backups and store copies off the machine, as described in our backup and recovery guide.

    Frequently Asked Questions

    How long does Home Assistant keep history by default?

    Detailed state history is kept for 10 days (purge_keep_days: 10). Long-term statistics, which are hourly mean, min and max values for sensors with a state_class, are kept forever.

    How do I reduce the size of the Home Assistant database?

    Find the entities with the most rows using a SQL query on the states and states_meta tables, exclude them under recorder: in configuration.yaml, lower purge_keep_days, then run recorder.purge_entities and recorder.purge with repack: true.

    Will lowering purge_keep_days delete my energy history?

    No. The Energy dashboard uses long-term statistics, which are not affected by purge_keep_days. Just do not exclude the energy sensors themselves from the recorder.

    Should I switch Home Assistant to MariaDB?

    Usually not. SQLite is the default, performs well for typical homes and is backed up automatically. MariaDB or PostgreSQL only makes sense if you already run and back up a database server.

    Can I exclude entities from the recorder in the UI?

    No. Recorder include and exclude rules are set in YAML under recorder: in configuration.yaml. Check the configuration and restart Home Assistant after changing them.

    Related guides

    Leave a comment

    Your email address will not be published. Required fields are marked *

    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    Coming soon
    The ready-made Home Assistant dashboard
    One email when it's ready, with an early-bird price. No spam. Privacy