Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ikpMF-0000wA-Tz for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Dec 2019 13:08:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ikpME-0003AL-6o for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Dec 2019 13:08:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ikpMD-0003AE-NB for pgsql-hackers@lists.postgresql.org; Fri, 27 Dec 2019 13:08:45 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ikpM6-0002Rr-Ry for pgsql-hackers@postgresql.org; Fri, 27 Dec 2019 13:08:44 +0000 Received: by mail-pj1-x1042.google.com with SMTP id r67so4723159pjb.0 for ; Fri, 27 Dec 2019 05:08:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=bEqPvLMSY8OQtNmbdZ1HVYFD9JAIia1lK8p82ryS9tA=; b=yIekW5V8FwfUoeVDebIS/rUoa/7r59ytVXtQ7wOTJ+QTIbuyykvemC5Hs312pxsg9F nzukmL7RwiDBeMmcoPpcggKD+Y/TtHUxXtj1cW/HsKPBVfKPxBlre91PA+qJ5tlATMRv YGZjYcmytL721BvaGLi7VWigd9eaaBdKvgbB4iPK8JUHE/KNGxZKaC27fenNZ9iJI8lw 5ZP1CygOt8X/iiaCNRMN+zm98ItOFSdS9nQGPf+/mRYayFWWdQHuzF0RKln9PKIly0eu M9VngGz43YCnualzDEHLyK2nFOfdJXDOngoLYm1S6rHV27ZZI+teF0Sh51yzO/fEQCKk /jzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=bEqPvLMSY8OQtNmbdZ1HVYFD9JAIia1lK8p82ryS9tA=; b=hUrSez6tn1GMriwMqI+WGXjLrLY+1xyFd6O2aTeFeUCY0ocWHvXFjXRhJorOAIirut 0xnC53Rqjws7rS7JHL08WKRIqzRrvHQN8Mi+OWv76aQLA/JXVc5iOg4KrjADXGz+ZGu+ cN0yY6PcoyB+Tpm7pumfoJR7WWrnGCmedINDO8wZfvF0dFQP8IetT/Q64jEcbGQ1+ZvJ 5cgkhIHu0jWpAk89UDWyrECPWTZ4liQl0CHIisvsT3m8ZOjnyzhPMLaA2oGdy8mRB6WE D8wF7jf2NTXjDSXlD1Zpd158qDp4c2AGEvIoNdfUikB6tQkzHmw3ZJypjLvYA0nhyTzB 6fjA== X-Gm-Message-State: APjAAAXg6qC8mXtJiPhXIlHs9na2CczFjjY6xqKtCoYiKCdt/Dr9qXlm vV9AKBm9YETdeR0P13EAlsSmkQ== X-Google-Smtp-Source: APXvYqwpaQDDa6tM7GPegMKeexGn5nCdbp/iWzUZ13sH9jcQMjEETLHtH8A4foRSwtUklR3KBSXRMA== X-Received: by 2002:a17:902:850a:: with SMTP id bj10mr25905152plb.317.1577452117192; Fri, 27 Dec 2019 05:08:37 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([190.95.19.128]) by smtp.gmail.com with ESMTPSA id d24sm42549828pfq.75.2019.12.27.05.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2019 05:08:36 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 90F09300A02; Fri, 27 Dec 2019 10:08:28 -0300 (-03) Date: Fri, 27 Dec 2019 10:08:28 -0300 From: Alvaro Herrera To: "tsunakawa.takay@fujitsu.com" Cc: Greg Nancarrow , Haribabu Kommi , Robert Haas , Laurenz Albe , Tom Lane , Dave Cramer , Jing Wang , PostgreSQL-development , Elvis Pranskevichus Subject: Re: Libpq support to connect to standby server as priority Message-ID: <20191227130828.GA21647@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Dec-27, tsunakawa.takay@fujitsu.com wrote: > From: Alvaro Herrera > > I'm not sure I understand why we end up with "prefer-read" in addition > > to "prefer-standby" (and similar seeming redundancy between "primary" > > and "read-write"). Do we really need more than one way to identify > > hosts' roles? It seems 0001 adds the "prefer-read" modes by checking > > transaction_read_only, and later 0002 adds the "prefer-standby" modes by > > checking in_recovery. I'm not sure that we're serving our users very > > well by giving them choice that ends up being confusing. In other words > > I think we should do only one of these things, not both. Maybe merge > > 0001 and 0002 in a single patch, and get rid of redundant modes. > > That's because the distinction read/write is different from > primary/standby. If default_transaction_read_only is on, even the > primary is read-only. That's why the syntax target_session_attrs = > {read-write | read-only} was introduced instead of target_server_type > = {primary | standby}. Personally, I only want target_server_type = > {primary | standby | prefer-standby}, and discard target_session_attrs > for simplicity of the functional specification and the code. So, we can know whether server is primary/standby by checking in_recovery, as opposed to knowing whether read-write which is done by checking transaction_read_only. So we can keep read-write as a synonym for "primary", and check in_recovery when used in servers that support the new GUC, and check transaction_read_only in older servers. It seems there's a lot of code that we can discard from the patch: first, we can discard checking for "read-only" altogether. Second, have us check transaction_read_only *only* if the server is of an older version. I would discard the whole thing about checking "SELECT pg_is_in_recovery()" also; let's skip straight to checking SHOW in_recovery (patch 0003). Let's not introduce a mechanism that ends up obsolete immediately. By the same token, I propose we don't mark transaction_read_only as a GUC_REPORT option, since we only do that to let it become obsolete immediately. If we connect to a server older than 13, just keep sending the SHOW query. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services