shmem_request_hook

A hook for requesting additional shared memory

shmem_request_hook is a hook for extensions loaded into memory which request additional shared memory.

shmem_request_hook was added in PostgreSQL 15.

Change history

Examples

Usage example for shmem_request_hook:

/*
 * Module load callback
 */
void
_PG_init(void)
{
        if (!process_shared_preload_libraries_in_progress)
                return;

	/*
         * Install hooks.
         */
#if (PG_VERSION_NUM >= 150000)
        prev_shmem_request_hook = shmem_request_hook;
        shmem_request_hook = extension_shmem_request;
#endif

        prev_shmem_startup_hook = shmem_startup_hook;
        shmem_startup_hook = extension_shmem_startup;

        /* ... */
}

#if (PG_VERSION_NUM >= 150000)
/*
 * shmem_requst_hook: request shared memory
 */
static void
extension_shmem_request(void)
{
        if (prev_shmem_request_hook)
                prev_shmem_request_hook();

        RequestAddinShmemSpace(MAXALIGN(sizeof(extensionSharedState)));

        RequestNamedLWLockTranche(TRANCHE_NAME, 1);
}
#endif

Categories

Extension, Hooks, Memory