简体   繁体   English

Postgresql如何执行PL/Python代码

[英]How is PL/Python code executed by Postgresql

When a PL/Python procedure is executed, the python code is executed by a Python interpreter.当执行 PL/Python 过程时,python 代码由 Python 解释器执行。 My question is, is the Python interpreter running as a separate process, or is it a shared library that gets linked to the calling databases process?我的问题是,Python 解释器是作为单独的进程运行,还是链接到调用数据库进程的共享库?

I'm concerned about what happens when we call something like plpy.execute(...).我担心当我们调用类似 plpy.execute(...) 时会发生什么。 If the python interpreter is running as a separate process I imagine there would be a lot of overhead involved in passing the result of the sql query back to the python interpreter, which would require reading from a file or pipe. If the python interpreter is running as a separate process I imagine there would be a lot of overhead involved in passing the result of the sql query back to the python interpreter, which would require reading from a file or pipe.

The language handler function ( plpython3_call_handler() ) loads the plpython3.so library into the PostgreSQL process, which is linked to libpython3.so .语言处理程序 function ( plpython3_call_handler plpython3_call_handler() ) 将plpython3.so库加载到 PostgreSQL 进程中,该进程链接到libpython3.so So the interpreter is loaded into the backend, it is not executed as a separate process (multiprocessing/multithreading is not allowed in PostgreSQL client backends, with the exception of parallel workers).所以解释器被加载到后端,它不是作为一个单独的进程执行的(PostgreSQL 客户端后端不允许多处理/多线程,并行工作者除外)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM