pgsql: Avoid dump/reload problems when using both plpython2 and plpytho - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid dump/reload problems when using both plpython2 and plpytho
Date
Msg-id E1aInFd-0004Og-6c@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid dump/reload problems when using both plpython2 and plpython3.

Commit 803716013dc1350f installed a safeguard against loading plpython2
and plpython3 at the same time, but asserted that both could still be
used in the same database, just not in the same session.  However, that's
not actually all that practical because dumping and reloading will fail
(since both libraries necessarily get loaded into the restoring session).
pg_upgrade is even worse, because it checks for missing libraries by
loading every .so library mentioned in the entire installation into one
session, so that you can have only one across the whole cluster.

We can improve matters by not throwing the error immediately in _PG_init,
but only when and if we're asked to do something that requires calling
into libpython.  This ameliorates both of the above situations, since
while execution of CREATE LANGUAGE, CREATE FUNCTION, etc will result in
loading plpython, it isn't asked to do anything interesting (at least
not if check_function_bodies is off, as it will be during a restore).

It's possible that this opens some corner-case holes in which a crash
could be provoked with sufficient effort.  However, since plpython
only exists as an untrusted language, any such crash would require
superuser privileges, making it "don't do that" not a security issue.
To reduce the hazards in this area, the error is still FATAL when it
does get thrown.

Per a report from Paul Jones.  Back-patch to 9.2, which is as far back
as the patch applies without work.  (It could be made to work in 9.1,
but given the lack of previous complaints, I'm disinclined to expend
effort so far back.  We've been pretty desultory about support for
Python 3 in 9.1 anyway.)

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/db8fa56d6ad15621ad4f74667bfd59533408ce16

Modified Files
--------------
src/pl/plpython/plpy_main.c |   81 +++++++++++++++++++++++++++++++++++++------
1 file changed, 71 insertions(+), 10 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Avoid dump/reload problems when using both plpython2 and plpytho
Next
From: Tom Lane
Date:
Subject: pgsql: Use LOAD not actual code execution to pull in plpython library.