← 返回日报
精读 预计 1 分钟

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

摘要

pgrust 是 Postgres 的 Rust 重写版本,目标兼容 Postgres 18.3,匹配超过 46,000 个回归查询的预期输出;磁盘兼容现有 Postgres 18.3 数据目录,可直接启动;未达生产就绪状态,未优化性能,部分扩展(如 PL/Python、PL/Perl、PL/Tcl)和 contrib 模块尚未兼容;路线图包括多线程内部、连接池、JSON 优化、快速 fork、存储实验、运行时保护等;提供 WebAssembly 演示、Docker 镜像(psql 客户端)、macOS/Debian/Ubuntu 源码构建命令、数据目录创建与运行脚本;回归测试 runner 使用 pgrust 的 --initdb 和自带 Postgres 18.3 测试文件,已验证匹配预期输出;历史记录含原版存档链接。

荐读理由

根据完整正文,照 Docker Compose 或 Build From Source 配置 + psql 命令即可一次拉起兼容 Postgres 18.3 的 pgrust 实例,盘兼容并过 46000+ 测试,移植扩展架构可直接照搬到你的 AI 工程项目

原文

pgrust

A Postgres rewrite in Rust.

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

Browser demo | Discord | Mailing list | Issues

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.

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.

Roadmap

  • 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 It

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.

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

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.

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.

Contact

License

pgrust is licensed under AGPL-3.0. See LICENSE.

Hacker News · 176 赞 · 226 评 讨论 → 阅读原文 →

这条对你有帮助吗?