Tune SQLite caches and maintain planner statistics
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
export function tuneConnection(handle: Database.Database, reader = false): void {
|
||||
handle.pragma(`cache_size = -${reader ? 32768 : 131072}`);
|
||||
handle.pragma('temp_store = MEMORY');
|
||||
// mmap is opt-in because the controller data directory can be a network mount.
|
||||
const mmapMiB = Number(process.env.EC_SQLITE_MMAP_MB ?? 0);
|
||||
if (Number.isSafeInteger(mmapMiB) && mmapMiB >= 0 && mmapMiB <= 32768) {
|
||||
handle.pragma(`mmap_size = ${mmapMiB * 1024 * 1024}`);
|
||||
}
|
||||
if (!reader) handle.pragma('journal_size_limit = 67108864');
|
||||
}
|
||||
Reference in New Issue
Block a user