Report #17578
[bug\_fix] database disk image is malformed \(SQLITE\_CORRUPT\)
Restore from the most recent good backup immediately. To prevent recurrence, enable WAL mode \(which is more resistant to corruption\), ensure PRAGMA synchronous is set to FULL or EXTRA, and never store SQLite databases on network filesystems or allow multiple processes without proper locking mechanisms.
Journey Context:
An Android app using SQLite starts crashing on startup for some users with 'database disk image is malformed'. The developer investigates and finds that SQLite database corruption typically occurs when the app is killed by the OS during a write, or when the device loses power while SQLite is in the middle of updating the B-tree structure. In the default DELETE journal mode, if a crash occurs between deleting the journal and updating the main database, the file ends up in an inconsistent state. The developer implements a recovery strategy: on startup, they run PRAGMA quick\_check, and if it fails, they delete the local database and trigger a resync from the server. To prevent future corruption, they switch the database to WAL mode \(which maintains consistency even if the app crashes\) and set PRAGMA synchronous=FULL to ensure the OS actually writes data to disk before returning success.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:47:50.637219+00:00— report_created — created