Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1udhu6-00BooW-Ir for pgpool-general@arkaria.postgresql.org; Mon, 21 Jul 2025 04:13:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1udht6-00Dakh-W0 for pgpool-general@arkaria.postgresql.org; Mon, 21 Jul 2025 04:12:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1udht6-00DakZ-Kx for pgpool-general@lists.postgresql.org; Mon, 21 Jul 2025 04:12:28 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1udht3-008tLP-37 for pgpool-general@lists.postgresql.org; Mon, 21 Jul 2025 04:12:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=Yg+uKrg/J/XVuew1LZs1U2xa0ErNCqCIqQ+iN0+AQyw=; b=ofbPpLsFMxT+YrIukxGv0it4gi dARjkeud3d9QtpTNInlYWleGXSYLs5fbAH9BMz5W0mQ86fFxL+j6vgssfPATH+CF1gyFeIHr4iVgA hmtPrccrLBO1uiBXWfgyDdI8dJGtqATCdaxbrp+7/d/9+ES0yoXEWc4GccuDFTXIGoLp0R1SHom50 a/HCIigPDPgjKP+loJKTk/D26nUevHf2rMgIHQ+0TV9+Z8Cc49txax+touH9BMa+U8OHscj1KH/eV LdkLQF3nX9hhLNwH7GuoIHtSbbLuVNKQTmIR49frVUOMo1ZiN8YfKRxXVx1Vou0p9EzHWJ4ImADgi wGfqqzdg==; Received: from [2409:11:4120:300:3691:ed30:1240:7d2] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1udht1-00DFjy-0t; Mon, 21 Jul 2025 04:12:25 +0000 Date: Mon, 21 Jul 2025 13:12:14 +0900 (JST) Message-Id: <20250721.131214.1600596684258021437.ishii@postgresql.org> To: emond.papegaaij@gmail.com Cc: pgpool-general@lists.postgresql.org Subject: Re: FATAL: simple query "BEGIN" arrived before ending an extended query message From: Tatsuo Ishii In-Reply-To: References: <20250710.115535.1767264216072187810.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_Jul_21_13_12_14_2025_691)--" Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:3691:ed30:1240:7d2 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Mon_Jul_21_13_12_14_2025_691)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi Emond, >> > The problem however, is that previously the error was only triggered when >> > using autosave, which is not a common setup, but now the error is >> triggered >> > even when using default configuration. This makes it impossible to >> combine >> > PgJDBC 42.7.6 and up with pgpool-II. I do not know what the plans are on >> > this from the side of PostgreSQL and PgJDBC, but I just wanted to raise >> > some awareness on this issue here. IMHO PostgreSQL should either >> explicitly >> > allow this (in which case pgpool-II needs to be fixed) or explicitly >> > disallow it (in which case PgJDBC needs to be fixed). >> >> As far as I know about PostgreSQL's side, Tom Lane said about this: >> https://www.postgresql.org/message-id/2069511.1706571615@sss.pgh.pa.us >> >> > I think it's poor practice, at best. You should end the >> > extended-protocol query cycle before invoking simple query. >> > >> > I'm disinclined to document, or make any promises about, >> > what happens if you mix the protocols. >> >> In my understanding he does not say PostgreSQL explicitely allows this >> (mixing extended and simple protocol message). >> > > It's more or less allowed without any errors, but the expected behavior is > not clear nor is it documented. It seems libpq even throws an error on the > client side when you try to do this: > > Jelte Fennema-Nio in > https://www.postgresql.org/message-id/CAGECzQQ1hs2DU9pmQq18Y%3DqK4nZqhXDVg-sGEa5K01Lj4XMmxw%40mail.gmail.com >> I totally agree that it makes sense to throw an error in this case. >> Libpq actually throws an error client side when a caller attempts to >> do this, but this is something that should be checked server side, >> given that the protocol docs specify this: >> docs> At completion of each series of extended-query messages, the >> frontend should issue a Sync message. > > >> > The current situation >> > is no good as we now simply cannot upgrade PgJDBC anymore (and the same >> > will be true for all other users of pgpool-II). >> >> Yeah. >> >> What I don't understand is, why PgJDBC decided to make it default >> (sending simple protocol query after extended query protocl without >> sync) even without autosave being set when they update PgJDBC to >> 42.7.7. >> > > It wasn't a real decision to make this happen more often. They fixed a bug > that caused many queries to be sent using the extended protocol even when > explicitly asked for a simple query: > https://github.com/pgjdbc/pgjdbc/issues/3724#issuecomment-3051773696 > > In our case we got sporadic errors. These errors are very hard to > reproduce. Some users were not able to login into our application at all, > others had no trouble whatsoever and some users got an error every once in > a while. Even when tests seem fine, you might get these errors later on. > None of our automated tests failed. On our testing environment we've only > seen the error twice in a period of 3 weeks. When we moved to production, > we triggered the error over 100 times in just 1 day! I would certainly not > recommend using PgJDBC 42.7.6 and up when using pgpool. I created a patch for pgpool to allow a simple query without ending a sequence of extended query protocol message by a sync message. The idea is, within SimpleQuery() (a function responsible for processing simple protocol query), check whether extended query protocol ends. If not, call ProcessBackendReposnse() to process any replies from backend such as parse complete, bind complete or command complete and so. After this, SimpleQuery() can process simple query as usual. I hope this solves the issue with PgJDBC 42.7.6. Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp ----Next_Part(Mon_Jul_21_13_12_14_2025_691)-- Content-Type: Application/Octet-Stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="allow_simple_query_after_extended_query.patch" ZGlmZiAtLWdpdCBhL3NyYy9wcm90b2NvbC9wb29sX3Byb3RvX21vZHVsZXMuYyBiL3NyYy9wcm90 b2NvbC9wb29sX3Byb3RvX21vZHVsZXMuYwppbmRleCAxMWJlZmU5NzkuLmUwMzBlN2I2ZCAxMDA2 NDQKLS0tIGEvc3JjL3Byb3RvY29sL3Bvb2xfcHJvdG9fbW9kdWxlcy5jCisrKyBiL3NyYy9wcm90 b2NvbC9wb29sX3Byb3RvX21vZHVsZXMuYwpAQCAtMjIyLDIwICsyMjIsMzkgQEAgU2ltcGxlUXVl cnkoUE9PTF9DT05ORUNUSU9OICpmcm9udGVuZCwKIAlzdHJsY3B5KHF1ZXJ5X3N0cmluZ19idWZm ZXIsIGNvbnRlbnRzLCBzaXplb2YocXVlcnlfc3RyaW5nX2J1ZmZlcikpOwogCiAJLyoKLQkgKiBD aGVjayBpZiBleHRlbmRlZCBxdWVyeSBwcm90b2NvbCBtZXNzYWdlIGVuZGVkLiAgSWYgbm90LCBy ZWplY3QgdGhlCi0JICogcXVlcnkgYW5kIHJhaXNlIGFuIGVycm9yIHRvIHRlcm1pbmF0ZSB0aGUg c2Vzc2lvbiB0byBhdm9pZCBoYW5naW5nIHVwLgotCSAqIEhvd2V2ZXIgaWYgd2UgYXJlIHByb2Nl c3NpbmcgYSByZXNldCBxdWVyeSAoZnJvbnRlbmQgPT0gTlVMTCksIHdlIHNraXAKLQkgKiB0aGUg Y2hlY2sgYXMgd2UgZG9uJ3Qgd2FudCB0byByYWlzZSBhIGVycm9yLgorCSAqIENoZWNrIGlmIGV4 dGVuZGVkIHF1ZXJ5IHByb3RvY29sIG1lc3NhZ2UgZW5kZWQuICBJZiBub3QsIHByb2Nlc3MgYW55 CisJICogcGVuZGluZyByZXNwb25zZSBm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