修復sqlite3資料庫
1 min readAug 26, 2019
Sqlite3 的 DB 可能會在斷電或某些 force kill 程式的狀況下爛掉,導致下次對這個 db 下指令時會出現
Error: database disk image is malformed
之類的狀況。
這時候有幾個方法先檢查 DB 是否勉強還可以用
- 快速檢查 index 狀況是否還正常
# sqlite3 file.db “ PRAGMA quick_check”
- 完整檢查 DB 狀況
# sqlite3 file.db “PRAGMA integrity_check”
檢查項目包含 out-of-order records, missing pages, malformed records, missing index entries, and UNIQUE and NOT NULL constraint errors.