SQLite vs PostgreSQL: Differences, Trade-offs and Which to Use
SQLite vs PostgreSQL: an embedded file vs a database server. How they differ on concurrency, types, features, deployment and backups, and when to pick each.
SQLite is a library that stores your whole database in one file and runs inside your app's process. PostgreSQL is a separate server that many clients connect to over a socket. That one difference drives the rest: SQLite needs no setup and is very fast for a single app on a single machine, but only one write transaction can run at a time and the file must live on a local disk that survives restarts. PostgreSQL handles many concurrent writers and several app servers, enforces types strictly, and has built-in users, replication and a far larger feature set, at the cost of running and maintaining a server. Pick SQLite for local tools, tests, embedded and desktop apps, and small to medium web apps that run on one server with a persistent disk. Pick PostgreSQL when you have several app instances, heavy concurrent writes, serverless or ephemeral hosting, or need its features. Many apps start on SQLite and move later; the migration is manageable if you plan for it.
Checked against the SQLite docs (when to use, STRICT tables, ALTER TABLE, WAL, VACUUM INTO, the release history), postgresql.org (the PostgreSQL 19 release announcement and the versioning policy), the Litestream docs and the pgloader SQLite docs in November 2026. The examples were run on SQLite 3.54.1 (the CLI, built from the official amalgamation) and PostgreSQL 19.0 (postgres:19-alpine).
At a glance
| SQLite | PostgreSQL | |
|---|---|---|
| Architecture | Library in your process, one file on disk | Server process, clients connect over TCP or a Unix socket |
| Setup | None; open a file | Install or rent a server, create users and databases |
| Concurrent writes | One write transaction at a time per database | Many, with row-level locking (MVCC) |
| Concurrent reads | Unlimited readers; with WAL, readers and the writer don't block each other | As many as you have connections; MVCC, so readers and writers don't block each other |
| Typing | Flexible by default; STRICT tables (3.37.0+) enforce types |
Strict, with a large type system (timestamps with time zone, UUID, arrays, ranges, enums, JSONB) |
| Foreign keys | Off by default, per connection (PRAGMA foreign_keys = ON) |
Always enforced |
ALTER TABLE |
Rename, add and drop columns; NOT NULL and CHECK changes since 3.53.0; no column type changes | Almost any change, many without a rewrite |
| Users and permissions | None; whoever can read the file can read everything | Roles, GRANT, row-level security |
| Replication | Not built in (Litestream and others add it) | Streaming and logical replication built in |
| Backups | .backup, VACUUM INTO, Litestream |
pg_dump, base backups plus WAL archiving for point-in-time recovery |
| Network access | Local file only | Designed for it |
| Current version | 3.54.1 (16 October 2026) | 19.0 (19 November 2026) |
Concurrency: the single-writer limit
The SQLite docs say it plainly: "SQLite supports an unlimited number of simultaneous readers, but it will only allow one writer at any instant in time." With WAL mode turned on, readers keep reading while a write is in progress, so a busy read-heavy site is fine. Writes queue.
What that looks like when a second process tries to write while one transaction is open, in our test:
sqlite3.OperationalError: database is locked
That came from a Python connection with timeout=0. With a busy timeout (PRAGMA busy_timeout = 5000, or Python's default timeout=5.0), the second writer waited about 2.5 seconds for the first transaction to commit, then succeeded. So the practical rules are: set a busy timeout, keep write transactions short, and don't hold a transaction open while you call an external API.
The SQLite docs also describe how far this goes: "a write transaction only takes milliseconds and so multiple writers can simply take turns", and its own estimate is that a site with "fewer than 100K hits/day should work fine", which it calls conservative. Where it stops working is lots of simultaneous writers that can't wait their turn, or several machines writing to the same database.
PostgreSQL was built for that case. Each connection gets its own server process, concurrent transactions write different rows without waiting for each other, and MVCC means readers never block writers. The cost is per-connection memory: max_connections defaults to 100, and apps with many instances usually need a pooler (Postgres Connection Pooling Explained).
Types: flexible vs strict
SQLite's default typing surprises people coming from Postgres. In an ordinary table, a column's declared type is a preference:
CREATE TABLE loose (id INTEGER PRIMARY KEY, qty INTEGER, created TEXT);
INSERT INTO loose (qty, created) VALUES ('abc', 12345);
SELECT qty, typeof(qty) FROM loose;
-- abc|text
SQLite stored the string 'abc' in an INTEGER column without complaint. It does convert where it can ('42' became the integer 42). Since 3.37.0 you can opt into enforcement with STRICT:
CREATE TABLE tight (id INTEGER PRIMARY KEY, qty INTEGER) STRICT;
INSERT INTO tight (qty) VALUES ('abc');
-- Error: cannot store TEXT value in INTEGER column tight.qty
STRICT tables accept only INT, INTEGER, REAL, TEXT, BLOB and ANY as column types. SQLite has no separate date, boolean or UUID types; dates are stored as text or numbers and handled with its date functions, booleans as 0 and 1.
PostgreSQL rejects the bad value outright:
ERROR: invalid input syntax for type integer: "abc"
LINE 1: INSERT INTO t (qty) VALUES ('abc');
^
It also has the types SQLite lacks: timestamptz, uuid, numeric for money, arrays, ranges, enums and JSONB with indexes. If your data model leans on any of those, that's a strong reason to pick Postgres.
Foreign keys are the other trap. In our SQLite test, inserting a row that referenced a missing parent succeeded silently. Foreign key enforcement is off unless each connection runs PRAGMA foreign_keys = ON; most ORMs and frameworks that support SQLite set it for you, but check.
Features
SQLite has added a lot in recent years. Features worth knowing, with the version that added them:
RETURNINGonINSERT,UPDATEandDELETE: 3.35.0 (2021).ALTER TABLE ... DROP COLUMN: 3.35.0.STRICTtables: 3.37.0.- JSONB, a binary JSON format stored as a BLOB: 3.45.0 (2024). The JSON functions (
json_extractand the rest) are built in. - Adding and removing
NOT NULLandCHECKconstraints withALTER TABLE: 3.53.0 (April 2026).
Two caveats. First, you get the SQLite version your runtime links against, not the latest. In our tests, python:3.13-slim (Debian 13) used SQLite 3.46.1 from the system library, while Node 22.23.5's built-in node:sqlite module bundles 3.54.1 (and still prints an experimental warning). Check with SELECT sqlite_version(); before relying on a feature. Second, SQLite still can't change a column's type: ALTER TABLE ... ALTER COLUMN qty TYPE TEXT is a syntax error. The documented workaround is to create a new table, copy the data across and rename it, which most migration tools do for you.
PostgreSQL's list is longer: window functions and CTEs (SQLite has those too), but also materialized views, table partitioning, full-text search with ranking and many languages, LISTEN/NOTIFY, row-level security, logical replication, and extensions such as PostGIS and pgvector. SQLite has full-text search through its FTS5 extension and supports loadable extensions, but the ecosystem is much smaller.
Deployment: a file vs a server
With SQLite, "deploying the database" means making sure one file lives on a disk that persists. That's easy on a VPS or any server with a normal filesystem, and it's where SQLite shines: no network hop, no credentials, no connection limits, and queries that run in microseconds because they're function calls.
It's also where SQLite goes wrong most often:
- Serverless functions can't keep a local file between invocations. Each instance may start with a fresh filesystem.
- Platforms with ephemeral disks wipe the container's filesystem on every deploy or restart, so the database silently resets to empty unless you mount a persistent volume.
- Several app instances can't share one SQLite file across machines. The SQLite docs advise against network filesystems, because "file locking logic is buggy in many network filesystem implementations", and WAL mode "does not work over a network filesystem" at all.
PostgreSQL avoids all three because the data lives in the database server, not next to your code. Any number of app instances, serverless functions or cron jobs can connect. The price is a server to run, patch, size and back up, or a managed service that does it for you.
If you want SQLite semantics without managing the file, hosted SQLite-compatible services exist (Turso, which Supabase is acquiring, and Cloudflare D1 among them), but each adds its own network layer and limits, so read their docs rather than assuming local SQLite behaviour.
Backups
SQLite: don't copy the file with cp while the app is writing to it; you can get a torn copy, and in WAL mode recent commits live in the -wal file. Use one of:
sqlite3 app.db ".backup backup.db" # online backup API
sqlite3 app.db "VACUUM INTO 'backup.db'" # compact copy, deleted data purged
The docs compare them: VACUUM INTO gives a minimal file with no deleted content left behind, while the backup API "uses fewer CPU cycles and can be executed incrementally". For continuous backups, Litestream runs beside your app and "continuously copies write-ahead log pages from disk to a replica" in object storage, and can restore to a chosen point. It's the usual choice for production SQLite.
PostgreSQL: pg_dump for logical backups of one database, and base backups plus WAL archiving for point-in-time recovery. How to Back Up a Postgres Database covers both. Managed Postgres services usually do this for you.
Whichever you use, test a restore. A backup you've never restored is a guess.
Which should you pick?
Pick SQLite when:
- It's a CLI, desktop, mobile or embedded app, or a local cache.
- It's a web app on one server with a persistent disk, mostly reads, with write bursts that can queue. Rails 8 and similar frameworks support this setup well.
- You want tests that run against a real database with zero setup (as long as production is SQLite too; testing on SQLite and running Postgres in production hides type and SQL differences).
Pick PostgreSQL when:
- You run, or will soon run, more than one app instance, or serverless functions.
- Many users write at the same time: chat, collaborative editing, job queues, high-volume ordering.
- You need its types (timestamps with time zones, UUID, JSONB with indexes), row-level security, replication, PostGIS or pgvector.
- Several services or people need network access to the same data with separate permissions.
- Your host's disk isn't persistent.
If you're unsure and the app will be deployed to a typical web host, Postgres is the safer default because it works on every hosting model. If you're building something small that will live on one server you control, SQLite is simpler and very fast. Is SQLite Good Enough for Production? goes deeper on the SQLite side, and PostgreSQL vs MySQL if Postgres isn't the only server option you're weighing.
Moving from SQLite to PostgreSQL later
The move is routine if you keep it in mind from the start:
- Use an ORM or query builder that supports both (Prisma, Drizzle, SQLAlchemy, Django, ActiveRecord), and avoid SQLite-only behaviour such as storing mixed types in a column.
STRICTtables help here. - Fix types before moving. Columns holding strings in integer columns, or dates in several formats, will fail Postgres's checks. Query with
typeof()to find them. - Recreate the schema with Postgres types through your migration tool, rather than copying SQLite's declared types.
- Copy the data. pgloader does this in one command,
pgloader sqlite:///path/to/file.db pgsql://pguser@pghost/dbname, with casting rules for SQLite types. For small databases, exporting to CSV and importing withCOPYworks too (Import a CSV into Postgres). - Reset sequences so new rows don't collide with copied IDs, then run your test suite against Postgres before switching traffic.
Quick checklist
- Count the app instances that will write to the database. More than one machine means Postgres.
- Check whether your host's disk persists across deploys. If not, use Postgres or mount a volume.
- On SQLite: enable WAL, set
busy_timeout, turn onforeign_keys, considerSTRICTtables. - Check
sqlite_version()before using newer features like JSONB or the 3.53ALTER TABLEchanges. - Set up backups (Litestream or
VACUUM INTOfor SQLite,pg_dumpor WAL archiving for Postgres) and test a restore. - If you'll likely outgrow SQLite, use an ORM that supports both and keep the data clean.
On EasySpawn, each server has a persistent disk, so a SQLite file survives deploys and restarts there, which isn't true on serverless platforms; you'd still want your own Litestream or VACUUM INTO backups for it. If you'd rather use Postgres, a managed PostgreSQL database is provisioned with the server, and Claude Code can run your migrations and copy the data across on the same machine. EasySpawn won't make SQLite's single writer go away, and if you need several app servers writing to one database, Postgres is the answer anywhere. See how it works or join the waitlist.
Related: Is SQLite Good Enough for Production? When It Works and When It Doesn't · SQLite WAL Mode: Faster Writes and Readers That Don't Block · PostgreSQL vs MySQL: Which Database Should You Choose? · Which Database Should an AI-Built App Use?
Keep reading
Supabase Error 406 "Not Acceptable" (PGRST116): Why .single() Fails and How to Fix It
A Supabase 406 almost always means .single() got zero rows or several. Why row-level security often causes it, and when to use .maybeSingle() or fix a policy.
Postgres "ERROR: permission denied for table": Causes and Fixes
Postgres "permission denied for table" means your role lacks a privilege on it. How to check grants, fix future tables with default privileges, and sequences.