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

From Greg Sabino Mullane
Subject Re: display hot standby state in psql prompt
Date
Msg-id CAKAnmmLf3Qpv54zM2u5N5XbbGDONtiz3F6yhM142O2mdQ3=f_A@mail.gmail.com
Whole thread Raw
In response to Re: display hot standby state in psql prompt  (Jim Jones <jim.jones@uni-muenster.de>)
List pgsql-hackers
On Wed, Jun 25, 2025 at 11:50 AM Jim Jones <jim.jones@uni-muenster.de> wrote:
Since I cannot get the value of transaction_read_only via PQparameterStatus.

Hmmm... we can at least get default_transaction_read_only. As fe-connect.c points out:
                    /*
                     * "transaction_read_only = on" proves that at least one
                     * of default_transaction_read_only and in_hot_standby is
                     * on, but we don't actually know which.  We don't care
                     * though for the purpose of identifying a read-only
                     * session, so satisfy the CONNECTION_CHECK_TARGET code by
                     * claiming they are both on.  On the other hand, if it's
                     * a read-write session, they are certainly both off.
                     */
Maybe that's good enough? It won't detect people starting a new transaction and declaring it read-only, but it should be sufficient to warn people when a connection is starting out in a read-only state. And it will still toggle auto-magically on promotion.

Cheers,
Greg

--
Enterprise Postgres Software Products & Tech Support

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Decompression bug in astreamer_lz4
Next
From: Michael Paquier
Date:
Subject: Re: pg_logical_slot_get_changes waits continously for a partial WAL record spanning across 2 pages