Postgres rewritten in Rust, now passing 100% of the Postgres regression tests

Postgres rewritten in Rust, now passing 100% of the Postgres regression tests

使用 Rust 重写的 Postgres,现已通过 100% 的 Postgres 回归测试

pgrust A Postgres rewrite in Rust. Browser demo | Discord | Mailing list | Issues pgrust 是一个使用 Rust 重写的 Postgres。浏览器演示 | Discord | 邮件列表 | 问题反馈

pgrust targets compatibility with Postgres 18.3 and matches Postgres’s expected output across more than 46,000 regression queries. pgrust is disk compatible with Postgres and can boot from an existing Postgres 18.3 data directory. The goal is to make Postgres easier to change from the inside: 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. pgrust 的目标是兼容 Postgres 18.3,并在超过 46,000 个回归查询中与 Postgres 的预期输出完全一致。pgrust 在磁盘格式上与 Postgres 兼容,可以直接从现有的 Postgres 18.3 数据目录启动。其目标是让 Postgres 的内部修改变得更容易:保持与 Postgres 一致的行为,以真实的 Postgres 测试作为基准(Oracle),并利用 Rust 和 AI 辅助编程来探索更深层次的服务器架构变更。

Status

状态

pgrust is not production-ready yet. It is not performance optimized yet. Existing Postgres extensions and procedural language extensions such as PL/Python, PL/Perl, and PL/Tcl are not generally compatible yet. Some bundled contrib modules are already ported, and more compatibility may be possible over time. pgrust 尚未达到生产就绪状态,也尚未进行性能优化。现有的 Postgres 扩展以及 PL/Python、PL/Perl 和 PL/Tcl 等过程语言扩展目前尚不完全兼容。部分捆绑的 contrib 模块已被移植,未来可能会实现更多兼容性。

Roadmap

路线图

  • multithreaded Postgres internals
  • 内置多线程 Postgres 内部架构
  • built-in connection pooling
  • 内置连接池
  • better JSON-heavy workload support
  • 更好的 JSON 密集型工作负载支持
  • fast forking and branching workflows
  • 快速分叉(forking)和分支工作流
  • storage experiments, including no-vacuum designs
  • 存储实验,包括无 Vacuum 设计
  • runtime guardrails for bad queries and AI-generated SQL
  • 针对不良查询和 AI 生成 SQL 的运行时防护
  • fewer sudden bad plan switches
  • 减少突发的错误执行计划切换

Try It

尝试使用

Try the WebAssembly demo at https://pgrust.com. 请访问 https://pgrust.com 体验 WebAssembly 演示。

Docker:

docker run -d --name pgrust -e POSTGRES_PASSWORD=secret malisper/pgrust:v0.1 && until docker exec -e PGPASSWORD=secret pgrust psql -h 127.0.0.1 -U postgres -c '\q' >/dev/null 2>&1; do sleep 1; done && docker exec -it -e PGPASSWORD=secret pgrust psql -h 127.0.0.1 -U postgres; docker rm -f pgrust

This uses the psql client inside the Docker image. malisper/pgrust:latest currently points at the same release, but v0.1 is the pinned launch image. 此命令使用 Docker 镜像内的 psql 客户端。malisper/pgrust:latest 目前指向同一版本,但 v0.1 是固定的发布镜像。

Build From Source

从源码构建

macOS:

brew install icu4c openssl@3 libpq
export LIBRARY_PATH="$(brew --prefix openssl@3)/lib:${LIBRARY_PATH:-}"
export PKG_CONFIG_PATH="$(brew --prefix openssl@3)/lib/pkgconfig:$(brew --prefix icu4c)/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export PATH="$(brew --prefix libpq)/bin:$PATH"

Debian/Ubuntu:

sudo apt-get update
sudo apt-get install -y build-essential pkg-config libicu-dev libssl-dev libldap2-dev libpam0g-dev postgresql-client-18

Build:

PGRUST_PGSHAREDIR="$PWD/vendor/postgres-18.3/share" \
cargo build --release --locked --bin postgres

Create a data directory:

target/release/postgres --initdb \
-D /tmp/pgrust-data \
-L "$PWD/vendor/postgres-18.3/share" \
--no-locale \
--encoding UTF8 \
-U postgres

Run pgrust:

ulimit -s 65520
RUST_MIN_STACK=33554432 target/release/postgres \
-D /tmp/pgrust-data \
-F \
-c listen_addresses= \
-k /tmp \
-p 5432 \
-c io_method=sync \
-c max_stack_depth=60000

Connect:

psql -h /tmp -p 5432 -U postgres -d postgres \
-c "select version(), 1 + 1 as two"

Regression Tests

回归测试

Run the Postgres regression tests against pgrust: 针对 pgrust 运行 Postgres 回归测试:

PGRUST_BIN="$PWD/target/release/postgres" \
scripts/run-regression

The runner uses pgrust’s own —initdb plus the vendored Postgres 18.3 test files in this repository. It needs a Postgres 18 psql client on PATH; if psql is somewhere else, set PGRUST_PSQL=/path/to/psql. 运行器使用 pgrust 自带的 —initdb 以及仓库中内置的 Postgres 18.3 测试文件。它需要 PATH 中存在 Postgres 18 的 psql 客户端;如果 psql 位于其他位置,请设置 PGRUST_PSQL=/path/to/psql。

Verified launch result: pgrust matched Postgres’s expected output across more than 46,000 regression queries. 验证发布结果:pgrust 在超过 46,000 个回归查询中与 Postgres 的预期输出完全匹配。

History

历史

This repository now contains the newer pgrust implementation that reached the regression-test milestone. The older public implementation is archived on archive/pre-fabled-2026-06-23. 本仓库现已包含达到回归测试里程碑的较新 pgrust 实现。旧的公开实现已归档至 archive/pre-fabled-2026-06-23。

Background: 背景资料:

Feedback

反馈

Please open an issue if something breaks, if setup is confusing, or if there is a Postgres improvement you want to see first. 如果遇到问题、设置过程令人困惑,或者有您希望优先看到的 Postgres 改进,请提交 Issue。

Contact 联系方式

License

许可证

pgrust is licensed under AGPL-3.0. See LICENSE. pgrust 采用 AGPL-3.0 许可证。详见 LICENSE 文件。