Report #66498
[bug\_fix] database disk image is malformed \(SQLITE\_CORRUPT\)
Restore from the most recent good backup immediately. If no backup exists, attempt to salvage data using \`.mode insert\` and \`.output dump.sql\` followed by \`.dump\` to generate a SQL dump of readable data, then recreate the database from the dump. To prevent recurrence: enable WAL mode \(\`PRAGMA journal\_mode=WAL;\`\), ensure \`PRAGMA synchronous = FULL;\` for critical data, and never copy the database file while it is open by another connection.
Journey Context:
A mobile app user reports the app crashes on launch. Logs reveal 'database disk image is malformed'. The developer traces this to a power loss event on the user's device mid-write. The SQLite file headers or B-tree pages are corrupted. The developer tries \`PRAGMA integrity\_check;\` which reports multiple errors like 'row xxx missing from index yyy' and 'page xxx is never used'. Since this is a client-side cache of server data, the simplest fix is to delete the malformed file and let the app re-sync from the cloud. However, for a primary store with no server backup, the developer uses the SQLite CLI: \`.mode insert\`, \`.output dump.sql\`, \`.dump\` to extract all readable data as SQL statements, then \`.read dump.sql\` into a new file. This recovers 99% of data. To prevent this, they switch the app to WAL mode and add a startup integrity check using \`PRAGMA quick\_check;\` to detect corruption early.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:05:46.318519+00:00— report_created — created