From 68cc06690bbaa8c0e91f2f04b0fcf512c21fac81 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 1 Jan 2026 06:49:58 -0800 Subject: [PATCH] Use TRUNCATE mode for WAL checkpoints PASSIVE checkpoints may not fully checkpoint when writers are active. TRUNCATE mode blocks writers briefly but ensures complete checkpointing, keeping the WAL small for consistent read performance under heavy load. --- internal/database/database.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index 8e20ce1..aac7744 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -2000,9 +2000,10 @@ func (d *Database) Analyze(ctx context.Context) error { } // Checkpoint runs a WAL checkpoint to transfer data from the WAL to the main database. -// Uses PASSIVE mode which doesn't block writers but may not checkpoint all frames. +// Uses TRUNCATE mode which blocks writers briefly but ensures complete checkpoint, +// keeping the WAL small for fast read performance. func (d *Database) Checkpoint(ctx context.Context) error { - _, err := d.db.ExecContext(ctx, "PRAGMA wal_checkpoint(PASSIVE)") + _, err := d.db.ExecContext(ctx, "PRAGMA wal_checkpoint(TRUNCATE)") if err != nil { return fmt.Errorf("failed to checkpoint WAL: %w", err) }