Skip to content
Back to search

pgx

Build Postgres Extensions with Rust!

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/pgcentralfoundation/pgrx with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/pgcentralfoundation/pgrx'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/tcdi--pgx/badge.svg)](/listings/tcdi--pgx)

HTML

<a href="/listings/tcdi--pgx"><img src="/api/listings/tcdi--pgx/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 461 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. ![Logo](art/pgrx-logo-color-transparent-475x518.png)
  2. # `pgrx`
  3. > Build Postgres Extensions with Rust!
  4. ![GitHub Actions badge](https://github.com/pgcentralfoundation/pgrx/actions/workflows/tests.yml/badge.svg)
  5. [![crates.io badge](https://img.shields.io/crates/v/pgrx.svg)](https://crates.io/crates/pgrx)
  6. [![docs.rs badge](https://docs.rs/pgrx/badge.svg)](https://docs.rs/pgrx)
  7. [![Twitter Follow](https://img.shields.io/twitter/follow/pgrx_rs.svg?style=flat)](https://twitter.com/pgrx_rs)
  8. [![Discord Chat](https://img.shields.io/discord/710918545906597938.svg)][Discord]
  9. `pgrx` is a framework for developing PostgreSQL extensions in Rust and strives to be as idiomatic and safe as possible.
  10. `pgrx` supports Postgres 15 through Postgres 18, plus Postgres 19rc2.
  11. ## Want to chat with us or get a question answered?
  12. + **Please join our [Discord Server][Discord].**
  13. + **We are also in need of financial [sponsorship](https://checkout.square.site/merchant/MLHG5M9GAXQPV/checkout/2OW2SULDQBSZ2JLHSLRZQLZH).**
  14. ## Key Features
  15. - **A fully managed development environment with [`cargo-pgrx`](cargo-pgrx/README.md)**
  16. + `cargo pgrx new`: Create new extensions quickly
  17. + `cargo pgrx init`: Install new (or register existing) PostgreSQL installs
  18. + `cargo pgrx run`: Run your extension and interactively test it in `psql` (or `pgcli`)
  19. + `cargo pgrx test`: Unit-test your extension across multiple PostgreSQL versions
  20. + `cargo pgrx regress`: Run SQL regression tests and compare their output with expected files
  21. + `cargo pgrx package`: Create installation packages for your extension, including RPM and DEB packages on Linux
  22. + `cargo pgrx migrate`: Optionally build upgrade scripts from one small SQL file per change
  23. + More in the [`README.md`](cargo-pgrx/README.md)!
  24. - **Target Multiple Postgres Versions**
  25. + Support from Postgres 15 to Postgres 19 from the same codebase
  26. + Use Rust feature gating to use version-specific APIs
  27. + Seamlessly test against all versions
  28. - **Automatic Schema Generation**
  29. + Implement extensions entirely in Rust
  30. + [Automatic mapping for many Rust types into PostgreSQL](#mapping-of-postgres-types-to-rust)
  31. + SQL schemas generated automatically (or manually via `cargo pgrx schema`)
  32. + Include custom SQL with `extension_sql!` & `extension_sql_file!`
  33. - **Automatic PostgreSQL C Macro Translation**
  34. + During binding generation, pgrx transpiles nearly all of PostgreSQL's function-style C `#define` macros into Rust `macro_rules!` macros
  35. + Call them through `pgrx::` with their original C names and `!`, such as `pgrx::VARSIZE_ANY!(ptr)`
  36. + Their behavior follows the selected PostgreSQL installation, compiler flags, and target
  37. + See [Using PostgreSQL C macros](docs/src/extension/c-macros.md) for extension examples and the [transpiler architecture](pgrx-c-macros/ARCHITECTURE.md) for implementation details
  38. - **Safety First**
  39. + Translates Rust `panic!`s into Postgres `ERROR`s that abort the transaction, not the process
  40. + Memory Management follows Rust's drop semantics, even in the face of `panic!` and `elog(ERROR)`
  41. + `#[pg_guard]` procedural macro to ensure the above
  42. + Postgres `Datum`s are `Option<T> where T: FromDatum`
  43. - `NULL` Datums are safely represented as `Option::<T>::None`
  44. - **First-class UDF support**
  45. + Annotate functions with `#[pg_extern]` to expose them to Postgres
  46. + Return `pgrx::iter::SetOfIterator<'a, T>` for `RETURNS SETOF`
  47. + Return `pgrx::iter::TableIterator<'a, T>` for `RETURNS TABLE (...)`
  48. + Create trigger functions with `#[pg_trigger]`
  49. - **Easy Custom Types**
  50. + `#[derive(PostgresType)]` to use a Rust struct as a Postgres type
  51. - By default, represented as a CBOR-encoded object in-memory/on-disk, and JSON as human-readable
  52. - Supports `#[pg_binary_protocol]` to generate binary protocol send/recv functions
  53. - Provide custom in-memory/on-disk/human-readable representations
  54. + `#[derive(PostgresEnum)]` to use a Rust enum as a Postgres enum
  55. + Composite types supported with the `pgrx::composite_type!("Sample")` macro
  56. - **Server Programming Interface (SPI)**
  57. + Safe access into SPI
  58. + Transparently return owned Datums from an SPI context
  59. - **Advanced Features**
  60. + Safe access to Postgres' `MemoryContext` system via `pgrx::PgMemoryContexts`
  61. + Executor/planner/transaction/subtransaction hooks
  62. + Safely use Postgres-provided pointers with `pgrx::PgBox<T>` (akin to `alloc::boxed::Box<T>`)
  63. + `#[pg_guard]` proc-macro for guarding `extern "C-unwind"` Rust functions that need to be passed into Postgres
  64. + Access Postgres' logging system through `eprintln!`-like macros
  65. + Direct `unsafe` access to large parts of Postgres internals via the `pgrx::pg_sys` module
  66. + New features added regularly!
  67. ## System Requirements
  68. PGRX has been tested to work on x86_64 Linux, aarch64 Linux, aarch64 macOS, and x86_64 Windows targets⹋.
  69. It is currently expected to work on other "Unix" OS with possible small changes, but those remain untested.
  70. The generated C macros need a target whose C data model the compiler can verify
  71. as LP64, LLP64, or ILP32, and whose Rust architecture, OS, and ABI pgrx
  72. recognizes. See
  73. [target limits](docs/src/extension/c-macros.md#understand-refusals-and-runtime-limits).
  74. A cross build has further requirements; see [Cross-compiling](#cross-compiling).
  75. - A Rust toolchain: `rustc`, `cargo`, and `rustfmt`. The recommended way to get these is from https://rustup.rs †
  76. - `git`
  77. - `libclang` 11 or greater, plus a `clang` driver and LLVM archiver from the same LLVM release
  78. - Debian-likes: `apt install clang llvm libclang-dev`
  79. - RHEL-likes: `yum install clang llvm`
  80. - Windows: download installers from https://github.com/llvm/llvm-project/releases
  81. - On Linux, pgrx's CI generates the C macros with every Clang major from 14 through 23, on x86_64 and aarch64, and requires those versions to generate the same macros. Other Clang versions are not tested on Linux.
  82. - `pgrx-pg-sys` uses the driver to find the target's system headers, to check the C macro profile against the PostgreSQL headers and to compile its native support archive, including the `cshim` feature. Its major version must match `libclang`. pgrx uses `CLANG_PATH` when it is set; otherwise it uses the first match among the `CLANG` recorded in a `pg_config` program's `--configure` output, the `clang` installed with `libclang`, and `clang-<major>` or `clang` on `PATH`.
  83. - The archiver is `llvm-ar` from the driver's LLVM release, or `llvm-lib` for Windows targets. pgrx looks for `llvm-ar-<major>` beside a `clang-<major>` driver, then `llvm-ar` beside the driver or beside its resolved path, such as Debian's `/usr/lib/llvm-<major>/bin/llvm-ar`. Without one, builds for Unix targets use the system `ar`, which works for native builds but may not index objects built for another target.
  84. - A failure to generate the C macros stops the build with an error that names the cause.
  85. - A driver that loads a default configuration file, as Gentoo's Clang does, is refused. Set `CLANG_NO_DEFAULT_CONFIG=1` to build without it.
  86. - C compiler
  87. - Linux and macOS: a host C compiler, which builds the generator's SHA-256 backend
  88. - Windows: MSVC, which Rust's MSVC targets need for linking
  89. - [PostgreSQL's build dependencies](https://wiki.postgresql.org/wiki/Compile_and_Install_from_source_code) ‡
  90. - Debian-likes: `sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config libicu-dev`
  91. - RHEL-likes: `sudo yum install -y bison-devel readline-devel zlib-devel openssl-devel wget ccache && sudo yum groupinstall -y 'Development Tools'`
  92. † PGRX has no MSRV policy, thus may require the latest stable version of Rust, available via Rustup
  93. ‡ A local PostgreSQL server installation is not required. On Linux and MacOS, `cargo pgrx` can download and compile PostgreSQL versions on its own. On Windows, `cargo pgrx` downloads precompiled PostgreSQL versions from EnterpriseDB.
  94. ⹋ PGRX has not been tested on 32-bit targets. The generated macro runtime's
  95. verified ILP32 model and the library's 32-bit Datum conversion code do not
  96. establish a supported 32-bit backend build. Official support would require
  97. ongoing technical and financial contributions.
  98. ### macOS
  99. Running PGRX on a Mac requires some additional setup.
  100. The Mac C compiler (clang) and related tools are bundled with [Xcode](https://developer.apple.com/xcode/).
  101. Xcode can be installed from the Mac App Store.
  102. For additional C libraries, it's easiest to use [Homebrew](https://brew.sh/). In particular,
  103. you will probably need these if you don't have them already:
  104. ```zsh
  105. brew install git icu4c pkg-config
  106. ```
  107. Postgres 16 and later build with ICU by default, and their config script does not automatically
  108. detect the Homebrew install directory. (Postgres 15 builds without ICU unless asked, so it does
  109. not have this problem.) You may see this error:
  110. ```configure: error: ICU library not found```
  111. To fix it, run
  112. ```
  113. export PKG_CONFIG_PATH=/opt/homebrew/opt/icu4c/lib/pkgconfig
  114. ```
  115. on the command line before you run ```cargo pgrx init```
  116. #### Troubleshooting
  117. 1. Every once in a while, Xcode will update itself and move the directory that contains
  118. the C compiler. When the Postgres ./config process runs during the build, it grabs the current directory
  119. and stores it, which means that there will be build errors if you do a full rebuild of your
  120. project and the old directory has disappeared. The solution is re-run `cargo pgrx init` so the
  121. Postgres installs get rebuilt.
  122. 2. If a build fails with errors like `unknown type name: uint8_t`:
  123. You may be using too-old Xcode. This often happens with an Apple Clang version below 15.
  124. This can be fixed by updating Xcode and the command-line tools. You may require an OS update
  125. if the Xcode version you must update to does not support your current macOS version.
  126. ### Windows
  127. Running PGRX on Windows requires MSVC prerequisites.
  128. On Windows, please follow https://rust-lang.github.io/rustup/installation/windows-msvc.html to set it up.
  129. ## Getting Started
  130. Before anything else, install the [system dependencies](#system-requirements).
  131. Now install the `cargo-pgrx` sub-command.
  132. ```bash
  133. cargo install --locked cargo-pgrx
  134. ```
  135. Once `cargo-pgrx` is ready you can initialize the "PGRX Home" directory:
  136. ```bash
  137. cargo pgrx init
  138. ```
  139. The `init` command downloads all currently supported PostgreSQL versions, compiles them
  140. to `${PGRX_HOME}`, and runs `initdb`.
  141. It's also possible to use an existing (user-writable) PostgreSQL install, or install a subset of versions, see the [`README.md` of `cargo-pgrx` for details](cargo-pgrx/README.md#first-time-initialization).
  142. Now you can begin work on a specific pgrx extension:
  143. ```bash
  144. cargo pgrx new my_extension
  145. cd my_extension
  146. ```
  147. This will create a new directory for the extension crate.
  148. ```
  149. $ tree
  150. .
  151. ├── Cargo.toml
  152. ├── my_extension.control
  153. ├── sql
  154. └── src
  155. └── lib.rs
  156. 2 directories, 3 files
  157. ```
  158. The new extension includes an example, so you can go ahead and run it right away.
  159. ```bash
  160. cargo pgrx run
  161. ```
  162. This compiles the extension to a shared library, copies it to the specified Postgres installation, starts that Postgres instance and connects you to a database named the same as the extension.
  163. Once `cargo-pgrx` drops us into `psql` we can [load the extension](https://www.postgresql.org/docs/15/sql-createextension.html) and do a SELECT on the example function.
  164. ```sql
  165. my_extension=# CREATE EXTENSION my_extension;
  166. CREATE EXTENSION
  167. my_extension=# SELECT hello_my_extension();
  168. hello_my_extension
  169. ---------------------
  170. Hello, my_extension
  171. (1 row)
  172. ```
  173. For more details on how to manage pgrx extensions see [Managing pgrx extensions](cargo-pgrx/README.md).
  174. ## Cross-compiling
  175. Cross-compiling builds an extension on one machine for another platform. pgrx
  176. does it from a *target bundle*, one file made from the target's PostgreSQL:
  177. 1) On the target platform, run [`tools/pgrx-collect-partial-bundle.sh`](tools/pgrx-collect-partial-bundle.sh).
  178. It needs only a POSIX shell, `tar` and PostgreSQL's server headers, and writes a *partial bundle*
  179. such as `pgrx-pg18-aarch64-unknown-linux-gnu.partial.tar.gz`. It can also take what `pg_config`
  180. reports from a file or from arguments, for headers in a sysroot whose `pg_config` cannot run.
  181. 2) Copy that file to the build host.
  182. 3) On the build host, run `cargo pgrx package --bundle <file>`. This needs a Rust toolchain that can link
  183. for the target, Clang, and the target's system headers, and no PostgreSQL, `pg_config` or `cargo pgrx init`.
  184. A partial bundle holds nothing generated, so it serves every pgrx version. To need only a linker on
  185. the build host, generate a *full bundle* instead with `cargo pgrx package --bundle-generate` in your
  186. extension's directory on the target. That needs Rust and Clang there, and has to be done again after
  187. each pgrx upgrade, since a full bundle is valid for one Rust target, PostgreSQL major version, pgrx
  188. version and `cshim` setting.
  189. The bundle comes from the target because the bindings, C macros and native
  190. support that pgrx builds from PostgreSQL's headers depend on how that PostgreSQL
  191. was built. The target platform can be a container or a CI runner. The
  192. [cross-compilation guide](docs/src/extension/build/cross-compile.md)
  193. describes both kinds of bundle, what pgrx verifies, and cross toolchains.
  194. Library names, package layout, and RPM/DEB generation follow the bundle's
  195. target. Cargo's `build.target`, `CARGO_BUILD_TARGET`, forwarded Cargo flags, and
  196. custom JSON target specifications do not select a target for cargo-pgrx.
  197. `cargo pgrx run` will not work.
  198. ## Upgrading
  199. To move an extension to a new `pgrx` release, install the matching `cargo-pgrx`, then update
  200. your crate's `pgrx` dependencies:
  201. ```bash
  202. cargo install cargo-pgrx --version <VERSION> --locked
  203. ```
  204. ```bash
  205. cargo pgrx upgrade
  206. ```
  207. A release that needs code or build changes has a migration guide in the top level of this
  208. repository, such as the [v0.20.0 Migration Guide](v0.20.0-MIGRATION.md).
  209. As new Postgres versions are supported by `pgrx`, you can re-run `cargo pgrx init` to download and compile them:
  210. ```bash
  211. cargo pgrx init
  212. ```
  213. ## Mapping of Postgres types to Rust
  214. | Postgres Type | Rust Type (as `Option<T>`) |
  215. |----------------------------|---------------------------------------------------------|
  216. | `bytea` | `Vec<u8>`, `&[u8]` (zero-copy in), or `pgrx::Bytea<'_>` (zero-copy in/out) |
  217. | `text` | `String` or `&str` (zero-copy) |
  218. | `varchar` | `String` or `&str` (zero-copy) or `char` |
  219. | `"char"` | `i8` |
  220. | `smallint` | `i16` |
  221. | `integer` | `i32` |
  222. | `bigint` | `i64` |
  223. | `oid` | `pgrx::pg_sys::Oid` |
  224. | `real` | `f32` |
  225. | `double precision` | `f64` |
  226. | `bool` | `bool` |
  227. | `json` | `pgrx::Json(serde_json::Value)` |
  228. | `jsonb` | `pgrx::JsonB(serde_json::Value)` |
  229. | `date` | `pgrx::Date` |
  230. | `time` | `pgrx::Time` |
  231. | `timestamp` | `pgrx::Timestamp` |
  232. | `time with time zone` | `pgrx::TimeWithTimeZone` |
  233. | `timestamp with time zone` | `pgrx::TimestampWithTimeZone` |
  234. | `anyarray` | `pgrx::AnyArray` |
  235. | `anyelement` | `pgrx::AnyElement` |
  236. | `box` | `pgrx::geo::Box` |
  237. | `circle` | `pgrx::geo::Circle` |
  238. | `line` | `pgrx::geo::Line` |
  239. | `lseg` | `pgrx::geo::LineSegment` |
  240. | `path` | `pgrx::geo::Path` |
  241. | `point` | `pgrx::geo::Point` |
  242. | `polygon` | `pgrx::geo::Polygon` |
  243. | `tid` | `pgrx::pg_sys::ItemPointerData` |
  244. | `cstring` | `&core::ffi::CStr` |
  245. | `inet` | `pgrx::Inet(String)` -- TODO: needs better support |
  246. | `numeric` | `pgrx::Numeric<P, S> or pgrx::AnyNumeric` |
  247. | `void` | `()` |
  248. | `ARRAY[]::<type>` | `Vec<Option<T>>` or `pgrx::Array<T>` (zero-copy) |
  249. | `int4range` | `pgrx::Range<i32>` |
  250. | `int8range` | `pgrx::Range<i64>` |
  251. | `numrange` | `pgrx::Range<Numeric<P, S>>` or `pgrx::Range<AnyRange>` |
  252. | `daterange` | `pgrx::Range<pgrx::Date>` |
  253. | `tsrange` | `pgrx::Range<pgrx::Timestamp>` |
  254. | `tstzrange` | `pgrx::Range<pgrx::TimestampWithTimeZone>` |
  255. | `NULL` | `Option::None` |
  256. | `internal` | `pgrx::Internal` |
  257. | `uuid` | `pgrx::Uuid([u8; 16])` |
  258. | `tsvector` | `&pgrx::TsVector` or `pgrx::TsVectorBuf` |
  259. | `tsquery` | `&pgrx::TsQuery` or `pgrx::TsQueryBuf` |
  260. There are also `IntoDatum` and `FromDatum` traits for implementing additional type conversions,
  261. along with `#[derive(PostgresType)]` and `#[derive(PostgresEnum)]` for automatic conversion of
  262. custom types.
  263. Note that `text` and `varchar` are converted to `&str` or `String`, so PGRX
  264. assumes any Postgres database you use it with has UTF-8-compatible encoding.
  265. Currently, PGRX will panic if it detects this is incorrect, to inform you, the
  266. programmer, that you were wrong. However, it is best to not rely on this
  267. behavior, as UTF-8 validation can be a performance hazard. This problem was
  268. previously assumed to simply not happen, and PGRX may decide to change the
  269. details of how it does UTF-8 validation checks in the future in order to
  270. mitigate performance hazards.
  271. The default Postgres server encoding is `SQL_ASCII`, and it guarantees neither
  272. ASCII nor UTF-8 (as Postgres will then accept but ignore non-ASCII bytes).
  273. For best results, always use PGRX with UTF-8, and set database encodings
  274. explicitly upon database creation.
  275. ## Digging Deeper
  276. - [cargo-pgrx sub-command](cargo-pgrx/)
  277. - [Custom Types](pgrx-examples/custom_types/)
  278. - [Postgres Operator Functions and Operator Classes/Families](pgrx-examples/operators/)
  279. - [Shared Memory Support](pgrx-examples/shmem/)
  280. - [various examples](pgrx-examples/)
  281. ## Caveats & Known Issues
  282. There are probably more issues than the ones listed here, but the primary ones of note are:
  283. - Threading is not really supported. Postgres is strictly single-threaded. As such, if you do venture into using threads, those threads **MUST NOT** call *any* internal Postgres function, or otherwise use any Postgres-provided pointer. There's also a potential problem with Postgres' use of `sigprocmask`. This was being discussed on the -hackers list, even with a patch provided, but the conversation seems to have stalled (https://www.postgresql.org/message-id/flat/5EF20168.2040508%40anastigmatix.net#4533edb74194d30adfa04a6a2ce635ba).
  284. - How to correctly interact with Postgres in an `async` context remains unexplored.
  285. - `pgrx` wraps a lot of `unsafe` code, some of which has poorly-defined safety conditions. It may be easy to induce illogical and undesirable behaviors even from safe code with `pgrx`, and some of these wrappers may be fundamentally unsound. Please report any issues that may arise.
  286. - Not all of Postgres' internals are included or even wrapped. This isn't due to it not being possible, it's simply due to it being an incredibly large task. If you identify internal Postgres APIs you need, open an issue and we'll get them exposed, at least through the `pgrx::pg_sys` module.
  287. - Sessions started before `ALTER EXTENSION my_extension UPDATE;` will continue to see the old version of `my_extension`. New sessions will see the updated version of the extension.
  288. - `pgrx` is used by many "in production", but it is not "1.0.0" or above, despite that being recommended by SemVer for production-quality software. This is because there are many unresolved soundness and ergonomics questions that will likely require breaking changes to resolve, in some cases requiring cutting-edge Rust features to be able to expose sound interfaces. While a 1.0.0 release is intended at some point, it seems prudent to wait until it seems like a 2.0.0 release would not be needed the next week and the remaining questions can be deferred.
  289. ## TODO
  290. There are a few things on our immediate TODO list
  291. - Automatic extension schema upgrade scripts (today, `cargo pgrx migrate` assembles them from hand-written SQL fragments)
  292. - Improved unit testing framework
  293. - Better/Safer API for Datum management
  294. - Improved generated bindings organization
  295. - Safely wrap more Postgres internal APIs
  296. - More examples -- especially around memory management and the various derive macros `#[derive(PostgresType/Enum)]`
  297. ## Feature Flags
  298. PGRX has optional feature flags for Rust code that do not involve configuring the version of Postgres used,
  299. but rather extend additional support for other kinds of Rust code. These are not included by default.
  300. ### "unsafe-postgres": Allow compilation for Postgres forks that have a different ABI
  301. As of Postgres 15, forks are allowed to specify they use a different ABI than canonical Postgres.
  302. Since pgrx makes countless assumptions about Postgres' internal ABI it is not possible for it to
  303. guarantee that a compiled pgrx extension will probably execute within such a Postgres fork. You,
  304. dear compiler runner, can make this guarantee for yourself by specifying the `unsafe-postgres`
  305. feature flag. Otherwise, a pgrx extension will fail to compile with an error similar to:
  306. ```
  307. error[E0080]: evaluation of constant value failed
  308. --> pgrx/src/lib.rs:151:5
  309. |
  310. 151 | / assert!(
  311. 152 | | same_slice(pg_sys::FMGR_ABI_EXTRA, b"xPostgreSQL\0"),
  312. 153 | | "Unsupported Postgres ABI. Perhaps you need `--features unsafe-postgres`?",
  313. 154 | | );
  314. | |_____^ the evaluated program panicked at 'Unsupported Postgres ABI. Perhaps you need `--features unsafe-postgres`?', pgrx/src/lib.rs:151:5
  315. |
  316. ```
  317. ### "no_thread_check_in_release": Skip the backend thread check in release builds
  318. Postgres may only be called from the backend's own thread. pgrx remembers the first thread that
  319. calls into Postgres and panics when another one does. That check runs on every call through
  320. pgrx's FFI guard, and several safe pgrx functions rely on it for their soundness.
  321. With the `no_thread_check_in_release` feature, a build without `debug_assertions`, which is what
  322. `cargo pgrx install --release` and `cargo pgrx package` make by default, compiles the check as a
  323. `const fn` that does nothing. Calling Postgres from another thread is then undefined behavior that
  324. nothing reports, including through pgrx's safe functions. A build with `debug_assertions`, such as
  325. the one `cargo pgrx test` makes by default, keeps the check.
  326. Cargo unifies features, so one crate that sets this one removes the check from every crate of the
  327. build that uses pgrx. Only set it in an extension whose every dependency keeps Postgres calls on
  328. the backend thread.
  329. `pgrx::assert_active_thread()` is the same check as a function you can call yourself. It runs in
  330. every build, whatever this feature says. A build without pgrx's own checks has no active thread
  331. until the first call, so make that call on the backend thread.
  332. ## Contributing
  333. We are most definitely open to contributions of any kind. Bug Reports, Feature Requests, and Documentation.
  334. If you'd like to contribute code via a Pull Request, please make it against our `develop` branch. The `master` branch is no longer used.
  335. Providing wrappers for Postgres' internals is not a straightforward task, and completely wrapping it is going
  336. to take quite a bit of time. `pgrx` is generally ready for use now, and it will continue to be developed as
  337. time goes on. Your feedback about what you'd like to be able to do with `pgrx` is greatly appreciated.
  338. ## Hacking
  339. When you run tests in this repository, the `#[pg_test]` harness builds and runs the checkout's
  340. `cargo-pgrx` with `cargo run`, so tests always use the revision you're working on. Set
  341. `CARGO_PGRX` to the path of a `cargo-pgrx` binary to use a different one.
  342. Other commands, such as `cargo pgrx init`, also need a `cargo-pgrx` from the same revision.
  343. Install one from the checkout as described in
  344. [Contributing](docs/src/contributing.md#dev-environment-setup), or run it without installing,
  345. as in `cargo run -p cargo-pgrx -- pgrx init`.
  346. Extensions can pin a matching `cargo-pgrx` with
  347. [cargo-local-install](https://github.com/MaulingMonkey/cargo-local-install). This repository's
  348. `Cargo.toml` has a `[workspace.metadata.local-install]` entry for it as an example: `cargo local-install`
  349. installs that `cargo-pgrx` into `./bin`, which you then prepend to your `PATH`.
  350. ## License
  351. ```
  352. Portions Copyright 2019-2021 ZomboDB, LLC.
  353. Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
  354. Portions Copyright 2023 PgCentral Foundation, Inc.
  355. All rights reserved.
  356. Use of this source code is governed by the MIT license that can be found in the LICENSE file.
  357. ```
  358. [Discord]: https://discord.gg/PMrpdJsqcJ
  359. [timecrate]: https://crates.io/crates/time

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.