Database size (#12010)

The forge knows how big its own database is, and which tables and indexes make it so. Bloat shows up on /system, not in a profiler.

Where to see it

How it is measured

Bun's SQLite is built without dbstat and without sqlite_dbpage, so src/system/db_size.ts reads the file itself. It reads in 4 MiB asynchronous chunks, so the event loop is never held. For every b-tree page it records the page's kind, its cells and its children. Then it walks each b-tree down from its root page in sqlite_schema:

On a seeded database these figures match SQLite's own dbstat page for page.

The file is read as of its last checkpoint, so pages still only in the WAL are not counted. The WAL's bytes are shown beside it. One walk is shared by /system, the terminal and the MCP tool. The forge walks at most once an hour, and only when someone opens /system or the terminal's System screen, or calls the tool. A walk reads the whole file once: on a 4.5 GB database that is 4.5 GB of reads, at most once an hour, and none in an hour nobody asks. A walk that fails is logged (database size walk failed) and is tried again an hour later.

Growth, and when the owner hears

On its two-minute tick, the forge keeps the file's first size reading of each UTC day in db_size_day, and keeps the last 60 days.

Growth a day is the file's size now minus the oldest reading from the last seven days, divided by the time between them. Growth is not shown until the readings span 20 hours.

The vitals add a need, linked to /system, when either of these is true:

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs