What is in the HealthSQL database?

Updated

8 views over 7 tables, in one SQLite file at ~/Library/Application Support/HealthSQL/health.db. Start with daily for any question about a day or a trend: it holds Apple Health's own total for each day, the number the Health app shows.

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. This page is written so an agent can use it as its reference. It is generated from the code of healthsql version 0.1.0; healthsql with no arguments, or the health_overview MCP tool, prints the same views and columns together with your own metrics and their date ranges.

Rules for agents

Views

daily

START HERE for any question about a day or a trend. One row for each day. Every number is Apple Health's own total for that day, the number the Health app shows: when the Watch, the iPhone and a ring all recorded the same steps, Health counts them once. Sleep columns come from nights; night N is the night that ends on the morning of day N. spo2 and body_fat are 0-1 fractions.

Columns: day, steps, distance_m, flights, active_kcal, basal_kcal, exercise_min, stand_min, daylight_min, resting_hr, hrv_ms, hr_avg, hr_min, hr_max, walking_hr, respiratory_rate, spo2, vo2max, wrist_temp_c, weight_kg, body_fat, asleep_min, deep_min, rem_min, awake_min, fell_asleep, woke, sleep_source

days

Health's own total for each metric and day, for every metric (the list is below). stat says what value is: 'sum' for a metric that adds up (steps, energy), 'avg' for one that does not (heart rate), with min and max. Use this, never a sum over samples, for a daily number.

Columns: metric, day, stat, value, min, max, unit

nights

One row for each night of sleep, from one source (the one with sleep stages; if two have stages, the longer). nights_by_source has the same columns for every source that recorded the night.

Columns: night, asleep_min, deep_min, rem_min, core_min, awake_min, in_bed_min, fell_asleep, woke, source, source_name

nights_by_source

One row for each night and each source that recorded it. Use it to compare a watch with a ring, or to pick a source other than the one nights chose.

Columns: night, source, source_name, asleep_min, deep_min, rem_min, core_min, awake_min, in_bed_min, fell_asleep, woke

sleep

One row for each sleep stage interval, from every source. night is the day the person woke; an interval that starts at 18:00 or later belongs to the next day's night. Two sources that recorded the same night both appear: filter by source_name before you add minutes.

Columns: night, stage, minutes, start_local, end_local, source, source_name, start_ts, end_ts

workouts

One row for each workout. A ring or another app can write its own copy of a workout the Watch recorded: check source_name before you count. data is the whole record: stats for every measure, events, metadata.

Columns: day, start_local, activity, minutes, meters, avg_hr, max_hr, kcal, source, source_name, data, start_ts, end_ts

samples

One row for each raw measurement or logged event, from every source. For a value at a time of day, or one source's own numbers. NEVER sum it for a daily total: sources overlap, so use days. Always filter by metric; there are millions of rows. Units never depend on the phone's settings: lengths are m, body mass kg, energy kcal, temperature degC, and a percent is a 0-1 fraction. data holds metadata (m), and for a sample that holds many values n, min, max and series ([time, value]).

Columns: metric, day, start_local, end_local, value, unit, source, source_name, data, start_ts, end_ts

rings

One row for each day of Activity rings, with the goals.

Columns: day, move_kcal, move_goal_kcal, exercise_min, exercise_goal_min, stand_hours, stand_goal_hours

The columns of daily

One row per day. Each column is Health's own value for that day, from the type named here (the full Health identifier begins with HKQuantityTypeIdentifier). The sleep columns come from nights: night N is the night that ends on the morning of day N.

ColumnApple Health typeValue
stepsStepCountthe day's total or average
distance_mDistanceWalkingRunningthe day's total or average
flightsFlightsClimbedthe day's total or average
active_kcalActiveEnergyBurnedthe day's total or average
basal_kcalBasalEnergyBurnedthe day's total or average
exercise_minAppleExerciseTimethe day's total or average
stand_minAppleStandTimethe day's total or average
daylight_minTimeInDaylightthe day's total or average
resting_hrRestingHeartRatethe day's total or average
hrv_msHeartRateVariabilitySDNNthe day's total or average
hr_avgHeartRatethe day's total or average
hr_minHeartRatethe day's lowest
hr_maxHeartRatethe day's highest
walking_hrWalkingHeartRateAveragethe day's total or average
respiratory_rateRespiratoryRatethe day's total or average
spo2OxygenSaturationthe day's total or average
vo2maxVO2Maxthe day's total or average
wrist_temp_cAppleSleepingWristTemperaturethe day's total or average
weight_kgBodyMassthe day's total or average
body_fatBodyFatPercentagethe day's total or average

The other columns: day (YYYY-MM-DD, local time), and from nights asleep_min, deep_min, rem_min, awake_min, fell_asleep, woke and sleep_source.

Tables

The views read these. Join types, units and sources by their ids. records.id is the Health record's UUID, stored as 16 bytes; healthsql query prints it as text.

TableColumns
typestype_id, type, metric
unitsunit_id, unit
sourcessource_id, source, name, device
recordsid, kind, type_id, start_ts, end_ts, value, unit_id, source_id, data
day_totalstype_id, day, stat, value, low, high, unit_id
deletedid
filesname, size

records: The table under the views above, with every raw record: kind is q quantity, c category, w workout, route (data.points: [time, lat, lon, altitude, speed, accuracy]), mind, ecg, rings. Join types, units and sources by their ids.

records.kind is q (quantity), c (category), w (workout), route, mind (State of Mind), ecg or rings. day_totals.stat is sum for a metric that adds up and avg for one that does not, with low and high.

Example queries

SELECT day, steps, active_kcal, resting_hr, hrv_ms, asleep_min FROM daily ORDER BY day DESC LIMIT 14
SELECT strftime('%Y-%W', day) AS week, round(avg(steps)) AS steps, round(avg(resting_hr), 1) AS resting_hr, round(avg(asleep_min)) AS asleep_min FROM daily WHERE day >= date('now', '-90 day') GROUP BY week
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
SELECT day, round(value, 1) AS vo2max FROM days WHERE metric = 'VO2Max' ORDER BY day DESC LIMIT 30
SELECT strftime('%H', start_local) AS hour, round(avg(value)) AS heart_rate FROM samples WHERE metric = 'HeartRate' AND start_ts >= unixepoch('now', '-1 day') GROUP BY hour

Commands and their answers

CommandAnswer
healthsqlJSON: phone_synced, problem, every view with its columns, the examples, each metric with its unit and date range
healthsql query "SELECT ..."JSON: rows, truncated (more than 2000 rows), phone_synced, and problem when there is one
healthsql statusJSON: ok, phone_synced, problem, record and day counts, the folder and database paths; exit code 1 when not ok
healthsql syncReads every waiting file, however long it takes
healthsql setupChecks the Mac, builds the database, says how to connect each agent
healthsql connect <client>Registers the MCP server with claude-code, codex, claude-desktop, cursor
healthsql mcpServes health_overview and health_query over stdio (MCP guide)

A query and the overview first read new files for up to 45 seconds; whatever is left waits for the next call, and problem says so. SQL is SQLite's dialect, read-only, one statement per query.

Where the files are