How to Repair a Corrupted SQLite Database in Sonarr or Radarr
The corrupted database error in Sonarr or Radarr (identified in logs with the message database disk image is malformed) occurs when the internal SQLite file (sonarr.db or radarr.db) becomes corrupted due to interrupted writes, sudden server power outages, or file lock synchronization issues on network-attached storage systems.
Quick Diagnostics
Backups/scheduled/ folderThe corrupted database error in Sonarr or Radarr (identified in logs with the message database disk image is malformed) occurs when the internal SQLite file (sonarr.db or radarr.db) becomes corrupted due to interrupted writes, sudden server power outages, or file lock synchronization issues on network-attached storage systems.
Step-by-Step Solution
-
1
Step 1: Detener el contenedor o servicio afectado
Before manipulating the database, you must make sure that there are no processes writing to it. Stop the corresponding Docker container:
BASHdocker stop sonarr -
2
Step 2: Ejecutar los comandos de recuperación de SQLite
Access the directory where container settings are saved (typically
/docker/sonarr/or/home/user/appdata/sonarr/) and execute the SQLite rescue tools in your terminal:BASH# Exportar los datos sanos del archivo corrupto a una plantilla de recuperación sqlite3 sonarr.db ".recover" | sqlite3 clean.db # Respaldar la base de datos corrupta original mv sonarr.db sonarr.db.bak # Reemplazar la base de datos por la versión limpia recuperada mv clean.db sonarr.db # Verificar que los permisos del archivo sean correctos (ejemplo para Docker) chmod 664 sonarr.db -
3
Step 3: Reiniciar el servicio
Start the container or service again. Sonarr will read the restored file without issues:
BASHdocker start sonarr
Prevention Advice
Recommended security practices:
- Never mount your media container databases (
sonarr.db,radarr.db, orplex.db) on shared network paths via protocols such as NFS or SMB/CIFS. SQLite is not designed to coordinate simultaneous access with network latency. The lack of consistency in file locking across the network will corrupt the indexing index immediately upon the slightest connection fluctuation, destroying your configurations irreversibly.