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.
This commit is contained in:
Jeffrey Paul 2026-01-01 06:49:58 -08:00
parent 4f62b280c5
commit 68cc06690b

View File

@ -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)
}