sqlite3.DatabaseError: database disk image is malformed
The SQLite file is corrupted.
Seen on:
SQL
Meaning
Usually from copying the DB while it was being written, crashes during writes on unsafe storage, or network filesystems.
Common causes
- File copied while open/with -wal not copied
- Power loss / crash on unsafe storage
- NFS/SMB storage
⚡ Quick fix
- Restore from backup
- Try recovery: sqlite3 bad.db ".recover" | sqlite3 fixed.db
- Back up with .backup or VACUUM INTO, not file copy
Detailed fix by platform
SQL
sqlite3 broken.db ".recover" | sqlite3 recovered.db
How to diagnose
- Integrity — PRAGMA integrity_check
- Copy — How was the file copied?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026