Re: Ability to reference other extensions by schema in extension scripts

From: Sandro Santilli <strk(at)kbt(dot)io>
To: Regina Obe <lr(at)pcorp(dot)us>
Cc: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Ability to reference other extensions by schema in extension scripts
Date: 2023-02-28 22:46:08
Message-ID: 20230228224608.ak7br5shev4wic5a@c19
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Feb 26, 2023 at 01:39:24AM -0500, Regina Obe wrote:

> > 1) Just don't allow any extensions referenced by other
> > extensions to be relocatable.
> Attached is my revision 3 patch, which follows the proposed #1.
> Don't allow schema relocation of an extension if another extension
> requires it.

I've built a version of PostgreSQL with this patch applied and I
confirm it works as expected.

The "ext1" is relocatable and creates a function ext1log():

=# create extension ext1 schema n1;

The "ext2" is relocatable and creates a function ext2log() relying
on the ext1log() function from "ext1" extension, referencing
it via @extschema:ext1@:

=# create extension ext2 schema n2;
=# select n2.ext2log('hello'); -- things work here
ext1: ext2: hello

By creating "ext2", "ext1" becomes effectively non-relocatable:

=# alter extension ext1 set schema n2;
ERROR: cannot SET SCHEMA of extension ext1 because other extensions
require it
DETAIL: extension ext2 requires extension ext1

Drop "ext2" makes "ext1" relocatable again:

=# drop extension ext2;
=# alter extension ext1 set schema n2;

Upon re-creating "ext2" the referenced ext1 schema will be
the correct one:

=# create extension ext2 schema n1;
=# select n1.ext2log('hello');
ext1: ext2: hello

The code itself builds w/out warnings with:

mkdir build
cd build
make 2> ERR # ERR is empty

The testsuite reports all successes:

make check
All 213 tests passed.

Since I didn't see the tests for extension in there, I've also
explicitly run that portion:

make -C src/test/modules/test_extensions/ check
test test_extensions ... ok 32 ms
test test_extdepend ... ok 12 ms
All 2 tests passed.

As mentioned already the downside of this patch is that it would
not be possibile to change the schema of an otherwise relocatable
extension once other extension depend on it, but I can't think of
any good reason to allow that, as it would mean dependent code
would need to always dynamically determine the install location
of the objects in that extension, which sounds dangerous, security


Libre GIS consultant/developer

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2023-02-28 22:47:09 Re: RFC: logical publication via inheritance root?
Previous Message Sandro Santilli 2023-02-28 22:13:55 Re: Ability to reference other extensions by schema in extension scripts