質問

If a SQLite database using write-ahead logging is interrupted with un-checkpointed transactions (due to a power failure or whatever), then reopened with the temporary -wal file missing, will the database open cleanly to its state as of the last checkpoint, or will it be corrupted in some way?

We're trying to get SQLite working with iCloud (yes, we know you're not supposed to do that, but we also make a Windows and an Android app and need a cross-platform database solution), and we think that WAL provides a potential way to avoid having to maintain two copies of our database - we'd keep the -wal file outside of iCloud but store the main database in it, thus avoiding the problem of iCloud backing up rollback journals (or backing up databases mid-transaction without those journals).

役に立ちましたか?

解決

The file format documentation mentions a "hot WAL file", but this applies only to uncommitted data.

The database file itself does not contain any information about committed data in the -wal file, i.e., transactions before a checkpoint typically do not alter the main database file at all. Therefore, deleting the -wal file will simply restore the database to the state it was after the last checkpoint (which is outdated, but consistent); all transactions committed later will just be lost.

他のヒント

See the "Checkpointing" section of SQLite's Write-Ahead Logging. From what I understand, the data in the WAL file would simply not be committed.

In other words, you'd lose the data in the .WAL file that hasn't yet been committed, but the main database itself should be perfectly fine.

It can lead to db corruption when WAL file would be deleted during checkpointing operation. In case of unfinished db modification WAL file is necessary to complete the changes, otherwise db file is in transient state.
DB and WAL file create complete picture of the db state.
It is also explicitly stated in https://www.sqlite.org/howtocorrupt.html#delhotjrnl that
"SQLite must see the journal files in order to recover from a crash or power failure."

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top