{"record":{"id":"c0dadeb2d7f31403","repo":"linera-io/linera-protocol","slug":"failed-to-create-sqlite-database-file-database-u","errorCode":null,"errorMessage":"failed to create SQLite database file: {database_url}, error: {e}","messagePattern":"failed to create SQLite database file: (.+?), error: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-indexer/lib/src/db/sqlite/mod.rs","lineNumber":76,"sourceCode":"}\n\npub struct SqliteDatabase {\n    pool: SqlitePool,\n}\n\nimpl SqliteDatabase {\n    /// Creates a new SQLite database connection.\n    pub async fn new(database_url: &str) -> Result<Self, SqliteError> {\n        if !database_url.contains(\"memory\") {\n            match std::fs::exists(database_url) {\n                Ok(true) => {\n                    tracing::info!(?database_url, \"opening existing SQLite database\");\n                }\n                Ok(false) => {\n                    tracing::info!(?database_url, \"creating new SQLite database\");\n                    // Create the database file if it doesn't exist\n                    std::fs::File::create(database_url).unwrap_or_else(|e| {\n                        panic!(\"failed to create SQLite database file: {database_url}, error: {e}\")\n                    });\n                }\n                Err(e) => {\n                    panic!(\n                        \"failed to check SQLite database existence. file: {database_url}, error: {e}\"\n                    )\n                }\n            }\n        }\n        let pool = SqlitePoolOptions::new()\n            .max_connections(5)\n            .connect(database_url)\n            .await\n            .map_err(SqliteError::Database)?;\n        let db = Self { pool };\n        db.initialize_schema().await?;\n        Ok(db)\n    }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-indexer/lib/src/db/sqlite/mod.rs#L58-L94","documentation":"When the Linera indexer opens its SQLite database and the file does not yet exist, SqliteDb::new creates it with std::fs::File::create and panics if the OS call fails. The message includes the database path and the underlying io::Error, so the real cause (usually a missing parent directory, permission denied, or a read-only filesystem) is visible at the end of the panic output.","triggerScenarios":"Launching the indexer with a --database path whose parent directory does not exist, is not writable by the current user, sits on a read-only mount, or when the disk is full. Only fires when the file is confirmed absent (Ok(false) from the existence check) and creation then fails.","commonSituations":"Pointing the indexer at /var/lib/... or other root-owned directories without mkdir/chown first; container deployments that mount an empty read-only volume; typos in the database path (e.g. a missing directory component); CI runs as an unprivileged user.","solutions":["Create the parent directory: mkdir -p /path/to/data","Make sure the directory is writable by the running user (chown/chmod or move the DB under $HOME or /tmp)","Check the volume is mounted read-write and has free space (df)","Re-run and confirm the new file appears; subsequent starts take the 'opening existing SQLite database' path"],"exampleFix":"# before\nlinera-indexer --database /var/lib/nonexistent-dir/indexer.db\n\n# after\nmkdir -p /var/lib/nonexistent-dir && chown \"$USER\" /var/lib/nonexistent-dir\nlinera-indexer --database /var/lib/nonexistent-dir/indexer.db","handlingStrategy":"validation","validationCode":"let path = std::path::Path::new(database_url);\nif let Some(parent) = path.parent() {\n    std::fs::create_dir_all(parent)\n        .unwrap_or_else(|e| panic!(\"cannot create {}: {e}\", parent.display()));\n}\nassert!(\n    parent.map(|p| p.writable()).unwrap_or(false) || path.writable(),\n    \"no write permission for {}\",\n    path.display()\n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the data directory in deployment scripts/systemd (ExecStartPre=mkdir -p)","Run the indexer as a user that owns the data directory","Use absolute paths in config so relative-cwd changes can't redirect file creation"],"tags":["sqlite","indexer","filesystem","permissions","startup"],"backgroundTag":"database-file-creation-failed","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}