Skip to content

---

title: SQLite vs Postgres, measured: every number and the code

slug: sqlite-vs-postgres

lang: en

published: 2026-11-12

words: 1033

lines: 94

size: 5.6 KB

read: 6 min read

reel: Don't use Postgres, you're making a mistake

---

SQLite vs Postgres, measured: every number and the code

Don't use Postgres, you're making a mistake

I loaded the same million orders into SQLite and PostgreSQL and tested both on one machine, with the same queries and the same disk. SQLite won reads by 14.5x. PostgreSQL won as soon as many programs wrote at once. This page has every number, why each one happened, and what the reel only named.

The code, the raw results and the method are public: github.com/SinaFtpAi/sqlite-vs-postgres. You can run it on your own machine. The charts of every test are in its README.

The setup

  • One machine: Intel Core i7-12700K, 12 logical CPUs in WSL2, 19.1 GB RAM, an ext4 disk.
  • PostgreSQL 18.6 and SQLite 3.54.1, both built from their official sources.
  • 1,000,000 orders for 100,000 users, generated from one seed, so both engines get the same rows.
  • Every test ran 5 times. The numbers below are the medians.
  • Fair by design: both stores on the same disk (a RAM disk is refused, it would hide the fsync cost), the same 64 MiB cache, every worker its own process with one connection, and every write its own transaction.

Reads from one program: SQLite is 14.5x faster

Reading one order by its id, SQLite did 168,617 reads a second and PostgreSQL 11,619.

The reason is where the database runs. SQLite is a library: the database is a file, and the query runs inside your own program. PostgreSQL is a separate server, so every query leaves your program, goes to the server and comes back.

It is not the network. Over its Unix socket, with no TCP at all, PostgreSQL did 11,732 a second, the same. The cost is the trip to another process.

Many writers: SQLite makes them queue

SQLite lets only one program write at a time. The others wait for the lock. With 16 programs writing at once:

SetupInserts a secondSlowest insertErrors
SQLite, waits up to 5 s for the lock40,7564.7 s4 failed after 5 s
SQLite, does not wait94.6% failed with database is locked
PostgreSQL7,66218 ms0

So in SQLite each writer either waits in line up to 5 seconds, or almost every insert fails. PostgreSQL let all 16 in together with no errors.

The fast mode and what it costs

SQLite's 40,756 above comes from its fast mode: WAL with synchronous = NORMAL. In that mode a power cut can roll back the last commits. The file stays consistent, it does not corrupt, but what you saved last may be gone.

PostgreSQL with its defaults (fsync = on, synchronous_commit = on) does not lose a committed write. To compare fairly, I put SQLite in the same safe mode:

sql
PRAGMA journal_mode = WAL;
PRAGMA synchronous = FULL;
PRAGMA busy_timeout = 5000;

At the same safety, with the same 16 writers, PostgreSQL wrote 7,662 inserts a second and SQLite 1,081: about 7x. These runs depend on fsync and vary a lot on this disk (PostgreSQL 2,720 to 10,600 a second over the 5 runs, SQLite 202 to 1,308), but PostgreSQL wrote more in every run, between 4.7x and 34x.

With one writer at the same safety, the two are about even: SQLite 1,140 a second, PostgreSQL 1,191. The gap only opens when many programs write together.

Every other number

TestSQLitePostgreSQL
Newest orders of one user (one program)36,045 a second8,216 a second
Point reads, 16 programs858,069 a second167,088 a second
Mixed, 16 programs, 90% reads168,543 ops a second52,564 ops a second
Write p99 in the mixed test18.3 ms5.7 ms
One insert per commit, fast mode34,425 a second
Count orders by status151 ms130 ms
Top users by spend1,130 ms1,779 ms
Load 1,000,000 rows1.9 s10.9 s

What PostgreSQL gives a bigger project

The reel only named these. None of them was measured here; this is what they are and why they matter once an app grows.

  • HA (high availability). PostgreSQL streams every change to a second server (streaming replication). If the main server dies, the replica is promoted and the app keeps running. Tools like Patroni automate that failover. With SQLite the database is one file on one machine.
  • pgvector. An extension that stores embeddings and searches them by similarity, inside the same database as the rest of your data. This is what most RAG and AI search setups need.
  • PostGIS. Geographic types and queries: distance, "what is inside this area", nearest neighbours, with spatial indexes.
  • Roles and permissions. Users, roles, grants per table and row level security, so each service gets only what it needs. SQLite has no users: whoever can open the file can read it.

To be fair to SQLite: it has add-ons too, sqlite-vec for vectors and SpatiaLite for geography. The difference is how much of this is ready, maintained and used in production at scale.

So which one?

  • One app, a few users, mostly reads: SQLite. It is faster, it is one file, there is no server to run, back up or secure. Use WAL mode and decide on synchronous knowing what it costs.
  • Many programs or workers writing at once: PostgreSQL. SQLite will make them queue or fail them.
  • You need HA, vectors, maps or real permissions: PostgreSQL.

Limits of this test

  • One machine and one disk. On WSL2 the disk goes through a virtual layer, so fsync may cost differently on a native Linux server or a Mac.
  • Latencies are closed loop service times, so the tails are understated.
  • 16 workers on 12 logical CPUs oversubscribe the machine.

The full method, every setting and its reason, is in docs/METHOD.md. To run it yourself:

bash
git clone https://github.com/SinaFtpAi/sqlite-vs-postgres.git
cd sqlite-vs-postgres
uv sync
uv run dbbench install
uv run dbbench all
en6 min read