Skip to content

Commit efe7a5d

Browse files
committed
Merge branch 'master' of github.com:okbob/plpgsql_check
2 parents 48648b6 + 83cf31f commit efe7a5d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/plpgsql_check.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ void _PG_fini(void);
9292

9393
#endif
9494

95+
#if PG_VERSION_NUM >= 150000
96+
shmem_request_hook_type prev_shmem_request_hook = NULL;
97+
#endif
9598
shmem_startup_hook_type prev_shmem_startup_hook = NULL;
9699

97100
bool plpgsql_check_regress_test_mode;
@@ -305,14 +308,25 @@ _PG_init(void)
305308
PGC_POSTMASTER, 0,
306309
NULL, NULL, NULL);
307310

311+
#if PG_VERSION_NUM < 150000
312+
/*
313+
* If you change code here, don't forget to also report the
314+
* modifications in plpgsql_check_profiler_shmem_request() for pg15 and
315+
* later.
316+
*/
308317
RequestAddinShmemSpace(plpgsql_check_shmem_size());
309318

310319
RequestNamedLWLockTranche("plpgsql_check profiler", 1);
311320
RequestNamedLWLockTranche("plpgsql_check fstats", 1);
321+
#endif
312322

313323
/*
314324
* Install hooks.
315325
*/
326+
#if PG_VERSION_NUM >= 150000
327+
prev_shmem_startup_hook = shmem_request_hook;
328+
shmem_request_hook = plpgsql_check_profiler_shmem_request;
329+
#endif
316330
prev_shmem_startup_hook = shmem_startup_hook;
317331
shmem_startup_hook = plpgsql_check_profiler_shmem_startup;
318332
}
@@ -334,6 +348,9 @@ _PG_init(void)
334348
void
335349
_PG_fini(void)
336350
{
351+
#if PG_VERSION_NUM >= 150000
352+
shmem_request_hook = prev_shmem_request_hook;
353+
#endif
337354
shmem_startup_hook = prev_shmem_startup_hook;
338355

339356
/* Be more correct, and clean rendezvous variable */
@@ -343,4 +360,4 @@ _PG_fini(void)
343360
fmgr_hook = plpgsql_check_next_fmgr_hook;
344361
}
345362

346-
#endif
363+
#endif

src/plpgsql_check.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ extern int plpgsql_check_profiler_max_shared_chunks;
321321
extern needs_fmgr_hook_type plpgsql_check_next_needs_fmgr_hook;
322322
extern fmgr_hook_type plpgsql_check_next_fmgr_hook;
323323

324+
#if PG_VERSION_NUM >= 150000
325+
extern void plpgsql_check_profiler_shmem_request(void);
326+
#endif
324327
extern void plpgsql_check_profiler_shmem_startup(void);
325328

326329
extern Size plpgsql_check_shmem_size(void);
@@ -386,6 +389,9 @@ extern bool plpgsql_check_runtime_pragma_vector_changed;
386389
* functions from plpgsql_check.c
387390
*/
388391

392+
#if PG_VERSION_NUM >= 150000
393+
extern shmem_request_hook_type prev_shmem_request_hook;
394+
#endif
389395
extern shmem_startup_hook_type prev_shmem_startup_hook;
390396

391397
extern PLpgSQL_plugin **plpgsql_check_plugin_var_ptr;

src/profiler.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,26 @@ plpgsql_check_shmem_size(void)
606606
return num_bytes;
607607
}
608608

609+
/*
610+
* Request additional shared memory resources.
611+
*
612+
* If you change code here, don't forget to also report the modifications in
613+
* _PG_init() for pg14 and below.
614+
*/
615+
#if PG_VERSION_NUM >= 150000
616+
void
617+
plpgsql_check_profiler_shmem_request(void)
618+
{
619+
if (prev_shmem_request_hook)
620+
prev_shmem_request_hook();
621+
622+
RequestAddinShmemSpace(plpgsql_check_shmem_size());
623+
624+
RequestNamedLWLockTranche("plpgsql_check profiler", 1);
625+
RequestNamedLWLockTranche("plpgsql_check fstats", 1);
626+
}
627+
#endif
628+
609629
/*
610630
* Initialize shared memory used like permanent profile storage.
611631
* No other parts use shared memory, so this code is completly here.

0 commit comments

Comments
 (0)