pgrust: A Rust Rewrite of Postgres Using LLMs
pgrust: A Rust Rewrite of Postgres Using LLMs
Overview of pgrust
pgrust is an experimental project that rewrites PostgreSQL in Rust, leveraging Large Language Models (LLMs) to accelerate the development process. The project aims to modernize the database architecture while maintaining compatibility with the original PostgreSQL specification, currently passing 100% of the Postgres regression tests.
Key Architectural Changes and Performance
The author, @malisper, has implemented several fundamental changes to the database architecture to improve performance over the original C-based implementation:
- Threading Model: pgrust replaces the traditional process-per-connection model used by PostgreSQL with a thread-per-connection model.
- Transaction Workloads: The project reports a 50% performance increase over PostgreSQL for transaction-heavy workloads.
- Analytical Workloads: pgrust claims to be approximately 300x faster than PostgreSQL on analytical workloads, though it remains roughly 2x slower than Clickhouse on the Clickbench benchmark.
Technical Critique and Safety Concerns
Despite the performance claims, the project has faced significant scrutiny from the technical community regarding the safety and quality of the generated code.
Use of Unsafe Rust
A primary concern raised by reviewers is the extensive use of unsafe blocks. Analysis of the codebase revealed 2,664 instances of unsafe { and 1,835 unsafe fn, leading some critics to argue that the project is an "AI generated transpilation with extensive use of raw pointers" rather than a redesign that leverages Rust's memory safety guarantees.
Reliability vs. Test Coverage
Community members have highlighted the distinction between passing a test suite and being production-ready. Critics argue that the reliability of PostgreSQL stems from decades of "real world production scars" rather than just regression tests. Furthermore, it was noted that the standard Postgres regression tests do not specifically validate the new threaded architecture, which is a critical point of potential failure.
The Role of LLMs in Software Rewrites
The development of pgrust has sparked a broader debate about the viability of using LLMs for large-scale system rewrites.
The "AI Rewrite" Paradigm
Observers have noted a shift in how software is developed when LLMs are involved:
- Reviewability: Traditional code review is becoming impractical. One reviewer noted that reviewing 7,101 commits generated in less than a month is unfeasible for humans.
- Overfitting to Tests: There is a risk that LLMs may "overfit" the solution to the test suite, treating the tests as a literal specification and monkey-patching the code to pass specific data points rather than implementing the intended general behavior.
- Maintenance: Some argue that projects generated by AI are harder to maintain because the authors may not have acquired the discipline of organic project growth, and future contributors may be forced to use AI tokens just to understand or modify the code.
Potential for Modernization
Conversely, some argue that LLMs make it easier to migrate legacy infrastructure to modern languages and frameworks that were previously too difficult to port manually. This perspective suggests that the future of software verification will shift away from human code review and toward more robust regression test suites and "evals."
Legal and Licensing Considerations
There is an ongoing discussion regarding the licensing of pgrust. While the original PostgreSQL project uses the PostgreSQL license, pgrust is licensed under the AGPL-3.0. This has raised questions about whether a rewrite based on the original source code should be bound by the original license.