惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
The Cloudflare Blog
IT之家
IT之家
V
V2EX
雷峰网
雷峰网
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
小众软件
小众软件
博客园 - 叶小钗
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
A
About on SuperTechFans
B
Blog
月光博客
月光博客
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI

Anže's Blog

The 15-Year-Old iptables Rule That Broke My DNS Fedidevs 9h Outage Postmortem Letting Claude Upgrade My Raspberry Pi Agents Day Lisbon DjangoCon Europe 2026 How to Safely Update Your Dependencies Speeding Up Django Startup Times with Lazy Imports Typing Your Django Project in 2026 Claude Fixes User Bug Jekyll to Hugo Migration Advent of Code 2025 🎄 Django bulk_update Memory Issue Migrating Gunicorn to Granian Disable Network Requests When Running Pytest Disable Runserver Warning in Django 5.2 Autogenerating og:images with Jekyll Power Outages and Gunicorn PID Files UV with Django Go-like Error Handling Makes No Sense in JavaScript or Python Packages Do Not Match the Hashes Pip Error Gotchas with SQLite in Production Fedidevs Dev Update #2 Django SQLite Production Config Django Streaming HTTP Responses Deploying a Django Project to My Raspberry Pi (Video) Thoughts on Code Reviews Django SQLite Benchmark Django, SQLite, and the Database Is Locked Error No Downtime Deployments with Gunicorn Writing a Pytest Plugin
SQLite Write-Ahead Logging
Anže Pečar · 2023-11-03 · via Anže's Blog

I’ve been working with SQLite lately. It has become my go-to database for all projects!

Blocking writes

One problem I encountered was that, by default, it uses rollback journal, where any write to the database will also block all reads. Because of this, my fedidevs.com site became unresponsive for about an hour every night while the nightly job inserted fresh data.

The solution was to enable Write-Ahead Logging. WAL allows multiple readers to access the database, even if the table is being written to simultaneously. The link above has a few disadvantages listed, but for most web-server use cases, WAL is the better option.

Enabling WAL

Enable WAL by setting the journal_mode to WAL:

sqlite3 db.sqlite3 'PRAGMA journal_mode=WAL;'

The PRAGMA command only has to be run once per database. The setting is persistent.

.wal files

When WAL is enabled, SQLite will create .wal and .shm files. The .wal file records transactions committed but not yet applied to the main database. The .shm file is used for shared memory and caching.

Do remember to keep an eye on your .wal file sizes. Certain operations (like VACUUM) can make them grow as large or even larger than the database itself. If that happens to you as it did to me, you can regain the disk space by running the wal_checkpoint command:

sqlite3 db.sqlite3 'PRAGMA wal_checkpoint(TRUNCATE);'

The article SQLite: Vacuuming the WALs is worth a read if you need to run VACUUM often.

Conclusion

With WAL enabled and the VACUUM command removed, fedidevs.com (and other sites) are running smoothly - bound only by the fact that my Raspberry Pi runs on a very slow SD card 😅

I’ll write a post about my Raspberry Pi setup in the future.