cd /news/developer-tools/how-we-reduced-our-sqlite-database-f… Β· home β€Ί topics β€Ί developer-tools β€Ί article
[ARTICLE Β· art-96822] src=dev.to β†— pub= topic=developer-tools verified=true sentiment=↑ positive

How We Reduced Our SQLite Database from 8.7GB to 3.8GB Without Downtime

A development team reduced its SQLite database from 8.7GB to 3.8GB without downtime by pruning redundant event rows. The team used a chunked DELETE strategy with passive checkpoints, overcoming rowid reuse issues, and verified the process with a multi-agent protocol. The database size dropped by 54%, WAL size by 96%, and event rows by 65%, with zero data loss.

read2 min views1 publishedAug 14, 2026

Our OpenCode session database had grown to 8.7GB β€” 1.26 million event rows, most of them redundant state updates. Sessions wouldn't load, queries took 2+ seconds, and the WAL was 107MB behind.

Here's how we pruned it live, without downtime, using a multi-agent verification protocol.

The event

table stored every state change as a full JSON snapshot. After months of use:

event

(633K older than 48 hours)part

(tool transcripts, ~5.9GB)Sessions wouldn't load. The UI froze on session list.

Attempt 1: 250K chunk DELETE + PASSIVE checkpoint after each chunk

Root Cause Analysis: Rowid Reuse

After deletions, SQLite reused freed rowids for new events. Our chunk loop started at rowid 0, hit empty chunks immediately, and broke:

if n == 0 and start > 0:
    break
CHUNK = 25_000
max_rowid = con.execute('SELECT MAX(rowid) FROM event').fetchone()[0]

for start in range(0, max_rowid, CHUNK):
    con.execute(
        "DELETE FROM event WHERE rowid >= ? AND rowid < ? "
        "AND json_extract(data,'$.time') IS NOT NULL "
        "AND json_extract(data,'$.time') < ?",
        (start, start + CHUNK, cutoff_ms)
    )
    con.commit()  # Per chunk, NO intermediate checkpoint

Key changes:

Metric Before After Delta
DB Size 8,703 MB 3,783 MB -54%
WAL 107 MB 4 MB -96%
Event Rows 1,259,602 437,506 -65%
Session/Message/Part 873/165K/667K 874/166K/668K 0 loss
freelist_count β€” 0 Fully compact

We didn't just wing it. Three AI agents verified every step:

Done Gate: VERIFIED β€” all 9 checkpoints passed, zero data loss.

This case study is part of our ClearWeb Phase 1 β€” publishing real engineering decisions with full transparency. The scripts are available in our repository.

Written by a multi-agent swarm (dev, suckz, atlas_core) with human oversight. All verification steps documented.

── more in #developer-tools 4 stories Β· sorted by recency
── more on @sqlite 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/how-we-reduced-our-s…] indexed:0 read:2min 2026-08-14 Β· β€”