December 5, 2026

SQLite WAL Mode Explained: What Changes, What It Costs, and a Test of Each Claim

An open ledger with a long paper roll of entries unspooling beside it

One line of SQL turns on write-ahead logging in SQLite, and it is often recommended as a free speed-up. It is fast. It also changes how commits, readers and files behave, and it comes with a list of limits the documentation spells out. Each claim below is paired with a test on SQLite 3.53.1, run from Python on an ext4 disk.

Video: Aaron Francis on YouTube

Two ways to make a commit safe

The rollback journal

A database has to survive a crash in the middle of a write. SQLite’s default method is a rollback journal. The documentation describes it as writing a copy of the original unchanged database content into a separate journal file, then writing the changes directly into the database. If something fails, the journal holds what is needed to put things back. The commit happens when the journal is deleted.

The write-ahead log

WAL, available since version 3.7.0 in July 2010, turns that around. The original content stays in the database file and changes are appended to a separate WAL file. A commit happens when a special commit record is appended to the log. The main file is not touched at commit time at all.

That inversion explains everything that follows: the speed, the concurrency, the extra files, and the need for a clean-up step called a checkpoint.

File cabinet

Turning it on

One pragma, and it sticks

PRAGMA journal_mode=WAL;

A fresh database reports delete as its journal mode. After the pragma it reports wal, and two new files appear beside the database after the first insert:

a.db        8192 bytes
a.db-shm   32768 bytes
a.db-wal    4152 bytes

The -wal file is the log. The -shm file backs the wal-index, a shared-memory structure that, in the documentation’s words, helps readers locate pages in the WAL quickly. The docs add that it rarely exceeds 32 KiB, which is exactly the size seen here.

When the last connection closed, both extra files disappeared and only a.db remained. On reopening, the mode was still wal. The documentation states this directly: unlike the other journaling modes, PRAGMA journal_mode=WAL is persistent. It is a property of the database file, set once. PRAGMA journal_mode=DELETE reverts it.

Is it faster?

2,000 single-row commits

The first advantage the documentation lists is that WAL is significantly faster in most scenarios. The test inserted 2,000 rows one at a time, each in its own transaction, which is the worst case for commit overhead. Three runs per setting, best run shown:

Journal mode synchronous Time for 2,000 commits Commits per second
DELETE FULL 1.02 s about 1,970
WAL FULL 0.28 s about 7,040
WAL NORMAL 0.02 s about 93,300

Same durability setting, different journal: WAL was roughly 3.6 times faster. The documentation gives two reasons that fit the result. Disk writes tend to be more sequential, and WAL uses many fewer fsync() calls.

These are numbers from one virtual machine on one day. The ratio is the useful part. The absolute figures will be different on any other disk.

What synchronous=NORMAL gives up

The third row is where the large gain is, and it is not free. With synchronous at FULL, writers sync the WAL on every commit. At NORMAL that sync is skipped and only checkpoints sync.

The pragma documentation is careful about what that means. WAL mode with NORMAL is “safe from corruption” and always consistent. What it loses is durability: a transaction committed just before a power loss or system crash might roll back. The database will be intact and the last few commits may be missing. For a cache or an analytics table that trade is easy. For a ledger it is not.

Library interior

Readers and writers at the same time

The test

The second listed advantage is concurrency: readers do not block writers and a writer does not block readers. Two connections were opened to one database. The reader began a transaction and counted the rows. The writer then tried an insert, with a half-second timeout.

Mode Reader sees Writer’s insert Reader, same transaction Reader, new transaction
DELETE 1 row database is locked 1 row 1 row
WAL 1 row succeeded 1 row 2 rows

In rollback mode an open read transaction locked the writer out. In WAL mode the write went through while the reader was still mid-transaction.

Snapshots

The fourth column is the subtle one. After the write had committed, the reader, still inside its original transaction, went on seeing one row. The documentation explains the mechanism: each reader records an end mark in the WAL when its transaction starts, and that mark stays fixed for the duration, so that a read transaction only sees the database content as it existed at a single point in time. A new transaction saw both rows.

Still one writer

