0Pricing

pgrust: Postgres Rewritten in Rust Is 300x Faster on Analytical Workloads — And Passes 100% of Regression Tests

pgrust rewrites PostgreSQL in Rust with 100% regression test compatibility. Get 300x faster analytical performance and modern thread-per-connection architecture. 1,800+ GitHub stars.

C
CoddyKit Team · 6 min read · 1,104 words
pgrust: Postgres Rewritten in Rust Is 300x Faster on Analytical Workloads — And Passes 100% of Regression Tests
Quick Answer: pgrust is an open-source project that rewrites PostgreSQL in Rust while maintaining 100% compatibility with Postgres 18.3. It passes all 46,000+ regression tests, offers thread-per-connection architecture, and delivers 50% faster transaction workloads and 300x faster analytical queries. Built with AI-assisted programming, it's disk-compatible with existing Postgres data directories.

What happens when you take one of the most reliable database systems ever built and rewrite it from scratch in Rust? You get pgrust — a project that's currently exploding on GitHub with nearly 800 stars per day.

The premise sounds almost too ambitious: rewrite PostgreSQL, a database with decades of battle-tested reliability, in a completely different language. But pgrust isn't just an academic exercise. It's passing 100% of Postgres's regression test suite — all 46,000+ queries — and delivering performance improvements that would make any database administrator sit up and pay attention.

Why Rewrite Postgres in Rust?

PostgreSQL's codebase is written in C, a language that's served it well for over 35 years. But C comes with well-known trade-offs: manual memory management, buffer overflows, and a class of bugs that Rust was specifically designed to eliminate.

The pgrust team, led by Marvin Liang (malisper), isn't trying to "fix" Postgres. Instead, they're using Rust's safety guarantees as a foundation to explore deeper architectural changes that would be risky in C.

"The goal is to make Postgres easier to change from the inside," the project states. "Keep the behavior Postgres-shaped, keep the real Postgres tests as the oracle, and use Rust plus AI-assisted programming to explore deeper server changes."

The Performance Numbers That Matter

Here's where pgrust gets really interesting. The team has been working on a new version (not yet published) that delivers staggering performance improvements:

  • Transaction workloads: 50% faster than PostgreSQL
  • Analytical workloads: 300x faster than PostgreSQL
  • ClickBench performance: Only 2x slower than ClickHouse (a purpose-built analytical database)

That last point is crucial. A general-purpose database that's within 2x of a specialized analytical engine — while maintaining full PostgreSQL compatibility — is remarkable.

The secret? A thread-per-connection model instead of Postgres's traditional process-per-connection architecture. This eliminates the overhead of forking processes and allows for much better resource utilization under heavy concurrent workloads.

100% Regression Test Compatibility

The most impressive technical achievement isn't the performance — it's the compatibility. pgrust passes 100% of PostgreSQL's regression test suite, which includes over 46,000 queries covering everything from basic SQL operations to complex window functions, CTEs, and edge cases that have been discovered over decades of production use.

This isn't just "mostly compatible." It's disk compatible. You can point pgrust at an existing Postgres 18.3 data directory and it will boot up and read your data. That level of compatibility requires implementing not just the SQL layer, but the storage format, WAL (Write-Ahead Logging), and internal data structures.

# Run pgrust with an existing Postgres data directory
docker run -d --name pgrust \
  -e POSTGRES_PASSWORD=secret \
  -v /your/postgres/data:/var/lib/postgresql/data \
  malisper/pgrust:v0.1

# Connect using standard psql
docker exec -it pgrust psql -h 127.0.0.1 -U postgres

Built with AI-Assisted Programming

One of the most fascinating aspects of pgrust is how it was built. The team used AI-assisted programming tools to accelerate the rewrite process, which is no small feat when you're reimplementing a database with millions of lines of code.

This isn't just about writing code faster. AI assistance helps maintain consistency across the codebase, catch edge cases, and ensure that the Rust implementation matches Postgres's behavior exactly. It's a real-world example of how AI can be used for large-scale system rewrites.

Real-World Example: Migrating an Existing Postgres Instance

Let's say you have a production PostgreSQL 18.3 instance and want to test pgrust:

# 1. Stop your current Postgres instance
sudo systemctl stop postgresql

# 2. Back up your data directory (always!)
cp -r /var/lib/postgresql/18/main /var/lib/postgresql/18/main.backup

# 3. Run pgrust pointing to the same data directory
pgrust -D /var/lib/postgresql/18/main \
  -c listen_addresses='*' \
  -p 5432

# 4. Your applications connect normally — no changes needed
psql -h localhost -p 5432 -U youruser -d yourdb

Because pgrust is disk-compatible, your existing data, indexes, and configuration work without modification. The wire protocol is identical, so your application code doesn't need to change.

What's Coming Next

The pgrust team has outlined several areas they're actively exploring:

  • Multithreaded internals: Better parallelism within queries
  • Built-in connection pooling: Eliminate the need for PgBouncer
  • Improved JSON support: Faster JSON-heavy workloads
  • Fast forking and branching: Quick database cloning for testing
  • No-vacuum storage designs: Eliminate VACUUM overhead
  • Runtime guardrails: Protection against bad queries and AI-generated SQL

That last point is particularly timely. As AI coding assistants generate more SQL, having runtime protection against poorly optimized queries becomes increasingly important.

Key Benefits

  • Memory safety: Rust's ownership model eliminates entire classes of bugs
  • Performance: 50-300x faster depending on workload type
  • Compatibility: Drop-in replacement for PostgreSQL 18.3
  • Modern architecture: Thread-per-connection instead of process-per-connection
  • Future-proof: Easier to extend and modify than the C codebase
  • Open source: AGPL-3.0 license with active community

Is pgrust Production-Ready?

The honest answer: not yet. The project explicitly states "pgrust is not production-ready yet. It is not performance optimized yet." However, the 100% regression test compatibility and disk compatibility suggest it's moving in that direction rapidly.

Existing Postgres extensions and procedural languages (PL/Python, PL/Perl, PL/Tcl) are not generally compatible yet, though some contrib modules have been ported. For organizations that rely heavily on extensions, this is a limitation to watch.

Frequently Asked Questions

What is pgrust?

pgrust is an open-source project that rewrites PostgreSQL in Rust while maintaining full compatibility with PostgreSQL 18.3. It passes all regression tests and offers significant performance improvements.

Is pgrust faster than PostgreSQL?

Yes, significantly. The latest version is 50% faster on transaction workloads and 300x faster on analytical workloads. It's within 2x of ClickHouse's performance on analytical benchmarks.

Can I use pgrust with my existing Postgres data?

Yes. pgrust is disk-compatible with PostgreSQL 18.3 and can boot from an existing Postgres data directory without requiring data migration.

Does pgrust support Postgres extensions?

Not all of them yet. Some contrib modules are ported, but third-party extensions and procedural languages (PL/Python, PL/Perl, PL/Tcl) are not generally compatible in the current version.

Is pgrust production-ready?

Not yet. The project is still in active development and the team explicitly states it's not production-ready. However, the 100% regression test compatibility suggests it's progressing quickly.

What license is pgrust?

pgrust is licensed under AGPL-3.0, which means it's open source but has copyleft requirements for derivative works.

How was pgrust built so quickly?

The team used AI-assisted programming tools to accelerate development. This allowed them to maintain consistency across the large codebase and ensure compatibility with PostgreSQL's behavior.

ProgrammingTutorialCoddyKit

Enjoyed this article?

Explore more tutorials and insights to level up your coding skills.

Browse All Articles →