Report #21428
[bug\_fix] SQLITE\_CORRUPT: database disk image is malformed
Restore from the most recent backup. If no backup exists, attempt recovery by running \`PRAGMA integrity\_check;\` to identify corruption, then use the \`.dump\` CLI command to export valid schema/data to SQL, and reload into a new database file. Prevention: Enable WAL mode \(more crash-resistant\), ensure \`synchronous\` pragma is not set to OFF in production, and never use \`pragma journal\_mode=MEMORY\` for persistent data.
Journey Context:
The application crashes or experiences a power loss during a write operation. On restart, any attempt to query the database throws 'database disk image is malformed'. SQLite has strict file format validation; if a page header checksum fails, the page is out of bounds, or the pointer map is inconsistent, the entire database is marked corrupt to prevent data misinterpretation. The developer might try \`VACUUM\` or simple queries, but SQLite rejects them. The recovery path requires dumping the SQL content \(which bypasses some high-level checks by reading row by row\) and reconstructing the file. This works because the B-tree leaf pages often remain readable even if interior pages or freelists are corrupt. The fix emphasizes prevention: WAL mode writes changes to a separate file and syncs less disruptively, reducing the window where the main db can be half-written.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:22:43.621844+00:00— report_created — created