“Database disk image is malformed” is SQLite’s corruption error. The result code is SQLITE_CORRUPT, numeric value 11. SQLite has detected that part of the database file’s internal structure does not match what it expects. The pages or indexes are wrong. This guide walks you through working out whether the damage is limited to indexes or has hit the table data, then salvaging as much content as possible.

What Does “Database Disk Image is Malformed” Mean?

This error means the database file is internally inconsistent. Do not confuse it with “file is not a database.” That is a separate result code, SQLITE_NOTADB, numeric value 26. It usually means the file header is wrong or the file is encrypted, not that page contents are damaged. SQLITE_CORRUPT tells you the database’s pages or indexes do not match the expected structure.

Stop writing to the file. Make a copy immediately. Include the main database file and any sidecar files with the -wal or -journal extensions. Those may hold committed changes not yet in the main file.

Step 1 Copy Your Database Files

Before you try any fix, copy the database and its associated -wal and -journal files to a safe location. This is not optional. Attempt a repair on the original and something goes wrong, you have no way to undo it. Use a file manager or command line.

  1. Close any application that might have the database open.
  2. Copy the database file (for example, mydata.db) to a backup name.
  3. Also copy mydata.db-wal and mydata.db-journal if they exist.

After copying, work only on the copy. Keep the original untouched until you are satisfied with the result.

Step 2 Run an Integrity Check

Full Check Versus Quick Check

SQLite provides two built-in commands to assess damage: PRAGMA integrity_check; and PRAGMA quick_check;. The full check returns “ok” on a healthy database and lists specific problems otherwise. The quick check is faster but less thorough. Run the full check first.

From the sqlite3 command-line shell:

PRAGMA integrity_check;

If the output lists errors like “row missing from index” or “wrong # of entries in index,” the damage may be limited to indexes. If the output shows errors about table pages or repeats “database disk image is malformed,” the underlying table data is likely affected.

Step 3 Fix Index-Only Damage with REINDEX

If the integrity check reports problems only with indexes (for example, “row missing from index” or “wrong # of entries in index”), you can often repair the database by rebuilding the indexes from the table data. The REINDEX; command drops and recreates all indexes, using the actual table contents as the source of truth.

Open the database in the sqlite3 shell and type:

REINDEX;

Run PRAGMA integrity_check; again. If it returns “ok,” your database is healthy. If the check still reports errors, the damage is not limited to indexes. Move to the salvage methods below.

Step 4 Salvage Data with .recover

When Table Data Is Damaged

When the table data itself is damaged, REINDEX will not help. The sqlite3 command-line shell includes a dedicated salvage command called .recover, added in version 3.29.0 (2019). It reads past damaged pages and retrieves as much content as possible.

Running the Command

Pipe the output of .recover into a new database file:

sqlite3 broken.db .recover | sqlite3 fixed.db

This creates a new database, fixed.db, containing the salvaged data. Rows from damaged pages may land in a special table named lost_and_found. Inspect that table after the operation to see if any data you need ended up there.

.recover Versus .dump

.recover is more robust than .dump for this purpose. The .dump command also exports SQL, but it stops or skips data when it hits a corrupt page. .recover is built specifically to continue reading past damage.

Step 5 Use .dump as a Fallback

If .recover is not available (you have an older version of sqlite3), try .dump. The command exports the database as SQL statements. It is not designed for corruption. When it encounters a corrupt page, it may stop entirely or skip the problematic data. You can end up with an incomplete export.

To use .dump:

sqlite3 broken.db .dump | sqlite3 fixed.db

After the dump, run PRAGMA integrity_check; on the new database to see if it is clean. If you see errors, or if the dump stopped with a corruption message, rely on .recover instead.

Step 6 Verify the Salvaged Database

Structural Checks

Once you have a salvaged file, verify it before you use it. Run PRAGMA integrity_check; on the new database. If it returns “ok,” the structure is sound. Then run PRAGMA quick_check; for a faster confirmation.

Data Completeness

Check the lost_and_found table if it exists. That table may contain rows that could not be matched to their original tables. Compare the row counts of your main tables with your backups, if you have them. Salvage is not guaranteed to save everything, but it retrieves the majority of the data in most cases.