Repository navigation
feat(db): check free disk before a full vacuum - #164
Merged
Merged
Conversation
A full VACUUM needs free disk of about twice the cache at its peak, and a short disk used to show only when SQLite failed after minutes of work. tg db vacuum now compares the free disk of the cache's file system with 2.2 times the file plus 64 MB before it prunes or writes anything, and fails at once with disk_full, the bytes needed and free. tg status shows the same check next to its vacuum hint. Fixes #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
feat/vacuum-disk-check
branch
from
November 17, 2026 20:29
cc2ccba to
8cb99be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A full
tg db vacuum(daemon stopped) needs free disk of about twice the cache at its peak: the new copy plus the WAL. A short disk used to show only when SQLite failed withSQLITE_FULL, after minutes of work, and the VACUUM was rolled back.Now, before a full VACUUM,
tg db vacuumreads the free disk of the cache's file system (statfs,bavail × bsize) and compares it with 2.2 times the cache file plus 64 MB. The storage benchmark's peaks were up to 2.16 times the file (3.37 GB for a 1.56 GB cache), so 2.2× covers every measured peak; the 64 MB covers small caches and what other programs write meanwhile. When the disk is short, it fails before it prunes or writes anything, withGENERAL_ERROR,details.reason: "disk_full"(the same reason the SQLite failure reports),needed_bytesandfree_bytes. The suggestion: free some space, or, for a cache with incremental auto_vacuum, start the daemon and runtg db vacuumagain, since the incremental mode needs no copy. The incremental mode (daemon running) is not checked.tg status --format prettyshows the same check next to its vacuum hint when the hinted command would run a full vacuum.Before / After
Before:
tg db vacuumon a short disk ran for minutes, then failed withdisk_fulland rolled back.After:
{ "success": false, "error": { "code": "GENERAL_ERROR", "message": "Not enough disk space to vacuum the cache of account 1: a full VACUUM needs about 64.8 MB of free disk and only 19.1 MB is free. Nothing was changed.", "details": { "account_id": 1, "reason": "disk_full", "needed_bytes": 67973940, "free_bytes": 20000000 }, "suggestion": "Free some disk space, or start the daemon (tg daemon start) and run tg db vacuum --account 1 again: then it releases the free pages in place, without a copy" } }tg status:Tests
db.e2e.test.ts): enough free disk runs the full vacuum; too little fails at once with the details and the incremental suggestion, and leaves the pruned rows and free pages untouched; a cache without auto_vacuum gets the free-space suggestion only; the incremental mode ignores a tiny disk.status.e2e.test.ts): the hint shows the shortfall for a full vacuum (daemon stopped, and daemon running with a cache without auto_vacuum), and not for the incremental mode.TELEGRAM_SYNC_CLI_TEST_FREE_DISK_BYTES(documented indocs/testing.md).bun run check,bun run test(2243 pass),bun run test:e2e(374 pass).Docs:
docs/cli-commands.md(the check, the error, the status hint),docs/storage.md(why 2.2× plus 64 MB),docs/testing.md, CHANGELOG.Fixes #119
🤖 Generated with Claude Code