Minetest Gameplay EP182 Troubleshooting and Repairing a Corrupt SQlite Game Database

 

I give a very basic look into the SQlite database used in the Minetest Game.  While playing the game I observed a large amount of lag and trouble trying to place blocks.  The game then crashed and would not restart.  Trying to start the game from the application menu gave no error messages and would just force quit.  Running the game from the terminal this is the error message I received and found documented in the from debug.txt file found in the games main directory,

 

2018-06-20 23:44:19: WARNING[Server]: active block modifiers took 503ms (longer than 200ms)
2018-06-20 23:44:21: ERROR[Server]: An unhandled exception occurred: Failed to save block: database disk image is malformed
2018-06-20 23:44:21: ERROR[Server]: In thread 0x70000c237000:
2018-06-20 23:44:21: ERROR[Server]: /Users/travis/build/krondor-game/minetest/src/server.cpp:72: virtual void *ServerThread::run(): A fatal error occured: Failed to save block: database disk image is malformed
2018-06-20 23:44:21: ERROR[Server]: Debug stacks:
2018-06-20 23:44:21: ERROR[Server]: DEBUG STACK FOR THREAD 0x70000c237000:
2018-06-20 23:44:21: ERROR[Server]: #0 virtual void *ServerThread::run()
2018-06-20 23:44:21: ERROR[Server]: DEBUG STACK FOR THREAD 0x70000c2ba000:
2018-06-20 23:44:21: ERROR[Server]: #0 virtual void *EmergeThread::run()
2018-06-20 23:44:21: ERROR[Server]: DEBUG STACK FOR THREAD 0x7fff908be380:
2018-06-20 23:44:21: ERROR[Server]: #0 int main(int, char **)
2018-06-20 23:44:21: ERROR[Server]: #1 Dedicated server branch
2018-06-20 23:44:21: ERROR[Server]: #2 void dedicated_server_loop(Server &, bool &)
Abort trap: 6
richards-MacBook-Air:~ richard$

 

This error cause the game to crash as the world was loading.  Another indication that something was wrong with the database file is the presence of the “map.sqlite-journal file”.  This means that data was not yet written to the database.  One will not see this file while the game in shutdown.  One will see this file briefly while data is being processed by the database.

To repair this database file I first copied the file to a different folder and opened it using DB Browser for SQlite.  There are other tools like DBeaver and SQlite Studio that provide a  GUI application to manage the database. One may also use the SQlite command line shell tools provided by SQlite.

I used the “Pragma integrity_check” command to, well, check the integrity of the database.  The following errors were found,

Results from integrity check
Results from integrity check

The next command is to run “vacuum”  in the SQL editor.

The VACUUM command rebuilds the database file, repacking it into a minimal amount of disk space.

Source SQlite.

I ran the integrity check again which returned “OK”.  I moved the repaired database file back into the world folder and restarted the game.  Minetest loaded and is running great.

If the vacuum command does not repair the database file then one may try exporting the database to a SQL file and then importing the SQL file into a new database file.

A quick word on backups.  One may simply copy the world folder while the game is shutdown to a different folder that will provide a backup of the world to that point in time.  Never copy an open database file.  This will cause corruption.   I always have four copies of the world files that I may use on different servers and computers.  I have a years worth of builds for my main world and do not want to lose them.

Hopefully one will never need to repair the game but not all is lost and most of the time the database file may be repaired.

 

Happy Building!

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.