Do I need WAL mode for a read-heavy SQLite database

Back to list2025-01-30
You

Do I need WAL mode for a read-heavy SQLite database?

ChatGPT

Almost always. In the default journal mode a writer blocks readers; in WAL they proceed in parallel:

PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;

The tradeoff is that WAL needs shared memory, so it does not work over most network filesystems. On a local disk it is strictly better for this workload.

You

SQLite has no date type. What do people store?

ChatGPT

Integer Unix seconds for anything you compare or sort, and ISO-8601 text only when humans read the file directly. Mixing the two in one column is the failure mode, because comparisons then silently sort text against numbers.

You

My SQLite file never shrinks after deletes.

ChatGPT

Freed pages are reused, not returned, unless you ask:

PRAGMA auto_vacuum = INCREMENTAL;   -- set before the first table is created
PRAGMA incremental_vacuum(1000);

On an existing database only a full VACUUM reclaims space, and it needs room for a second copy of the file while it runs.