When to use SQLite (and when to switch to PostgreSQL)
SQLite is the right choice when the database lives with the app: desktop, tests, CLIs and mid-size sites. The real limits: concurrent writes and the network.
The architecture meeting ran two hours. The team debated PostgreSQL versus MySQL. Someone brought up Aurora Serverless. Another person mentioned CockroachDB "just to have it on the table." Nobody said SQLite — it felt too amateur. The project was an ETL script that ran once a day and needed to join two CSV files. SQLite would have solved it in ten minutes.
The short answer, if you're in a hurry: use SQLite when the database lives with the application (same machine, ideally the same process) and writes don't come from many places at once. Desktop and mobile apps, command-line tools, tests, low-to-medium traffic websites, and read replicas at the edge all fit. Switch to PostgreSQL (or MySQL) when several servers need to write to the same database over the network, when write concurrency is high, or when the data outgrows what comfortably fits on one machine.
The rest of the post is the detail on each side of that line, with what the official SQLite documentation says and what I tested.
SQLite is not a toy database
The project's Most Widely Deployed page estimates there are over one trillion SQLite databases in active use — databases, not devices: each smartphone carries hundreds of .db files. It's in every Android device, every iPhone, every Mac, every Windows 10/11 install, and in Firefox, Chrome, and Safari. VS Code stores its UI state in a SQLite file (state.vscdb). The documentation explicitly recommends production use — with a clear list of when not to.
The fundamental difference from Postgres or MySQL is architectural: SQLite has no server. No separate process, no TCP connection, no network authentication. It's a library that reads and writes directly to a file. Your application links the library, opens the file, and runs normal SQL queries.
import sqlite3
conn = sqlite3.connect("my_database.db")
rows = conn.execute("SELECT * FROM orders WHERE status = 'pending'").fetchall()
This isn't a hidden limitation. It's intentional design, and it defines both where SQLite shines and where it breaks.
Where SQLite beats a server database
Desktop and mobile applications
Any app that needs local persistence on a device — desktop, mobile, terminal — has SQLite as the natural choice. No server to configure, no port to open, no service to keep running. The database is the file, and it ships with the app.
CLI tools and processing scripts
If you're building a command-line tool that needs persistence — result cache, execution history, local index — SQLite is the right format. More structured than JSON, more queryable than CSV, lighter than any server. The ETL from the opening fits here: import both CSVs into tables, run a JOIN, and the two-hour meeting becomes a ten-minute script.
# SQLite as a queryable data format
sqlite3 data.db "SELECT city, COUNT(*) FROM customers GROUP BY city ORDER BY 2 DESC"
You can ship the .db as an artifact, open it in DB Browser for SQLite, and query it from any language. It's a file format with SQL on top.
Tests — with an important caveat
An in-memory database is one line:
conn = sqlite3.connect(":memory:")
It accepts the schema, runs queries, and disappears when the connection closes. For testing logic that only uses portable SQL, it's fast and isolated. But if production runs Postgres and the code uses JSONB, Postgres-specific ON CONFLICT behavior, or engine-specific types, a test that passes on SQLite proves nothing about production. In that case, run the real database in a container — I cover that trade-off in unit test vs integration test.
The edge and read replicas
SQLite's most recent wave is at the edge. Cloudflare D1 is a managed database with SQLite semantics, and Turso runs on libSQL, a SQLite fork, with replicas embedded in the application. The logic is simple: if the database fits in a file, you can replicate it close to users and serve reads locally, with writes centralized. Fly.io's LiteFS remains an open-source project, but the managed LiteFS Cloud service was shut down on October 15, 2024 — if you go that route, backups are on you (Litestream is the most cited option).
The four cases where the docs tell you to use another database
The Appropriate Uses For SQLite page lists four situations where a client/server database tends to work better:
- Client/server applications. If many computers will access the same database over a network, use a server database. SQLite does work over a network filesystem (NFS, SMB), but the docs warn that file locking is buggy in many implementations — and broken locking means two clients writing the same page at once, which means corruption. The docs' own rule: avoid SQLite when the same database is accessed directly, with no application server in between, from many computers at the same time.
- High-volume websites. The docs' reference is that sites with fewer than 100K hits per day work fine — and they stress it's a conservative estimate, already demonstrated at ten times that. The problem shows up when volume forces you to spread the application across several machines.
- Very large datasets. The formal limit is 281 TB, but long before that you'll want a database that distributes data and load.
- High write concurrency. SQLite allows one writer at a time for the whole database. With WAL, readers don't block the writer and the writer doesn't block readers, but writes still queue.
conn = sqlite3.connect("database.db", timeout=5.0) # wait up to 5 s for the lock instead of failing immediately
conn.execute("PRAGMA journal_mode=WAL")
# Ten workers writing at once still queue up:
# one writes, the others wait (or get "database is locked" when the timeout expires)
Notice that all four cases are about topology and concurrency, not about whether the project is "serious." A critical system with a single process writing falls outside all of them.
Typing: flexible by default, STRICT when you need it
By default, SQLite has flexible typing: a column's declared type is an "affinity," not a constraint. In a regular table, 'thirty' goes into an INTEGER column without an error. Since version 3.37.0 (November 2021), however, there are STRICT tables, which reject the value with SQLITE_CONSTRAINT_DATATYPE. I ran this on SQLite 3.49.2:
CREATE TABLE regular (id INTEGER PRIMARY KEY, age INTEGER);
INSERT INTO regular (age) VALUES ('thirty');
SELECT age, typeof(age) FROM regular; -- thirty|text (accepted)
CREATE TABLE strict_t (id INTEGER PRIMARY KEY, age INTEGER) STRICT;
INSERT INTO strict_t (age) VALUES ('thirty');
-- Error: cannot store TEXT value in INTEGER column strict_t.age
INSERT INTO strict_t (age) VALUES ('30'); -- converted losslessly: stored as integer 30
So "SQLite accepts anything in any column" is only true for non-strict tables. What's genuinely missing if you come from Postgres are rich types like JSONB, UUID, INET, arrays, and ranges — SQLite has JSON functions and the ->/->> operators, but stores JSON as text (or as its own JSONB blob format) and has no native UUID type.
WAL mode: what changes in practice
SQLite's default journal mode is the rollback journal. WAL (Write-Ahead Logging) is the alternative almost everyone should turn on for apps with simultaneous reads and writes:
conn.execute("PRAGMA journal_mode=WAL") # persistent: stored in the database file
conn.execute("PRAGMA synchronous=NORMAL") # trade-off: faster, less durable
Three details the documentation makes clear and many people get wrong:
journal_mode=WALis persistent: it applies to every connection and survives closing the database. The other modes don't.- WAL does not work over a network filesystem — all processes must be on the same machine, because the WAL index uses shared memory.
- With
synchronous=NORMALin WAL mode, the docs warn that transactions are no longer durable: a power loss can roll back the latest commits (the database stays intact, it just loses the most recent transactions). For a cache or rebuildable data, that's a great trade-off; for money, keepFULL, which is the default.
SQLite in production: the real criterion
The right question isn't "is the project big enough to deserve Postgres?" It's: is the database local to the application, or does it need to be accessed over the network by several machines?
If the database lives on the same machine as the application and writes aren't highly concurrent, SQLite is a legitimate production choice: zero external dependencies, simple backups, and a complete SQL API. If the database must be shared across several application servers, or concurrent write volume is high, use a server database. To choose between the two most common ones, I wrote a PostgreSQL vs MySQL comparison focused on transactions, JSON, and extensions.
This criterion is different from the SQL versus NoSQL debate — if the question is whether you need a relational database at all, the relational vs NoSQL post covers that decision.
Frequently asked questions
Is SQLite production-ready or just for development?
It's production-ready, with conditions. The official docs cite desktop and mobile apps, embedded devices, data analysis, and low-to-medium traffic websites — fewer than 100K hits per day as a conservative reference, already demonstrated at ten times that. Transactions are ACID, including across power loss with synchronous=FULL (the default). The criterion is topology and write concurrency, not project size.
What's the size limit of a SQLite database?
The documented limit is 281 TB. In practice the bottleneck shows up much earlier from write concurrency, not size: a large database read all the time and written by a single process works well; a small one with dozens of simultaneous writers struggles.
How do I back up SQLite in production?
Don't copy the file with cp while the application writes — you can capture an inconsistent state. Use the online backup API (the CLI's .backup command) or, since SQLite 3.27.0, VACUUM INTO, which produces a consistent, compact copy without stopping the application:
sqlite3 production.db ".backup backup_$(date +%Y%m%d).db"
sqlite3 production.db "VACUUM INTO 'backup_$(date +%Y%m%d)_vacuum.db'"
VACUUM INTO requires that the target file not exist. Per the docs, it uses more CPU than the backup API but produces a smaller file with no leftover deleted data.
SQLite or PostgreSQL for a small project?
If it's a web app on a single server with little concurrent writing, SQLite does the job and simplifies operations. If you already know you'll have more than one application server, parallel workers writing, or need types like JSONB and arrays, start with PostgreSQL — migrating later costs more than spinning up a managed Postgres on day one. The PostgreSQL vs MySQL comparison helps with the next step.
SQLite is a choice for people who know the options
It's not the choice of someone who can't run another database. It's the choice of someone who knows enough not to use a bazooka where a knife works. Inflating infrastructure because "you'll need scale someday" creates systems that are more expensive and harder to operate, with no benefit while the volume doesn't justify it.
For scripts, CLIs, desktop and mobile apps, tests of portable logic, the edge, and systems with one writer and many readers, SQLite is the right tool. For a service with several servers writing to the same database, it isn't — and that's in the official documentation, not my opinion. Since most of the SQL you write runs in both worlds with minor changes, I review queries in the SQL Formatter before porting them from one database to the other; that's where the ON CONFLICT clause or the function that only exists on one side shows up.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.