Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwtz4-0001Kj-G2 for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Jan 2021 21:35:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kwtz2-0005RU-Ey for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Jan 2021 21:35:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwtz2-0005Qq-8V for pgsql-hackers@lists.postgresql.org; Tue, 05 Jan 2021 21:35:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwtyy-0000JE-5r for pgsql-hackers@postgresql.org; Tue, 05 Jan 2021 21:35:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 105LYqGd3425297; Tue, 5 Jan 2021 16:34:52 -0500 From: Tom Lane To: Greg Nancarrow cc: Alvaro Herrera , Anastasia Lubennikova , Peter Smith , "Smith, Peter" , David Steele , "Tsunakawa, Takayuki" , Haribabu Kommi , Robert Haas , Laurenz Albe , Dave Cramer , Jing Wang , PostgreSQL-development , Elvis Pranskevichus Subject: Re: Libpq support to connect to standby server as priority In-reply-to: References: <20201124225917.GA21884@alvherre.pgsql> <325979.1606259987@sss.pgh.pa.us> <388250.1606266434@sss.pgh.pa.us> <493358.1606322607@sss.pgh.pa.us> Comments: In-reply-to Greg Nancarrow message dated "Tue, 01 Dec 2020 19:09:10 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3425295.1609882492.1@sss.pgh.pa.us> Date: Tue, 05 Jan 2021 16:34:52 -0500 Message-ID: <3425296.1609882492@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Greg Nancarrow writes: > Posting an updated set of patches. I've reviewed and pushed most of v20-0001, with the following changes: * I realized that we had more moving parts than necessary for in_hot_standby. We don't really need two static variables, one is sufficient --- and we shouldn't make the SHOW hook have side-effects, that's just dangerous. * The documentation patches were missing an addition to config.sgml, as well as failing to list the new GUC in the two places where we document all GUC_REPORT variables. What I did *not* push was the change to mark transaction_read_only as GUC_REPORT. I find that idea highly dubious, for a couple of reasons: * It'll create useless ParameterStatus traffic during normal operations of an application using "START TRANSACTION READ ONLY" or the like. * I do not think it will actually work for the desired purpose of finding out the read-only state during session connection. AFAICS, we don't set XactReadOnly to a meaningful value except when starting a transaction. Yeah, we'll run a transaction during login because we have to examine the system catalogs ... but do we start a new one after absorbing the effects of, say, ALTER USER SET default_transaction_read_only? I doubt it, and even if it works today it'd be fragile, because someday somebody will try to collapse any multiple transactions during startup into one transaction. I think what we want to do is mark default_transaction_read_only as GUC_REPORT, instead. That will give a reliable report of what the state of its GUC is, and you can combine it with is_hot_standby to decide whether the session should be considered read-only. If you don't get those two GUC values during connection, then you can fall back on "SHOW transaction_read_only". Setting this back to waiting on author. regards, tom lane