Report #94609
[bug\_fix] database disk image is malformed \(SQLite\)
Restore from backup. Prevention: Enable WAL mode \(PRAGMA journal\_mode=WAL\) to use checkpointing instead of in-place overwrites, ensure PRAGMA synchronous=FULL \(or NORMAL with WAL\), and avoid writing to database files on network filesystems \(NFS, SMB\). Root cause: Partial page write or interrupted checkpoint in rollback-journal mode, or lack of fsync guarantees on network drives, leading to inconsistent on-disk state.
Journey Context:
IoT edge device using SQLite for local time-series data. After unexpected power cuts in the field, several devices reported 'database disk image is malformed' on application start. Examination with sqlite3 CLI confirmed PRAGMA integrity\_check; failed with 'database disk image is malformed'. Attempted recovery with .recover command but data was partially corrupted. Root cause analysis: devices used default DELETE journal mode. When OS lost power during a write, the 4KB page size write was partially committed to disk \(torn page\), and the rollback journal wasn't sufficient to recover because the journal itself was truncated. Fix: For new deployments, enforced WAL mode \(PRAGMA journal\_mode=WAL\) which writes changes to separate -wal file and checkpoints atomically, making corruption far less likely. Also added battery-backed write cache on new hardware. For recovery: implemented automated backup to S3 every hour, with local .backup command, so corrupted devices can be remotely wiped and restored.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:23:03.117607+00:00— report_created — created