pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedNames of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
8+ messages / 4 participants
[nested] [flat]
* Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
@ 2022-10-01 12:05 Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Peter J. Holzer @ 2022-10-01 12:05 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 2022-09-30 17:59:01 -0700, Bryn Llewellyn wrote:
> set rls.tenant_id=42;
This works because there is a "." in the name. Without the "."
PostgreSQL complains:
hjp=> set rls_tenant_id=42;
ERROR: unrecognized configuration parameter "rls_tenant_id"
I think I sort of knew this but had forgotten about it, so checked the
manual for the exact rules. Unfortunately I couldn't find them (I
checked https://www.postgresql.org/docs/14/sql-set.html,
https://www.postgresql.org/docs/14/config-setting.html,
https://www.postgresql.org/docs/14/functions-admin.html#FUNCTIONS-ADMIN-SET,
and browser the table of content and the index).
From the documentation I get the impression that you can only set
existing parameters, not your own.
I therefore suggest adding something like this to the section
"configuration_parameter" in
https://www.postgresql.org/docs/14/sql-set.html:
| In addition, any name including a single dot (".") can be set. This
| allows an application to define its own run-time parameters. Using the
| application name as a prefix reduces the probability of name conflicts
| with other applications or extensions.
(This of course assumes that the behaviour is intentional and not a
bug.)
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
@ 2022-10-01 12:24 ` Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
0 siblings, 1 reply; 8+ messages in thread
From: Julien Rouhaud @ 2022-10-01 12:24 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi,
On Sat, Oct 01, 2022 at 02:05:53PM +0200, Peter J. Holzer wrote:
> On 2022-09-30 17:59:01 -0700, Bryn Llewellyn wrote:
> > set rls.tenant_id=42;
>
> This works because there is a "." in the name. Without the "."
> PostgreSQL complains:
>
> hjp=> set rls_tenant_id=42;
> ERROR: unrecognized configuration parameter "rls_tenant_id"
>
> I think I sort of knew this but had forgotten about it, so checked the
> manual for the exact rules. Unfortunately I couldn't find them (I
> checked https://www.postgresql.org/docs/14/sql-set.html,
> https://www.postgresql.org/docs/14/config-setting.html,
> https://www.postgresql.org/docs/14/functions-admin.html#FUNCTIONS-ADMIN-SET,
> and browser the table of content and the index).
>
> From the documentation I get the impression that you can only set
> existing parameters, not your own.
>
> I therefore suggest adding something like this to the section
> "configuration_parameter" in
> https://www.postgresql.org/docs/14/sql-set.html:
>
> | In addition, any name including a single dot (".") can be set. This
> | allows an application to define its own run-time parameters. Using the
> | application name as a prefix reduces the probability of name conflicts
> | with other applications or extensions.
>
> (This of course assumes that the behaviour is intentional and not a
> bug.)
This is intentional, and documented at
https://www.postgresql.org/docs/14/runtime-config-custom.html.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
@ 2022-10-01 12:42 ` Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 16:12 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Peter J. Holzer @ 2022-10-01 12:42 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 2022-10-01 20:24:21 +0800, Julien Rouhaud wrote:
> On Sat, Oct 01, 2022 at 02:05:53PM +0200, Peter J. Holzer wrote:
> > On 2022-09-30 17:59:01 -0700, Bryn Llewellyn wrote:
> > > set rls.tenant_id=42;
> >
> > This works because there is a "." in the name. Without the "."
> > PostgreSQL complains:
> >
> > hjp=> set rls_tenant_id=42;
> > ERROR: unrecognized configuration parameter "rls_tenant_id"
> >
> > I think I sort of knew this but had forgotten about it, so checked the
> > manual for the exact rules. Unfortunately I couldn't find them
[...]
> > From the documentation I get the impression that you can only set
> > existing parameters, not your own.
> >
> > I therefore suggest adding something like this to the section
> > "configuration_parameter" in
> > https://www.postgresql.org/docs/14/sql-set.html:
> >
[...]
> > (This of course assumes that the behaviour is intentional and not a
> > bug.)
>
> This is intentional, and documented at
> https://www.postgresql.org/docs/14/runtime-config-custom.html.
So it's there but hard to find (I did read the table of contents at
https://www.postgresql.org/docs/14/runtime-config.html but I guess after
all the subchapters about specific configuration parameters I didn't
notice the one generic subchapter near the end).
I think referring to that chapter from
https://www.postgresql.org/docs/14/sql-set.html and possibly other
places would help.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
@ 2022-10-01 16:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-01 18:57 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Bryn Llewellyn <bryn@yugabyte.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2022-10-01 16:12 UTC (permalink / raw)
To: Peter J. Holzer <hjp-pgsql@hjp.at>; +Cc: pgsql-general@lists.postgresql.org
"Peter J. Holzer" <hjp-pgsql@hjp.at> writes:
> On 2022-10-01 20:24:21 +0800, Julien Rouhaud wrote:
>> This is intentional, and documented at
>> https://www.postgresql.org/docs/14/runtime-config-custom.html.
> So it's there but hard to find (I did read the table of contents at
> https://www.postgresql.org/docs/14/runtime-config.html but I guess after
> all the subchapters about specific configuration parameters I didn't
> notice the one generic subchapter near the end).
> I think referring to that chapter from
> https://www.postgresql.org/docs/14/sql-set.html and possibly other
> places would help.
Up to now, there's been an intentional policy of not documenting
this very prominently, because doing so would encourage people
to abuse such variables as application state variables. I say
"abuse" because the code supporting such variables isn't really
designed to support lots of them.
There has been a patch in the works for a long time to provide a
better mechanism for application state variables [1]. Separately,
I did some work recently towards alleviating the performance
problems with lots of custom parameters [2]. It appears from
the discussion in [2] that we're probably going to stick to the
policy of not encouraging use of custom parameters as application
state, although if [1] keeps failing to land maybe that will change?
regards, tom lane
[1] https://www.postgresql.org/message-id/flat/CAFj8pRD053CY_N4=6SvPe7ke6xPbh=K50LUAOwjC3jm8Me9Obg@mail....
[2] https://www.postgresql.org/message-id/flat/2982579.1662416866@sss.pgh.pa.us
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 16:12 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-10-01 18:57 ` Bryn Llewellyn <bryn@yugabyte.com>
2022-10-01 19:19 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Bryn Llewellyn @ 2022-10-01 18:57 UTC (permalink / raw)
To: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>; +Cc: Peter J. Holzer <hjp-pgsql@hjp.at>; pgsql-general list <pgsql-general@lists.postgresql.org>
> tgl@sss.pgh.pa.us wrote:
>
> Up to now, there's been an intentional policy of not documenting
>
> «
> 20.16. Customized Options
> https://www.postgresql.org/docs/14/runtime-config-custom.html <https://www.postgresql.org/docs/14/runtime-config-custom.html;
> »
>
> very prominently[*], because doing so would encourage people to abuse such variables as application state variables. I say "abuse" because the code supporting such variables isn't really designed to support lots of them.
I hinted at a different approach in an earlier turn in this thread:
https://www.postgresql.org/message-id/35254B0B-6501-4CF6-A13F-76D03756C2B2@yugabyte.com
I sketched only how you might handle the case where the session state is just a single value—by using a one-row, one-column temporary table with "on commit delete rows". But the general approach is to use a two column temporary table for key-value pairs. This approach is what the PG doc sketches here:
«
43.13. Porting from Oracle PL/SQL
https://www.postgresql.org/docs/current/plpgsql-porting.html
Since there are no packages, there are no package-level variables either. This is somewhat annoying. You can keep per-session state in temporary tables instead.
»
(That article of faith, "there are no packages and there never, ever will be", saddens me.)
Because PG has no event trigger that fires on session creation (why is this?), I've settled on this optimistic pattern:
begin
insert into pg_temp.flag(val) values(true);
exception when undefined_table then
get stacked diagnostics msg = message_text;
if msg != 'relation "pg_temp.flag" does not exist' then
raise;
else
create temp table pg_temp.flag(val boolean not null) on commit delete rows;
insert into pg_temp.flag(val) values(true);
end if;
end;
The code would need to be more elaborate (and use "upsert") for key-value pairs. But that's easy to do.
Do the experts on this list disapprove of this pattern and prefer (for a future regime) something like the Pavel Stehule scheme that Tom mentioned?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[*] I didn't know that there was a PG doc policy sometimes not to call out a bad practice but, rather, to hide away (in an obscure backwater in the docs) the account of a feature that’s considered to be better avoided except in special cases. This effectively hides it from Google search (and similar) too because of the circular notion that few people find it, and fewer still publish pages that include the link,… and so on.
I suppose that calling the thing an "option" while the doc for the "set" SQL statement uses the term of art "run-time parameter" is another “bad practice admonition by obscurity” notion. (I've referred to the thing as a "user-defined run-time parameter" in informal emails to colleagues. But that is a lot of syllables.)=
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 16:12 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
2022-10-01 18:57 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Bryn Llewellyn <bryn@yugabyte.com>
@ 2022-10-01 19:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-02 05:33 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Bryn Llewellyn <bryn@yugabyte.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2022-10-01 19:19 UTC (permalink / raw)
To: Bryn Llewellyn <bryn@yugabyte.com>; +Cc: Peter J. Holzer <hjp-pgsql@hjp.at>; pgsql-general list <pgsql-general@lists.postgresql.org>
Bryn Llewellyn <bryn@yugabyte.com> writes:
> get stacked diagnostics msg = message_text;
> if msg != 'relation "pg_temp.flag" does not exist' then
This is pretty fragile --- eg, it will fall over with translated
messages. I think you could presume that if the error condition
name is undefined_table then you know what to do.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 16:12 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
2022-10-01 18:57 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Bryn Llewellyn <bryn@yugabyte.com>
2022-10-01 19:19 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-10-02 05:33 ` Bryn Llewellyn <bryn@yugabyte.com>
2022-10-02 06:21 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Bryn Llewellyn @ 2022-10-02 05:33 UTC (permalink / raw)
To: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>; +Cc: Peter J. Holzer <hjp-pgsql@hjp.at>; pgsql-general list <pgsql-general@lists.postgresql.org>
> tgl@sss.pgh.pa.us wrote:
>
>> bryn@yugabyte.com writes:
>>
>> get stacked diagnostics msg = message_text;
>> if msg != 'relation "pg_temp.flag" does not exist' then
>
> This is pretty fragile --- eg, it will fall over with translated messages. I think you could presume that if the error condition name is undefined_table then you know what to do.
Mea culpa. I should have stressed that my code was meant to be a sketch rather than the real thing. So my use of "on commit delete rows" suits the "hard shell paradigm" that I described here:
https://www.postgresql.org/message-id/F0A23614-749D-4A89-84C5-119D4000F9FE@yugabyte.com
where the client code does:
check out connection
call a user-defined API subprogram
release connection
and where I therefore want automatic check-out-duration session state.
In a different use case, I'd want session-duration session state. There. I'd use "on commit preserve rows".
About testing what "message_text" from "get stacked diagnostics msg" returns, yes… of course its sensitivity to the current choice of national language is a non-starter. I don't like to assume more than I have to. So I might say this:
if msg !~ '"pg_temp.flag"' then
But, then again, I might decide that it's just too fussy.
I've seen this pattern in use:
create temp table if not exists pg_temp.flag(val boolean not null) on commit delete rows;
insert into pg_temp.flag(val) values(true);
But doing a DDL before every use of the session-state representation felt heavier than assuming that it's there and creating the table only if it isn't. But I haven't done any timing tests. Is the "create… if not exists" so lightweight when the to-be-created object does exist that I'm fussing over nothing?
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 16:12 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
2022-10-01 18:57 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Bryn Llewellyn <bryn@yugabyte.com>
2022-10-01 19:19 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Tom Lane <tgl@sss.pgh.pa.us>
2022-10-02 05:33 ` Re: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Bryn Llewellyn <bryn@yugabyte.com>
@ 2022-10-02 06:21 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2022-10-02 06:21 UTC (permalink / raw)
To: Bryn Llewellyn <bryn@yugabyte.com>; +Cc: Peter J. Holzer <hjp-pgsql@hjp.at>; pgsql-general list <pgsql-general@lists.postgresql.org>
Bryn Llewellyn <bryn@yugabyte.com> writes:
> I've seen this pattern in use:
> create temp table if not exists pg_temp.flag(val boolean not null) on commit delete rows;
> insert into pg_temp.flag(val) values(true);
> But doing a DDL before every use of the session-state representation felt heavier than assuming that it's there and creating the table only if it isn't. But I haven't done any timing tests. Is the "create… if not exists" so lightweight when the to-be-created object does exist that I'm fussing over nothing?
Fair question. My gut feeling is that the subtransaction created by the
BEGIN ... EXCEPTION construct is more expensive than a no-op CREATE
IF NOT EXISTS. I've not measured it though; and I'm pretty sure that
the answer would vary depending on how often you expect the code to fall
through versus needing to create the table.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2022-10-02 06:21 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-10-01 12:05 Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts) Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 12:24 ` Julien Rouhaud <rjuju123@gmail.com>
2022-10-01 12:42 ` Peter J. Holzer <hjp-pgsql@hjp.at>
2022-10-01 16:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-01 18:57 ` Bryn Llewellyn <bryn@yugabyte.com>
2022-10-01 19:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-02 05:33 ` Bryn Llewellyn <bryn@yugabyte.com>
2022-10-02 06:21 ` Tom Lane <tgl@sss.pgh.pa.us>
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