Report #95226
[bug\_fix] SQLite database disk image is malformed \(SQLITE\_CORRUPT\)
Restore from the most recent good backup; to prevent recurrence, enable WAL mode and ensure synchronous=NORMAL or FULL to guarantee durability, and avoid running SQLite on network filesystems like NFS or SMB which can cause corruption.
Journey Context:
IoT edge device running SQLite on Raspberry Pi loses power during a write operation. On reboot, application fails to start with 'sqlite3.DatabaseError: database disk image is malformed'. PRAGMA integrity\_check; returns errors about missing pages and btree corruption. Check dmesg: filesystem errors, SD card I/O errors. Realize device was using journal\_mode=DELETE with synchronous=OFF for performance. A power loss during a commit left the database partially written \(torn page\). The rollback journal was insufficient to recover because pages were partially written to the main file. Decision: No repair tool is fully safe, so restore from the nightly backup taken before the outage. To prevent this, reconfigure to PRAGMA journal\_mode=WAL; which is more resilient to power loss due to append-only log, and set PRAGMA synchronous=NORMAL; to ensure the OS flushes writes. Also monitor SD card health.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:24:58.877955+00:00— report_created — created