There aren't any extended error codes for sqlite_corrupt. Its just error code 
11 "database disk image is malformed".

I have the line numbers where the corruption is getting hit (they vary, but 
several are in btreeInitPage)

> What exactly are you "saving" ?  The database file ?  Or the WAL file too ?  
> Or the SHM file too ?

As for what I'm saving off, I do a byte for byte copy on the database files 
that were used in the statement that detected corruption (this is automated). 
I'm not copying the "-shm" or "-wal" files (an oversight which I'll fix). I was 
hoping to figure out if its likely capturing the "-wal" file would find the 
corruption, or if I could determine that the page its failing on was from the 
file I have (in which case something else is presumably going wrong).

In terms of pragmas during normal usage: user_version, recursive_triggers, 
cache_size, mmap_size (max size is set to 15 MiB; which covers the files in 
question entirely), journal_mode (=wal). The only somewhat recent addition is 
mmap (along with an upgrade from to 3.16.2).

These databases are stored on a local disk (admittedly using an encrypting 
loop-back adapter). I doubt that I'll necessarily be able to track down what is 
causing the corruption given how infrequently it ends up occurring, storing the 
corrupt copies is my attempt at being able to track them down (since they are 
very infrequent and automatically "recovered" from).

From: sqlite-users <> on behalf of 
Simon Slavin <>
Sent: Monday, November 6, 2017 3:53:41 PM
To: SQLite mailing list
Subject: Re: [sqlite] Tracking database corruption

On 6 Nov 2017, at 10:38pm, Nicholas Lovell <> wrote:

> When getting sqlite_corrupt when reading from a database, is there a way to 
> know if a particular failure came from reading/initializing a page from a WAL 
> file, or the database disk file?

Obtain the extended error code to learn more than you already know:


> Specifically I've been seeing a number of failures around btreeInitPage. 
> However when I pull up the saved copies I make whenever corruption occurs and 
> run "pragma integrity_check", its coming up as "ok".

What exactly are you "saving" ?  The database file ?  Or the WAL file too ?  Or 
the SHM file too ?

It would probably be useful to figure out what’s causing your corruption.  What 
PRAGMAs does your program use under normal use ?  Are you using anything clever 
like shared cache ?  Also, is your database stored on a disk in the computer 
running SQLite or it is accessed remotely, perhaps across a network ?

sqlite-users mailing list


This email and any attachments may contain confidential and privileged material 
for the sole use of the intended recipient. Any review, copying, or 
distribution of this email (or any attachments) by others is prohibited. If you 
are not the intended recipient, please contact the sender immediately and 
permanently delete this email and any attachments. No employee or agent of TiVo 
Inc. is authorized to conclude any binding agreement on behalf of TiVo Inc. by 
email. Binding agreements with TiVo Inc. may only be made by a signed written 
sqlite-users mailing list

Reply via email to