diff options
author | Michael Paquier <michael@paquier.xyz> | 2023-07-31 17:09:24 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2023-07-31 17:09:24 +0900 |
commit | c9af054653077699189884c336a65e23a7c8aebb (patch) | |
tree | 7c58a0dc246c3b432f6169236db0cc1688e63e92 /doc/src | |
parent | 39055cb4ccd5b521ceb802b6a8194de912a422cc (diff) | |
download | postgresql-c9af054653077699189884c336a65e23a7c8aebb.tar.gz postgresql-c9af054653077699189884c336a65e23a7c8aebb.zip |
Support custom wait events for wait event type "Extension"
Two backend routines are added to allow extension to allocate and define
custom wait events, all of these being allocated in the type
"Extension":
* WaitEventExtensionNew(), that allocates a wait event ID computed from
a counter in shared memory.
* WaitEventExtensionRegisterName(), to associate a custom string to the
wait event ID allocated.
Note that this includes an example of how to use this new facility in
worker_spi with tests in TAP for various scenarios, and some
documentation about how to use them.
Any code in the tree that currently uses WAIT_EVENT_EXTENSION could
switch to this new facility to define custom wait events. This is left
as work for future patches.
Author: Masahiro Ikeda
Reviewed-by: Andres Freund, Michael Paquier, Tristan Partin, Bharath
Rupireddy
Discussion: https://postgr.es/m/b9f5411acda0cf15c8fbb767702ff43e@oss.nttdata.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/monitoring.sgml | 11 | ||||
-rw-r--r-- | doc/src/sgml/xfunc.sgml | 45 |
2 files changed, 52 insertions, 4 deletions
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 588b720f57e..f4fc5d814fb 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -1117,11 +1117,14 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i <note> <para> - Extensions can add <literal>LWLock</literal> types to the list shown in - <xref linkend="wait-event-lwlock-table"/>. In some cases, the name + Extensions can add <literal>Extension</literal> and + <literal>LWLock</literal> types + to the list shown in <xref linkend="wait-event-extension-table"/> and + <xref linkend="wait-event-lwlock-table"/>. In some cases, the name assigned by an extension will not be available in all server processes; - so an <literal>LWLock</literal> wait event might be reported as - just <quote><literal>extension</literal></quote> rather than the + so an <literal>Extension</literal> or <literal>LWLock</literal> wait + event might be reported as just + <quote><literal>extension</literal></quote> rather than the extension-assigned name. </para> </note> diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 9620ea9ae38..d6345a775b6 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -3453,6 +3453,51 @@ if (!ptr) </para> </sect2> + <sect2 id="xfunc-addin-wait-events"> + <title>Shared Memory and Custom Wait Events</title> + + <para> + Add-ins can define custom wait events under the wait event type + <literal>Extension</literal>. The add-in's shared library must be + preloaded by specifying it in <literal>shared_preload_libraries</literal>, + and register a <literal>shmem_request_hook</literal> and a + <literal>shmem_startup_hook</literal> in its + <function>_PG_init</function> function. + <literal>shmem_request_hook</literal> can request a shared memory size + to be later used at startup by calling: +<programlisting> +void RequestAddinShmemSpace(int size) +</programlisting> + </para> + <para> + <literal>shmem_startup_hook</literal> can allocate in shared memory + custom wait events by calling while holding the LWLock + <function>AddinShmemInitLock</function> to avoid any race conditions: +<programlisting> +uint32 WaitEventExtensionNew(void) +</programlisting> + Next, each process needs to associate the wait event allocated previously + to a user-facing custom string, which is something done by calling: +<programlisting> +void WaitEventExtensionRegisterName(uint32 wait_event_info, const char *wait_event_name) +</programlisting> + An example can be found in <filename>src/test/modules/worker_spi</filename> + in the PostgreSQL source tree. + </para> + <para> + Custom wait events can be viewed in + <link linkend="monitoring-pg-stat-activity-view"><structname>pg_stat_activity</structname></link>: +<screen> +=# SELECT wait_event_type, wait_event FROM pg_stat_activity + WHERE backend_type ~ 'worker_spi'; + wait_event_type | wait_event +-----------------+----------------- + Extension | worker_spi_main +(1 row) +</screen> + </para> + </sect2> + <sect2 id="extend-cpp"> <title>Using C++ for Extensibility</title> |