Support for Postgres 17
Hi, the Postgres community has cut the REL_17_STABLE branch. Do we know when PL/Rust (therefore pgrx) will support Postgres 17? Thanks.
$ cargo pgrx init --pg17 /usr/local/pgsql/bin/pg_config
error: unexpected argument '--pg17' found
tip: a similar argument exists: '--pg16'
Usage: cargo pgrx init <--pg11 <PG11>|--pg12 <PG12>|--pg13 <PG13>|--pg14 <PG14>|--pg15 <PG15>|--pg16 <PG16>|--base-port <BASE_PORT>|--base-testing-port <BASE_TESTING_PORT>|--configure-flag <CONFIGURE_FLAG>|--valgrind>
For more information, try '--help'.
pgrx has been going through some major work to help improve its overall soundness as it relates to managing Postgres-allocated memory. Once that work is complete, pl/rust will get a refresh.
Between now and then, I'm sure we'll get pg17 support added to pgrx proper, but that won't be reflected here in pl/rust until aforementioned tasks are complete.
It's on our radar -- if that's any comfort.
Thanks, so the priority is to rework pgrx memory soundness before pg17 support will be available for plrust?
Do you have a rough idea of the timeline? say, before or after the planned PG17 release in September?
Thanks, so the priority is to rework pgrx memory soundness before pg17 support will be available for plrust?
Yes
Do you have a rough idea of the timeline? say, before or after the planned PG17 release in September?
No
Clearly our preference is for the stars to align, but work takes time.
Hi @johnrballard, I understand that you're the maintainer of the PL/Rust project now. Is there any timeline on updating PL/Rust to support PG17?
Hello! Any chance of an update to PL/Rust for Postgres 17 soonish? Thanks!
Hi, waiting on pg17 support also. Would appreciate any news, Thanks.
I was interested in PL/Rust, but I already use Postgresql 17 and The lack of support for Version 17 is a bummer.
TL;DR I made untrusted PL/Rust work for Postgres 17 (https://github.com/andreas/plrust/tree/feat/pg17)
I've tried to make PL/Rust support Postgres 17 and wanted to share my learnings, in case other people can benefit or want to help the effort. I should caveat this by saying I'm no Rust developer, and much of this work was done with the help of an LLM. You can see the patch here: https://github.com/tcdi/plrust/compare/main...andreas:plrust:feat/pg17
The first problem to solve is upgrading pgrx to a more recent version, which supports Postgres 17. I chose to target v0.12.8. The most important breaking change came from https://github.com/pgcentralfoundation/pgrx/pull/1701, which reworks how return values of #[pg_extern] are handled:
This also breaks returning values from
#[pg_extern]functions that were relying onIntoDatumimplementations being enough.
plrust was relying on IntoDatum for plrust_call_handler, so the patch rewrites it to not use #[pg_extern] and use lower-level APIs instead.
Upgrading pgrx to v0.12.8 also required upgrading Rust, as plrust was pinned to Rust 1.72.0. This turned out to be much more difficult. plrust includes a standard library replacement, postgrestd, which is a modified version of the standard library for Rust 1.72.0. I followed the upgrade guide (pro tip: use git-filter-repo rather than git subtree split! It takes minutes instead of hours), and resolved thousands of merge conflicts with the help of an LLM. However, even with everything merged nicely, the build failed. It turns out that Rust has changed significantly between 1.72.0 and 1.80.0 in regards to replacement standard libraries. postgrestd previously used RUSTC_BOOTSTRAP and a custom sysroot, but that no longer works. I tried to make it work with the flag -Zbuild-std, which seems to be the new approach, but ultimately had to give up.
Using postgrestd is only required of for trusted PL/Rust though. Unable to resolve this issue, I pursued building an untrusted version of PL/Rust instead. This "just" required bumping the Rust version in rust-toolchain.toml, fixing some compilation errors, and updating some build steps (see Dockerfile.try).
Here's a short terminal excerpt from when it finally worked 🙌
> docker run -it tcdi/try-plrust
Starting Postgresql...
Starting PostgreSQL 17 database server: main.
Installing plrust
WARNING: plrust is **NOT** compiled to be a trusted procedural language
CREATE EXTENSION
Starting psql
psql (17.5 (Debian 17.5-1.pgdg110+1))
Type "help" for help.
postgres(plrust)=# create function foo() returns int as $$ Ok(Some(42)) $$ language plrust;
CREATE FUNCTION
postgres(plrust)=# select foo();
foo
-----
42
(1 row)