From 9324c8c580655800331b0582b770e88c01b7a5c4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 26 Mar 2025 10:59:42 -0400 Subject: Introduce PG_MODULE_MAGIC_EXT macro. This macro allows dynamically loaded shared libraries (modules) to provide a wired-in module name and version, and possibly other compile-time-constant fields in future. This information can be retrieved with the new pg_get_loaded_modules() function. This feature is expected to be particularly useful for modules that do not have any exposed SQL functionality and thus are not associated with a SQL-level extension object. But even for modules that do belong to extensions, being able to verify the actual code version can be useful. Author: Andrei Lepikhov Reviewed-by: Yurii Rashkovskii Reviewed-by: Tom Lane Discussion: https://postgr.es/m/dd4d1b59-d0fe-49d5-b28f-1e463b68fa32@gmail.com --- doc/src/sgml/func.sgml | 22 ++++++++++++++++++++++ doc/src/sgml/xfunc.sgml | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 907c9ef7efa..5bf6656deca 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -25040,6 +25040,28 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n); + + + + pg_get_loaded_modules + + pg_get_loaded_modules () + setof record + ( module_name text, + version text, + file_name text ) + + + Returns a list of the loadable modules that are loaded into the + current server session. The module_name + and version fields are NULL unless the + module author supplied values for them using + the PG_MODULE_MAGIC_EXT macro. + The file_name field gives the file + name of the module (shared library). + + + diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 9f22dacac7d..35d34f224ef 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -1954,6 +1954,9 @@ CREATE FUNCTION square_root(double precision) RETURNS double precision magic block + + PG_MODULE_MAGIC + To ensure that a dynamically loaded object file is not loaded into an @@ -1968,6 +1971,30 @@ CREATE FUNCTION square_root(double precision) RETURNS double precision PG_MODULE_MAGIC; +or + +PG_MODULE_MAGIC_EXT(parameters); + + + + + The PG_MODULE_MAGIC_EXT variant allows the specification + of additional information about the module; currently, a name and/or a + version string can be added. (More fields might be allowed in future.) + Write something like this: + + +PG_MODULE_MAGIC_EXT( + .name = "my_module_name", + .version = "1.2.3" +); + + + Subsequently the name and version can be examined via + the pg_get_loaded_modules() function. + The meaning of the version string is not restricted + by PostgreSQL, but use of semantic versioning + rules is recommended. -- cgit v1.2.3