Cloud & Infrastructure · Databases
pgrust: Someone Rewrote Postgres in Rust and It Passes Every Regression Test
In under three months, one developer rebuilt Postgres from scratch in Rust using AI coding agents, and pgrust now matches Postgres 18.3's output across more than 46,000 regression queries. Here's what it actually is, and isn't, and why it matters.
Abhishek Gupta
5 min read
Sponsored
A developer working alone rebuilt Postgres from scratch in Rust and, in under three months, got it to match PostgreSQL 18.3’s output across every query in the standard regression test suite, more than 46,000 of them, plus the isolation tests that check concurrent transaction behavior. It’s called pgrust, and the honest headline isn’t “Postgres is being replaced.” It’s “an AI-assisted rewrite of one of the most battle-tested C codebases in existence went from a third of tests passing to all of them in a matter of weeks.”
What pgrust actually is
pgrust is exactly what it sounds like: PostgreSQL reimplemented from the ground up in Rust, not a Rust wrapper around the existing C engine, not a piecemeal port of individual files. The project’s creator, writing as malisper, made a deliberate choice early on to start from nothing rather than try to gradually convert the existing 30-plus-year-old C codebase in place. Converting in place risks long stretches where the system doesn’t run at all. Starting fresh meant something executable existed from day one, even if it only handled a fraction of Postgres’s behavior.
The project now sits at roughly 250,000 lines of Rust and covers the major Postgres subsystems: the query parser, planner, executor, storage layer, and transaction handling, all reimplemented well enough to reproduce Postgres 18.3’s behavior on the full regression suite. That’s a meaningfully high bar. Postgres’s regression tests exist precisely to catch subtle behavioral drift, edge cases in type coercion, locking semantics, error messages, that a superficially similar reimplementation would get wrong.
Where the speed came from
The part worth paying attention to isn’t the Rust rewrite itself, people have taken swings at reimplementing Postgres before. It’s the timeline. The project went from a first working skeleton to 100% regression compatibility in a period the creator describes in weeks, not years, and credits AI coding agents, mainly Codex, as the reason. The workflow was consistent throughout: point the agent at the relevant piece of Postgres’s C source, have it explain what that component actually does, then build a minimal Rust equivalent and check it against the regression tests.
That’s a specific and fairly disciplined use of AI coding agents, closer to “AI as a reverse-engineering and translation accelerant against a known, testable target” than “AI writes a database from a prompt.” The project’s own progress updates track the climb: an early post titled the project sitting at 67% Postgres compatibility “and accelerating,” followed weeks later by a post announcing 100% of the regression suite passing. Postgres’s regression suite functioned as ground truth the whole way through, which is likely why the result holds up. Without that oracle, an AI-assisted rewrite of something this complex would have no reliable signal for whether it was drifting from correct behavior. Teams exploring AI agents for large, unfamiliar codebases should take the same lesson: the agent needs a testable target, not just a task description, or speed comes at the cost of correctness you won’t notice until production.
What it isn’t, and why that matters more than what it is
pgrust is not production-ready, and the project doesn’t pretend otherwise. Passing regression tests demonstrates behavioral compatibility on a known set of cases. It says nothing about performance under load, since the project explicitly hasn’t been optimized yet, and it says nothing about the years of accumulated edge-case hardening that comes from running a database in front of real, adversarial, unpredictable traffic. Postgres earned its reputation for reliability the slow way, through decades of production incidents that shaped the code. A reimplementation, however faithful to the test suite, hasn’t been through that yet.
The stated goal backs this up: the project isn’t trying to be a drop-in production replacement soon. It’s trying to make Postgres’s internals easier to safely modify, using Rust’s compiler guarantees as a substitute for some of the manual discipline the C codebase currently demands. The motivation the creator cites lines up with real, well-known Postgres pain points: over 350 tunable settings where a single misconfiguration can take the whole database down, vacuum-related issues that are a leading cause of Postgres outages in practice, and a query planner that occasionally makes choices that surprise experienced operators. Those are exactly the kinds of problems where “the compiler catches a class of bug before it ships” is a genuinely useful property to have, separate from any argument about which language is faster.
What this means if you run Postgres in production
Nothing changes for you today. Don’t migrate anything to pgrust, and don’t expect to for a long while, if ever, given how much production hardening separates “passes the regression suite” from “trustworthy with your data.” What’s worth internalizing instead is the pattern: a single developer, with the right test oracle and a disciplined workflow, used AI coding agents to compress a rewrite that would traditionally take a team years into a project measured in weeks. That’s relevant whether or not you ever touch pgrust, because it’s the same pattern showing up in database migration projects and legacy modernization work more broadly: the bottleneck used to be developer-hours to understand and reimplement unfamiliar code. That bottleneck is loosening, and the projects that benefit most are the ones with an existing, thorough test suite to check the AI-assisted work against.
If pgrust matures into something with real performance characteristics and a production track record, that’s a story worth revisiting. For now, it’s a genuinely impressive proof of concept, and a useful data point on how fast AI-assisted rewrites of complex systems can move when there’s a rigorous oracle to check them against.
Frequently asked questions
- What is pgrust?
- pgrust is a from-scratch reimplementation of PostgreSQL in Rust, built by developer Michael Malis (writing as malisper). It targets behavioral compatibility with Postgres 18.3 and now passes the full Postgres regression test suite, over 46,000 queries, plus the isolation tests, which check concurrent transaction behavior.
- Is pgrust ready to replace Postgres in production?
- No, and the project doesn't claim to be. It's explicitly experimental: not performance-optimized, and passing regression tests demonstrates matching output on known test cases, not the years of edge-case hardening a production database needs. Treat it as a research project, not a migration target.
- How did one person rewrite something as complex as Postgres this fast?
- By starting from scratch instead of trying to port the existing C codebase piece by piece, and by leaning heavily on AI coding agents, primarily Codex, to read the Postgres C source, explain how each subsystem worked, and generate a minimal Rust implementation of it. The project went from roughly a third of regression tests passing to 100% in a period of weeks.
- Why rewrite Postgres at all? What's wrong with the C version?
- Nothing is fundamentally broken about Postgres, it's one of the most reliable databases in production use. But the motivation cited for pgrust is that Postgres has over 350 tunable settings where misconfiguring one can take the database down, vacuum-related issues are a leading cause of Postgres outages, and the query planner can occasionally make surprising choices. The bet is that a Rust codebase, with the compiler's help, is a safer surface to experiment with fixes for those classes of problems.
- Does this mean Rust is replacing C for systems programming?
- Not on its own, but it's another data point in a trend that includes Rust components landing in the Linux kernel and other C-heavy infrastructure projects adopting Rust piecemeal. pgrust is notable less for the language choice and more for how fast an AI-assisted rewrite got there.
Sources
Sponsored
More from this category
More from Cloud & Infrastructure
R.01 The AWS CloudFront Outage That Took Down Canvas, Blackboard, and Hugging Face at Once
R.02 Kubernetes 1.36 Haru: What's Actually Worth Upgrading For
R.03 AWS's Trillion-Dollar Billing Bug Is a Warning About Automated Cost Alerts
Sponsored
Discussion
Join the conversation.
Comments are powered by GitHub Discussions. Sign in with your GitHub account to leave a comment.
Sponsored