{"record":{"id":"bde1233d939a9bd4","repo":"thedotmack/claude-mem","slug":"failed-to-apply-sqlite-pragma-name","errorCode":null,"errorMessage":"Failed to apply SQLite pragma ${name}","messagePattern":"Failed to apply SQLite pragma (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/sqlite/connection.ts","lineNumber":30,"sourceCode":"}\n\nfunction hasUserTables(db: Database): boolean {\n  const row = db.prepare(`\n    SELECT name\n    FROM sqlite_master\n    WHERE type = 'table'\n      AND name NOT LIKE 'sqlite_%'\n    LIMIT 1\n  `).get() as { name: string } | undefined;\n  return row != null;\n}\n\nfunction runRequiredPragma(db: Database, sql: string, name: string): void {\n  try {\n    db.run(sql);\n  } catch (error) {\n    const err = error instanceof Error ? error : new Error(String(error));\n    logger.warn('DB', `Failed to apply SQLite pragma ${name}`, { sql }, err);\n    throw error;\n  }\n}\n\nexport function applySqliteConnectionPragmas(\n  db: Database,\n  options: SqlitePragmaOptions = {},\n): void {\n  const {\n    enableWal = true,\n    enableIncrementalAutoVacuum = true,\n  } = options;\n\n  runRequiredPragma(db, `PRAGMA busy_timeout = ${SQLITE_BUSY_TIMEOUT_MS}`, 'busy_timeout');\n  runRequiredPragma(db, 'PRAGMA foreign_keys = ON', 'foreign_keys');\n  runRequiredPragma(db, 'PRAGMA synchronous = NORMAL', 'synchronous');\n  runRequiredPragma(db, `PRAGMA journal_size_limit = ${SQLITE_JOURNAL_SIZE_LIMIT_BYTES}`, 'journal_size_limit');\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/sqlite/connection.ts#L12-L48","documentation":"applySqliteConnectionPragmas() runs required pragmas (journal_mode=WAL, incremental auto_vacuum, etc.) on every new SQLite connection. runRequiredPragma() logs the pragma name and SQL, then rethrows — connection setup aborts and the caller gets the original SQLite error.","triggerScenarios":"PRAGMA journal_mode=WAL on a read-only database or a filesystem without WAL shared-memory support (SMB/NFS); setting auto_vacuum while the DB is inside a transaction; permission errors creating the -wal/-shm sibling files.","commonSituations":"DB file moved onto a network share or cloud-synced folder (Dropbox/OneDrive); file ownership/permissions changed (EACCES/EROFS); a container or VM opening the file without write permission; another process holding an exclusive lock.","solutions":["Move the DB onto a local writable disk — WAL fundamentally requires it","Fix permissions on the DB file and its directory (WAL creates -wal/-shm files alongside)","Close any other process holding the DB before restarting","Check the logged sql field to see exactly which pragma failed and reproduce it in a sqlite shell","If WAL truly cannot be used, pass enableWal: false via SqlitePragmaOptions where the connection is created"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { accessSync, constants } from 'node:fs';\nimport { dirname } from 'node:path';\n\nfunction assertDbWritable(dbPath: string): void {\n  accessSync(dirname(dbPath), constants.W_OK); // -wal/-shm siblings are created here\n  try {\n    accessSync(dbPath, constants.W_OK);\n  } catch {\n    // creating a new file is fine; an existing unwritable one is not\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  applySqliteConnectionPragmas(db, { enableWal: true });\n} catch (err) {\n  // fail fast with a configuration error naming the DB path;\n  // never proceed with a half-configured connection\n  throw new Error(`SQLite connection setup failed for ${dbPath}: ${String(err)}`);\n}","preventionTips":["Never place SQLite WAL databases on network or cloud-synced filesystems","Grant write access to the whole DB directory, not just the file","Open each DB from one process at a time to avoid exclusive-lock pragma failures"],"tags":["sqlite","pragma","wal","connection-setup","filesystem"],"backgroundTag":"sqlite-pragma-failed","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}