sqlite3.DatabaseError: database disk image is malformed
It can happen that the database gets corrupted. The error message you will get is something like sqlite3.DatabaseError: database disk image is malformed
This can be fixed by replacing it with a backup database. If you do not have backup of that file or the backup is to old, you can try the following steps:
- Make sure TerrariumPI is not running:
sudo service terrariumpi stop
- Enter the TerrariumPI folder and enable the Python environment:
cd /home/pi/TerrariumPI
source venv/bin/activate
- Enter the
contrib
folder:cd contrib
- Run the
fix_db.py
script and answer the questions:./fix_db.py
. This will take some time. - When done, the database should be restored.
- Start TerrariumPI
sudo service terrariumpi start
A backup of the broken database is left at data/terrariumpi.db.broken
. You can delete this database when TerrariumPI is running again. rm data/terrariumpi.db.broken
If this happens a lot, you could look at the FAQ item: Tune database settings to improve the database storage.
This post is licensed under CC BY 4.0 by the author.