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 1lqkdZ-0001Fs-BZ for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Jun 2021 22:55:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lqkdY-0006Ro-B0 for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Jun 2021 22:55:56 +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 1lqkdY-0006Rg-3H for pgsql-hackers@lists.postgresql.org; Tue, 08 Jun 2021 22:55:56 +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 1lqkdR-00014W-PY for pgsql-hackers@lists.postgresql.org; Tue, 08 Jun 2021 22:55:55 +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 158MtkCV1250963; Tue, 8 Jun 2021 18:55:46 -0400 From: Tom Lane To: Mark Dilger cc: PostgreSQL Hackers Subject: Re: logical replication of truncate command with trigger causes Assert In-reply-to: References: Comments: In-reply-to Mark Dilger message dated "Tue, 08 Jun 2021 14:52:14 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1250961.1623192946.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 08 Jun 2021 18:55:46 -0400 Message-ID: <1250962.1623192946@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Mark Dilger writes: > On master, when a statement level trigger is fired for a replicated trun= cate command, the following stack trace is generated: Hmm. > I believe the issue was introduced in commit 84f5c2908da which added Ens= urePortalSnapshotExists. That's not going to work in the case of logical= replication, because there isn't an ActivePortal nor a snapshot. The right way to say that is "commit 84f5c2908da exposed the pre-existing unsafe behavior of this code". It's not okay to run arbitrary user code without holding a snapshot to protect TOAST dereference operations. I suppose that either apply_dispatch or LogicalRepApplyLoop needs to grow some more snapshot management logic, but I've not looked at that code much, so I don't have an opinion on just where to add it. There's a reasonable case to be made that running user code outside a Portal is a just-plain-bad idea, so we should fix the logical apply worker to make it create a suitable Portal. I speculated about that in the commit message for 84f5c2908da, but I don't feel like taking point on such work. regards, tom lane