On 28/10/2025 00:55, Fujii Masao wrote:
> If we mark transaction_read_only as GUC_REPORT, wouldn't the reset value
> be sent automatically at the end of the transaction? It seems like we wouldn't
> need any new mechanism for that. However, the downside might be that
> more ParameterStatus messages would be sent, potentially adding overhead.
I tried that, but simply marking it as GUC_REPORT does not reset the
variable when the transaction ends.
== guc_parameters.dat ==
{ name => 'transaction_read_only', type => 'bool', context =>
'PGC_USERSET', group => 'CLIENT_CONN_STATEMENT',
short_desc => 'Sets the current transaction\'s read-only status.',
flags => 'GUC_NO_RESET | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE |
GUC_DISALLOW_IN_FILE | GUC_REPORT',
variable => 'XactReadOnly',
boot_val => 'false',
check_hook => 'check_transaction_read_only',
},
== prompt.c ==
...
const char *hs = PQparameterStatus(pset.db, "in_hot_standby");
const char *ro = PQparameterStatus(pset.db,
"default_transaction_read_only");
const char *tr = PQparameterStatus(pset.db, "transaction_read_only");
if (!hs || !ro || !tr)
strlcpy(buf, _("unknown"), sizeof(buf));
else if (strcmp(hs, "on") == 0 || strcmp(ro, "on") == 0 || strcmp(tr,
"on") == 0)
strlcpy(buf, "read-only", sizeof(buf));
else
strlcpy(buf, "read/write", sizeof(buf));
...
== test ==
psql (19devel)
Type "help" for help.
postgres=# \set PROMPT1 '[%i] # '
[read/write] # BEGIN;
BEGIN
[read/write] # SET transaction_read_only TO on;
SET
[read-only] # END;
COMMIT
[read-only] # SHOW transaction_read_only;
transaction_read_only
-----------------------
off
(1 row)
[read-only] #
So I assumed that the reset happens during transaction cleanup, which
might not send parameter status updates.
Am I missing something?
Thanks!
Best, Jim