> On Mar 31, 2024, at 09:59, Peter J. Holzer <hjp-pgsql@hjp.at> wrote:
> Is this an acceptable performance penalty per API call? If not, is it
> really necessary to check this on every call? Maybe it can be done just
> once per session or once per hour.
It's probably not required to check it every API call. Two places come to mind:
_PG_init -- Although I don't know the possibility or wisdom of reading from a file there.
shmem_startup_hook -- It's definitely OK to read from a file there.
Remember that you have the full ability to crash PostgreSQL in an extension, so it really needs to be bulletproof. You
don'twant the shared library to fail to load if the license isn't valid. Instead:
-- If the functionality is exposed as functions, return an error when one of those functions is used, if the extension
isnot licensed.
-- If the functionality modifies PostgreSQL behavior, disable that modification.
If you are validating the license via a network call... I would counsel against having a network call as part of
PostgreSQL'sstartup process. It might work to make the call on-demand the first time the extension is used, and the
resultstored locally, although I would limit that to function calls rather than, say, a hook into the planner.
You also need to decide exactly how you want to distribute this extension. Most PostgreSQL extensions are supplied as
sourceand built against PostgreSQL.