by simonw · 4y ago · 0 comments
When you run "PRAGMA journal_mode=wal;" against a database file the mode is permanently changed for that file - and the .db-wal and .db-shm files for that database will appear in the same directory as it.
Any future connections to that database will use it in WAL mode - until you switch the mode on it back, at which point it will go back to journal mode.
It makes sense when you think about it - of course a database can only be in one or the other modes, not both, so the setting must be at the database file level. But it took me a while to understand.
I wrote some notes on this here: https://til.simonwillison.net/sqlite/enabling-wal-mode
"Transactions involving multiple attached databases are atomic, assuming that the main database is not ":memory:" and the journal_mode is not WAL. If the main database is ":memory:" or if the journal_mode is WAL, then transactions continue to be atomic within each individual database file. But if the host computer crashes in the middle of a COMMIT where two or more database files are updated, some of those files might get the changes where others might not."
https://sqlite.org/lang_attach.html
Systems designed for DML against multiple database files should eschew WAL mode.