SQLITE_CORRUPT_VTAB
SQLiteERRORNotableDatabase CorruptionMEDIUM confidence

database disk image is malformed (virtual table)

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
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'")

expected output

sqlite3.DatabaseError: database disk image is malformed

Fix

Rebuild the FTS5 index

WHEN When FTS5 shadow tables are out of sync.

Rebuild the FTS5 index
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

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 documentation ↗

sqlite3.h — SQLITE_CORRUPT_VTAB = 267

FTS5 documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All SQLite errors