Re: postgresql custom variable in pg_settings table

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Yi Sun <yinan81(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: postgresql custom variable in pg_settings table
Date: 2024-01-09 14:38:00
Message-ID: CACJufxGo8fVjdeLo4N83gB_2q39Z4x-uGQfRRyX-m=rrsiApHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 9, 2024 at 3:38 PM Yi Sun <yinan81(at)gmail(dot)com> wrote:
>
> Hello,
>
>
>
> But can not select it from pg_settings, as we use pgwatch2 to monitor, to avoid pgwatch2 script change prefer to use pg_setting not current_setting() function, is it possible to get the custom variable from pg_setting please? Thanks

the following minimum c function doing that.
you can use LOAD (https://www.postgresql.org/docs/16/sql-load.html) to
load it, which will make it session persistent.
to make it always persistent, you need to make it in the
shared_preload_libraries.
of course, you can define more Custom Variables.

#include "postgres.h"
#include "funcapi.h"
#include "fmgr.h"
#include "utils/guc.h"
PG_MODULE_MAGIC;
static int test_guc = 2;
void
_PG_init(void)
{
/* Define custom GUC variables. */
DefineCustomIntVariable("patroni.count",
"test .",
"Valid range is 1 .. 11.",
&test_guc,
2,
1,
11,
PGC_USERSET,
0,
NULL,
NULL,
NULL);
MarkGUCPrefixReserved("patroni");
}

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2024-01-09 15:13:28 Re: ERROR: invalid byte sequence for encoding UTF8: 0x00
Previous Message Kiran K V 2024-01-09 12:18:23 ERROR: invalid byte sequence for encoding UTF8: 0x00