{"record":{"id":"5b39b7118480e2f3","repo":"benbjohnson/litestream","slug":"set-synchronous-w","errorCode":null,"errorMessage":"set synchronous: %w","messagePattern":"set synchronous: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":89,"sourceCode":"\t\tslog.Warn(\"Could not remove existing database\", \"error\", err)\n\t}\n\n\tdb, err := sql.Open(\"sqlite3\", c.DB)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open database: %w\", err)\n\t}\n\tdefer db.Close()\n\n\tif _, err := db.Exec(fmt.Sprintf(\"PRAGMA page_size = %d\", c.PageSize)); err != nil {\n\t\treturn fmt.Errorf(\"set page size: %w\", err)\n\t}\n\n\tif _, err := db.Exec(\"PRAGMA journal_mode = WAL\"); err != nil {\n\t\treturn fmt.Errorf(\"set journal mode: %w\", err)\n\t}\n\n\tif _, err := db.Exec(\"PRAGMA synchronous = NORMAL\"); err != nil {\n\t\treturn fmt.Errorf(\"set synchronous: %w\", err)\n\t}\n\n\tfor i := 0; i < c.TableCount; i++ {\n\t\ttableName := fmt.Sprintf(\"test_table_%d\", i)\n\n\t\tcreateSQL := fmt.Sprintf(`\n\t\t\tCREATE TABLE %s (\n\t\t\t\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\t\t\t\tdata BLOB,\n\t\t\t\ttext_field TEXT,\n\t\t\t\tint_field INTEGER,\n\t\t\t\tfloat_field REAL,\n\t\t\t\ttimestamp INTEGER\n\t\t\t)\n\t\t`, tableName)\n\n\t\tif _, err := db.Exec(createSQL); err != nil {\n\t\t\treturn fmt.Errorf(\"create table %s: %w\", tableName, err)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L71-L107","documentation":"populateDatabase wraps a failed \"PRAGMA journal_mode = WAL\" execution. The command switches the test database into WAL mode, which litestream requires in order to monitor the WAL and produce LTX files. If SQLite refuses the mode change, the tool cannot simulate a litestream-backed database and returns immediately.","triggerScenarios":"db.Exec(\"PRAGMA journal_mode = WAL\") returns an error: the database file is on a filesystem that does not support shared memory (e.g. some network mounts), the file is locked by another connection, or the database is corrupted.","commonSituations":"Running the populate tool against a database on an NFS/SMB mount; a second litestream or sqlite process holding an exclusive lock; leftover -wal/-shm files with stale permissions.","solutions":["Move the database to a local filesystem that supports shared memory (not NFS/SMB).","Close other connections holding locks on the database before populating.","Check that the -wal and -shm companion files are writable by the current user.","Inspect the wrapped SQLite error (the %w cause) for the specific SQLITE_ code."],"exampleFix":"// before\nlitestream-test populate -db /mnt/nfs/data.db   // WAL unsupported on NFS\n// after\nlitestream-test populate -db /var/tmp/data.db   // local filesystem","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(dbPath); err == nil {\n    // reject known WAL-incompatible network mounts\n    if isNetworkMount(filepath.Dir(dbPath)) {\n        return fmt.Errorf(\"WAL mode unsupported on network filesystem: %s\", filepath.Dir(dbPath))\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := db.Exec(\"PRAGMA journal_mode = WAL\"); err != nil {\n    return fmt.Errorf(\"set journal mode (is the fs local? is the db locked?): %w\", err)\n}","preventionTips":["Keep SQLite databases on local filesystems, never NFS/SMB.","Close other connections before switching journal mode.","Verify write access to the -wal and -shm companion files.","Read journal_mode back (SELECT PRAGMA journal_mode) to confirm WAL took effect."],"tags":["sqlite","wal","pragma"],"backgroundTag":"database-query-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}