[odb-users] How to enable sqlite WAL in ODB

Boris Kolpackov boris at codesynthesis.com
Mon Oct 17 08:30:59 EDT 2022

Luke Zou <luke.zou at ringcentral.com> writes:

> odb::transaction t(db->begin());
> db->execute ("PRAGMA journal_mode=WAL");
> t.commit();
> But I get the exception "cannot change into wal mode from within a 
> transaction". Try to put db->execute ("PRAGMA journal_mode=WAL");
> without putting it in the transaction will also "operation can only
> be performed in transaction" this exception.

The way to execute a statement outside of a transaction is to use
the connection directly. Something like this should do the trick:

db->connection ()->execute ("PRAGMA journal_mode=WAL");

> Will all connections switch to WAL at the same time after opening?

Quoting from 3.3. "Persistence of WAL mode"[1]:

"The persistence of WAL mode means that applications can be converted to using
SQLite in WAL mode without making any changes to the application itself. One
has merely to run "PRAGMA journal_mode=WAL;" on the database file(s) using the
command-line shell or other utility, then restart the application."

"The WAL journal mode will be set on all connections to the same database 
file if it is set on any one connection."

I would still suggest executing this pragma at the start of your
application, before any other connections are created to the

[1] https://www.sqlite.org/wal.html

More information about the odb-users mailing list