mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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 <lepihov@gmail.com> Reviewed-by: Yurii Rashkovskii <yrashk@omnigres.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/dd4d1b59-d0fe-49d5-b28f-1e463b68fa32@gmail.com
This commit is contained in:
@ -25040,6 +25040,28 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n);
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry role="func_table_entry"><para role="func_signature">
|
||||
<indexterm>
|
||||
<primary>pg_get_loaded_modules</primary>
|
||||
</indexterm>
|
||||
<function>pg_get_loaded_modules</function> ()
|
||||
<returnvalue>setof record</returnvalue>
|
||||
( <parameter>module_name</parameter> <type>text</type>,
|
||||
<parameter>version</parameter> <type>text</type>,
|
||||
<parameter>file_name</parameter> <type>text</type> )
|
||||
</para>
|
||||
<para>
|
||||
Returns a list of the loadable modules that are loaded into the
|
||||
current server session. The <parameter>module_name</parameter>
|
||||
and <parameter>version</parameter> fields are NULL unless the
|
||||
module author supplied values for them using
|
||||
the <literal>PG_MODULE_MAGIC_EXT</literal> macro.
|
||||
The <parameter>file_name</parameter> field gives the file
|
||||
name of the module (shared library).
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry role="func_table_entry"><para role="func_signature">
|
||||
<indexterm>
|
||||
|
@ -1954,6 +1954,9 @@ CREATE FUNCTION square_root(double precision) RETURNS double precision
|
||||
<indexterm zone="xfunc-c-dynload">
|
||||
<primary>magic block</primary>
|
||||
</indexterm>
|
||||
<indexterm zone="xfunc-c-dynload">
|
||||
<primary><literal>PG_MODULE_MAGIC</literal></primary>
|
||||
</indexterm>
|
||||
|
||||
<para>
|
||||
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
|
||||
<programlisting>
|
||||
PG_MODULE_MAGIC;
|
||||
</programlisting>
|
||||
or
|
||||
<programlisting>
|
||||
PG_MODULE_MAGIC_EXT(<replaceable>parameters</replaceable>);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The <literal>PG_MODULE_MAGIC_EXT</literal> 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:
|
||||
|
||||
<programlisting>
|
||||
PG_MODULE_MAGIC_EXT(
|
||||
.name = "my_module_name",
|
||||
.version = "1.2.3"
|
||||
);
|
||||
</programlisting>
|
||||
|
||||
Subsequently the name and version can be examined via
|
||||
the <function>pg_get_loaded_modules()</function> function.
|
||||
The meaning of the version string is not restricted
|
||||
by <productname>PostgreSQL</productname>, but use of semantic versioning
|
||||
rules is recommended.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user