WAL vs Normal Modes in Sqlite/Room

WAL vs Normal (DELETE/TRUNCATE) journal modes in SQLite/Room, specifically for read/write behavior.
🔹 1. Normal mode (DELETE / TRUNCATE journal)
When SQLite is in DELETE or TRUNCATE mode:
Write path:
Copy the database into a temporary journal file.
Apply changes to the main database.
Delete/truncate the journal.
Read path:
Reads always come from the main database file only.
No merging is required.
✅ Advantages:
Very safe (data goes directly to DB).
Simple, fewer moving parts.
No separate
-wal
file.
❌ Disadvantages:
Slower for many small writes, because the whole DB (or pages) must be journaled.
Writers block readers → no concurrent reads while writing.
🔹 2. WAL mode (Write-Ahead Logging)
When SQLite is in WAL mode (Room default):
Write path:
Changes go into the WAL file (
database-wal
) → very fast append.The main DB (
database
) is not touched until a checkpoint merges WAL back into it.
Read path:
Reads come from both main DB + WAL (SQLite merges them internally).
So, you see the latest values even if they are only in the WAL file.
✅ Advantages:
Much faster writes (append-only).
Readers and writers don’t block each other → great concurrency.
❌ Disadvantages:
Until checkpoint runs, data only lives in the WAL file.
On sudden power loss, the last WAL writes may not reach flash (depending on
PRAGMA synchronous
).You can have “old data” if the WAL wasn’t replayed correctly on reboot.
🔹 WAL vs Normal Read/Write
Feature | WAL mode | Normal (DELETE/TRUNCATE) |
Write speed | Faster (append) | Slower (copy + update) |
Read speed | Slightly slower (merge DB + WAL) | Simple (from DB only) |
Concurrency | Readers don’t block writers | Writers block readers |
Durability (power cut) | Risk of last writes lost if not flushed | Safer, writes go direct |
File count | database + database-wal + database-shm | Just database |
Best use case | Apps with frequent updates, high concurrency | Embedded/automotive, safety-critical |
WAL → Faster, but you risk stale/old values after reboot if the WAL wasn’t checkpointed.
Normal (TRUNCATE) → Safer (writes go to DB directly), slightly slower, but in AAOS safety matters more than speed.
✅ Switch to TRUNCATE journal mode (if your use-case tolerates it)
This avoids WAL and writes directly to the main DB:
val db = Room.databaseBuilder(context, AppDatabase::class.java, "app_db")
.setJournalMode(RoomDatabase.JournalMode.TRUNCATE)
.build()
✅ Force DB close on shutdown
If you know when your service is being destroyed (like onDestroy
), call:
db.close()
This forces pending transactions to sync.
Subscribe to my newsletter
Read articles from MIDHUN S directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
