SQLite check integrity and fix common problems

Every now and then you need to check the integrity of an SQLite database. The command for this is:

sqlite>PRAGMA integrity_check;

This will either report the problems or just return “ok”

If it does report problems one solution I always try first is to do an export/import of the database:

>sqlite3 database.db
sqlite>.output backup.db

>sqlite3 database_fixed.db
sqlite>.read backup.db

>mv database_fixed.db database.db

This usually fix many of the common problems like “disk image is malformed” and “database is locked”

Tested on OSX 10.6.8 and SQLite v3.7.6 (MacPorts)

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

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