Repository navigation
v0.20.0-beta.1
Pre-releaseWelcome to pgrx v0.20.0-beta.1, the second beta of v0.20.0.
This one fills in the generated C macros, fixes how caught Postgres ERRORs are rethrown, trims a lot of third-party dependencies from extension builds and cargo-pgrx, and adds TsVector and TsQuery types. It also fixes beta.0 failing to build with LLVM 18, which is what Ubuntu 24.04 installs by default.
Install with:
$ cargo install cargo-pgrx --version 0.20.0-beta.1 --lockedAnd update your extension's dependencies with cargo pgrx upgrade --to =0.20.0-beta.1.
A few of these changes can break code that built against beta.0. The v0.20.0 Migration Guide has been updated for all of them, and each section below links to the part that applies.
This is still a beta. Please keep trying it with your extensions and tell us what breaks before 0.20.0 ships.
Generated C Macros
- Generate CHECK_FOR_INTERRUPTS and other builtin macros under Clang 18 by @eeeebbbbrrrr in #2459
With LLVM 18, beta.0 generated none of CHECK_FOR_INTERRUPTS!, likely!, unlikely!, pg_bswap*! and friends, so the pgrx crate itself failed to compile. That's fixed.
- Generate the same C macros for assert-enabled and release PostgreSQL by @eeeebbbbrrrr in #2461
cargo pgrx init builds Postgres with --enable-cassert and packaged Postgres is built without it. In beta.0 that changed which macros existed and which needed unsafe, so an extension could compile against one and not the other. Now pg_sys offers the same items against both. What you'll notice:
- Bindings that only an assert-enabled Postgres declares are gone from every build, such as
MemoryContextCheck,castNodeImpland theUSE_ASSERT_CHECKINGconstant. - Assertion functions such as
AssertTransactionIdInAllowableRangeare now macros in both builds. pg_sys::Assert!is a statement, and a macro needsunsafewherever its assert-enabled definition does.PageValidateSpecialPointer!is one that now needs it everywhere.- Assertions only run against a server built with them. A failed one prints Postgres'
TRAP:line with the Rust file and line, and aborts.
See Assert-enabled and release PostgreSQL.
- Generate C macros that paste a prefix onto a type operand, such as
IsA,castNodeandmakeNodeby @eeeebbbbrrrr in #2465 - Generate
makeNode!on PostgreSQL 15 and 16 by translating GNU statement expressions by @eeeebbbbrrrr in #2468
IsA!, castNode!, makeNode! and the lfirst_node! family of list macros are now generated on every supported Postgres version. The type operand is the Rust type, and all of them need unsafe:
if unsafe { pg_sys::IsA!(node, pg_sys::Query).is_true() } {
let query = unsafe { pg_sys::castNode!(pg_sys::Query, node).get() };
}OpExpr, DistinctExpr and NullIfExpr are one Rust type with three node tags, so none of them is accepted as the type operand. Use pg_sys::nodeTag! or PgNode::is_a_ptr for those. See Node macros.
- Generate the same C macros on Linux as on macOS where system headers repeat
NULL, and under libclang 15 by @eeeebbbbrrrr in #2470 - Run the thread check once per generated C macro expansion by @eeeebbbbrrrr in #2478
- Wrap a generated
sizeofoperand inunsafeonly when it needs it by @eeeebbbbrrrr in #2479
#2470 restores BoxPGetDatum! and 27 other macros that were missing under libclang 15 and earlier. #2478 makes a macro that reads several Postgres globals, like BufferGetPage!, run pgrx's active-thread check once instead of once per read. One side effect: a temporary created inside an operand of such a macro is now dropped when the macro finishes, not at the end of your statement.
Error Handling
- Rethrow caught Postgres ERRORs intact, and flush only after handling one by @eeeebbbbrrrr in #2458
Rethrowing a CaughtError::PostgresError after something else had flushed Postgres' error stack, for example when a PgTryBuilder catch handler returned the error for its caller to rethrow, failed with errstart was not called or raised a different error. pgrx now keeps a copy of every field of a caught ERROR and raises that copy when Postgres no longer has the original, so handlers such as PL/pgSQL's GET STACKED DIAGNOSTICS see the same error either way.
PgTryBuilder::execute also no longer flushes the error stack after a Rust panic or an ErrorReport, which could discard an ERROR that C code calling into Rust was still handling.
If you swallow a Postgres ERROR with std::panic::catch_unwind, it stays on Postgres' error stack. Catch it with PgTryBuilder instead, or call pg_sys::FlushErrorState() afterwards. See Caught PostgreSQL errors.
Dependencies
- Cut third-party dependencies from extension builds and cargo-pgrx by @eeeebbbbrrrr in #2452
Extension builds, extension test builds and cargo install cargo-pgrx all compile noticeably fewer crates. An extension's test build no longer pulls in postgres, tokio and their dependencies, and installing cargo-pgrx on Linux no longer needs OpenSSL's development headers. That came with some changes you may need to act on:
pgrx_tests::client()andpgrx_tests::postgresneed the newclientfeature ofpgrx-tests. Seepgrx_tests::client.cargo-pgrxno longer hasrustlsandnative-tlsfeatures. Remove them from anycargo install cargo-pgrx --features ...command. It always uses rustls with the platform's certificate store, and still honors the proxy environment variables.cargo pgrx initunpacks Postgres with thetaron yourPATHon Linux and macOS, and downloads the.tar.gzarchive instead of.tar.bz2.pgrx::nullable::BitSliceNullsis replaced byNullBitmapandRawArray::nulls_bitsliceis gone, along with thebitvecdependency. See Array null bitmaps.PgXactCallbackEventno longer implementsenum_map::Enum.pgrx-pg-config's API changed for code that uses it directly. Seepgrx-pg-config.
This also fixes raw string arguments to #[pg_extern] attributes, which the old parsing mangled.
New Features
pgrx now has types for Postgres' tsvector and tsquery. &TsVector and &TsQuery are zero-copy function arguments, and TsVectorBuf and TsQueryBuf are Rust-owned copies. They come with the matching, concatenation, boolean and phrase operators, lexeme and query item iterators, TsConfig, the to_tsvector and to_tsquery style constructors, and ts_rank and ts_rank_cd ranking.
Testing
- Let
pgrx_tests::client()connect from#[pg_test]functions by @eeeebbbbrrrr in #2455
pgrx_tests::client() used to work only from the test process. It now also works inside a #[pg_test] function, so a test can open a second session without looking up the server's address by hand.
- Let dependent extensions share the tests schema by @eeeebbbbrrrr in #2464
An extension that depends on another pgrx extension can now keep its #[pg_schema] mod tests. The test harness creates the tests schema itself, and both extensions share it. If you have test builds of dependency extensions already installed, rebuild and reinstall them.
cargo-pgrx
- Retry cargo-pgrx's fetch of PostgreSQL's release list by @eeeebbbbrrrr in #2477
cargo pgrx init now tries each of its downloads up to four times.
Windows
- Fix a test hang, cargo pgrx regress, user names and LLVM 22 on Windows by @eeeebbbbrrrr in #2466
cargo pgrx regress now works on Windows, where it used to print passed=0 failed=0. pgrx-pg-sys builds with LLVM 22. Test binaries no longer hang forever when Windows reuses a process id. And the test framework and cargo pgrx bench ask Windows for the account name instead of trusting USERNAME, which fixes connecting from an SSH session.
Documentation
- [doc] libicu-dev is required on debian by @daamien in #2474
- Describe the assertion and node macro changes in the 0.20.0 migration guide by @eeeebbbbrrrr in #2467
Project Administrativa
- Fix Cargo manifest warnings and fail the packaging CI job on warnings by @eeeebbbbrrrr in #2450
- Run CI in parallel and only for the crates a change affects by @eeeebbbbrrrr in #2451
- Remove the stale benching lockfile and unused .gitignore files by @eeeebbbbrrrr in #2460
- Retry transient network failures in CI setup downloads by @eeeebbbbrrrr in #2463
- Bound apt-get's waits in CI setup by @eeeebbbbrrrr in #2472
- Regenerate the release bindings and the docs.rs C macro snapshot by @eeeebbbbrrrr in #2471
- Generate the C macros under every Clang from 14 to 23 in CI and compare them by @eeeebbbbrrrr in #2473
- Retry rustup's downloads in CI by @eeeebbbbrrrr in #2476
- Skip the Clang matrix for pgrx-macros and pgrx-sql-entity-graph changes by @eeeebbbbrrrr in #2481
CI now generates the C macros under every Clang from 14 to 23 and compares the results, so a break like the Clang 18 one above gets caught before a release.
Thanks
Thanks to @ibotty for the text search types and to @daamien for the documentation fix. Your work is appreciated!
Full Changelog: v0.20.0-beta.0...v0.20.0-beta.1