Report #71301
[bug\_fix] SQLite database disk image is malformed \(SQLITE\_CORRUPT\)
The root cause is typically hardware failure, power loss during write, or filesystem bugs causing partial page writes. SQLite's rollback journal or WAL mode is designed to prevent this, but if the -journal or -wal file is deleted or corrupted, the database can be left inconsistent. The fix is to restore from a backup. If no backup exists, attempt partial recovery using .dump to extract readable data to a new database, then run PRAGMA integrity\_check to assess damage.
Journey Context:
An embedded device running SQLite experiences a power outage during a write operation. On reboot, the application fails to open the database with 'database disk image is malformed'. The developer first attempts to run PRAGMA integrity\_check; which reports 'rowid 12345 missing from index sqlite\_autoindex\_...' and multiple btree errors. Realizing the rollback journal \(-journal file\) was on a different filesystem that got corrupted or was manually deleted, the data pages are partially committed. Since the device syncs to a cloud backup every night, the developer restores the last known good backup from S3, accepting the loss of last 4 hours of local data. For future resilience, they enable WAL mode \(which is more resilient to corruption from power loss\) and implement a battery-backed write cache on the device hardware.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:15:35.458169+00:00— report_created — created