PostgreSQL dynamic update C language function

PostgreSQL loads functions written in C language (including other languages ​​compatible with C language, such as C++, Rust, etc.) dynamically. After the function is CREATE FUNCTIONcreated , it will not be loaded immediately. It is loaded only when it is called for the first time, and it is loaded into the memory of the session process. At this time, even if we delete the .so file, if the function has been called once before the session, the client can continue to call the function.

If we rewrite the function code, regenerate the .so file, and overwrite the old version of the .so file with the new .so file, if we call the function in an existing session, sometimes the function version error "ERROR unrecognized" will be reported. function API version, sql status: XX000"; sometimes it is more serious, which will cause Segment Fault of the process of the current session, causing the entire PostgreSQL to crash and restart. At this time, even if it is used CREATE OR REPLACE FUNCTIONto reload the function, it will cause PostgreSQL to restart.

The only feasible solution is to version the .so file, add a version number to each compiled .so file, each version of the file is different, copy the new version of the file to PKGLIBDIR, and then CREATE OR REPLACE FUNCTIONreplace old version with function, so even if it is called in an established session, it will call the new version of the function. Older versions of .so files can also be deleted.

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324132986&siteId=291194637