From c64484e5432f8eee5daa0c658cd93b65f559c5a9 Mon Sep 17 00:00:00 2001 From: Sean Kenneth Doherty <328402569+seankd3@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:57:39 -0600 Subject: [PATCH] fix(shared): SQLite reads keep sorts and temp tables in memory again #24194 set temp_store = MEMORY so SQLite temp files stop blocking the server. That pragma runs only on the writer. The reader workers added for concurrent reads open their own connections and set only busy_timeout, so every read that sorts or builds a temp table spills to a file in the system temp directory. Each reader now sets temp_store = MEMORY when it opens. Co-Authored-By: Claude Opus 5.5 --- packages/shared/src/nodeSqliteClient.test.ts | 12 ++++++++++++ packages/shared/src/nodeSqliteClient.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/packages/shared/src/nodeSqliteClient.test.ts b/packages/shared/src/nodeSqliteClient.test.ts index 24910bc0bf9cf..023d61ab67800 100644 --- a/packages/shared/src/nodeSqliteClient.test.ts +++ b/packages/shared/src/nodeSqliteClient.test.ts @@ -595,6 +595,18 @@ it.effect("keeps the reader read-only even if a statement turns query_only off", ), ); +it.effect("keeps a reader's sorts and temp tables in memory, not in temp files", () => + withReaderClient((sql) => + Effect.gen(function* () { + const rows = yield* sql<{ temp_store: number }>`PRAGMA temp_store`.pipe( + sql.withTransaction, + SqliteClient.readOnly, + ); + assert.equal(rows[0]?.temp_store, 2); + }), + ), +); + it.effect("keeps read-only work inside a write transaction on the writer", () => withReaderClient((sql) => sql.withTransaction( diff --git a/packages/shared/src/nodeSqliteClient.ts b/packages/shared/src/nodeSqliteClient.ts index da521a7c6036d..1b46015d89f48 100644 --- a/packages/shared/src/nodeSqliteClient.ts +++ b/packages/shared/src/nodeSqliteClient.ts @@ -214,6 +214,8 @@ try { allowExtension: workerData.allowExtension, }); next.exec("PRAGMA busy_timeout = 5000;"); + // Callers set pragmas only on the writer, so a reader would sort and build temp tables in files. + next.exec("PRAGMA temp_store = MEMORY;"); // Reads the header, so a file that is not a database fails here rather than on first use. const mode = String(next.prepare("PRAGMA journal_mode").get().journal_mode).toLowerCase(); // Without WAL a reader's shared lock blocks the writer's commits, so refuse.