11

I am looking for a command line utility to validate SQLite databases. I ran into a situation in some inherited code where an application fails to startup because an attempt to access a database produced the following error:

database disk image is malformed

So I need to instrument some validation code in the application. Additionally, though, I need a tool that I can run from the Linux prompt to tell me simply if the database is corrupt or not.

Thanks

linsek
  • 3,334
  • 9
  • 42
  • 55

2 Answers2

20

You can do something like this:

sqlite3 database.db "PRAGMA integrity_check"
Yura Beznos
  • 546
  • 4
  • 9
10

You can use PRAGMA integrity_check on the database.

If the Database is corrupted you can use this SQLite command:

cd $DATABASE_LOCATION
echo '.dump'|sqlite3 $DB_NAME|sqlite3 new_repaired_$DB_NAME
mv $DB_NAME corrupt_$DB_NAME
mv new_repaired_$DB_NAME $DB_NAME
Oscerd
  • 1,616
  • 11
  • 14