Skip to content

Commit 0c14f48

Browse files
committed
Add ability to enable/disable extension on the run
1 parent deb89bc commit 0c14f48

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

pg_show_plans.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "postgres.h"
1515
/* Comments just indicate which includes are still in use. */
1616
#include "commands/explain.h" /* To explain statements. */
17+
#include "fmgr.h" /* PG_RETURN_VOID() */
1718
#include "funcapi.h" /* To return sets in SQL funcs. */
1819
#include "lib/stringinfo.h" /* StringInfo */
1920
#include "miscadmin.h" /* process_shared_preload_libraries_in_progress */
@@ -94,10 +95,16 @@ static void pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags);
9495
static void pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
9596
uint64 count, bool execute_once);
9697

98+
/* Enables the extension. */
99+
Datum pg_show_plans_enable(PG_FUNCTION_ARGS);
100+
/* Disables the extension. */
101+
Datum pg_show_plans_disable(PG_FUNCTION_ARGS);
97102
/* Show query plans of all the currently running statements. */
98103
Datum pg_show_plans(PG_FUNCTION_ARGS);
99104

100105
PG_FUNCTION_INFO_V1(pg_show_plans);
106+
PG_FUNCTION_INFO_V1(pg_show_plans_enable);
107+
PG_FUNCTION_INFO_V1(pg_show_plans_disable);
101108

102109
/* Global Variables */
103110
/* Shared extension state. */
@@ -413,6 +420,19 @@ pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
413420
PG_END_TRY();
414421
}
415422

423+
Datum
424+
pg_show_plans_enable(PG_FUNCTION_ARGS)
425+
{
426+
pgsp->is_enabled = true;
427+
PG_RETURN_VOID();
428+
}
429+
430+
Datum
431+
pg_show_plans_disable(PG_FUNCTION_ARGS)
432+
{
433+
pgsp->is_enabled = false;
434+
PG_RETURN_VOID();
435+
}
416436
Datum
417437
pg_show_plans(PG_FUNCTION_ARGS)
418438
{

0 commit comments

Comments
 (0)