From 05f31e457ec8723a9e59e898c38c83e9c2955073 Mon Sep 17 00:00:00 2001 From: Johnny Date: Tue, 20 Jan 2026 21:53:31 +0800 Subject: [PATCH] fix: add mmap size setting to database connection to prevent OOM errors --- store/db/sqlite/sqlite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/store/db/sqlite/sqlite.go b/store/db/sqlite/sqlite.go index 3b4a30f8d..642e728cf 100644 --- a/store/db/sqlite/sqlite.go +++ b/store/db/sqlite/sqlite.go @@ -33,6 +33,7 @@ func NewDB(profile *profile.Profile) (store.Driver, error) { // good practice to be explicit and prevent future surprises on SQLite upgrades. // - Journal mode set to WAL: it's the recommended journal mode for most applications // as it prevents locking issues. + // - mmap size set to 0: it disables memory mapping, which can cause OOM errors on some systems. // // Notes: // - When using the `modernc.org/sqlite` driver, each pragma must be prefixed with `_pragma=`. @@ -41,7 +42,7 @@ func NewDB(profile *profile.Profile) (store.Driver, error) { // - https://pkg.go.dev/modernc.org/sqlite#Driver.Open // - https://www.sqlite.org/sharedcache.html // - https://www.sqlite.org/pragma.html - sqliteDB, err := sql.Open("sqlite", profile.DSN+"?_pragma=foreign_keys(0)&_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)") + sqliteDB, err := sql.Open("sqlite", profile.DSN+"?_pragma=foreign_keys(0)&_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)&_pragma=mmap_size(0)") if err != nil { return nil, errors.Wrapf(err, "failed to open db with dsn: %s", profile.DSN) }