How to recover deleted records from a SQLite database?
Solved SQL & Databases
RK
Rachel Kim
August 8, 2019
2 replies
6,530 views
Reviewed by moderators

Our app deleted rows from its SQLite file due to a bug. No backup because it is a local desktop app. Has VACUUM run? No idea. Are deleted SQLite rows recoverable at all?

Accepted Answer
Verified by Edwin J. Hoffer, Database Specialist ยท Reviewed August 2019

Depends entirely on VACUUM. SQLite marks deleted pages as free but leaves the bytes until VACUUM or new writes reclaim them.

1
Copy the database file right now and stop the app touching the original. Every write risks the free pages.
2
Run SysTools SQLite Recovery on the copy. It scans free pages and unallocated space and rebuilds deleted rows where the bytes survive.
3
Check for a sidecar too: a -wal file next to the database can hold recent row images even after deletion.

WAL file had most of it and the free page scan got the rest. 96 percent of rows recovered. Solved.