How do I get my Apple Health data into a database?

Updated

Install HealthSQL on your iPhone and run its command on your Mac: it builds a SQLite database at ~/Library/Application Support/HealthSQL/health.db from every Health record, and keeps it current from your iCloud Drive. The other route is Apple's Export All Health Data, an XML file you convert yourself, again each time you want fresh data.

HealthSQL is an iPhone app and a command-line tool that copy your whole Apple Health record into a local SQLite database on your computer, so AI agents can query it with SQL or MCP.

The two routes

HealthSQLApple's export.xml and a converter
How you get the dataThe iPhone app writes new records to iCloud Drive; healthsql reads them into SQLiteIn the Health app, Export All Health Data, move the zip to your Mac, run a converter
FreshnessCurrent to the iPhone's last export, and every answer says when that wasAs old as the last time you exported
Daily totalsApple Health's own totals, as the Health app shows themYou compute them, and a plain sum counts overlapping devices twice
Effort after setupNone with the automatic purchase; open the app otherwiseThe whole routine, each time
CostFree export when you open the app; $7.99 once for automaticFree

Apple documents the export in Share your health data: "You can export all of your health and fitness data from Health in XML format." For a one-time look at old history, that is enough. More on its trouble for AI use: export.xml and AI.

What is in the database

Start from the views; they do the joins for you.

ViewWhat it holds
dailySTART HERE for any question about a day or a trend.
daysHealth's own total for each metric and day, for every metric (the list is below).
nightsOne row for each night of sleep, from one source (the one with sleep stages; if two have stages, the longer).
nights_by_sourceOne row for each night and each source that recorded it.
sleepOne row for each sleep stage interval, from every source.
workoutsOne row for each workout.
samplesOne row for each raw measurement or logged event, from every source.
ringsOne row for each day of Activity rings, with the goals.

The views read 7 tables: one row per record, with its type, unit and source by id, and Health's daily totals beside them. Every column: schema reference.

Example SQL

SELECT day, steps, active_kcal, resting_hr, hrv_ms, asleep_min FROM daily ORDER BY day DESC LIMIT 14
SELECT night, asleep_min, deep_min, rem_min, fell_asleep, woke, source_name FROM nights ORDER BY night DESC LIMIT 7
SELECT day, activity, minutes, meters, avg_hr, source_name FROM workouts ORDER BY start_ts DESC LIMIT 10

Run any of them with healthsql query "...". The answer is JSON: the rows, whether they were cut at 2000, and phone_synced.

Use any SQLite tool

health.db is a plain SQLite file. Open it read-only in sqlite3, Datasette, DB Browser for SQLite or a notebook:

sqlite3 -readonly "$HOME/Library/Application Support/HealthSQL/health.db" "SELECT count(*) FROM daily"

Other tools do not read the iPhone's new files, so run healthsql sync first when you want the latest data. The database is a copy: delete it and healthsql builds it again from the files in iCloud Drive.

Daily totals, not sums

Your Watch, your iPhone and a ring each record the same steps, as separate samples. A SUM over raw samples adds all of them. The daily and days views hold the totals Apple Health itself computes for each day, which count each stretch of time once. Use them for any daily number, and the samples view for a value at a time of day or for one device's own numbers. Why sums double count.

Questions

Is there an Apple Health SQL or SQLite export built into iOS?

No. Apple's only full export is XML (Apple, as of November 2026). Getting SQL means converting that file, or using an app that writes the data out for you.

Can I write my own tables into it?

Use a separate database for your own tables and attach health.db read-only. healthsql may rebuild health.db from the files, for example after an update that changes its tables.

Which records are not in it?

Clinical records need a separate permission from Apple, and iOS asks about medications and vision prescriptions one item at a time, so the export leaves them out, along with ECG voltages, heartbeat series and audiograms. See the export format.