Re: display hot standby state in psql prompt - Mailing list pgsql-hackers

From Srinath Reddy Sadipiralla
Subject Re: display hot standby state in psql prompt
Date
Msg-id CAFC+b6oEYiW4Nh7vVWyYi5n6g1ac2=E71JP5NaoT2ARjzsTR6g@mail.gmail.com
Whole thread Raw
In response to Re: display hot standby state in psql prompt  (Jim Jones <jim.jones@uni-muenster.de>)
Responses Re: display hot standby state in psql prompt
List pgsql-hackers
Hi Jim,

On Tue, Jul 22, 2025 at 4:40 PM Jim Jones <jim.jones@uni-muenster.de> wrote:
Hi

On 21.07.25 21:12, Greg Sabino Mullane wrote:
> Seems good enough for me. I think as long as we document it well, it's
> only going to be a net positive, even with some edge cases.

I just moved the patch from PG19-Drafts to PG19-2 commitfest.[1]

Thanks a lot for the feedback!

Best regards, Jim

1 - https://commitfest.postgresql.org/patch/5872/

+1 for the patch,i have reviewed and tested this patch, except these below cosmetic changes it LGTM.

cosmetic changes:
1) add comment about %i in get_prompt api.
2) maybe we can use read-write instead of read/write to be consistent with the
    naming such as options of target_session_attrs uses read-write.

testing:

=> in primary node:

psql (19devel)
Type "help" for help.

postgres=# \set PROMPT1 '[%i] # '
[read/write] # set default_transaction_read_only=on;
SET
[read-only] # set default_transaction_read_only=off;
SET
[read/write] # show in_hot_standby ;
 in_hot_standby
----------------
 off
(1 row)

[read/write] # set default_transaction_read_only=on;
SET
[read-only] # show in_hot_standby ;
 in_hot_standby
----------------
 off
(1 row)

[read-only] # \q

=> in replica node

psql (19devel)
Type "help" for help.

postgres=# \set PROMPT1 '[%i] # '
[read-only] # show in_hot_standby ;
 in_hot_standby
----------------
 on
(1 row)

[read-only] # show default_transaction_read_only;
 default_transaction_read_only
-------------------------------
 off
(1 row)

[read-only] # set default_transaction_read_only=on;
SET
[read-only] # set transaction_read_only=on;
SET
[read-only] # set transaction_read_only=off;
ERROR:  cannot set transaction read-write mode during recovery
[read-only] # select pg_promote();
 pg_promote
------------
 t
(1 row)

[read-only] # show in_hot_standby ;
 in_hot_standby
----------------
 off
(1 row)

[read-only] # show default_transaction_read_only;
 default_transaction_read_only
-------------------------------
 on
(1 row)

[read-only] # set default_transaction_read_only=off;
SET
[read/write] #
 

--
Thanks,
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/

pgsql-hackers by date:

Previous
From: Andrei Lepikhov
Date:
Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment
Next
From: Michael Paquier
Date:
Subject: Re: recoveryStopsAfter is not usable when recovery_target_inclusive is false