2121#include "storage/spin.h"
2222#include "utils/memutils.h"
2323#include "utils/resowner.h"
24+ #include "pgstat.h"
2425
2526#include "pg_wait_sampling.h"
2627
2728static volatile sig_atomic_t shutdown_requested = false;
2829
2930static void handle_sigterm (SIGNAL_ARGS );
30- static void collector_main (Datum main_arg );
3131
3232/*
3333 * Register background worker for collecting waits history.
@@ -41,8 +41,13 @@ register_wait_collector(void)
4141 worker .bgw_flags = BGWORKER_SHMEM_ACCESS ;
4242 worker .bgw_start_time = BgWorkerStart_ConsistentState ;
4343 worker .bgw_restart_time = 0 ;
44- worker .bgw_main = collector_main ;
4544 worker .bgw_notify_pid = 0 ;
45+ #if PG_VERSION_NUM >= 100000
46+ memcpy (worker .bgw_library_name , "pg_wait_sampling" , BGW_MAXLEN );
47+ memcpy (worker .bgw_function_name , CppAsString (collector_main ), BGW_MAXLEN );
48+ #else
49+ worker .bgw_main = collector_main ;
50+ #endif
4651 snprintf (worker .bgw_name , BGW_MAXLEN , "pg_wait_sampling collector" );
4752 worker .bgw_main_arg = (Datum )0 ;
4853 RegisterBackgroundWorker (& worker );
@@ -263,7 +268,7 @@ millisecs_diff(TimestampTz tz1, TimestampTz tz2)
263268/*
264269 * Main routine of wait history collector.
265270 */
266- static void
271+ void
267272collector_main (Datum main_arg )
268273{
269274 HTAB * profile_hash = NULL ;
@@ -351,9 +356,15 @@ collector_main(Datum main_arg)
351356 * Wait until next sample time or request to do something through
352357 * shared memory.
353358 */
359+ #if PG_VERSION_NUM >= 100000
360+ rc = WaitLatch (& MyProc -> procLatch , WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH ,
361+ Min (history_period - (int )history_diff ,
362+ profile_period - (int )profile_diff ), PG_WAIT_EXTENSION );
363+ #else
354364 rc = WaitLatch (& MyProc -> procLatch , WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH ,
355365 Min (history_period - (int )history_diff ,
356366 profile_period - (int )profile_diff ));
367+ #endif
357368
358369 if (rc & WL_POSTMASTER_DEATH )
359370 proc_exit (1 );
0 commit comments