I built a database Postgres clients can talk to
What building a Postgres-compatible database in Rust taught me about benchmarks, snapshots, and testing against the real thing.
Postgres
The protocol every client already speaksGeethDB
An engine written from scratch in RustI wanted to know if I could build a database that Postgres clients connect to, with nothing from Postgres underneath. My goal was ten times faster than Postgres. I called it GeethDB.
I built it in Rust over a weekend in August 2026. The code is AI-generated; I directed the design and decided what to test. It didn’t get anywhere near ten times faster, and the useful part was working out why.
Postgres on the outside
GeethDB speaks the PostgreSQL wire protocol. psql, drivers, and ORMs connect to it without changes, because they’re talking to something that sounds like Postgres. Behind the protocol, it has its own parser, planner, executor, and storage.
That split was the whole idea. Compatibility is the part that decides whether anyone can use a new database, so I took it as given and rebuilt what’s underneath.
The build / explore each layer
From a psql prompt to the disk
psql connects unmodified
Speak Postgres on the outside
The server implements the Postgres wire protocol, so psql, tokio-postgres and other drivers connect without changes. Nothing from Postgres runs underneath.
The first benchmark was humbling
I measured it against a real Postgres 15 on the same machine, using the same client. Opening a connection was almost nine times faster, because Postgres starts a process for every connection and GeethDB doesn’t. Everything else was slower. A point lookup took 805 µs, about 26 times longer than Postgres.
Each gap had a specific cause. There were no indexes, so every lookup scanned the whole table. Scans copied every row before the filter ran, so a query that matched nothing still took four times longer than Postgres. Prepared statements were re-planned on every execution, and results were buffered whole before anything was sent.
So each had a specific fix. After adding indexes, cursors, cached plans, and streamed results, the gaps closed.
The benchmark / three runs
How geethdb compared with Postgres, run by run
In memory, no indexes. Postgres had durability turned off.
Above 1× means geethdb was ahead. Latency rows compare medians; throughput rows compare operations per second.
The numbers & the setup
| Workload | geethdb | Postgres |
|---|---|---|
| Connect | 175 µs | 1,559 µs |
| SELECT 1 | 32 µs | 28.8 µs |
| Full scan | 1,739 µs | 660 µs |
| Range scan | 818 µs | 41.8 µs |
| Point lookup | 805 µs | 31.3 µs |
| Lookups/sec | 8,050 /s | 142,232 /s |
Apple M5 Max, Postgres 15.17 with fsync and synchronous_commit off, a 10,000-row table, the same tokio-postgres client over loopback. geethdb had no indexes, so every lookup scanned the table; Postgres had one.
Parity isn’t a win, though. Postgres has had decades of work on exactly these paths, and matching it on a small workload, before adding durability or transactions, says very little. The one real difference is connection setup, and people already put a pooler in front of Postgres to fix that.
The third run is the engine as it is today, and it’s slower on scans. That’s the price of a later change, which I get to below.
The gap that wasn’t real
Once GeethDB could write to disk, I benchmarked writes. A single insert took 3,787 µs in GeethDB and 56 µs in Postgres. That looked like a 68× disaster.
It was two different amounts of work. On macOS, Rust’s sync_data asks the drive to confirm the write actually reached it. Postgres’s default setting there doesn’t wait for the drive. When I told Postgres to wait too, its insert took about 3.9 ms, the same as mine.
Writes / the same insert, two settings
The 68× gap that wasn’t real
geethdb looks 68 times slower at writing.
Median single-row INSERT on one connection, 2,000 writes. Only the flush setting changes between the two views.
Test setup & limits
Apple M5 Max, Postgres 15.17, the same tokio-postgres client over loopback. I measured the macOS behavior directly rather than from documentation: changing only Postgres’s wal_sync_method moved its insert from 56 µs to about 3.9 ms. Other operating systems and drives will differ.
A gap between two benchmarks is a question to ask, not an answer to believe.
I’d have been just as wrong if the gap had gone the other way. A number only means something when both sides are doing the same work.
Transactions without a vacuum
Postgres marks every row with the transaction that created and deleted it, and sweeps the dead versions up later. That sweep is vacuum, and it’s one of the things people complain about most.
I tried a different shape. In GeethDB, each table’s committed state is immutable. A snapshot is just a pointer to it, so readers never wait for writers, and an old version is freed when the last reader lets go.
Snapshots / copy on write
Changing a row without disturbing a reader
One root page leads to every row. A reader that starts at R1 sees this tree for as long as it holds R1.
Writers use first-committer-wins. If a row has changed since a transaction first touched it, the commit fails with Postgres’s 40001 serialization error rather than overwriting work it never saw. READ COMMITTED and REPEATABLE READ both behave the way they do in Postgres.
SERIALIZABLE is accepted but runs as REPEATABLE READ. Snapshot isolation allows write skew, and I didn’t want to claim a guarantee the database doesn’t give.
The bug that read old data
The same idea carries over to disk. I built a buffer pool and a copy-on-write B+tree, where a version of a table is a single page number. Changing a row copies the page, then its parent, up to the root, and never overwrites anything an older version can reach.
My first version freed a replaced page straight away. That looks fine, since nothing in the new tree uses it. But a reader holding an older root can still reach it, and the next write recycled the page underneath that reader.
The bug / when is a page free?
Reusing a page one reader still needs
Reader: holding root → page 12
A reader is holding an old root. It reaches page 12, where row 7 is 100.
A simplified model of the failure. In the real test, a held root returned the changed value instead of the original.
A test caught it. It holds an old root, keeps writing, and checks the old root still returns the old data. It came back with the new value.
The fix is to retire a page instead of freeing it. A retired page is tagged with the generation that replaced it, and it only rejoins the free list once no older reader remains. That also decides how big the file gets. Without reuse, 500,000 small rows took 11.4 GiB on disk. With it, they took 82.6 MiB.
A database bigger than its memory
Everything so far lived in memory, with the disk only keeping a log. That was the oldest limit in the design: the whole database had to fit in RAM. The buffer pool and the tree were built to remove it, and moving the real tables onto them was the last step.
I kept the log as the commit path. A commit still appends one record and waits for one flush. A checkpoint writes the dirty pages and resets the log, and recovery opens the pages as of the last checkpoint and replays the log on top.
That added a second rule for reusing a page. It can’t be reused while a live reader can reach it, and it can’t be reused while the last checkpoint still needs it. I only believed in the second rule after removing it: the crash test then read garbage after recovery.
To test the result I loaded a million rows, each an integer key and 400 bytes of text, into a server with an 8 MB buffer pool. The file came to 435 MiB, 54 times the pool. The server’s memory peaked at 130 MiB while loading and sat at 115 MiB after a reopen. The previous build peaked at about 4.6 GiB on the same load.
Memory / a 435 MiB database
One million rows, an 8 MB buffer pool
About 36× less memory, for a database bigger than the memory it uses.
Resident memory of the real server process, read from ps. The vertical line marks the 435 MiB database. Linear scale.
The numbers & the limits
| Measure | Before | Now |
|---|---|---|
| Rows | 1,000,000 | 1,000,000 |
| Buffer pool | none, rows in memory | 8 MB |
| Load rate | 69,419 rows/s | 111,197 rows/s |
| Ready after reopening | 0.41 s | 0.33 s |
| Point read, p50 / p99 | 34 / 75 µs | 35 / 74 µs |
| Full scan of all rows | 0.08 s | 0.26 s |
Table of one million rows: an integer primary key and 400 bytes of text. Same load and same machine (Apple M5 Max) for both. The OS page cache still holds the file, so the reads are warm, not cold-disk reads. Indexes are still held in memory.
Point reads stayed at about 35 µs. Scans got slower. Before, a scan handed out pointers to rows already in memory; now every row is decoded from a page. Reading all million rows took 0.08 seconds before and 0.26 now, and a full scan of the 10,000-row benchmark table takes about 1.2 ms against Postgres’s 0.6 ms. I know how to speed both up, and I haven’t.
Memory still isn’t free. Indexes are held in memory and rebuilt when the database opens, so memory follows the indexes more than the rows. Sorts and joins also work in memory, and deleting rows doesn’t shrink the file. The reads in my test were warm too, because the operating system still had the file cached. I never measured a cold disk.
What I’m taking away
The biggest surprise was how much of the work was compatibility. Real tools ask for the catalog, error codes, and type identifiers before they run a single query, and each is a place to be subtly wrong.
The tests that mattered most used something independent. An unrelated Postgres driver found bugs my own client code never would, and the crash tests start the real server, write over the wire, and kill -9 it, including with a 1 MB buffer pool.
GeethDB isn’t a Postgres replacement. It has no CHECK constraints, no ALTER TABLE, and no subqueries in expressions, and DDL isn’t transactional. It’s a working database with an honest list of what it can’t do, and a much clearer idea of what building one takes.