Skip to content

event table dominates the database: 9.03 GB of event log for 1.09 GB of message content #53760

Closed as duplicate

Description

@adrianurdaneta

Summary

After ~8 months of use, opencode.db on this machine reached 11,370,909,696 B. Almost all of it is the append-only event table: 9,029,068,170 B of event payload against 1,093,108,053 B of actual message content in part.

It is not stale history. 68% of those events belong to sessions touched in the previous month, and sessions older than 90 days have zero events, so the growth tracks recent activity rather than accumulated age.

Environment

  • opencode 1.18.32, Windows 11
  • database at ~/.local/share/opencode/opencode.db
  • ~8 months of use, 1,075 sessions

Measurements

All taken with opencode db "<query>", before any cleanup:

Metric Value
opencode.db file size 11,370,909,696 B
PRAGMA page_count × PRAGMA page_size 2,776,101 × 4096 B
PRAGMA freelist_count 0 (no free pages, so VACUUM alone would not have reclaimed anything)
SELECT COUNT(*) FROM event 1,364,445
SELECT SUM(LENGTH(data)) FROM event 9,029,068,170 B (~6.6 KB per row)
SELECT COUNT(*) FROM part 346,255
SELECT SUM(LENGTH(data)) FROM part 1,093,108,053 B
SELECT COUNT(DISTINCT aggregate_id) FROM event 1,071
SELECT COUNT(*) FROM event_sequence 1,071
SELECT COUNT(*) FROM session 1,075

COUNT(DISTINCT aggregate_id) equals the event_sequence row count, and every aggregate id matches a session id (0 aggregates without a session), so the event log is one stream per session.

Distribution by session age

Bucketing sessions by last activity, with the event payload summed per session:

Session age Sessions Events
0–7 days 388 431,487
7–30 days 677 928,926
30–90 days 6 4,032
90–180 days 3 0
>180 days 1 0

Concentration: the heaviest single session held 1,034,594,099 B of payload in 74,738 events, and one orchestration session together with its sub-session tree accounted for 315,229 events (the parent alone held the 1.03 GB above).

Workaround (verified)

Deleting finished sessions through the CLI and compacting:

opencode session delete <session-id>   # also removes the session's sub-session tree
opencode db "VACUUM"

This took the file from 11,370,909,696 B to 4,892,659,712 B — a 6,478,249,984 B reduction — and PRAGMA quick_check returns ok afterwards.

Two operational notes from doing it: VACUUM writes the whole database through the WAL, so the WAL grows to roughly the database size until it is checkpointed (and a wal_checkpoint(TRUNCATE) needs a writable connection; a read-only one reports log: 0 and changes nothing). Also, deleting a session removes its sub-session tree, so the reclaimed space can be much larger than the deleted session itself.

Questions

  1. Is the per-event payload duplication intentional — an event-sourced design that stores the full part content in every event — or is it unexpected?
  2. Is there a supported retention or compaction path, or a plan to store deltas/references instead of the full payload per event?
  3. Would a documented retention policy (for example, dropping the event log of archived sessions) be a welcome contribution?

I searched the tracker for database, sqlite, storage and size before opening this and found nothing, so apologies if it duplicates something I could not find.

Activity

  1. opencode-agent commented on Oct 7, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed measurements and the verified cleanup steps! This looks like the same problem tracked in #33356: the event table grows without limit (mostly full-snapshot message.updated / message.part.updated events), with no retention or compaction, so VACUUM alone can't reclaim the space. That issue also covers your questions about whether storing a full payload per event is intended and about adding a retention or compaction path (see the proposal discussed there, #36710). Your numbers and the delete-session + VACUUM workaround would be useful to add there.

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. github-actions commented on Oct 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    • #33356: Unbounded growth of the event table, dominated by retained message.updated.1 snapshots, with no retention or compaction.
    • #46833: opencode.db grew to about 9 GB, with most payload in large message.updated.1 event snapshots.
    • #47729: Unbounded event-table growth and lack of a retention policy or cleanup command.
  3. opencode-agent commented on Oct 8, 2026

    @opencode-agent
    Contributor

    Closing this as a duplicate of #33356, since there's been no reply saying how it's different. Please follow that issue for unbounded event table growth and any retention or compaction work. Your measurements and the delete-session + VACUUM workaround would be a useful comment there. If your case does turn out to be different, reply here and we can reopen. Thanks for the thorough report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions