用 Rust 重写的 Postgres,现已通过 100% 的 Postgres 回归测试
Postgres rewritten in Rust, now passing 100% of the Postgres regression tests

原始链接: https://github.com/malisper/pgrust

**pgrust** 是一个实验性的 PostgreSQL Rust 重写项目,旨在保持与 Postgres 18.3 的完全兼容。它在磁盘格式上兼容,允许直接从现有的 Postgres 数据目录启动,目前已通过超过 46,000 项回归测试。 该项目的主要目标是使数据库内部结构更加模块化,并更易于修改。通过利用 Rust 的安全性以及人工智能辅助开发,团队旨在实现以往在 C 语言代码库中难以实现的功能创新,例如原生多线程、内置连接池、无 Vacuum(垃圾回收)存储架构,以及对高频 JSON 工作负载的增强支持。 虽然 pgrust 尚未达到生产就绪状态,且缺乏对现有扩展(如 PL/Python 或 PL/Perl)的广泛支持,但它为高级数据库实验提供了一个现代化的基础。用户可以通过 WebAssembly 演示、Docker 镜像或在本地构建源码来探索该项目。项目采用 AGPL-3.0 许可证,欢迎社区反馈和贡献,共同塑造 Postgres 生态系统的未来。

```Hacker News最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交登录Postgres 已用 Rust 重写,现已通过 100% 的 Postgres 回归测试 (github.com/malisper)15 分,SweetSoftPillow 发布于 1 小时前 | 隐藏 | 过往 | 收藏 | 2 条评论帮助 gingersnap 2 分钟前 | 下一条 [–] 我开始看到很多此类重写项目,它们依赖测试来证明其有效性。但让 Postgres 和 SQLite 这类软件如此可靠的,并非主要是测试,而是真实生产环境中的历练。可靠性源于在生产环境中运行多年所积累的经验。回复juliangmp 3 分钟前 | 上一条 [–] 我觉得我们需要极力区分“重写”和“AI 重写”。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:```
相关文章

原文

A Postgres rewrite in Rust.

Postgres 18.3 Regression queries: 46k+ License: AGPL-3.0

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 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.

  • multithreaded Postgres internals
  • built-in connection pooling
  • better JSON-heavy workload support
  • fast forking and branching workflows
  • storage experiments, including no-vacuum designs
  • runtime guardrails for bad queries and AI-generated SQL
  • fewer sudden bad plan switches

Try the WebAssembly demo at https://pgrust.com.

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.

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"

Run the Postgres regression tests against pgrust:

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.

Verified launch result: pgrust matched Postgres's expected output across more than 46,000 regression queries.

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.

Background:

Please open an issue if something breaks, if setup is confusing, or if there is a Postgres improvement you want to see first.

pgrust is licensed under AGPL-3.0. See LICENSE.

联系我们 contact @ memedata.com