tursodatabase/turso · error · anyhow::Error

Unable to access database schema. The database may be using…

Error message

Unable to access database schema. The database may be using an older SQLite version or may not be properly initialized.

What it means

Raised while listing indexes (.indexes) when the schema query fails with 'no such table: sqlite_schema'. The CLI string-matches that error and reports that the database cannot be inspected because it may predate sqlite_schema or is not properly initialized (cli/app.rs:1649). Everything else falls through to the generic wrapper.

Solutions

  1. Check you opened the intended path - wrong file is the most common cause
  2. If the file is an empty placeholder, create any table to initialize the schema, then retry
  3. Verify the file is a real SQLite database (header magic 'SQLite format 3', or open it with sqlite3)
  4. For genuine legacy databases, convert with a current sqlite3 (open plus VACUUM INTO) before using tursodb

Example fix

# before
touch empty.db && tursodb empty.db
# .indexes -> Unable to access database schema...
# after
tursodb real.db
Defensive patterns

Strategy: validation

Validate before calling

let mut f = std::fs::File::open(&path)?;
let mut magic = [0u8; 16];
f.read_exact(&mut magic)?;
anyhow::ensure!(&magic == b"SQLite format 3\0", "not a SQLite database: {path}");

Type guard

fn is_sqlite_file(header: &[u8]) -> bool {
    header.starts_with(b"SQLite format 3\0")
}

Prevention

When it happens

Trigger: Running .indexes on a zero-byte placeholder file, on a database created by a very old SQLite that only has sqlite_master, or on a file that is not a SQLite database at all so no schema table exists.

Common situations: Pointing the CLI at an empty placeholder created with touch; opening a non-SQLite file by mistake; fixtures exported from legacy SQLite versions.

Related errors


AI-assisted analysis of tursodatabase/turso@492c4a71cd (2026-08-20). Data as JSON: /api/errors/f2a09c7d9c361959. Report an issue: GitHub.

Appendix: source

Thrown at cli/app.rs:1659

                Some(ref tbl_name) => format!(
                    "SELECT name FROM {name}.sqlite_schema WHERE type='index' AND tbl_name = '{tbl_name}' ORDER BY 1"
                ),
                None => format!("SELECT name FROM {name}.sqlite_schema WHERE type='index' ORDER BY 1"),
            };
            let handler = |row: &turso_core::Row| {
                if let Ok(Value::Text(idx)) = row.get::<&Value>(0) {
                    if let Some(prefix) = prefix {
                        indexes.push_str(prefix);
                        indexes.push('.');
                    }
                    indexes.push_str(idx.as_str());
                    indexes.push(' ');
                }
                Ok(())
            };
            if let Err(err) = self.handle_row(&sql, handler) {
                if err.to_string().contains("no such table: sqlite_schema") {
                    return Err(anyhow::anyhow!("Unable to access database schema. The database may be using an older SQLite version or may not be properly initialized."));
                } else {
                    return Err(anyhow::anyhow!("Error querying schema: {}", err));
                }
            }
        }
        if !indexes.is_empty() {
            let _ = self.writeln(indexes.trim_end().as_bytes());
        }
        Ok(())
    }

    fn display_tables(&mut self, pattern: Option<&str>) -> anyhow::Result<()> {
        let mut tables = String::new();

        for name in self.database_names()? {
            let prefix = (name != "main").then_some(&name);
            let sql = match pattern {
                Some(pattern) => format!(

View on GitHub (pinned to 492c4a71cd)