From 3a4c7766e95046e117660782c83fd94aca9224a8 Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Sun, 29 Mar 2026 17:29:02 +1300 Subject: [PATCH] Feature: Add option to disable auto-VACUUMing of the SQLite database (#661) --- cmd/root.go | 3 +++ config/config.go | 4 ++++ internal/storage/cron.go | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index a232016..ddb9b89 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -86,6 +86,7 @@ func init() { rootCmd.Flags().StringVarP(&config.Database, "database", "d", config.Database, "Database to store persistent data") rootCmd.Flags().BoolVar(&config.DisableWAL, "disable-wal", config.DisableWAL, "Disable WAL for local database (allows NFS mounted DBs)") rootCmd.Flags().BoolVar(&config.DisableVersionCheck, "disable-version-check", config.DisableVersionCheck, "Disable version update checking") + rootCmd.Flags().BoolVar(&config.DisableAutoVACUUM, "disable-auto-vacuum", config.DisableAutoVACUUM, "Disable auto-VACUUM for the database") rootCmd.Flags().IntVar(&config.Compression, "compression", config.Compression, "Compression level to store raw messages (0-3)") rootCmd.Flags().StringVar(&config.Label, "label", config.Label, "Optional label identify this Mailpit instance") rootCmd.Flags().StringVar(&config.TenantID, "tenant-id", config.TenantID, "Database tenant ID to isolate data") @@ -202,6 +203,8 @@ func initConfigFromEnv() { config.DisableVersionCheck = getEnabledFromEnv("MP_DISABLE_VERSION_CHECK") + config.DisableAutoVACUUM = getEnabledFromEnv("MP_DISABLE_AUTO_VACUUM") + if len(os.Getenv("MP_COMPRESSION")) > 0 { config.Compression, _ = strconv.Atoi(os.Getenv("MP_COMPRESSION")) } diff --git a/config/config.go b/config/config.go index ff2bfea..bc10097 100644 --- a/config/config.go +++ b/config/config.go @@ -46,6 +46,10 @@ var ( // @see https://sqlite.org/wal.html DisableWAL bool + // DisableAutoVACUUM will disable the auto-VACUUM of the local SQLite database when messages + // are deleted and a preconfigured threshold is reached. + DisableAutoVACUUM bool + // Compression is the compression level used to store raw messages in the database: // 0 = off, 1 = fastest (default), 2 = standard, 3 = best compression Compression = 1 diff --git a/internal/storage/cron.go b/internal/storage/cron.go index 3286ffd..52b29d7 100644 --- a/internal/storage/cron.go +++ b/internal/storage/cron.go @@ -16,6 +16,14 @@ import ( // Database cron runs every minute func dbCron() { + if config.DisableAutoVACUUM { + if sqlDriver == "rqlite" { + logger.Log().Warn("[db] disable-auto-vacuum has no effect as rqlite handles vacuuming automatically") + } else { + logger.Log().Infof("[db] auto-VACUUM is disabled") + } + } + for { time.Sleep(60 * time.Second) @@ -35,7 +43,7 @@ func dbCron() { deletedPercent = float64(deletedSize * 100 / total) } // only vacuum the DB if at least 1% of mail storage size has been deleted - if deletedPercent >= 1 { + if !config.DisableAutoVACUUM && deletedPercent >= 1 { logger.Log().Debugf("[db] deleted messages is %f%% of total size, reclaim space", deletedPercent) vacuumDb() }