A PostgreSQL extension for high-performance real-time analytics on time-series and event data.
pgcentralfoundation/pgrx
A Rust framework for building PostgreSQL extensions, with tooling to set up, run, test and package them across Postgres versions.
- Stars
- 4,823
- Forks
- 342
- Open issues
- 343
- Last commit
- 8 days ago
What is it?
pgrx is a framework for writing PostgreSQL extensions in Rust. It maps Rust functions, types and enums to Postgres objects, and generates the SQL schema for them automatically, so an extension can be written entirely in Rust while still exposing functions and custom types to SQL.
The cargo-pgrx subcommand manages the development workflow: it creates new extension projects, downloads and builds Postgres versions, launches an interactive psql session with the extension loaded, runs tests across multiple Postgres versions, and produces installation packages. The project supports Postgres 13 through 18, plus a 19 beta, from a single codebase.
The framework focuses on safety: Rust panics are turned into Postgres errors that abort the transaction rather than the process, and memory management follows Rust's drop semantics. It also provides access to SPI, memory contexts, hooks and the raw pg_sys bindings for lower-level work.
Key features
- 01Scaffold, run, test and package extensions with the cargo-pgrx command
- 02Support for Postgres 13 through 18 from one codebase
- 03Generate SQL schemas automatically from Rust annotations like #[pg_extern]
- 04Define custom Postgres types and enums with derive macros
- 05Panics become Postgres errors that abort only the transaction
- 06Access SPI, memory contexts, hooks and raw pg_sys internals
Use cases
- Writing a custom Postgres data type or index-related function in Rust
- Building a PostgreSQL extension that wraps a Rust library for use in SQL queries
- Testing an extension against several Postgres major versions in CI
Quick start
- 1
Install the cargo-pgrx subcommand
cargo install --locked cargo-pgrx - 2
Initialize the PGRX home directory (downloads and compiles supported PostgreSQL versions)
cargo pgrx init - 3
Create a new extension project
cargo pgrx new my_extension - 4
Run the example extension in psql
cargo pgrx run
Things to know
- The license is not clearly specified in the project metadata, so check the repository's license before use.
- The init step downloads and compiles several PostgreSQL versions, which takes time and disk space.
- Cross-compiling is only demonstrated under nix and needs manual setup elsewhere.
In collections
Topics
FAQ
- What is pgrx?
- A Rust framework for building PostgreSQL extensions, with tooling to set up, run, test and package them across Postgres versions. pgrx is a framework for writing PostgreSQL extensions in Rust. It maps Rust functions, types and enums to Postgres objects, and generates the SQL schema for them automatically, so an extension can be written entirely in Rust while still exposing functions and custom types to SQL.
- Is pgrx free to use? What license does it have?
- pgrx is open source under the Other license. Check the license terms before using it in commercial products.
- Is pgrx still maintained?
- Actively maintained. The last commit to pgrx was on Oct 30, 2026.
- What can I use pgrx for?
- Writing a custom Postgres data type or index-related function in Rust Building a PostgreSQL extension that wraps a Rust library for use in SQL queries Testing an extension against several Postgres major versions in CI
- How do I install pgrx?
- Install the cargo-pgrx subcommand: cargo install --locked cargo-pgrx Initialize the PGRX home directory (downloads and compiles supported PostgreSQL versions): cargo pgrx init Create a new extension project: cargo pgrx new my_extension Run the example extension in psql: cargo pgrx run
- Where can I get pgrx?
- The source code and installation instructions are on GitHub: https://github.com/pgcentralfoundation/pgrx
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Non-blocking PostgreSQL client for Node.js, with a pure JavaScript driver and optional native libpq bindings.
A Postgres command-line client with auto-completion and syntax highlighting, an alternative to the stock psql shell.
A curated, community-maintained list of PostgreSQL software, libraries, tools, extensions and learning resources.
An in-process SQL database written in Rust, compatible with SQLite's dialect, file format and C API, with an experimental Postgres frontend.
A transparent MySQL and Postgres cache that sits in front of your database and keeps cached query results in sync via the replication stream.