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 1gNh6F-0002Ww-DZ for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Nov 2018 16:36:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gNh6C-0005Ns-PT for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Nov 2018 16:36:04 +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 1gNh6C-0005K6-EU for pgsql-hackers@lists.postgresql.org; Fri, 16 Nov 2018 16:36:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNh69-0004iE-Rl for pgsql-hackers@postgresql.org; Fri, 16 Nov 2018 16:36:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wAGGZldY028778; Fri, 16 Nov 2018 11:35:48 -0500 From: Tom Lane To: Laurenz Albe cc: Haribabu Kommi , Robert Haas , Jing Wang , Pg Hackers , "Tsunakawa, Takayuki" Subject: Re: Libpq support to connect to standby server as priority In-reply-to: <096a642cff0dd68b8157a5f8838e1762d0050d18.camel@cybertec.at> References: <1530710078.2411.29.camel@cybertec.at> <67be09458f276c0c95a4b2a2a383dca9775d19cd.camel@cybertec.at> <26890.1542047012@sss.pgh.pa.us> <096a642cff0dd68b8157a5f8838e1762d0050d18.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Mon, 12 Nov 2018 21:26:53 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28776.1542386147.1@sss.pgh.pa.us> Date: Fri, 16 Nov 2018 11:35:47 -0500 Message-ID: <28777.1542386147@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laurenz Albe writes: > Tom Lane wrote: >> I don't like this patch at all: the business with keeping two connections >> open seems impossibly fragile and full of race conditions. > As it is now, the patch doesn't keep two connections open. It remembers > the index of the host of the first successful writable connection, but > closes the connection, and opens another one to that host if no read-only > host can be found. Oh! The reason I assumed it wasn't doing that is that such a behavior seems completely insane. If the point is to keep down the load on your master server, then connecting only to immediately disconnect is not a friendly way to do that --- even without counting the fact that you might later come back and connect again. If that's the best we can do, we should forget the whole feature and just recommend putting slave servers first in your hosts list when you want prefer-slave. regards, tom lane