Public: anyone can read this; the crew can change it.

Database: one-shot compaction at boot (opt-in), incremental vacuum after, decision retention #16726

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

/data/forge.db is 4.9 GB with 64% free pages (768,629 of 1,200,635): retention drains since 11-13 (event 180 → 30 days, samples, the deploy ledger) freed about 2.5 GB that autovacuum=0 keeps inside the file. The live data is about 1.77 GB. decision (135 MB) was the one big table with no retention.

Notes

opened this

/data/forge.db is 4.9 GB with 64% free pages (768,629 of 1,200,635): retention drains since 11-13 (event 180 → 30 days, samples, the deploy ledger) freed about 2.5 GB that auto_vacuum=0 keeps inside the file. The live data is about 1.77 GB. decision (135 MB) was the one big table with no retention.

One-time compaction at boot (opt-in, one-shot)

  • Runs only when data/compact-on-boot exists; the marker is removed first. No marker, nothing runs, whatever the freelist.
  • TRUNCATE checkpoint (refused if another connection holds the file) → row counts for every table → VACUUM INTO with auto_vacuum=INCREMENTAL pending.
  • The copy must pass quick_check, match every table's count, and be auto_vacuum=2. Only then is the old file hard-linked as forge.db.before-compact-<UTC> (there is never a moment without a forge.db) and the copy renamed over it.
  • Any failure: forge.db byte-identical, partial copy removed, reason logged, normal boot. A 45 s ceiling for the whole job (run.sh waits 60 s for healthz); disk checked before the copy; each step's ms under [compact].
  • The kept file is named with its size on /system "Database size", the terminal's size screen and the MCP size read. The forge never deletes it.
  • Measured with this code on vxrail on a 4.3 GB-live copy: 21.7 s (VACUUM INTO 15.8 s, check 5.6 s). Expect about 9 s added to the one release that carries it.

Staying small

  • retention-vacuum: incremental_vacuum(256) at the existing 5% duty pacing (35 ms median slices measured), logging pages and bytes returned per pass.

decision retention

  • src/system/retention_decisions.ts, KEEP_DAYS = 90 beside the other windows: on crew rows (next, retry, land, guard, place) older than 90 days with an outcome, state becomes {}; every other column stays, so the ledger's stats still read every row. lean and hand (a person's vote or tap) stay whole forever; a land still at a wall keeps its state. Every reader of state listed.

How-to: docs/features/database-compaction.md. Using it needs the owner's yes to the extra seconds, then /srv/forge/data/compact-on-boot (uid 1000) before that release.

tsc clean; gate 0 failures; touched tests fail only where clean main does (Mac cells).

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs