#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);
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;
}
/*
+ * 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.
*/
file = AllocateFile(PGSP_DUMP_FILE, PG_BINARY_R);
if (file == NULL)
{
- if (errno == ENOENT)
- return; /* ignore not-found error */
+ /* ignore not-found error */
+ if (errno != ENOENT)
+ goto read_error;
+
/* No existing persisted stats file, so we're done */
- goto read_error;
+ if (pfile)
+ FreeFile(pfile);
+ return;
}
buffer_size = plan_size;