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
sqlite>.dump
sqlite>.quit

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

>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)

Comments are closed.

Niklas Tech Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.