pgrx
pgrx copied to clipboard
Proposal for versioned .so support in pgx
We would like to have first-class versioned .so support in pgx. This implies that
- pgx generates a versioned shared object file
- Generated pgx schema "points to" versioned shared object file
As a concrete example, let's begin with a "fresh" pgx project:
> cargo pgx new test
> cd test
And now run:
> cargo pgx package --pg_config ~/.pgx/14.1/pgx-install/bin/pg_config
installing extension
Copying control file to `/share/postgresql/extension/test.control`
Copying shared library to `/lib/postgresql/test.so`
# ...
Copying extension schema file to `/share/postgresql/extension/test--1.0.sql`
Finished installing test
This produces the following SQL schema:
-- src/lib.rs:5
-- test::hello_test
CREATE OR REPLACE FUNCTION "hello_test"() RETURNS text /* &str */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hello_test_wrapper';
With versioned .so support, pgx would do the following:
> cargo pgx package --pg_config ~/.pgx/14.1/pgx-install/bin/pg_config
installing extension
Copying control file to `share/postgresql/extension/test.control`
Copying shared library to `/lib/postgresql/test-1.0.so`
# ...
Copying extension schema file to `/share/postgresql/extension/test--1.0.sql`
Finished installing test
Note: pgx extracted the version number from the .control file, and installed the .so suffixed with the version.
With the following SQL schema:
-- src/lib.rs:5
-- test::hello_test
CREATE OR REPLACE FUNCTION "hello_test"() RETURNS text /* &str */
STRICT
LANGUAGE c /* Rust */
AS '$libdir/test-1.0', 'hello_test_wrapper';
Note: it would probably be necessary to remove the module_pathname entry from the .control file.
In my opinion one of the sticking points with this approach are that it is "different", and not backwards compatible with what pgx has been doing until now. For that reason it may be necessary to consider whether this mode should be optionally enabled.
We chatted about this and wanted to set up a follow up meeting with @eeeebbbbrrrr .
I think it looks reasonable and we want to do something like this, we just need to consider the implementation details.
I believe this was added some time ago and has been seemingly used successfully, with examples and tests. Closing.