// SQLite error reference

SQLITE_CORRUPT: database disk image is malformed

SQLite found the database file's structure damaged. Stop writing to it, take a copy, and recover what you can with the .recover command or from a backup.

Result code
SQLITE_CORRUPT
Name
11
Category
Primary result codes
Error message
database disk image is malformed

What it means

SQLITE_CORRUPT (11) means SQLite read something in the file that doesn't fit its format: a broken page, a bad pointer, an index entry with no matching row. SQLite doesn't corrupt files on its own in normal use; the SQLite documentation ("How To Corrupt An SQLite Database File") lists what does: files copied while a transaction is open, broken file locking (often on network file systems), deleting a hot journal, hardware or storage faults, and writes into the file by other code.

SQLITE_CORRUPT_INDEX is a special case where only an index is damaged and REINDEX may fix it.

Common causes

  • Copying or backing up the database file while it was being written, or copying it without its -wal file.
  • Deleting a -journal or -wal file left after a crash.
  • A network file system or container volume with unreliable locking, letting two writers in at once.
  • Disk, memory or power failures, or a storage layer that ignores fsync.
  • Another part of the program writing to the file directly through an open file descriptor.

How to fix it

  1. Stop writing to the database and make a copy of the file and any -wal and -journal files before you try anything.

  2. Measure the damage.

    PRAGMA integrity_check;
  3. If only indexes are affected, rebuild them.

    REINDEX;
  4. Otherwise recover the data into a new file with the sqlite3 shell's .recover command, then check the result: sqlite3 broken.db .recover | sqlite3 recovered.db.

  5. Restore from a backup if the recovery is incomplete, and make future backups with VACUUM INTO or the backup API rather than copying the file while it is in use.

    VACUUM INTO '/backups/app-2026-11-09.db';

Related errors

More primary result codes errors

The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.

// fewer errors, faster fixes

Work on SQLite in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQLite and the other databases you use.