OSDN Git Service

Make maximum plan length configurable
authorKyotaro Horiguchi <horikyota.ntt@gmail.com>
Thu, 25 Nov 2021 00:23:11 +0000 (09:23 +0900)
committerKyotaro Horiguchi <horikyota.ntt@gmail.com>
Thu, 25 Nov 2021 10:37:02 +0000 (19:37 +0900)
The maximum length of plan texts was not configurable. However, it is
apparently intended to be configurable.  Let's complete that work now.

docs/index.html
pg_store_plans.c

index 1ee4398..9a49f99 100644 (file)
@@ -379,6 +379,17 @@ parameter can only be set at server start.
       this setting.
      </P>
 </DD>
+<TT CLASS="VARNAME">pg_store_plans.max_plan_length</TT>
+  (<TT CLASS="TYPE">integer</TT>)</DT>
+<DD>
+<P> <TT CLASS="VARNAME">pg_store_plans.max_plan_length</TT> is the
+maximum byte length of plans in the raw (shortened JSON) format to
+store.  The plan text is truncated at the length if it is longer than
+that value. The default value is 5000.  This parameter can only be set
+at server start.
+</P>
+</DD>
+<DT>
 <DT>
 <TT CLASS="VARNAME">pg_store_plans.plan_format</TT>
  (<TT CLASS="TYPE">enum</TT>)
index 784ee26..3fd8cfe 100644 (file)
@@ -63,7 +63,7 @@ PG_MODULE_MAGIC;
 
 /* This constant defines the magic number in the stats file header */
 static const uint32 PGSP_FILE_HEADER = 0x20180613;
-static const uint32 store_plan_size = 5000;
+static int max_plan_len = 5000;
 
 /* XXX: Should USAGE_EXEC reflect execution time and/or buffer usage? */
 #define USAGE_EXEC(duration)   (1.0)
@@ -317,6 +317,19 @@ _PG_init(void)
                                                        NULL,
                                                        NULL);
 
+       DefineCustomIntVariable("pg_store_plans.max_plan_length",
+         "Sets the maximum length of plans stored by pg_store_plans.",
+                                                       NULL,
+                                                       &max_plan_len,
+                                                       5000,
+                                                       100,
+                                                       INT32_MAX,
+                                                       PGC_POSTMASTER,
+                                                       0,
+                                                       NULL,
+                                                       NULL,
+                                                       NULL);
+
        DefineCustomEnumVariable("pg_store_plans.track",
                           "Selects which plans are tracked by pg_store_plans.",
                                                         NULL,
@@ -499,7 +512,7 @@ pgsp_shmem_startup(void)
        {
                /* First time through ... */
                shared_state->lock = &(GetNamedLWLockTranche("pg_store_plans"))->lock;
-               shared_state->plan_size = store_plan_size;
+               shared_state->plan_size = max_plan_len;
                shared_state->cur_median_usage = ASSUMED_MEDIAN_INIT;
        }
 
@@ -1234,7 +1247,7 @@ shared_mem_size(void)
        Size            entrysize;
 
        size = MAXALIGN(sizeof(pgspSharedState));
-       entrysize = offsetof(pgspEntry, plan) +  store_plan_size;
+       entrysize = offsetof(pgspEntry, plan) + max_plan_len;
        size = add_size(size, hash_estimate_size(store_size, entrysize));
 
        return size;