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 1m3VQG-000228-DI for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Jul 2021 03:18:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3VQF-0007M8-9B for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Jul 2021 03:18:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3VQF-0007M0-2E for pgsql-bugs@lists.postgresql.org; Wed, 14 Jul 2021 03:18:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3VQ8-0005Hb-LL for pgsql-bugs@lists.postgresql.org; Wed, 14 Jul 2021 03:18:54 +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 16E3Ieg03453637; Tue, 13 Jul 2021 23:18:41 -0400 From: Tom Lane To: Japin Li cc: John Naylor , =?utf-8?Q?L=C3=A6titia?= Avrot , pgsql-bugs@lists.postgresql.org Subject: Re: Statistics updates is delayed when using `commit and chain` In-reply-to: References: <2950681.1626103840@sss.pgh.pa.us> Comments: In-reply-to Japin Li message dated "Wed, 14 Jul 2021 09:55:42 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3453635.1626232720.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 13 Jul 2021 23:18:40 -0400 Message-ID: <3453636.1626232720@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Japin Li writes: > On Mon, 12 Jul 2021 at 23:30, Tom Lane wrote: >> I do not think this is a bug at all. The behavior is, and always has >> been, that we report stats when we are about to wait for client input >> and are not inside a transaction. Likewise for NOTIFY. The proposed >> patch randomly changes that in a way that is very likely to break >> clients. > Sorry, I'm not very clearly why we can not process NOTIFY when a transac= tion is > end. The protocol contract for that is that NOTIFY is delivered *between* transactions. With the proposed patch, the notification can be delivered in the middle of the new transaction created by COMMIT AND CHAIN. This creates semantic issues --- in particular, if that second transaction is later rolled back, does that mean we should re-send the notification? The NOTIFY man page describes this explicitly: ... Secondly, if a listening session receives a notification signal while it is within a transaction, the notification event will not be delivered to its connected client until just after the transaction is completed (either committed or aborted). Again, the reasoning is that if a notification were delivered within a transaction that was later aborted, one would want the notification to be undone somehow =E2=80=94= but the server cannot =E2=80=9Ctake back=E2=80=9D a notification once it h= as sent it to the client. So notification events are only delivered between transactions. (protocol.sgml is a bit wishy-washy about this point, but I think we should lock the wording there down harder. We have never delivered notifies intra-transaction, and now is no time to start.) regards, tom lane