Re: display hot standby state in psql prompt
Jim Jones <jim.jones@uni-muenster.de>
From: Jim Jones <jim.jones@uni-muenster.de>
To: Fujii Masao <masao.fujii@gmail.com>,
Nathan Bossart <nathandbossart@gmail.com>
Cc: Srinath Reddy Sadipiralla <srinath2133@gmail.com>,
Greg Sabino Mullane <htamfids@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-10-28T11:03:48Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
psql: Add %i prompt escape to indicate hot standby status.
- dddbbc253b92 19 (unreleased) landed
-
Mark search_path as GUC_REPORT
- 28a1121fd912 18.0 cited
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