querylog: checkpoint every 8192 wal pages instead of 1000

This commit is contained in:
2026-08-21 18:43:45 +02:00
parent 324704b53f
commit 9b0b7c19f4
7 changed files with 140 additions and 3 deletions
+25
View File
@@ -754,6 +754,9 @@ pub const Pragmas = struct {
journal_wal: bool = true,
synchronous_normal: bool = true,
foreign_keys: bool = true,
/// Null leaves SQLite's 1000-page default. A caller that sets it owns the
/// durability consequences, which depend on what the database holds.
wal_autocheckpoint_pages: ?i32 = null,
};
/// MUST be called before any transaction is opened: `PRAGMA foreign_keys` is a
@@ -785,6 +788,16 @@ pub fn applyPragmas(self: *Db, p: Pragmas) Error!void {
return error.SqliteError;
}
}
if (p.wal_autocheckpoint_pages) |pages| {
var buf: [64]u8 = undefined;
const sql = std.fmt.bufPrintZ(&buf, "PRAGMA wal_autocheckpoint = {d};", .{pages}) catch unreachable;
try self.exec(sql);
const applied = try self.queryInt("PRAGMA wal_autocheckpoint");
if (applied != pages) {
log.warn("PRAGMA wal_autocheckpoint = {d} reported {d}", .{ pages, applied });
return error.SqliteError;
}
}
}
/// A write transaction.
@@ -907,6 +920,18 @@ test "applyPragmas succeeds and foreign_keys reads back as 1" {
try testing.expectEqual(@as(i64, 1), try db.queryInt("PRAGMA foreign_keys"));
}
test "applyPragmas leaves wal_autocheckpoint at the default unless a page count is given" {
var db = try openMemory();
defer db.close();
try applyPragmas(&db, .{});
try testing.expectEqual(@as(i64, 1000), try db.queryInt("PRAGMA wal_autocheckpoint"));
var configured = try openMemory();
defer configured.close();
try applyPragmas(&configured, .{ .wal_autocheckpoint_pages = 8192 });
try testing.expectEqual(@as(i64, 8192), try configured.queryInt("PRAGMA wal_autocheckpoint"));
}
test "open on a directory path returns error.CantOpen and leaks no handle" {
var i: usize = 0;
while (i < 1000) : (i += 1) {