pgrust README

README проекта с github.com/malisper/pgrust. Одним файлом markdown: README.md.

pgrust

A Postgres-compatible database, rewritten in Rust, built for fast analytics on your Postgres data.

Postgres 18.6 Version: v0.4-beta License: AGPL-3.0

Try pgrust in your browser →   |   Discord   |   Updates   |   Issues

New: Video of Michael's talk at PlanetScale on pgrust — and the slides.

How AI Changes the Economics of JIT Compilers

v0.4-beta is out: the release post and what's new.

pgrust is a drop-in replacement for Postgres built for fast analytics. It is wire compatible and SQL dialect compatible with Postgres 18, so your existing drivers, ORMs, psql and tools work unchanged. It is Postgres rebuilt the way it would be built in 2026.

Every line is Rust, written to match the behavior of the C implementation. Rust makes it easy to re-architect several core Postgres pieces. pgrust has:

and many other really awesome pieces. The scheduler and the memory manager go after two of the four horsemen behind thousands of Postgres outages.

Quickstart

In your browser: https://pgrust.com, a full pgrust server compiled to WebAssembly, no install.

On your machine: download a release tarball from https://pgrust.com/downloads/v0.4-beta/. Each one is self-contained: it carries pgrust's own bin/postgres, bin/initdb and bin/psql plus the share files they read, so you do not need a PostgreSQL install. The Linux binaries need glibc 2.34 or newer (Debian 12, Ubuntu 22.04, RHEL/Rocky 9 and later); the macOS binaries need macOS 11 or newer.

Tarball Runs on
pgrust-0.4-beta-linux-x86_64.tar.gz any x86-64 CPU
pgrust-0.4-beta-linux-aarch64.tar.gz any 64-bit Arm CPU
pgrust-0.4-beta-linux-x86_64-znver3.tar.gz tuned for AMD Zen 3 and newer
pgrust-0.4-beta-linux-aarch64-neoverse-v2.tar.gz tuned for Neoverse-V2 (AWS Graviton4, NVIDIA Grace)
pgrust-0.4-beta-macos-arm64.tar.gz macOS on Apple Silicon
pgrust-0.4-beta-macos-x86_64.tar.gz macOS on Intel
pgrust-0.4-beta-macos-universal.tar.gz macOS, either (both architectures in one binary)

The Linux builds are profile-guided optimized. The tuned builds use instructions only those CPUs (and newer ones) have; when in doubt, take the generic build. Every tarball has a .sha256 file next to it, and MANIFEST.txt lists them all.

Linux

# Pick your build: linux-x86_64, linux-aarch64, linux-x86_64-znver3 or
# linux-aarch64-neoverse-v2 (see the table above).
PLATFORM=linux-x86_64

# Download pgrust, verify the checksum and unpack it.
curl -LO "https://pgrust.com/downloads/v0.4-beta/pgrust-0.4-beta-$PLATFORM.tar.gz"
curl -LO "https://pgrust.com/downloads/v0.4-beta/pgrust-0.4-beta-$PLATFORM.tar.gz.sha256"
sha256sum -c "pgrust-0.4-beta-$PLATFORM.tar.gz.sha256"
tar xzf "pgrust-0.4-beta-$PLATFORM.tar.gz"
cd pgrust-0.4-beta-linux-*/

# Create a data directory with pgrust's initdb.
bin/initdb -D /tmp/pgrust-data --no-locale --encoding UTF8 -U postgres

# Start the server. It runs in the foreground and logs to this terminal.
ulimit -s 65520
RUST_MIN_STACK=33554432 bin/postgres \
  -D /tmp/pgrust-data \
  -k /tmp -p 5432 \
  -c listen_addresses= \
  -c io_method=sync \
  -c max_stack_depth=60000

Leave the server running and connect from a second terminal, in the same directory:

bin/psql -h /tmp -p 5432 -U postgres -c "select version()"

