Scenario:
Example of such functions can be seen in my other question: Python function hangs when called from within sql function
My assumptions (what this seems like to me):
If these assumptions are wrong, please also correct me and explain. Or even point me to documentation where this can be found, I have not succeeded in finding it yet.
PG server stores both the python function (step 1) code and plpythonu code somewhere at first compilation, where ?
The Python code for the pl/python function its self (but not any modules, libraries, etc) is stored in the pg_proc
table in the database.
The compiled Python bytecode gets stored in the syscache in memory when it's first run by a given backend. It isn't updated after that if files on disk change. New connections will see the new code, old connections the existing code.