Thread

  1. Re: display hot standby state in psql prompt

    Greg Sabino Mullane <htamfids@gmail.com> — 2025-06-26T00:52:06Z

    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
    
    --
    Crunchy Data - https://www.crunchydata.com
    Enterprise Postgres Software Products & Tech Support