You should see PostgreSQL 18.6 (pgrust 0.4-beta, build <commit>) on ..., where <commit> is the short commit the binary was built from. bin/postgres --version prints pgrust 0.4-beta (PostgreSQL 18.6 compatible).

Docker

The prebuilt image on Docker Hub, malisper/pgrust, is a drop-in replacement for the official postgres image: same env vars (POSTGRES_PASSWORD, POSTGRES_USER, POSTGRES_DB, PGDATA, ...), same /docker-entrypoint-initdb.d init scripts, same data volume at /var/lib/postgresql/data. It carries the same postgres and initdb binaries as the Linux release tarballs above, and initializes the cluster with pgrust's own initdb; the only C PostgreSQL component in the image is psql for the init scripts. malisper/pgrust:v0.4-beta is multi-arch (amd64 + arm64); v0.4-beta-amd64 and v0.4-beta-arm64 pin one architecture.

docker run -d --name pgrust -e POSTGRES_PASSWORD=secret -p 5432:5432 malisper/pgrust:v0.4-beta

Then connect, with your own psql or the one in the image:

psql -h localhost -p 5432 -U postgres
docker exec -it pgrust psql -U postgres

malisper/pgrust:latest still points at v0.3; use the v0.4-beta tag to get this release. A data volume written by v0.3 holding columnar tables needs the dump and restore described under Stopping, restarting, cleaning up.

macOS

# Pick your build: macos-arm64 (Apple Silicon), macos-x86_64 (Intel) or
# macos-universal (both).
PLATFORM=macos-arm64

# Download pgrust, verify the checksum and unpack it. Download with curl: curl
# does not set the quarantine flag a browser download gets, so Gatekeeper stays
# out of the way (see the note below).
curl -LO "https://pgrust.com/downloads/v0.4-beta/pgrust-0.4-beta-$PLATFORM.tar.gz"
curl -LO "https://pgrust.com/downloads/v0.4-beta/pgrust-0.4-beta-$PLATFORM.tar.gz.sha256"
shasum -a 256 -c "pgrust-0.4-beta-$PLATFORM.tar.gz.sha256"
tar xzf "pgrust-0.4-beta-$PLATFORM.tar.gz"
cd "pgrust-0.4-beta-$PLATFORM"

# Create a data directory with pgrust's initdb.
bin/initdb -D /tmp/pgrust-data --no-locale --encoding UTF8 -U postgres

# Start the server. It runs in the foreground and logs to this terminal.
ulimit -s 65520
RUST_MIN_STACK=33554432 bin/postgres \
  -D /tmp/pgrust-data \
  -k /tmp -p 5432 \
  -c listen_addresses= \
  -c io_method=sync \
  -c max_stack_depth=60000

Leave the server running and connect from a second terminal, in the same directory:

bin/psql -h /tmp -p 5432 -U postgres -c "select version()"

A note on Gatekeeper: the macOS binaries are signed ad hoc, not notarized by Apple. Downloaded with curl as above, they are never quarantined and none of this comes up. If you download with a browser instead, macOS refuses to run them with "Apple could not verify ... is free of malware". Clear the flag with xattr -dr com.apple.quarantine pgrust-0.4-beta-$PLATFORM, or approve each binary under System Settings > Privacy & Security > "Open Anyway".

Columnar tables

Columnar storage (pgrcolumnar) is a table access method. Register it once in each database, then create tables with USING pgrcolumnar:

CREATE ACCESS METHOD pgrcolumnar TYPE TABLE HANDLER heap_tableam_handler;

CREATE TABLE events (id bigint, kind text, val double precision, at timestamp)
  USING pgrcolumnar;

Stopping, restarting, cleaning up

When to use pgrust

Status

We're working with a few early design partners and are targeting production readiness in Q1 2027. Testing and reliability are our top priority; see Testing for how we verify pgrust against Postgres. We run pgrust ourselves internally today.

Extensions

pgrust ships the most-used Postgres extensions built in: pgvector, pg_cron, pg_stat_statements, pg_trgm, hstore, pgcrypto, postgres_fdw and most of contrib. Install them with CREATE EXTENSION as usual.

