SQLite supports several journal modes, each offering advantages in performance, concurrency, and the way changes are logged and applied. This guide explains the journal modes available in SQLite so you can choose the right one for your application.
PRAGMA journal_mode = WAL;
- Description
- Writes all changes first into a separate
-wal
file. Readers continue to see a consistent snapshot of the main database while writers append to the WAL. On checkpoint or close, changes are merged back.
- Writes all changes first into a separate
- Use Cases
- High‑concurrency apps with many readers and occasional writers
- Situations where write bursts must not block reads
PRAGMA journal_mode = DELETE;
- Description
- The default mode. Before each transaction, modified pages are saved in a rollback journal file. On commit, changes are applied to the main file and the journal is deleted.
- Use Cases
- Simple single‑user applications
- Environments with low concurrency
PRAGMA journal_mode = TRUNCATE;
- Description
- Like DELETE, except the journal file is truncated to zero length instead of deleted. Fewer filesystem operations can yield a small speed boost.
- Use Cases
- Similar to DELETE, but on filesystems where deleting is expensive
PRAGMA journal_mode = PERSIST;
- Description
- Keeps the journal file around but zeroes its header to mark it “empty.” Avoids delete/truncate overhead while still providing rollback safety.
- Use Cases
- High‑write workloads where reducing file‑create/delete churn matters
PRAGMA journal_mode = MEMORY;
- Description
- Stores the rollback journal entirely in RAM. Eliminates all journal‑related disk I/O—fastest transactions, but if the process crashes, uncommitted changes and the journal itself are lost.
- Use Cases
- In‑memory or temporary caches where speed is crucial and data persistence is not a concern.
PRAGMA journal_mode = OFF;
- Description
- Turns off rollback journaling completely. Writes go straight to the main database file without any atomic rollback, risking corruption on failures.
- Use Cases
- Read‑only media (e.g., CD/DVD)
- Transient data where speed beats reliability
Quick Tip
- WAL is the only journal mode that stays set permanently across connections and restarts.
- All other modes (DELETE, TRUNCATE, PERSIST, MEMORY, OFF) will revert to DELETE when you reopen the database.