Configs2026年7月24日·1 分钟阅读

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.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
pgrust
先审查命令
npx -y tokrepo@latest install 224d0122-8738-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产