diff --git a/src/plpgsql_check.c b/src/plpgsql_check.c index e839a70..c5a53dd 100644 --- a/src/plpgsql_check.c +++ b/src/plpgsql_check.c @@ -92,6 +92,9 @@ void _PG_fini(void); #endif +#if PG_VERSION_NUM >= 150000 +shmem_request_hook_type prev_shmem_request_hook = NULL; +#endif shmem_startup_hook_type prev_shmem_startup_hook = NULL; bool plpgsql_check_regress_test_mode; @@ -305,14 +308,25 @@ _PG_init(void) PGC_POSTMASTER, 0, NULL, NULL, NULL); +#if PG_VERSION_NUM < 150000 + /* + * If you change code here, don't forget to also report the + * modifications in plpgsql_check_profiler_shmem_request() for pg15 and + * later. + */ RequestAddinShmemSpace(plpgsql_check_shmem_size()); RequestNamedLWLockTranche("plpgsql_check profiler", 1); RequestNamedLWLockTranche("plpgsql_check fstats", 1); +#endif /* * Install hooks. */ +#if PG_VERSION_NUM >= 150000 + prev_shmem_startup_hook = shmem_request_hook; + shmem_request_hook = plpgsql_check_profiler_shmem_request; +#endif prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = plpgsql_check_profiler_shmem_startup; } @@ -334,6 +348,9 @@ _PG_init(void) void _PG_fini(void) { +#if PG_VERSION_NUM >= 150000 + shmem_request_hook = prev_shmem_request_hook; +#endif shmem_startup_hook = prev_shmem_startup_hook; /* Be more correct, and clean rendezvous variable */ @@ -343,4 +360,4 @@ _PG_fini(void) fmgr_hook = plpgsql_check_next_fmgr_hook; } -#endif \ No newline at end of file +#endif diff --git a/src/plpgsql_check.h b/src/plpgsql_check.h index cee4a34..2938a68 100644 --- a/src/plpgsql_check.h +++ b/src/plpgsql_check.h @@ -321,6 +321,9 @@ extern int plpgsql_check_profiler_max_shared_chunks; extern needs_fmgr_hook_type plpgsql_check_next_needs_fmgr_hook; extern fmgr_hook_type plpgsql_check_next_fmgr_hook; +#if PG_VERSION_NUM >= 150000 +extern void plpgsql_check_profiler_shmem_request(void); +#endif extern void plpgsql_check_profiler_shmem_startup(void); extern Size plpgsql_check_shmem_size(void); @@ -386,6 +389,9 @@ extern bool plpgsql_check_runtime_pragma_vector_changed; * functions from plpgsql_check.c */ +#if PG_VERSION_NUM >= 150000 +extern shmem_request_hook_type prev_shmem_request_hook; +#endif extern shmem_startup_hook_type prev_shmem_startup_hook; extern PLpgSQL_plugin **plpgsql_check_plugin_var_ptr; diff --git a/src/profiler.c b/src/profiler.c index 73eac14..e710745 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -606,6 +606,26 @@ plpgsql_check_shmem_size(void) return num_bytes; } +/* + * Request additional shared memory resources. + * + * If you change code here, don't forget to also report the modifications in + * _PG_init() for pg14 and below. + */ +#if PG_VERSION_NUM >= 150000 +void +plpgsql_check_profiler_shmem_request(void) +{ + if (prev_shmem_request_hook) + prev_shmem_request_hook(); + + RequestAddinShmemSpace(plpgsql_check_shmem_size()); + + RequestNamedLWLockTranche("plpgsql_check profiler", 1); + RequestNamedLWLockTranche("plpgsql_check fstats", 1); +} +#endif + /* * Initialize shared memory used like permanent profile storage. * No other parts use shared memory, so this code is completly here.