Notes on SQLite in Production
SQLite has a reputation problem. It is “not a real database” — which is technically true and also completely beside the point for most applications.
The write lock
SQLite allows exactly one writer at a time. Everything else can read concurrently. For a blog, which writes a few times a day and reads constantly, this is a perfect fit.
The practical guidance:
- Set a
busy_timeoutso writers wait rather than fail - Use WAL mode so readers never block on the writer
- Keep one connection if you are not careful about lock ordering
db.SetMaxOpenConns(1) // simplest correct configuration
When to reach for something else
Reach for Postgres when you need:
- Concurrent writers across multiple processes
- Row-level security
- Replication
- Analytical queries over billions of rows
Until one of those is a real requirement, SQLite will be simpler, faster to operate, and easier to reason about.
Backups are easy
A hot backup of a SQLite database is a file copy:
sqlite3 blog.db ".backup 'backup.db'"
That simplicity is worth more than the features you are not using.
Comments 0
No comments yet. Be the first to share your thoughts.