@@ -89,6 +89,8 @@ static void set_state(const bool state);
8989static const char * show_state (void );
9090/* Set query plan output format: text, json, ... */
9191static void set_format (const int format );
92+ /* Propagate GUC variable value to shared memory (assign hook). */
93+ static void prop_format_to_shmem (int newval , void * extra );
9294static const char * show_format (void );
9395/* Check the extension has been properly loaded. */
9496static inline void shmem_safety_check (void );
@@ -109,11 +111,6 @@ static void pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
109111/* Enables/Disables the extension. */
110112Datum pg_show_plans_enable (PG_FUNCTION_ARGS );
111113Datum pg_show_plans_disable (PG_FUNCTION_ARGS );
112- /* Sets query plan output format. */
113- Datum pgsp_format_text (PG_FUNCTION_ARGS );
114- Datum pgsp_format_json (PG_FUNCTION_ARGS );
115- Datum pgsp_format_yaml (PG_FUNCTION_ARGS );
116- Datum pgsp_format_xml (PG_FUNCTION_ARGS );
117114/* Show query plans of all the currently running statements. */
118115Datum pg_show_plans (PG_FUNCTION_ARGS );
119116
@@ -195,9 +192,9 @@ _PG_init(void)
195192 & plan_format ,
196193 EXPLAIN_FORMAT_TEXT ,
197194 plan_formats ,
198- PGC_POSTMASTER ,
195+ PGC_USERSET ,
199196 0 ,
200- NULL , NULL , show_format );
197+ NULL , prop_format_to_shmem , show_format );
201198
202199 /* Save old hooks, and install new ones. */
203200#if PG_VERSION_NUM >= 150000
@@ -346,11 +343,21 @@ show_state()
346343static void
347344set_format (const int format )
348345{
349- shmem_safety_check ();
350- if (is_allowed_role ())
346+ /* Shared memory may not be fully available at server start, so we do not
347+ * check for pgsp_hash availability here. That is why the following line is
348+ * commented out. */
349+ /* shmem_safety_check(); */
350+
351+ if (pgsp != NULL && is_allowed_role ())
351352 pgsp -> plan_format = format ;
352353}
353354
355+ static void
356+ prop_format_to_shmem (int newval , void * extra )
357+ {
358+ set_format (newval );
359+ }
360+
354361static const char *
355362show_format ()
356363{
@@ -521,34 +528,6 @@ pg_show_plans_disable(PG_FUNCTION_ARGS)
521528 PG_RETURN_VOID ();
522529}
523530
524- Datum
525- pgsp_format_text (PG_FUNCTION_ARGS )
526- {
527- set_format (EXPLAIN_FORMAT_TEXT );
528- PG_RETURN_VOID ();
529- }
530-
531- Datum
532- pgsp_format_json (PG_FUNCTION_ARGS )
533- {
534- set_format (EXPLAIN_FORMAT_JSON );
535- PG_RETURN_VOID ();
536- }
537-
538- Datum
539- pgsp_format_yaml (PG_FUNCTION_ARGS )
540- {
541- set_format (EXPLAIN_FORMAT_YAML );
542- PG_RETURN_VOID ();
543- }
544-
545- Datum
546- pgsp_format_xml (PG_FUNCTION_ARGS )
547- {
548- set_format (EXPLAIN_FORMAT_XML );
549- PG_RETURN_VOID ();
550- }
551-
552531Datum
553532pg_show_plans (PG_FUNCTION_ARGS )
554533{
0 commit comments