@@ -85,7 +85,7 @@ static void append_query_plan(ExplainState *es);
8585/* on_shmem_exit() callback to delete hash entry on client disconnect. */
8686static void cleanup (int code , Datum arg );
8787/* Set extension state, either enable or disable. */
88- static void set_state (const bool state );
88+ static void set_state (bool state , void * extra );
8989static const char * show_state (void );
9090/* Set query plan output format: text, json, ... */
9191static void set_format (const int format );
@@ -108,14 +108,9 @@ static void pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags);
108108static void pgsp_ExecutorRun (QueryDesc * queryDesc , ScanDirection direction ,
109109 uint64 count , bool execute_once );
110110
111- /* Enables/Disables the extension. */
112- Datum pg_show_plans_enable (PG_FUNCTION_ARGS );
113- Datum pg_show_plans_disable (PG_FUNCTION_ARGS );
114111/* Show query plans of all the currently running statements. */
115112Datum pg_show_plans (PG_FUNCTION_ARGS );
116113
117- PG_FUNCTION_INFO_V1 (pg_show_plans_enable );
118- PG_FUNCTION_INFO_V1 (pg_show_plans_disable );
119114PG_FUNCTION_INFO_V1 (pg_show_plans );
120115
121116/* Global Variables */
@@ -164,9 +159,9 @@ _PG_init(void)
164159 NULL ,
165160 & start_enabled ,
166161 true,
167- PGC_POSTMASTER ,
162+ PGC_USERSET ,
168163 0 ,
169- NULL , NULL , show_state );
164+ NULL , set_state , show_state );
170165 DefineCustomIntVariable ("pg_show_plans.max_plan_length" ,
171166 gettext_noop ("Set the maximum plan length. "
172167 "Note that this module allocates (max_plan_length*max_connections) "
@@ -318,10 +313,14 @@ cleanup(int code, Datum arg)
318313}
319314
320315static void
321- set_state (const bool state )
316+ set_state (bool state , void * extra )
322317{
323- shmem_safety_check ();
324- if (is_allowed_role ())
318+ /* Shared memory may not be fully available at server start, so we do not
319+ * check for pgsp_hash availability here. That is why the following line is
320+ * commented out. */
321+ /* shmem_safety_check(); */
322+
323+ if (pgsp != NULL && is_allowed_role ())
325324 pgsp -> is_enabled = state ;
326325}
327326
@@ -510,20 +509,6 @@ pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
510509 PG_END_TRY ();
511510}
512511
513- Datum
514- pg_show_plans_enable (PG_FUNCTION_ARGS )
515- {
516- set_state (true);
517- PG_RETURN_VOID ();
518- }
519-
520- Datum
521- pg_show_plans_disable (PG_FUNCTION_ARGS )
522- {
523- set_state (false);
524- PG_RETURN_VOID ();
525- }
526-
527512Datum
528513pg_show_plans (PG_FUNCTION_ARGS )
529514{
0 commit comments