# What is in the HealthSQL database?

Source: https://healthsql.app/docs/schema · Updated 2026-11-30

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

- **For any daily number, use `daily` or `days`.** They hold Apple Health's own total for each day. Never sum `samples` for a day: a watch, a phone and a ring each record the same steps, and the sum counts them two or three times.
- **For sleep, use `nights`:** one row per night, from one source. `nights_by_source` has every source that recorded the night.
- **Say how fresh the data is.** Every answer carries `phone_synced`. iOS lets no app read Health while the iPhone is locked, so new data arrives after the person next unlocks the phone.
- **Unknown is not zero.** A day with no total for a metric has no row, or a null in `daily`.
- **Units never depend on the phone's region:** lengths are meters, mass is kg, energy is kcal, temperature is degC, and a percent is a 0-1 fraction.
- **When an answer has a `problem`, tell the person what it says.** It names the one act that clears it.
- **The rows you read go to your model provider.** Read summaries when you do not need every sample, and do not copy the database or the export files anywhere.
- **You are not a doctor.** Report what the data shows, and send medical questions to a clinician.

## 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.

| Column | Apple Health type | Value |
|---|---|---|
| `steps` | `StepCount` | the day's total or average |
| `distance_m` | `DistanceWalkingRunning` | the day's total or average |
| `flights` | `FlightsClimbed` | the day's total or average |
| `active_kcal` | `ActiveEnergyBurned` | the day's total or average |
| `basal_kcal` | `BasalEnergyBurned` | the day's total or average |
| `exercise_min` | `AppleExerciseTime` | the day's total or average |
| `stand_min` | `AppleStandTime` | the day's total or average |
| `daylight_min` | `TimeInDaylight` | the day's total or average |
| `resting_hr` | `RestingHeartRate` | the day's total or average |
| `hrv_ms` | `HeartRateVariabilitySDNN` | the day's total or average |
| `hr_avg` | `HeartRate` | the day's total or average |
| `hr_min` | `HeartRate` | the day's lowest |
| `hr_max` | `HeartRate` | the day's highest |
| `walking_hr` | `WalkingHeartRateAverage` | the day's total or average |
| `respiratory_rate` | `RespiratoryRate` | the day's total or average |
| `spo2` | `OxygenSaturation` | the day's total or average |
| `vo2max` | `VO2Max` | the day's total or average |
| `wrist_temp_c` | `AppleSleepingWristTemperature` | the day's total or average |
| `weight_kg` | `BodyMass` | the day's total or average |
| `body_fat` | `BodyFatPercentage` | the 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.

| Table | Columns |
|---|---|
| `types` | `type_id`, `type`, `metric` |
| `units` | `unit_id`, `unit` |
| `sources` | `source_id`, `source`, `name`, `device` |
| `records` | `id`, `kind`, `type_id`, `start_ts`, `end_ts`, `value`, `unit_id`, `source_id`, `data` |
| `day_totals` | `type_id`, `day`, `stat`, `value`, `low`, `high`, `unit_id` |
| `deleted` | `id` |
| `files` | `name`, `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

```sql
SELECT day, steps, active_kcal, resting_hr, hrv_ms, asleep_min FROM daily ORDER BY day DESC LIMIT 14
```

```sql
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
```

```sql
SELECT night, asleep_min, deep_min, rem_min, fell_asleep, woke, source_name FROM nights ORDER BY night DESC LIMIT 7
```

```sql
SELECT day, activity, minutes, meters, avg_hr, source_name FROM workouts ORDER BY start_ts DESC LIMIT 10
```

```sql
SELECT day, round(value, 1) AS vo2max FROM days WHERE metric = 'VO2Max' ORDER BY day DESC LIMIT 30
```

```sql
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

| Command | Answer |
|---|---|
| `healthsql` | JSON: `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 status` | JSON: `ok`, `phone_synced`, `problem`, record and day counts, the folder and database paths; exit code 1 when not ok |
| `healthsql sync` | Reads every waiting file, however long it takes |
| `healthsql setup` | Checks 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 mcp` | Serves `health_overview` and `health_query` over stdio ([MCP guide](https://healthsql.app/mcp)) |

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

- The iPhone's files: `~/Library/Mobile Documents/iCloud~dkbuilds~HealthSQL/Documents` (set `HEALTHSQL_EXPORT_DIR` to read another folder).
- The database: `~/Library/Application Support/HealthSQL/health.db` (set `HEALTHSQL_DB` to use another path). It is a copy; delete it and it is built again from the files.
- The format of the iPhone's files: [export format](https://healthsql.app/docs/format).
