[PR #15045] [CLOSED] app/store: VACUUM and REINDEX SQLite on close #20258

Closed
opened 2026-04-16 07:31:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15045
Author: @joaquinhuigomez
Created: 3/24/2026
Status: Closed

Base: mainHead: fix/sqlite-vacuum-on-close


📝 Commits (1)

  • 7fc7072 app/store: VACUUM and REINDEX SQLite database on close

📊 Changes

1 file changed (+5 additions, -0 deletions)

View changed files

📝 app/store/database.go (+5 -0)

📄 Description

Summary

Fixes #15021 — after deleting chats the SQLite database file retains its peak size because SQLite does not automatically reclaim space from deleted rows.

This adds VACUUM and REINDEX calls to the database shutdown path (right after the existing WAL checkpoint). On quit, the database is compacted and indexes are rebuilt, keeping the on-disk footprint proportional to actual stored data.

Details

  • VACUUM rewrites the database file, reclaiming unused pages left behind by deleted rows (e.g. removed chats and their messages/attachments).
  • REINDEX rebuilds all indexes for consistent query performance after compaction.
  • Both operations run during graceful shutdown only, so there is zero impact on runtime performance.
  • Errors from VACUUM/REINDEX are intentionally discarded (matching the existing pattern for the WAL checkpoint) since a failure here should not prevent the application from closing.

Test plan

  • Create several long chats, note db.sqlite file size
  • Delete all chats from the UI
  • Quit Ollama
  • Verify db.sqlite is significantly smaller after restart

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/15045 **Author:** [@joaquinhuigomez](https://github.com/joaquinhuigomez) **Created:** 3/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/sqlite-vacuum-on-close` --- ### 📝 Commits (1) - [`7fc7072`](https://github.com/ollama/ollama/commit/7fc70724634e4b73bed08bd27c3e5140486a7f69) app/store: VACUUM and REINDEX SQLite database on close ### 📊 Changes **1 file changed** (+5 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `app/store/database.go` (+5 -0) </details> ### 📄 Description ## Summary Fixes #15021 — after deleting chats the SQLite database file retains its peak size because SQLite does not automatically reclaim space from deleted rows. This adds `VACUUM` and `REINDEX` calls to the database shutdown path (right after the existing WAL checkpoint). On quit, the database is compacted and indexes are rebuilt, keeping the on-disk footprint proportional to actual stored data. ## Details - `VACUUM` rewrites the database file, reclaiming unused pages left behind by deleted rows (e.g. removed chats and their messages/attachments). - `REINDEX` rebuilds all indexes for consistent query performance after compaction. - Both operations run during graceful shutdown only, so there is zero impact on runtime performance. - Errors from VACUUM/REINDEX are intentionally discarded (matching the existing pattern for the WAL checkpoint) since a failure here should not prevent the application from closing. ## Test plan - Create several long chats, note `db.sqlite` file size - Delete all chats from the UI - Quit Ollama - Verify `db.sqlite` is significantly smaller after restart --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 07:31:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#20258