What are you actually trying to do and how are you consuming. There are methods in HA to extract data from the dB. Specifically recorder.get_statistics was just released in 2025.6
If you actually need direct then the schema is documented in the developer docs.
Nathan’s got the answer. But I’ll offer another idea for possible future use.
You can save data directly to a csv file and skip the database. Use the File integration to set define the output file. Then create an automation to use action: notify.send_message to send data to that file. You can set the automation to trigger each time an entity changes, or once a day to record summary data like total, min and/or max values, or whenever you need.
I get database and dump data named “state” from specific “attributes_id” from table states.
sqlite3 -header -csv /home/homeassistant/.homeassistant/home-assistant_v2.db "SELECT state_id, state, last_updated_ts, attributes_id FROM states WHERE last_updated_ts>1592334844 AND attributes_id=6531;" > export_infinity_attributes_6531.csv
I believe the default Recorder purge_keep_days is 10. After that, old events and states data are purged and, for some types of data, summarized in the statistics tables.
This one-size-fits-all approach is less than ideal, but there are so many possible ways to use HA, and so many different requirements end users have, that we each need to develop a retention strategy for which works for us. That takes some effort.
Some ways to address this include saving the data elsewhere, as I mentioned above, or setting purge_keep_days to a large number and then creating automations to selectively purge those data which only need shorter retention periods.
Be careful though. Some entities excessively spam the database. With a long retention period, you risk a bloated database which slows down backups and updates, and is more easily corrupted.