File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ static void cleanup(int code, Datum arg);
8888static void set_state (const bool state );
8989/* Set query plan output format: text, json, ... */
9090static void set_format (const int format );
91+ /* Check the extension has been properly loaded. */
92+ static inline void shmem_safety_check (void );
9193/* Check whether the user has required privileges. */
9294static bool is_allowed_role (void );
9395/* Hook functions. */
@@ -324,17 +326,31 @@ void cleanup(int code, Datum arg)
324326void
325327set_state (const bool state )
326328{
329+ shmem_safety_check ();
327330 if (is_allowed_role ())
328331 pgsp -> is_enabled = state ;
329332}
330333
331334void
332335set_format (const int format )
333336{
337+ shmem_safety_check ();
334338 if (is_allowed_role ())
335339 pgsp -> plan_format = format ;
336340}
337341
342+ inline void
343+ shmem_safety_check (void )
344+ {
345+ if (pgsp && pgsp_hash )
346+ return ;
347+
348+ ereport (ERROR ,
349+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
350+ errmsg ("pg_show_plans must be loaded"
351+ "via shared_preload_libraries" )));
352+ }
353+
338354bool
339355is_allowed_role (void )
340356{
@@ -520,6 +536,8 @@ pg_show_plans(PG_FUNCTION_ARGS)
520536 int curr_nest ;
521537 bool is_done ;
522538
539+ shmem_safety_check ();
540+
523541 if (SRF_IS_FIRSTCALL ())
524542 {
525543 MemoryContext oldcontext ;
You can’t perform that action at this time.
0 commit comments