pgref.dev/sqlite/errors/SQLITE_CORRUPT_VTAB
SQLITE_CORRUPT_VTABERRORTier 2 — Caution⚠️ MEDIUM confidence

database disk image is malformed (virtual table)

Category: Database CorruptionVersions: SQLite 3.43.0+

What this means

SQLITE_CORRUPT_VTAB (extended code 267) is returned by a virtual table implementation when it detects that its underlying data store is corrupted or returns data that violates the expected schema contract. Unlike SQLITE_CORRUPT which indicates B-tree file corruption, SQLITE_CORRUPT_VTAB is generated by the virtual table module itself — such as FTS5 detecting inconsistency in its shadow tables.

Why it happens

  1. 1An FTS5 or FTS4 full-text search index whose shadow tables are out of sync with the main content table
  2. 2A custom virtual table extension detecting internal inconsistency in its backing store
  3. 3Manual edits to shadow tables (fts5_data, fts5_config) that break internal invariants

How to reproduce

An FTS5 index shadow table is manually corrupted.

trigger — this will ERROR
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute("CREATE VIRTUAL TABLE docs USING fts5(title, body)")
conn.execute("INSERT INTO docs VALUES ('Hello', 'World')")
# Corrupt the FTS5 internal tables directly:
conn.execute("DELETE FROM docs_data")  # removes B-tree pages
conn.execute("SELECT * FROM docs WHERE docs MATCH 'Hello'")
sqlite3.DatabaseError: database disk image is malformed

Fix 1: Rebuild the FTS5 index

When FTS5 shadow tables are out of sync.

fix
import sqlite3
conn = sqlite3.connect('mydb.db')
conn.execute("INSERT INTO docs(docs) VALUES('rebuild')")
conn.commit()

Why this works

The special INSERT ... VALUES('rebuild') command instructs FTS5 to reconstruct all its shadow tables from the main content table, correcting any inconsistencies.

What not to do

Manually edit FTS5 or FTS4 shadow tables

Why it's wrong: These tables use internal binary formats and B-tree structures. Any manual edit will almost certainly corrupt the index and trigger SQLITE_CORRUPT_VTAB.

Version notes

SQLite 3.43.0+SQLITE_CORRUPT_VTAB extended code formalised to distinguish virtual table corruption from file-level B-tree corruption.

Sources

📚 Official docs: https://www.sqlite.org/rescode.html#corrupt_vtab

🔧 Source ref: sqlite3.h — SQLITE_CORRUPT_VTAB = 267

📖 Further reading: FTS5 documentation

Confidence assessment

⚠️ MEDIUM confidence

MEDIUM — extended code is documented but less commonly encountered than the base SQLITE_CORRUPT. FTS5 rebuild semantics are documented in the FTS5 reference.

See also

📄 Reference pages

FTS5 documentationvirtual tables
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →