---
title: "SQLite's WAL mode is fast fast"
url: "https://aaronfrancis.com/videos/sqlites-wal-mode-is-fast-fast"
path: "/videos/sqlites-wal-mode-is-fast-fast"
type: video
author: Aaron Francis
published: 2024-07-10
topic: Databases
keywords: [sqlite wal mode, sqlite, wal mode, sqlite performance, sqlite benchmarking, rollback mode, sqlite default mode, database performance, high performance sqlite, sqlite optimization]
youtube_url: "https://www.youtube.com/watch?v=qf0GqRz-c74"
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# SQLite's WAL mode is fast fast

## Chapters

- How Fast is WAL Mode
- Benchmarking Code
- What is WAL Mode
- Why Change Default to WAL Mode

## Transcript

**Aaron Francis:** This has probably happened to you. You're hanging out with all your friends, everybody's got a nice cold water in their hands, and the conversation naturally turns to SQLite as it always does, and everybody's like, "Make sure you use WAL mode." And you're just like, "Yeah, WAL mode is awesome." And no one ever says what WAL mode is. I'm gonna tell you what WAL mode is, but first I'm gonna show you that it's 10 times faster than rollback mode.

**Aaron Francis:** Let me show you how. So I have two databases here. We're gonna open SQLite3 database, and we're gonna open rollback.sqlite. And if we look at... What do we wanna look at? We wanna look at PRAGMA journalmode. And if we look at journal mode, we are in delete journal mode, which is a form of rollback.

**Aaron Francis:** And if we open a different one here, SQLite3 database, let's open wal.sqlite. We'll clear that out, and we wanna do the same thing over here, PRAGMA journalmode. And if we check that, we are in WAL mode. You can set WAL mode equal, or you can set journal mode equal to WAL by doing that.

**Aaron Francis:** You likely wanna do that before there's any data in the database. All right, let's get out of here, and let's get out of here. I have written a benchmarking script, which I will show you later. But what we're gonna do is we're gonna run arbench, which is the benchmarking script. The DB, we're gonna say, let's open the rollback database.

**Aaron Francis:** Queries, let's run, uh, let's run 2,000 queries from 25 different processes, and let's see how that goes. Spinning up, and there they go. Look at all the processes. Good job, guys. Keep going. And wow, that took a long time.

**Aaron Francis:** All right, it took 7.2 seconds. Blegh, not great. 6,000, 6,500 reads per second. 33... No, 300 writes. Ooh, that's not great. Let's run this again. arbench DB=wal. Queries, uh, let's do the same number of queries, which I definitely remember was 2,000 queries.

**Aaron Francis:** So we'll run 2,000 queries again with processes set to 25 again and pay close attention. Here we go. Get ready. Go. And we're done. Look at that. Look how much faster it is.

**Aaron Francis:** All right. 568 milliseconds, so more than an order of magnitude, 83,000 reads per second, more than an order of magnitude, and 4,300, again, more than 10 times faster. You can check the p50 through 99 down here. It is so much faster.

**Aaron Francis:** Let's, just for giggles, run, uh, let's run 15,000 processes... No, 15,000 queries in 50 processes. So we're gonna spin up 50 separate processes, each running 15,000 queries. And so we've spawned 50. There they go. Not so bad.

**Aaron Francis:** Done. Great. So 95,000 reads per second, 5,000 writes per second. I have fixed the mix of reads and writes to be 95% approximately reads, 5% approximately writes, and so that's where that number is coming from. You can see how fast this is.

**Aaron Francis:** Let me show you the benchmarking code real fast, and then, uh, I'll explain what WAL mode actually is so you can impress your friends at the next party. So down here... Well, up here, we just have some stuff to spin up the processes and spawn it all. But all of the actual commands or the, the SQL queries are down here. 5% of the time, we're gonna write, and we're just writing into a key value store.

**Aaron Francis:** That's it. It's a very simple... It's very simple queries. Um, the, the point of this benchmark is to compare WAL mode versus rollback mode, not necessarily to simulate production traffic. Um, INSERT into kv key value with those two bound in. ON CONFLICT, SQLite has upserts. Did you know that SQLite has upserts? ON CONFLICT, update the value.

**Aaron Francis:** So that's what happens when we write, which is 5% of the time, and when we read, we just select star from kv where key equals key. And I have seeded these random number or these randomness generators, I have seeded them so that, that they, uh, all are, are the same between two different benchmarks. So when we did rollback and WAL, they were using the same, the exact same values.

**Aaron Francis:** We still got 10 times the performance in WAL mode. Now, what is WAL mode? Well, SQLite has two different modes. It has the rollback journal, and it has the write-ahead log. Let's talk about the rollback journal first, and then we will compare that to the write-ahead log. A database, a SQLite database, is a single file, and within that single file are multiple blocks of equal size.

