Detecting mismatched WAL files
(1) By fernandocc on 2020-09-25 19:00:00 [link] [source]
In WAL journaling mode, if a
-wal file exists at the time the first database connection is opened, SQLite will attempt to integrate those changes. However, I couldn't find any documentation describing what happens if the WAL file is accidentally mismatched. For instance, a user could accidentally restore a backup of the main database file, but fail to remove an existing
In my very limited testing, it seems to me that SQLite blindly accepts a
-wal file without any sort of validation. Is this the expected behavior? And if so, is there a way to make SQLite validate and fail to checkpoint if the
-wal file is somehow mismatched?
Thank you in advance.
(2) By David Raymond (dvdraymond) on 2020-09-28 14:47:08 in reply to 1 [source]
That is section 1.4 in How To Corrupt An SQLite Database File and is indeed the expected behavior.
You can see what's in the header for the WAL file here "What database did it come from" is stored as the name of the file itself. I'm not quite sure what else you could put in there as a validation. Maybe the file change counter? Or does that not get used in WAL mode?