Report #25217
[bug\_fix] SQLite: database disk image is malformed \(SQLITE\_CORRUPT\) after power loss
Enable WAL mode and set PRAGMA synchronous=NORMAL \(or FULL for critical data\) to ensure the write-ahead log is properly synced to disk before commit returns, preventing partial page writes during power loss.
Journey Context:
An IoT edge device running SQLite experiences abrupt power cuts during active writes. Upon reboot, SQLite reports database disk image is malformed and the database is unusable. Forensic analysis reveals the database was in DELETE journal mode with synchronous=OFF \(set for performance\). When power failed mid-write, the rollback journal was incomplete and the main database file was left with a partially written page. The recovery strategy involves switching to WAL mode, which uses checksums on every page in the WAL to detect incomplete writes, and setting synchronous=NORMAL to ensure the OS flushes WAL data to disk at commit, preventing corruption on power loss.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:43:50.430416+00:00— report_created — created