Corrupt database: `.recover` fails almost immediately, but other commands still work
(1) By Impossibly Stupid (droleary) on 2025-01-05 21:01:18 [source]
Probably less of a bug report than a suggested documentation change. In development/testing of an RSS feed reader (on a stock Raspberry Pi install, if that helps any), I somehow managed to corrupt the DB, and for the first time ever I found myself on the recovery page.
I got a bit worried when this happened:
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> .recover
BEGIN;
PRAGMA writable_schema = on;
PRAGMA encoding = 'UTF-8';
PRAGMA page_size = '4096';
PRAGMA auto_vacuum = '0';
PRAGMA user_version = '0';
PRAGMA application_id = '0';
sql error: SQL logic error (1)
sqlite>
Looked like it was really stuffed, so I figured there was no harm in poking around further. Both .tables
and .schema
gave normal enough results. I started doing a few basic select
queries, and many of them returned results that looked perfectly fine! I don't know what expected behavior is for a corrupt database, but things seemed to be far better than .recover
had lead me to believe.
So I essentially went through all the ways I could see documented to copy a DB. Many of them failed with errors, but two "worked". Doing a .dump
gave me a file that appeared to be mostly complete, although the last line is:
ROLLBACK; -- due to errors
I never bothered further with that, because the other command was .clone
, which resulted in a DB that appears to be entirely functional, and I've been using it without problem for the last couple days. The only thing lost appears to be a couple of the feed items, where a count from the corrupt DB gave 1306 whereas the clone gave 1304.
If the bad DB would be at all useful to examine, let me know. It's only about 10MB, and the feed data it contains is nothing particularly private. Like I said, I don't know that .recover
is doing anything wrong that needs to be debugged, but the recovery page really would benefit from a "try all the things" message.
(2) By Simon Slavin (slavin) on 2025-01-06 12:58:27 in reply to 1 [link] [source]
I can't help with this, but I'm curious. What does
PRAGMA integrity_check
say ?
(3) By Dan Kennedy (dan) on 2025-01-06 14:14:27 in reply to 1 [link] [source]
If the bad DB would be at all useful to examine, let me know.
It would be quite useful I think. Could you make it available?
Thanks,
Dan.
(4) By Impossibly Stupid (droleary) on 2025-01-06 20:36:38 in reply to 2 [link] [source]
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> PRAGMA integrity_check;
*** in database main ***
Page 133: btreeInitPage() returns error code 11
Page 2340 is never used
Runtime error: database disk image is malformed (11)
sqlite>
(5) By Impossibly Stupid (droleary) on 2025-01-06 20:41:51 in reply to 3 [link] [source]
Here it is, until at least the end of the month (I'm not sure how much it's going to start getting constantly spidered for no good reason).
(6) By Stephan Beal (stephan) on 2025-01-07 13:38:24 in reply to 5 [link] [source]
(I'm not sure how much it's going to start getting constantly spidered for no good reason).
For future reference, you can also email such links to support @ this domain. Including a reference to a forum post discussion in such mails is always helpful, as it provides context. (That is: emails with links to dbs, and no context to them, are likely to be ignored.)