A second test had one connection hold a write transaction open while another tried to insert. In WAL mode the second writer got database is locked, the same as in rollback mode. The documentation’s reason is one sentence: since there is only one WAL file, there can only be one writer at a time. WAL removes the collision between readers and writers. It does nothing for two writers.

Checkpoints, and a log that would not shrink

Moving the log back

Changes cannot pile up in the log forever. Transferring them into the main database file is called a checkpoint, and by default SQLite runs one automatically when the WAL reaches 1,000 pages. The test database confirmed the setting: PRAGMA wal_autocheckpoint returned 1000, with a 4,096-byte page size.

After 3,000 inserts of 3 KB each with no reader connected, the files stood at:

g.db       12,161,024 bytes
g.db-wal    4,128,272 bytes

The log sat at about 4 MB, the size the documentation predicts for 1,000 pages, while the main file had grown to 12 MB. A checkpoint does not normally shrink the WAL file. SQLite starts overwriting it from the beginning.

Checkpoint starvation

Then a second connection opened a read transaction and left it open, and 3,000 more rows went in.

g.db-wal   38,229,512 bytes

The log grew to 38 MB, more than nine times its steady size. A manual checkpoint explained why:

PRAGMA wal_checkpoint(PASSIVE);
-- returns 0 | 9279 | 120

According to the pragma reference the three numbers are a busy flag, the number of pages in the log, and the number moved back into the database. Of 9,279 pages, 120 had been checkpointed. The open reader was pinning the rest.

The WAL documentation describes this precisely. A checkpoint must stop when it reaches a page past the end mark of any current reader, and “a long-running read transaction can prevent a checkpointer from making progress.” With overlapping readers and never a gap, it warns, the file will grow without bound.

Once the reader committed:

PRAGMA wal_checkpoint(TRUNCATE);
-- returns 0 | 0 | 0      g.db-wal is now 0 bytes

TRUNCATE is the strongest of four modes. PASSIVE does what it can without waiting for anyone. FULL and RESTART wait for readers and block writers while they run. TRUNCATE does the same and then cuts the file to zero bytes.

The practical lesson is to keep read transactions short. A forgotten open cursor in a long-lived process is enough to do what the test did.

Stack of papers

The limits the documentation lists

Same machine only

The first disadvantage in the official list is the one that rules WAL out for some setups: all processes using the database must be on the same host, because WAL does not work over a network filesystem. The shared-memory index is the reason.

The rest of the list

  • Transactions spanning several attached databases are atomic for each database but not across the set.
  • The page size cannot be changed after entering WAL mode.
  • For workloads that mostly read and seldom write, WAL might be slightly slower, which the docs put at perhaps 1 or 2 percent.
  • There are extra files to account for.

That last item has teeth. A WAL-mode database may be three files, not one. Copying only the .db file while the others hold uncheckpointed transactions is a way to lose data: the documentation warns that if a database file is separated from its WAL file, previously committed transactions might be lost or the database might become corrupted. The only safe way to remove a WAL file, it says, is to open the database and close it cleanly.

Not completely non-blocking

Queries can still return SQLITE_BUSY in WAL mode. The documentation names three cases: another connection holding the database in exclusive locking mode, the brief exclusive lock taken when the last connection closes and cleans up, and crash recovery.

A recent bug fix

The same page now carries a section on a defect in the WAL reset logic, which could affect databases with two or more connections writing or checkpointing at the same instant. It is described as rare and was fixed in version 3.51.3, dated March 13, 2026, with backports to 3.44.6 and 3.50.7. Anyone running heavy concurrent writes on an older build has a reason to check the version.

When to use it

WAL suits the common case of one machine, a local disk, many readers and a steady trickle of writes: a web application’s backing store, a desktop program, a service on a single server. The read-versus-write table above is the argument.

It does not suit a database on a network share, or one that will be burned to read-only media. For the second case the documentation recommends converting back to journal_mode=DELETE first.

Sources

  • SQLite documentation, “Write-Ahead Logging”: https://www.sqlite.org/wal.html
  • SQLite documentation, “Pragma statements supported by SQLite” (journal_mode, synchronous, wal_checkpoint, wal_autocheckpoint): https://www.sqlite.org/pragma.html

719 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *