Search code examples
postgresqlcachingincludeplperlglobal-namespace

PostgreSQL's plperlu interpreter's @INC and/or cached libraries: separate for different databases?


I have different versions of some libraries I'm developing, and want to, from within various plperl functions I've written, load a certain version based on current_database().

(IIRC using use rather than require is preferred, I think because it might cache the library?)

However, my fear is that different databases on the same server will have problems, in either way that I'm thinking of doing it:

1) use lib and then use--if more than one path gets stuck on @INC, it may not be the right one that gets used

2) require--even if this means the right one is always used in the current script, does it mean that the library gets reloaded every time? And either way, if libraries are kept loaded once used, is it possible that namespace pollution from different versions could result in bugs? (E.g. if I have something branch based on whether a variable is defined, and in one version it is by default, and in another it's not--will all the versions now act as if it is, unless I explicitly undefine it rather than just not defining it?)


Solution

  • If plperl is not loaded through shared_preload_libraries, each database session will have its own interpreter freshly initialized at first use, so the libraries included by one session cannot possibly interfere with another session.

    See PL/Perl Under the Hood in the manual for more.