SQLite Forum

How to detect which db is corrupted in case of multiple attached dbs?
Login

How to detect which db is corrupted in case of multiple attached dbs?

(1) By anonymous on 2021-08-12 04:32:55 [source]

The problem:

I have a connection to a db with attached dbs. It is possible that a stamement returns SQLITE_CORRUPT for query that may read/write several dbs in one transaction but it is not clear which one db is actually repsonsible for the error.

What I already did:

I list through all attached dbs and fire PRAGMA integrity_check; in order to find which db is corrupted but in some cases integrity check doesn't report problems. For instance, currently I have a db that has corrupted free page list the total sizes of free pages exeeceds expected number of free pages. During debug I put break point in sqlite3CorruptError and it fires in allocateBtreePage

  /* EVIDENCE-OF: R-05119-02637 The 4-byte big-endian integer at offset 36
  ** stores stores the total number of pages on the freelist. */
  n = get4byte(&pPage1->aData[36]);
  testcase( n==mxPage-1 );
  if( n>=mxPage ){
    return SQLITE_CORRUPT_BKPT;
  }

and integriyt check AFAIK doesn't validate free page list, therefore, reports no errors for such corruption.

So how can I relyably find a db that is corrupted for the case when there are many attached dbs?