{"record":{"id":"6cfdda8a99e3d403","repo":"benbjohnson/litestream","slug":"populate-database-w","errorCode":null,"errorMessage":"populate database: %w","messagePattern":"populate database: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":62,"sourceCode":"\t\treturn fmt.Errorf(\"database path required\")\n\t}\n\n\ttargetBytes, err := parseSize(c.TargetSize)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid target size: %w\", err)\n\t}\n\n\tslog.Info(\"Starting database population\",\n\t\t\"db\", c.DB,\n\t\t\"target_size\", c.TargetSize,\n\t\t\"row_size\", c.RowSize,\n\t\t\"batch_size\", c.BatchSize,\n\t\t\"table_count\", c.TableCount,\n\t\t\"page_size\", c.PageSize,\n\t)\n\n\tif err := c.populateDatabase(ctx, targetBytes); err != nil {\n\t\treturn fmt.Errorf(\"populate database: %w\", err)\n\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 {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L44-L80","documentation":"Run wraps any failure from populateDatabase as \"populate database\". populateDatabase opens the SQLite file, sets pragmas (page size, journal mode, synchronous), creates tables, and inserts rows until the target size is reached; any failure anywhere in that pipeline is surfaced with this wrapper, with the root cause preserved via %w.","triggerScenarios":"Any mid-population failure: SQL execution errors during table creation or batch inserts, disk becoming full while growing the DB to the target size, context cancellation/timeout, or connection failures.","commonSituations":"Disk filling up before reaching a large -target-size (most common for multi-GB targets); SQLITE_BUSY from concurrent access; invalid combination of flags (e.g., row-size larger than allowed by page size constraints); interrupted transactions.","solutions":["Read the wrapped inner error to identify the root cause (disk full vs SQL error vs busy).","Free disk space or lower `-target-size` so the database can actually reach the requested size.","Reduce contention: stop other processes writing to the same database, or lower `-batch-size`.","Adjust `-row-size`/`-page-size` to compatible values if the inner error indicates a SQLite limit violation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: enough free space for the target size?\nimport { statfsSync } from \"fs\";\nconst need = parseSizeBytes(targetSize); // e.g. 1GB -> 1e9\nconst { bavail, bsize } = statfsSync(path.dirname(dbPath));\nif (bavail * bsize < need * 1.2) throw new Error(\"insufficient free disk space for -target-size \" + targetSize);","typeGuard":null,"tryCatchPattern":"try {\n  await run(\"litestream-test\", [\"populate\", \"-db\", dbPath, \"-target-size\", targetSize]);\n} catch (e) {\n  if (String(e).includes(\"populate database\")) {\n    if (/disk I/O error|no space/i.test(String(e.cause ?? e))) {\n      console.error(\"Free disk space or lower -target-size, then retry.\");\n    }\n  }\n  throw e;\n}","preventionTips":["Check free disk space against the target size before populating.","Lower -row-size/-batch-size if you hit SQLite limits mid-run.","Avoid running other writers against the same DB during population."],"tags":["sqlite","cli","bulk-load"],"backgroundTag":"database-write-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}