pgrust doesn't load C extension binaries compiled for Postgres, but porting an existing extension to pgrust is straightforward, and we add new ones regularly. If you need an extension that isn't listed, open an issue and we'll prioritize it. PL/Python, PL/Perl and PL/Tcl are not supported yet.

Performance

Measured on c8g.4xlarge (AWS Graviton4), pgrust with pgrcolumnar, its builtin columnar layout, runs ClickBench's analytical queries up to 1,600x faster than PostgreSQL (per query, cold runs, against PostgreSQL's published results on the same instance type).

For a code-level walkthrough of one part of that speedup, read how batching, operator fusion, and SIMD speed up the query engine.

Writing

Testing

The most common question we get about pgrust is: how can anyone trust it? Passing a test suite doesn't mean our code is correct. Getting to the point where people can trust pgrust is our number one priority today.

To achieve that goal, we're taking several different approaches:

  1. Of the 3,400 user facing Postgres functions, we've formally verified that 1,397 have identical behavior in pgrust with Kani; 466 more are tested against Postgres. The ledger is proofs/USER_FACING_FUNCTIONS.tsv.
  2. We're engaging with Antithesis to do simulation testing of pgrust to battle test pgrust.
  3. We're doing aggressive differential fuzz testing to ensure pgrust's behavior is identical to Postgres's.

Unsafe Code

pgrust uses unsafe code, but only for the specific things that need it. Postgres represents every internal value as a Datum, an untyped 8 byte value, and Rust has no safe equivalent, so the code that packs and unpacks internal values is unsafe. The same goes for the places where pgrust must match Postgres' memory layouts byte for byte.

If there are particular unsafes that are not necessary and removing them would not have an impact on performance, let us know, as we would love to remove more unsafes.

Building from source

You need the Rust toolchain (any rustup install works; rust-toolchain.toml pins the build to Rust 1.96.0 and rustup fetches it automatically) and the RE2 regex library:

cargo build --release --locked -p main_main -p initdb

select version() names the build: a build in a git checkout prints its short commit (PostgreSQL 18.6 (pgrust 0.4-beta, build 1a2b3c4) on ...); set PGRUST_BUILD_ID at build time to choose the id, or build outside git for none. postgres --version prints pgrust 0.4-beta (PostgreSQL 18.6 compatible); postgres -V prints postgres (PostgreSQL) 18.6, the line PostgreSQL's own pg_ctl, initdb and pg_upgrade check.

The server binary lands at target/release/postgres, pgrust's initdb beside it, and the share tree it needs (postgres.bki, the setup SQL, timezone, timezonesets, tsearch data, extension files) is staged at target/release/share/. No C PostgreSQL is involved in creating or running a cluster:

target/release/initdb -D /tmp/pgrust-data --no-locale --encoding UTF8 -U postgres
ulimit -s 65520
RUST_MIN_STACK=33554432 target/release/postgres -D /tmp/pgrust-data \
  -k /tmp -p 5432 -c listen_addresses= -c io_method=sync -c max_stack_depth=60000

The time zone database is PostgreSQL 18.6's own compiled tzdata, read from share/timezone beside the binary (never the host zoneinfo, like C built without --with-system-tzdata). To use the system zoneinfo instead, build with PGRUST_SYSTEM_TZDATA=/usr/share/zoneinfo (C's --with-system-tzdata); PGRUST_TZDIR and PGRUST_PGSHAREDIR remain runtime overrides, not requirements. A data directory made by stock PostgreSQL 18 initdb still works too (same on-disk format). Release builds refuse to compile without RE2 on purpose: a build with only the fallback regex engine is drastically slower on regex heavy workloads. The binaries we publish additionally use --profile dist, which turns on fat LTO; it produces a faster binary but takes much longer to compile.

What's new in v0.4-beta

v0.4-beta is a beta: it shows what is coming in v0.4 while we finish stabilizing the rest.

Developing in the open

