SQLite Forum

Database WAL snapshot
Well, I looked at the code.

The sqlite3_snapshot is nothing more than a copy of the WAL-header as defined here:  <https://sqlite.org/walformat.html>

So, when the WAL is created, there is no valid WAL-Header until the first transaction is committed and the WAL structures are initialized.  Thereafter `sqlite3_snapshot_get` will work to get a checkpoint location even if the WAL file is checkpointed (unless you do a TRUNCATE checkpoint which deletes the WAL header).  However, the WAL file must have been initialized by writing at least one transaction to it sometime between when it is created and when `sqlite3_checkpoint_get` is called.

This means that if you "suddenly" decide that you want to use snapshots, you have to ensure that the WAL is properly initialized.  If you know that you will be using snapshots then you can simply set WAL persistence so that it isn't deleted when the connection closes (you need to set persistence for EVERY connection to the database).