malformed database 🗃️ SQL

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

  1. Restore from backup
  2. Try recovery: sqlite3 bad.db ".recover" | sqlite3 fixed.db
  3. Back up with .backup or VACUUM INTO, not file copy

Detailed fix by platform

SQL

  1. sqlite3 broken.db ".recover" | sqlite3 recovered.db

How to diagnose

  1. Integrity — PRAGMA integrity_check
  2. 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.