Up to v0.3 we developed pgrust privately and published it in large monthly releases. Starting with v0.4-beta, development happens in this repository: features, optimizations and bug fixes are pushed here as soon as they are ready, instead of being held back for the next release.

Implementation

Executor

Parallelism

Storage

Other

Roadmap

Next we're working on testing and battle testing pgrust and making it so people can trust pgrust with their data.

Beyond that we want to add:

Contributing

We are not actively accepting pull requests right now. If you want to help out with the project, reach out on Discord.

Please do still open an issue if something breaks, if setup is confusing, or if there is a Postgres behavior you want matched.

License

pgrust is licensed under AGPL-3.0. Portions derived from PostgreSQL remain under the PostgreSQL License. The JIT's code generator (crates/tpde/) is ported from TPDE (Apache-2.0 WITH LLVM-exception) and Fadec and Disarm (BSD-3-Clause). See NOTICE.

Acknowledgements: the research and other systems whose ideas pgrust uses are credited in ACKNOWLEDGEMENTS.md.

Contact

pgrust (malisper/pgrust)

Ищем в базе…

Что это такое?pgrust — это реализация PostgreSQL на Rust, написанная с нуля. Она совместима с Postgres по сетевому протоколу и диалекту SQL и при этом работает быстрее и Postgres, и ClickHouse.
Это полноценная замена моей базы Postgres или на неё придётся переходить с миграцией?Она совместима с настоящим Postgres по сетевому протоколу и диалекту SQL и проходит собственный набор регрессионных тестов Postgres. Опубликованный образ Docker можно использовать напрямую вместо официального образа postgres: он работает с теми же переменными окружения, скриптами инициализации и путём к тому данных.
Как попробовать pgrust?Скачайте бинарный файл для Linux (Debian/Ubuntu) и запустите сервер, затем подключитесь из второго терминала через psql; ваши данные сохраняются в каталоге данных и остаются после перезапусков. Также доступен готовый мультиархитектурный образ Docker, который можно использовать вместо официального образа postgres без изменений.
Безопасно ли использовать pgrust для реальных данных?Нет. В проекте прямо сказано, что он не готов к промышленной эксплуатации, и предупреждается не хранить в нём важные данные. Расширения PostgreSQL пока тоже не работают, так как стабильного интерфейса расширений (ABI) нет, а PL/Python, PL/Perl и PL/Tcl не перенесены.
Нужно ли pgrust специальное оборудование ARM, чтобы работать быстро?pgrust работает и на других платформах, но его JIT-компилятор и настройки производительности рассчитаны именно на ARM-инстансы AWS Graviton4; на других процессорах он будет работать, но не покажет результатов, как в опубликованных бенчмарках.
Насколько pgrust быстрее Postgres и ClickHouse?В ClickBench он оказался на 18,5% быстрее ClickHouse и в сотни раз быстрее Postgres при использовании встроенного колоночного формата pgrcolumnar. В режиме только чтения sysbench-oltp на объёме 300 ГБ он показал пропускную способность на 30% выше, чем PostgreSQL 18.3.
Откуда команда знает, что поведение pgrust действительно совпадает с Postgres?Они формально проверили совпадение поведения для 1000 из примерно 3000 пользовательских функций Postgres с помощью Kani (найдено 12 расхождений, 4 из которых оказались ошибками в самом Postgres), а также провели дифференциальное фаззинг-тестирование и симуляционное тестирование с помощью Antithesis.
Что изменилось в релизе v0.2?Появился новый векторизованный исполнитель запросов с push-моделью и JIT-компилятором на основе copy-and-patch, поточная модель параллелизма с планировщиком запросов на основе work-stealing, колоночный формат хранения pgrcolumnar и встроенный OOM killer, который завершает один рабочий процесс вместо того, чтобы позволить ОС убить весь сервер.
Какие есть похожие проекты?kividb, pgx, walshadow, bbtree, timescaledb, HikariCP, neon, pgbot
Автор
malisper
Размер
666.1 MB
Звёзды
6.2K
Возраст
7 мес
Коммиты · 90 дней