From d5c020cfab394adfab20378071ca2a82bf723f14 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi Date: Thu, 25 Nov 2021 09:23:11 +0900 Subject: [PATCH] Make maximum plan length configurable 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 | 11 +++++++++++ pg_store_plans.c | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index 1ee4398..9a49f99 100644 --- a/docs/index.html +++ b/docs/index.html @@ -379,6 +379,17 @@ parameter can only be set at server start. this setting.

+pg_store_plans.max_plan_length + (integer) +
+

pg_store_plans.max_plan_length 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. +

+
+
pg_store_plans.plan_format (enum) diff --git a/pg_store_plans.c b/pg_store_plans.c index 784ee26..3fd8cfe 100644 --- a/pg_store_plans.c +++ b/pg_store_plans.c @@ -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; -- 2.11.0