BUG #15646: Inconsistent behavior for current_setting/set_config - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15646: Inconsistent behavior for current_setting/set_config
Date
Msg-id 15646-0d3caee9f6266f60@postgresql.org
Whole thread Raw
Responses Re: BUG #15646: Inconsistent behavior for current_setting/set_config
List pgsql-bugs
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)


pgsql-bugs by date:

Previous
From: "Daniel Verite"
Date:
Subject: Re: BUG #15645: \COPY command not printing output in batch mode
Next
From: "Hans Buschmann"
Date:
Subject: AW: BUG #15641: Autoprewarm worker fails to start on Windows with huge pages in use Old PostgreSQL community/pgsql-bugs x