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 1legq7-0002ec-73 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 16:27:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1legq6-00035o-7Q for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 16:27:02 +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 1legq5-0002Nb-Oo for pgsql-hackers@lists.postgresql.org; Thu, 06 May 2021 16:27:01 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1legpx-0005Aq-W5 for pgsql-hackers@postgresql.org; Thu, 06 May 2021 16:27:00 +0000 Received: by mail-ot1-x32b.google.com with SMTP id u19-20020a0568302493b02902d61b0d29adso4589797ots.10 for ; Thu, 06 May 2021 09:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RICyjDwRe8vTCpvlH1OBg7nh/fxF9iQL1kNtyxMQLDM=; b=KZaE24WZ3YdcWMBngvbv0dHnFrD6sA+NnsGsRBkVFfpi7PHRz8I5xbBAKdGU41JG9g UMLqPUL7SDaG0iLGkS60iCA/I0Zs/z+sTvFcNOL80DZsWvMSLqba7h5aR3N+pjb+U5+D 0CqXRdscc9viYqA41t/n4Kh/0yIbVRGw6iEWzGgg5v9TZKNNQ1Qk8Zp5/jk49CFxqoEI UShe6v2jAl0IVdBgah9AsYxxjdQG9/AoQSx5q+mES6SJ+uKB/ednnJIM/fVWL2OV0GbN UuPzEhtjNgUHmHlJc2Fzq+xyTI8JuQgZoDO6odVX+Rki87BamRiD+2X2i3YHP6O0PgBj PbeA== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RICyjDwRe8vTCpvlH1OBg7nh/fxF9iQL1kNtyxMQLDM=; b=nyG1rjimW+npouL7Nbp9/Ew4P+fSldDjS5Eg4zNsHn2Rti6fozY6Iau/wAFjZ8skon UwCeDe099nyd/uQ4X2yqyxq1pJQitfYBjuLWFAaSu0hDVGj1XkIkftidJNBNXY1XtAr2 pzGE43n0XbcxDgVexr/KJYdG9gKHhDYlBJi+T0GmFW6HdjDZTtbhhkY2xLBXgW+xAc/d 0VaDGMU81DRxFnz6S6TSmPxRnNqjLW/Rv7N1MK5tln/hx5LRGkKTWYGsE052EpIiqy16 Q9LE6N+OXAKbI0O8zJEVXyXQBGPT0GQBF3SyMDuXUiGNkudQMYUFveH5uahkooO9RFlF GNSw== X-Gm-Message-State: AOAM533K4NO0eKFx8i83dPiJxRj4zHgUjoeWbhebUpRYsttVYVs9+0N6 Ge5CiXQPnXty00sOFspgRppmwQ== X-Google-Smtp-Source: ABdhPJxXJ0MILZ/jU2G/R00YJh2xnR4cBLTvu6hgHOcCUHZadcU+f7JMFsJfCawqMRieeByiTeZyqA== X-Received: by 2002:a9d:7a8a:: with SMTP id l10mr1950549otn.224.1620318412816; Thu, 06 May 2021 09:26:52 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g16sm583154oof.43.2021.05.06.09.26.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 May 2021 09:26:52 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 3F505800897; Thu, 6 May 2021 11:26:51 -0500 (CDT) Date: Thu, 6 May 2021 11:26:51 -0500 From: Justin Pryzby To: Tom Lane Cc: Hubert Zhang , tsunakawa.takay@fujitsu.com, pgsql-hackers@postgresql.org, Andreas Seltenreich , Bruce Momjian Subject: Re: Multiple hosts in connection string failed to failover in non-hot standby mode Message-ID: <20210506162651.GJ27406@telsasoft.com> References: <229507.1610056206@sss.pgh.pa.us> <770711.1610318330@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <770711.1610318330@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Jan 10, 2021 at 05:38:50PM -0500, Tom Lane wrote: > I wrote: > > The problems that I see in this area are first that there's no > > real standardization in libpq as to whether to append error messages > > together or just flush preceding messages; and second that no effort > > is made in multi-connection-attempt cases to separate the errors from > > different attempts, much less identify which error goes with which > > host or IP address. I think we really need to put some work into > > that. > > I spent some time on this, and here is a patch set that tries to > improve matters. > > 0001 changes the libpq coding rules to be that all error messages should > be appended to conn->errorMessage, never overwritten (there are a couple > of exceptions in fe-lobj.c) and we reset conn->errorMessage to empty only > at the start of a connection request or new query. This is something > that's been bugging me for a long time and I'm glad to get it cleaned up. > Formerly it seemed that a dartboard had been used to decide whether to use > "printfPQExpBuffer" or "appendPQExpBuffer"; now it's always the latter. > We can also get rid of several hacks that were used to get around the > mess and force appending behavior. > > 0002 then changes the reporting rules in fe-connect.c as I suggested, > so that you might get errors like this: > > $ psql -h localhost,/tmp -p 12345 > psql: error: could not connect to host "localhost" (::1), port 12345: Connection refused > Is the server running on that host and accepting TCP/IP connections? > could not connect to host "localhost" (127.0.0.1), port 12345: Connection refused > Is the server running on that host and accepting TCP/IP connections? > could not connect to socket "/tmp/.s.PGSQL.12345": No such file or directory > Is the server running locally and accepting connections on that socket? > > and we have a pretty uniform rule that errors coming back from a > connection attempt will be prefixed with the server address. 52a10224 broke sqlsmith, of all things. It was using errmsg as a test of success, instead of checking if the connection result wasn't null: conn = PQconnectdb(conninfo.c_str()); char *errmsg = PQerrorMessage(conn); if (strlen(errmsg)) throw dut::broken(errmsg, "08001"); That's clearly the wrong thing to do, but maybe this should be described in the release notes as a compatibility issue, in case other people had the same idea. Clearing errorMessage during success is an option.. -- Justin