pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
postgresql custom variable in pg_settings table
3+ messages / 3 participants
[nested] [flat]

* postgresql custom variable in pg_settings table
@ 2024-01-09 07:38 Yi Sun <yinan81@gmail.com>
  2024-01-09 08:18 ` Re: postgresql custom variable in pg_settings table Achilleas Mantzios - cloud <a.mantzios@cloud.gatewaynet.com>
  2024-01-09 14:38 ` Re: postgresql custom variable in pg_settings table jian he <jian.universality@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Yi Sun @ 2024-01-09 07:38 UTC (permalink / raw)
  To: PostgreSQL General <pgsql-general@lists.postgresql.org>

Hello,

We custom set variable

Added patroni.nodes_count = 2 in postgresql.conf

postgres=# show patroni.nodes_count;
 patroni.nodes_count
---------------------
 2
(1 row)

postgres=# select current_setting('patroni.nodes_count');
 current_setting
-----------------
 2
(1 row)

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

Best Regards
SY

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: postgresql custom variable in pg_settings table
  2024-01-09 07:38 postgresql custom variable in pg_settings table Yi Sun <yinan81@gmail.com>
@ 2024-01-09 08:18 ` Achilleas Mantzios - cloud <a.mantzios@cloud.gatewaynet.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Achilleas Mantzios - cloud @ 2024-01-09 08:18 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 1/9/24 09:38, Yi Sun wrote:

> Hello,
>
> We custom set variable
>
> Added patroni.nodes_count = 2 in postgresql.conf
>
> postgres=# show patroni.nodes_count;
>  patroni.nodes_count
> ---------------------
>  2
> (1 row)
>
> postgres=# select current_setting('patroni.nodes_count');
>  current_setting
> -----------------
>  2
> (1 row)
>
> 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

You may look into pg_file_settings :

select setting from pg_file_settings  where name = 'patroni.nodes_count';

>
> Best Regards
> SY

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: postgresql custom variable in pg_settings table
  2024-01-09 07:38 postgresql custom variable in pg_settings table Yi Sun <yinan81@gmail.com>
@ 2024-01-09 14:38 ` jian he <jian.universality@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: jian he @ 2024-01-09 14:38 UTC (permalink / raw)
  To: Yi Sun <yinan81@gmail.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Tue, Jan 9, 2024 at 3:38 PM Yi Sun <yinan81@gmail.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");
}





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2024-01-09 14:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 07:38 postgresql custom variable in pg_settings table Yi Sun <yinan81@gmail.com>
2024-01-09 08:18 ` Achilleas Mantzios - cloud <a.mantzios@cloud.gatewaynet.com>
2024-01-09 14:38 ` jian he <jian.universality@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox