{"record":{"id":"585af385b708509d","repo":"benbjohnson/litestream","slug":"set-page-size-w","errorCode":null,"errorMessage":"set page size: %w","messagePattern":"set page size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":81,"sourceCode":"\t}\n\n\tslog.Info(\"Database population complete\", \"db\", c.DB)\n\treturn nil\n}\n\nfunc (c *PopulateCommand) populateDatabase(ctx context.Context, targetBytes int64) error {\n\tif err := os.Remove(c.DB); err != nil && !os.IsNotExist(err) {\n\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,","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L63-L99","documentation":"After opening the database, populateDatabase executes `PRAGMA page_size = <N>` with the -page-size flag (default 4096) and wraps failures as \"set page size\". SQLite only accepts specific page sizes (512–65536, powers of two) and the pragma must run before the first write establishes the page size, so this fails when the value is illegal or the database was already initialized with a different page size.","triggerScenarios":"Running `litestream-test populate -page-size <N>` with N not a power of two in [512, 65536] (e.g., 3000, 100000, 0, negative), or issuing the pragma after the database file already has pages written (page size then becomes read-only).","commonSituations":"Users tuning page size for replication tests picking invalid values like 8192*2; flag parsing passing unexpected values; attempting to change page size on a database created by a previous run rather than a fresh file (note populate removes the existing file first, so stale-file cases are rare here).","solutions":["Use a valid page size: a power of two between 512 and 65536 (512, 1024, 2048, 4096, 8192, 16384, 32768, 65536), or just omit -page-size to use the 4096 default.","Let populate create a fresh database — do not reuse an existing file if you need a specific page size, since page size cannot change after pages are written.","Check the wrapped inner SQLite error message for the exact reason (\"not an integer\", out-of-range, etc.)."],"exampleFix":"// before\nlitestream-test populate -db ./test.db -page-size 100000\n// error: set page size\n\n// after\nlitestream-test populate -db ./test.db -page-size 16384","handlingStrategy":"validation","validationCode":"const VALID_PAGE_SIZES = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];\nif (!VALID_PAGE_SIZES.includes(pageSize)) {\n  throw new Error(`invalid -page-size ${pageSize}: must be a power of two between 512 and 65536`);\n}","typeGuard":"function isValidPageSize(n) {\n  return Number.isInteger(n) && n >= 512 && n <= 65536 && (n & (n - 1)) === 0;\n}","tryCatchPattern":"try {\n  await run(\"litestream-test\", [\"populate\", \"-db\", dbPath, \"-page-size\", String(pageSize)]);\n} catch (e) {\n  if (String(e).includes(\"set page size\")) {\n    console.error(`${pageSize} is not a valid SQLite page size; use a power of two in [512, 65536] or omit the flag (default 4096).`);\n  }\n  throw e;\n}","preventionTips":["Only use power-of-two page sizes from 512 to 65536.","Omit -page-size unless you specifically need to match a production page size.","Always let populate create a fresh file — page size cannot be changed after pages are written."],"tags":["sqlite","pragma","cli"],"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"}