OSDN Git Service

Follow new shared memory request convention since PG15
authorKyotaro Horiguchi <horikyota.ntt@gmail.com>
Wed, 30 Nov 2022 08:20:54 +0000 (17:20 +0900)
committerKyotaro Horiguchi <horikyota.ntt@gmail.com>
Wed, 30 Nov 2022 08:20:54 +0000 (17:20 +0900)
The procedure to request shared memory for extensions has been changed
in PG15.  Follow that convention only when the target PG version >=
15.

pg_store_plans.c

index a2fd7bd..e8b0d7c 100644 (file)
@@ -331,6 +331,11 @@ PG_FUNCTION_INFO_V1(pg_store_plans_info);
 #define ROLE_PG_READ_ALL_STATS         DEFAULT_ROLE_READ_ALL_STATS
 #endif
 
+#if PG_VERSION_NUM >= 150000
+static shmem_request_hook_type prev_shmem_request_hook = NULL;
+#endif
+
+static void pgsp_shmem_request(void);
 static void pgsp_shmem_startup(void);
 static void pgsp_shmem_shutdown(int code, Datum arg);
 static void pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags);
@@ -536,17 +541,17 @@ _PG_init(void)
 
        EmitWarningsOnPlaceholders("pg_store_plans");
 
-       /*
-        * Request additional shared resources.  (These are no-ops if we're not in
-        * the postmaster process.)  We'll allocate or attach to the shared
-        * resources in pgsp_shmem_startup().
-        */
-       RequestAddinShmemSpace(shared_mem_size());
-       RequestNamedLWLockTranche("pg_store_plans", 1);
+#if PG_VERSION_NUM < 150000    
+       pgsp_shmem_request();
+#endif
 
        /*
         * Install hooks.
         */
+#if PG_VERSION_NUM >= 150000
+       prev_shmem_request_hook = shmem_request_hook;
+       shmem_request_hook = pgsp_shmem_request;
+#endif
        prev_shmem_startup_hook = shmem_startup_hook;
        shmem_startup_hook = pgsp_shmem_startup;
        prev_ExecutorStart = ExecutorStart_hook;
@@ -577,6 +582,22 @@ _PG_fini(void)
 }
 
 /*
+ * pgsp_shmem_request: request shared memory to the core.
+ * Called as a hook in PG15 or later, otherwise called from _PG_init().
+ */
+static void
+pgsp_shmem_request(void)
+{
+#if PG_VERSION_NUM >= 150000
+       if (prev_shmem_request_hook)
+               prev_shmem_request_hook();
+#endif
+
+       RequestAddinShmemSpace(shared_mem_size());
+       RequestNamedLWLockTranche("pg_store_plans", 1);
+}
+
+/*
  * shmem_startup hook: allocate or attach to shared memory,
  * then load any pre-existing statistics from file.
  */