benbjohnson/litestream · error
set page size: %w
Error message
set page size: %w
What it means
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.
Source
Thrown at cmd/litestream-test/populate.go:81
}
slog.Info("Database population complete", "db", c.DB)
return nil
}
func (c *PopulateCommand) populateDatabase(ctx context.Context, targetBytes int64) error {
if err := os.Remove(c.DB); err != nil && !os.IsNotExist(err) {
slog.Warn("Could not remove existing database", "error", err)
}
db, err := sql.Open("sqlite3", c.DB)
if err != nil {
return fmt.Errorf("open database: %w", err)
}
defer db.Close()
if _, err := db.Exec(fmt.Sprintf("PRAGMA page_size = %d", c.PageSize)); err != nil {
return fmt.Errorf("set page size: %w", err)
}
if _, err := db.Exec("PRAGMA journal_mode = WAL"); err != nil {
return fmt.Errorf("set journal mode: %w", err)
}
if _, err := db.Exec("PRAGMA synchronous = NORMAL"); err != nil {
return fmt.Errorf("set synchronous: %w", err)
}
for i := 0; i < c.TableCount; i++ {
tableName := fmt.Sprintf("test_table_%d", i)
createSQL := fmt.Sprintf(`
CREATE TABLE %s (
id INTEGER PRIMARY KEY AUTOINCREMENT,
data BLOB,
text_field TEXT,View on GitHub (pinned to 4ed7a308f6)
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.).
Example fix
// before litestream-test populate -db ./test.db -page-size 100000 // error: set page size // after litestream-test populate -db ./test.db -page-size 16384
Defensive patterns
Strategy: validation
Validate before calling
const VALID_PAGE_SIZES = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
if (!VALID_PAGE_SIZES.includes(pageSize)) {
throw new Error(`invalid -page-size ${pageSize}: must be a power of two between 512 and 65536`);
} Type guard
function isValidPageSize(n) {
return Number.isInteger(n) && n >= 512 && n <= 65536 && (n & (n - 1)) === 0;
} Try / catch
try {
await run("litestream-test", ["populate", "-db", dbPath, "-page-size", String(pageSize)]);
} catch (e) {
if (String(e).includes("set page size")) {
console.error(`${pageSize} is not a valid SQLite page size; use a power of two in [512, 65536] or omit the flag (default 4096).`);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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).
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- database does not exist: %w
- open database: %w
- ensure test table: %w
- populate database: %w
- open database: %w
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/585af385b708509d.
Report an issue: GitHub.