pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #15646: Inconsistent behavior for current_setting/set_config
9+ messages / 6 participants
[nested] [flat]
* BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-20 16:10 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 9+ messages in thread
From: PG Bug reporting form @ 2019-02-20 16:10 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: kes-kes@yandex.ru
The following bug has been logged on the website:
Bug reference: 15646
Logged by: Eugen Konkov
Email address: kes-kes@yandex.ru
PostgreSQL version: 10.4
Operating system: (Debian 10.4-2.pgdg90+1)
Description:
Hi.
[documentation](https://www.postgresql.org/docs/11/functions-admin.html#FUNCTIONS-ADMIN-SET)
describes that:
>set_config sets the parameter setting_name to new_value. If is_local is
true, the new value will only apply to the current transaction.
Thus if I rollback transaction original value should be available.
But current behavior returns empty string instead of NULL (the initial
value) after transaction is rolled back. When I restart session, NULL is
returned again as it is expected.
( I expect NULL just because 'my.app_period' is not configuration variable
is not defined yet. The documentation (link provided above) does not cover
what should be returned)
How to reproduce steps:
$ make dbshell
psql -h databases -p 5433 -U tucha tucha ||:
psql (11.1 (Ubuntu 11.1-1.pgdg16.04+1), server 10.4 (Debian
10.4-2.pgdg90+1))
Type "help" for help.
We start a new session and check setting value before transaction. It is
NULL:
tucha=> select current_setting( 'my.app_period', true ) is null;
?column?
----------
t
(1 row)
We start transaction and change the setting value:
tucha=> begin;
BEGIN
tucha=> select set_config( 'my.app_period', 'some value', true );
set_config
------------
some value
(1 row)
We can see that value is changed. It is NOT NULL:
tucha=> select current_setting( 'my.app_period', true ) is null;
?column?
----------
f
(1 row)
tucha=> select current_setting( 'my.app_period', true );
current_setting
-----------------
some value
(1 row)
Here I finish transaction (it has no matter how: commit/rollback):
tucha=> rollback;
ROLLBACK
Here we can see that setting value is different from value that was before
transaction
tucha=> select current_setting( 'my.app_period', true ) is null;
?column?
----------
f
(1 row)
tucha=> \q
When I restart session I get NULL again (as expected):
kes@work ~/t $ make dbshell
psql -h databases -p 5433 -U tucha tucha ||:
psql (11.1 (Ubuntu 11.1-1.pgdg16.04+1), server 10.4 (Debian
10.4-2.pgdg90+1))
Type "help" for help.
tucha=> select current_setting( 'my.app_period', true ) is null;
?column?
----------
t
(1 row)
My database version:
tucha=> select version();
version
------------------------------------------------------------------------------------------
PostgreSQL 10.4 (Debian 10.4-2.pgdg90+1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian
(1 row)
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-20 17:01 Joe Conway <mail@joeconway.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 9+ messages in thread
From: Joe Conway @ 2019-02-20 17:01 UTC (permalink / raw)
To: kes-kes@yandex.ru, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@postgresql.org>
On 2/20/19 11:10 AM, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference: 15646
> Logged by: Eugen Konkov
> Email address: kes-kes@yandex.ru
> PostgreSQL version: 10.4
> Operating system: (Debian 10.4-2.pgdg90+1)
> Description:
>
> Hi.
>
> [documentation](https://www.postgresql.org/docs/11/functions-admin.html#FUNCTIONS-ADMIN-SET)
> describes that:
>
>>set_config sets the parameter setting_name to new_value. If is_local is
> true, the new value will only apply to the current transaction.
>
> Thus if I rollback transaction original value should be available.
>
> But current behavior returns empty string instead of NULL (the initial
> value) after transaction is rolled back. When I restart session, NULL is
> returned again as it is expected.
This has been discussed before and dismissed:
https://www.postgresql.org/message-id/flat/56842412.5000005%40joeconway.com
Personally I agree it is a bug, but I am not sure you will get much
support for that position.
Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-20 17:11 Tom Lane <tgl@sss.pgh.pa.us>
parent: Joe Conway <mail@joeconway.com>
0 siblings, 2 replies; 9+ messages in thread
From: Tom Lane @ 2019-02-20 17:11 UTC (permalink / raw)
To: Joe Conway <mail@joeconway.com>; +Cc: kes-kes@yandex.ru; pgsql-bugs@lists.postgresql.org
Joe Conway <mail@joeconway.com> writes:
> On 2/20/19 11:10 AM, PG Bug reporting form wrote:
>> But current behavior returns empty string instead of NULL (the initial
>> value) after transaction is rolled back. When I restart session, NULL is
>> returned again as it is expected.
> This has been discussed before and dismissed:
> https://www.postgresql.org/message-id/flat/56842412.5000005%40joeconway.com
> Personally I agree it is a bug, but I am not sure you will get much
> support for that position.
The fact that we allow undeclared user-defined GUCs at all is a bug IMO.
We need to find a way to replace that behavior with something whereby
the name and type of a parameter are declared up-front before you can
set it.
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-20 17:32 David G. Johnston <david.g.johnston@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 9+ messages in thread
From: David G. Johnston @ 2019-02-20 17:32 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Joe Conway <mail@joeconway.com>; KES <kes-kes@yandex.ru>; pgsql-bugs@lists.postgresql.org
On Wed, Feb 20, 2019 at 10:11 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Joe Conway <mail@joeconway.com> writes:
> > On 2/20/19 11:10 AM, PG Bug reporting form wrote:
> >> But current behavior returns empty string instead of NULL (the initial
> >> value) after transaction is rolled back. When I restart session, NULL is
> >> returned again as it is expected.
>
> > This has been discussed before and dismissed:
> > https://www.postgresql.org/message-id/flat/56842412.5000005%40joeconway.com
> > Personally I agree it is a bug, but I am not sure you will get much
> > support for that position.
>
> The fact that we allow undeclared user-defined GUCs at all is a bug IMO.
> We need to find a way to replace that behavior with something whereby
> the name and type of a parameter are declared up-front before you can
> set it.
We should at least document the existing working-as-intended behavior
then. This, the linked thread, and Bug # 14877 are all caused by
insufficient documentation of the current behavior. Users should be
informed that as far as the GUC system is concerned NULL and the empty
string are equivalent and that resetting uses the empty string while
never being set returns NULL.
Its immaterial whether its existence is due to a bug that simply
became acceptable or was an otherwise retrospectively poor design
decision - at this point we have to live with it and should treat it
as a proper and supported feature, if only in its current form. At
least until someone feels strongly enough to deprecate it and put
something else more suitable in its place.
David J.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-20 18:06 Jerry Sievert <jerry@legitimatesounding.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Jerry Sievert @ 2019-02-20 18:06 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Joe Conway <mail@joeconway.com>; KES <kes-kes@yandex.ru>; pgsql-bugs@lists.postgresql.org
Hi,
> On Feb 20, 2019, at 9:32 AM, David G. Johnston <david.g.johnston@gmail.com> wrote:
> Users should be
> informed that as far as the GUC system is concerned NULL and the empty
> string are equivalent and that resetting uses the empty string while
> never being set returns NULL.
>
Except that it’s not - the code path in guc.c uses what is passed as the boot value:
var->boot_val <https://doxygen.postgresql.org/structconfig__string.html#ad6895b2d95aa9e5c3ff2169d7fe2bc20; = bootValue;
It’s up to the extension developer to understand that this can be changed back to something other than the boot value and not actually be the boot value - you can see this assumption being made in plpgsql, pltcl, and plperl. The GUC system makes no notification that the two are equivalent, neither in code nor in documentation.
> Its immaterial whether its existence is due to a bug that simply
> became acceptable or was an otherwise retrospectively poor design
> decision - at this point we have to live with it and should treat it
> as a proper and supported feature, if only in its current form. At
> least until someone feels strongly enough to deprecate it and put
> something else more suitable in its place.
Agreed, but it needs to be documented, the current documentation gives only the boot value, and does not note that string variables are the only variables that behave differently and do not return to their boot value.
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-20 18:51 Joe Conway <mail@joeconway.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 9+ messages in thread
From: Joe Conway @ 2019-02-20 18:51 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: kes-kes@yandex.ru, PostgreSQL-development <pgsql-hackers@postgreSQL.org>
On 2/20/19 12:11 PM, Tom Lane wrote:
> Joe Conway <mail@joeconway.com> writes:
>> On 2/20/19 11:10 AM, PG Bug reporting form wrote:
>>> But current behavior returns empty string instead of NULL (the initial
>>> value) after transaction is rolled back. When I restart session, NULL is
>>> returned again as it is expected.
>
>> This has been discussed before and dismissed:
>> https://www.postgresql.org/message-id/flat/56842412.5000005%40joeconway.com
>> Personally I agree it is a bug, but I am not sure you will get much
>> support for that position.
>
> The fact that we allow undeclared user-defined GUCs at all is a bug IMO.
> We need to find a way to replace that behavior with something whereby
> the name and type of a parameter are declared up-front before you can
> set it.
(moving to hackers)
Perhaps we could do something like:
1. If the user-defined GUC is defined in postgresql.conf, et al, same
behavior as now
2. Backward compatibility concerns would be an issue, so create another
new GUC declare_custom_settings which initially defaults to false.
3. If declare_custom_settings is true, and the user-defined GUC is not
defined in postgresql.conf, then in order to create it dynamically
via SET or similar methods, you must do something like:
CREATE SETTING name TYPE guctype [LIST];
SET name TO value;
Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-26 12:35 Eugen Konkov <kes-kes@yandex.ru>
parent: Joe Conway <mail@joeconway.com>
0 siblings, 1 reply; 9+ messages in thread
From: Eugen Konkov @ 2019-02-26 12:35 UTC (permalink / raw)
To: PostgreSQL-development <pgsql-hackers@postgreSQL.org>
Hello,
Not sure I should open new issue or continue this one.
select set_config( 'my.some_conf', 'value', true );
does not issue warning if there is no transaction in progress.
I faced into this problem when call to stored function which make use
of configurations. and missed that this function has no effect because
there is no transaction in progress
--
Best regards,
Eugen Konkov
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-26 12:48 Eugen Konkov <kes-kes@yandex.ru>
parent: Eugen Konkov <kes-kes@yandex.ru>
0 siblings, 1 reply; 9+ messages in thread
From: Eugen Konkov @ 2019-02-26 12:48 UTC (permalink / raw)
To: PostgreSQL-development <pgsql-hackers@postgreSQL.org>
Hello
Documentation has no description how 'false' value for 'is_local' parameter interact with transaction
Do I understand correct?
https://www.postgresql.org/docs/11/functions-admin.html#FUNCTIONS-ADMIN-SET
>set_config sets the parameter setting_name to new_value. If is_local is true, the new value will only apply to the current transaction. If you want the new value to apply for the current session, use false instead.
If I use 'false' then transaction will not have effect, because I set the value to session?
tucha=> select current_setting( 'my.app_period', true );
current_setting
-----------------
(1 row)
tucha=> begin;
BEGIN
tucha=> select set_config( 'my.app_period', tstzrange( '-infinity', 'infinity' )::text, false );
set_config
----------------------
[-infinity,infinity)
(1 row)
tucha=> rollback;
ROLLBACK
NOTICE: session is rolled back and session value is rolled back despite on that I did not use 'true' as parameter for local:
tucha=> select current_setting( 'my.app_period', true );
current_setting
-----------------
(1 row)
tucha=> begin;
BEGIN
tucha=> select set_config( 'my.app_period', tstzrange( '-infinity', 'infinity' )::text, false );
set_config
----------------------
[-infinity,infinity)
(1 row)
tucha=> commit;
COMMIT
When I commit then the value is applied to session:
tucha=> select current_setting( 'my.app_period', true );
current_setting
----------------------
[-infinity,infinity)
(1 row)
--
Best regards,
Eugen Konkov
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #15646: Inconsistent behavior for current_setting/set_config
@ 2019-02-26 14:11 David G. Johnston <david.g.johnston@gmail.com>
parent: Eugen Konkov <kes-kes@yandex.ru>
0 siblings, 0 replies; 9+ messages in thread
From: David G. Johnston @ 2019-02-26 14:11 UTC (permalink / raw)
To: Eugen Konkov <kes-kes@yandex.ru>; +Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
On Tuesday, February 26, 2019, Eugen Konkov <kes-kes@yandex.ru> wrote:
> If I use 'false' then transaction will not have effect, because I set the
> value to session?
>
The current transaction is always affected. True meansonly; false causes
the change to persist beyond, for the life of the session.
Davis J.
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2019-02-26 14:11 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20 16:10 BUG #15646: Inconsistent behavior for current_setting/set_config PG Bug reporting form <noreply@postgresql.org>
2019-02-20 17:01 ` Joe Conway <mail@joeconway.com>
2019-02-20 17:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-02-20 17:32 ` David G. Johnston <david.g.johnston@gmail.com>
2019-02-20 18:06 ` Jerry Sievert <jerry@legitimatesounding.com>
2019-02-20 18:51 ` Joe Conway <mail@joeconway.com>
2019-02-26 12:35 ` Eugen Konkov <kes-kes@yandex.ru>
2019-02-26 12:48 ` Eugen Konkov <kes-kes@yandex.ru>
2019-02-26 14:11 ` David G. Johnston <david.g.johnston@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