From 3653e70a6d9affe85a6f6108d18e03fb23035fd2 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 17 Nov 2024 14:26:42 +0200 Subject: [PATCH] added periodic wal_checkpoint calls --- core/base.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/base.go b/core/base.go index 28948acc..9f20c3aa 100644 --- a/core/base.go +++ b/core/base.go @@ -1238,8 +1238,18 @@ func (app *BaseApp) registerBaseHooks() { Priority: 999, }) - app.Cron().Add("__pbPragmaOptimize__", "0 0 * * *", func() { - _, execErr := app.DB().NewQuery("PRAGMA optimize").Execute() + app.Cron().Add("__pbDBOptimize__", "0 0 * * *", func() { + _, execErr := app.NonconcurrentDB().NewQuery("PRAGMA wal_checkpoint(TRUNCATE)").Execute() + if execErr != nil { + app.Logger().Warn("Failed to run periodic PRAGMA wal_checkpoint for the main DB", slog.String("error", execErr.Error())) + } + + _, execErr = app.AuxNonconcurrentDB().NewQuery("PRAGMA wal_checkpoint(TRUNCATE)").Execute() + if execErr != nil { + app.Logger().Warn("Failed to run periodic PRAGMA wal_checkpoint for the auxiliary DB", slog.String("error", execErr.Error())) + } + + _, execErr = app.DB().NewQuery("PRAGMA optimize").Execute() if execErr != nil { app.Logger().Warn("Failed to run periodic PRAGMA optimize", slog.String("error", execErr.Error())) }