# pgrust — PostgreSQL Rewritten in Rust > A from-scratch reimplementation of PostgreSQL in Rust that passes the full PostgreSQL regression test suite, exploring memory-safe systems programming for database engines while maintaining wire-protocol compatibility. ## Install Save in your project root: # pgrust — PostgreSQL Rewritten in Rust ## Quick Use ```bash git clone https://github.com/malisper/pgrust.git cd pgrust cargo build --release ./target/release/pgrust --data-dir /tmp/pgrust-data # Connect with any PostgreSQL client: psql -h 127.0.0.1 -p 5432 ``` ## Introduction pgrust is an experimental reimplementation of the PostgreSQL database in Rust. It passes 100% of the standard PostgreSQL regression tests, demonstrating that a memory-safe language can faithfully reproduce the behavior of one of the most complex open-source C codebases. The project serves as both a research artifact and a foundation for exploring Rust-native database innovations. ## What pgrust Does - Implements the PostgreSQL wire protocol so standard clients like psql connect without modification - Passes the full PostgreSQL regression test suite covering SQL parsing, planning, and execution - Provides a storage engine compatible with PostgreSQL's on-disk format - Supports core SQL features including joins, subqueries, CTEs, window functions, and transactions - Eliminates entire classes of memory safety bugs present in the original C implementation ## Architecture Overview The codebase mirrors PostgreSQL's architecture — a postmaster process that forks (spawns) per-connection backends, each running a parser, planner, and executor. The parser produces an AST from SQL text, the planner generates query plans using cost-based optimization, and the executor walks the plan tree to produce results. The key difference is that all of this is written in safe Rust with minimal unsafe blocks, relying on Rust's ownership model for memory management instead of PostgreSQL's custom memory contexts. ## Self-Hosting & Configuration - Build from source with a recent Rust toolchain (1.75+) using cargo build --release - Initialize a data directory with the built-in initdb equivalent - Start the server pointing to the data directory and configure the listen port - Connect using any PostgreSQL client driver (libpq, JDBC, psycopg2) - Configuration parameters mirror PostgreSQL's postgresql.conf where implemented ## Key Features - Full PostgreSQL regression test compatibility proving behavioral fidelity - Memory safety through Rust's ownership and borrowing system - Wire-protocol compatibility with existing PostgreSQL client libraries - Single-binary deployment without external C library dependencies - AI-assisted development approach documented in the repository ## Comparison with Similar Tools - **PostgreSQL** — the original C implementation; pgrust is a Rust reimplementation aiming for compatibility - **CockroachDB** — distributed SQL in Go; pgrust is a single-node PostgreSQL clone - **Neon** — serverless Postgres with storage separation; pgrust is a complete engine rewrite - **DuckDB** — analytical database; pgrust targets OLTP workloads like PostgreSQL - **TiDB** — MySQL-compatible distributed DB; pgrust is PostgreSQL-compatible and single-node ## FAQ **Q: Is pgrust production-ready?** A: Not yet. It is an experimental project that demonstrates feasibility. Many PostgreSQL extensions and edge-case behaviors are still being implemented. **Q: Does it support PostgreSQL extensions?** A: Not currently. The extension loading mechanism from PostgreSQL has not been ported, so extensions like PostGIS or pg_vector are not available. **Q: How does performance compare to PostgreSQL?** A: Performance benchmarking is ongoing. The goal is compatibility first, with performance optimization as a secondary objective. **Q: Can I migrate an existing PostgreSQL database to pgrust?** A: In theory, the on-disk format compatibility allows this, but it is not recommended for production data given the project's experimental status. ## Sources - https://github.com/malisper/pgrust --- Source: https://tokrepo.com/en/workflows/asset-224d0122 Author: AI Open Source