**Aaron Francis:** We call those pages. So in a database, bunch of different pages. In rollback mode, in rollback mode, when, uh, something starts to write to the database, a process starts to write to the database, before it does, it takes that page, and it copies it out and sets it aside for safekeeping. Then it writes all of its data into the actual database file, and then when it is done, when the commit is finished, that is when that journal is deleted.

**Aaron Francis:** It could be truncated. It could be zeroed out, but regardless, the data is destroyed. And that actual deletion or truncation, that's what actually... Cements the commit. That's what makes the commit complete. As long as the journal still exists, that commit is not finished. This ensures that we have atomic commits and rollbacks, and we're never writing or reading anything that was half-finished.

**Aaron Francis:** That's the rollback mode. The WAL mode inverts that, and in- instead of copying the original data out, it leaves the original data in place, and it starts writing ahead to a log. Write-ahead log, WAL mode. That's crazy. So it starts writing ahead to a separate file, so you might see another file on your file system with dash W-A-L on it.

**Aaron Francis:** That is the write-ahead log. And so all of the readers can keep reading the database while the writer is writing to this write-ahead log. And at some point, a checkpoint happens, and that write-ahead log is taken and put back into the database as a single file, and then the write-ahead log file is actually deleted.

**Aaron Francis:** And so what this means is you can continue writing to the write-ahead log, and anytime a reader opens the database, it queries the write-ahead log and says, "What's the last, what's the last committed transaction?" And the write-ahead log says, "The last committed transaction was number five." And the reader reading the database says, "Great. I'm gonna read the actual database file and the write-ahead log file, but I am not going to go past transaction number five.

**Aaron Francis:** My universe is limited to the last transaction I see when I open the database." And that ensures that we stay in a consistent state for the entire time, the entire time that read is, is, uh, reading from the database. And then when a new reader starts reading, it's gonna see maybe a different latest transaction, but importantly, it's not gonna see any half-committed transactions.

**Aaron Francis:** It's not gonna read any partially finished stuff. And if the writer needs to roll back, it just deletes the end of the write-ahead log file. It doesn't have to touch the original database at all. So this is how you get that higher throughput, is all of these readers can continue reading the database file and the write-ahead log until a certain point, and that point is the checkpoint.

**Aaron Francis:** So every now and then, it is configurable, but every now and then, when a writer finishes writing, what will happen is we'll look at the write-ahead log and say, "Ooh, that's getting kind of big, isn't it? Let's take the write-ahead log, put it back, merge it back into the database, and then we'll start a new write-ahead log." And so this is the one setting on your SQLite database that you definitely want to change.

**Aaron Francis:** The default journal mode is delete. That is a historical artifact. Since 2010, WAL mode has been around, and you probably wanna use WAL mode for everything. Even forks of SQLite, like Libsql by the Turso team, they only support WAL mode. You'll find that many modern SQLite offerings either highly suggest or force you to use WAL mode.

**Aaron Francis:** If you wanna learn more about SQLite, I do have a course at highperformancesqlite.com. If you want to run SQLite in production and have somebody handle it all for you, you can check out Turso. Until the next time, see ya.

---

## Related on aaronfrancis.com

- [High Performance SQLite](/courses) *(Course · 2024-07-01 · shared: sqlite, sqlite wal mode, sqlite optimization)*
- [Ruby on Rails + SQLite with Stephen Margheim](/videos/ruby-on-rails-sqlite-with-stephen-margheim) *(Video · 2024-08-08 · shared: sqlite, sqlite wal mode, high performance sqlite)*
- [Distributed SQLite with Litestream and LiteFS](/videos/distributed-sqlite-with-litestream-and-litefs) *(Video · 2024-05-30 · shared: sqlite, sqlite wal mode, sqlite performance)*
- [About](/about) *(Page · 2026-11-25 · shared: sqlite, high performance sqlite)*
- [Laravel's Big Day](/podcast/laravels-big-day-959237a1) *(Podcast · 2025-02-27 · shared: high performance sqlite, sqlite)*

## Relevant Resources from Aaron Francis

- **[High Performance SQLite](https://databaseschool.com)** (overview on site: [/courses](/courses)): Comprehensive video course on running SQLite in production: WAL mode, concurrency, FTS5, strict tables, backups, and performance tuning.
- **[MySQL for Developers](https://databaseschool.com)** (overview on site: [/courses](/courses)): Full video course covering MySQL indexing, deferred joins, pagination, query plans, and schema design for application developers.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `sqlite wal mode` ([S](/llms/keywords/s.txt)), `wal mode` ([T-Z](/llms/keywords/t-z.txt)), `rollback mode` ([Q-R](/llms/keywords/q-r.txt)), `database performance` ([D-E](/llms/keywords/d-e.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
