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.96) (envelope-from ) id 1vchs5-009rQ6-08 for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2026 10:31:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vchs4-001QmF-04 for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2026 10:31:32 +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.96) (envelope-from ) id 1vchs3-001QlX-27 for pgsql-hackers@lists.postgresql.org; Mon, 05 Jan 2026 10:31:32 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vchs1-004dVh-2k for pgsql-hackers@lists.postgresql.org; Mon, 05 Jan 2026 10:31:32 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-4327778df7fso3888267f8f.3 for ; Mon, 05 Jan 2026 02:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1767609089; x=1768213889; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to; bh=g4d2E5u4cC+8WIuN4jTBcbosqToQUaNMNrv6ddWvS4o=; b=eNU9I3gwAlHHqdFSe988T8biHtXsj1Jm7TTjq3e1wSGMm+2dWs6nPcWIji2Mtp1BJA X9BcmZFMRUab9pNoM3Ev0BVtHhzSbGFpCSAR+dIK4//wP5J98XxCwy2xCYQB6x2dWC5j 4g/E89uxWzq8bTUSWxbdt/QRtnnpJMCcBTwKeZOZulYcAHVyEJ2PnMwYp83A6momUFpY eThx3jdJ8S5xuVjobbA3gXFKiUuuA6Ep4P1G2gLvBQ1nOraUV7lxF4fV9y0dtbwKJBCJ hTnCqXEI12SkYuTEhFipvTnw4zLxWCXhC+Vd/2k1pQy6cyEOA+aGrE0syxiKuVxBP0Ff 9PFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767609089; x=1768213889; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g4d2E5u4cC+8WIuN4jTBcbosqToQUaNMNrv6ddWvS4o=; b=Dky3SO/K7K/ODBIXzWcL958zsVnfed8C90RkNv2xeDDtXoB09tXUU/4PldP8CZJ/Go 1IRupnR2KxNPOeqVOpGBCPnQ9udUyRPAs19o4TsUUCHGUiZFt3w2zvQir8USfrDElh5K gA1oOYPGelwutrRr8knNus7L5PsXJ43xvc3XrKinJ3xlsIr+pVUjdZoHZxU0U9jBj+Sx ItmwSbXmKS8rKhEblnI1x+a4StW7bNK5R92flHwHUr/SK0tjDrjbcNtG1HXy6+0V5KwB ktJ9/AGb5bWtPVAktXedjJLeqg4UBKo7BJSl+jgRYGX2b0WwwolHgzFFfASn+OHdBzpn 7iHQ== X-Forwarded-Encrypted: i=1; AJvYcCXyQgyDwtUo7pq94imVXpntCth0gtFsYknTExq/SGz2h70CGC7cwh4Qlt+6fR6WplIrbAhthpDVa2KbBvXX@lists.postgresql.org X-Gm-Message-State: AOJu0YyvFXDitYRMUPttrrS5v/Jpf2N1+RcdU4x6hHTmVLC5667Syhbt 0j5+8OdWrS2oo+RF34XizLf1ACFhp9CIO20nCcnrhyL/DHZEWeTAek+5T8VXrtblOFc= X-Gm-Gg: AY/fxX72XVdfQF3pUolsf/MwQHwjndyj8kd9uwFMBiuCTlbeL8YE9K5ATfuaM4HIQyg Qtl/+ywI9Fy1CxYOVDKLo491E66hH0jymGy4dwebQbO33Lh4rrvQvMuOaN3A9a08tnGuNm6SzsJ 9HNcK5PAXxm9usMbcr/Uz9F/fP4MYBL63n/KvfD3+XjYl+O2bmEVOZtoIb6EGlaPzs3WBWGdbWw VR6jKcC6E0NNT2UqWGutZvXxsoWoCkWe0AfhitGiuw2pJ+GShghMUK1Xk4crcBWr3rycSH0PlEo 9Hvu7Yv/QAT06WPs2ASjQEI+ZwUNa1570PdWvQVF3VuadbsJQ4241FqvKMWCq1mV8rDA/vAuLZT hQhqOPtzSBoH2sDgYiehQz/LCYA2nsxHo7uDGBd4ZHpcnDs/N4JmvwJzwuj1OlVUfrOZ+8O4buY BjGDZE1unqKMSUnoaL1QP+SKoR X-Google-Smtp-Source: AGHT+IFoN30rTPbNhJDrPZ3ZA5lQesv8zZOPUq6+25IV5IHJy0OqeWEZRCJ97nvPlhNA1bGb7Js5bA== X-Received: by 2002:a05:6000:2893:b0:432:a9fb:68f8 with SMTP id ffacd0b85a97d-432a9fb6a7fmr7902825f8f.1.1767609088734; Mon, 05 Jan 2026 02:31:28 -0800 (PST) Received: from localhost (109-81-168-246.rct.o2.cz. [109.81.168.246]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324ea1aee5sm101513854f8f.4.2026.01.05.02.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 02:31:28 -0800 (PST) From: Antonin Houska To: Alvaro Herrera cc: Mihail Nikalayeu , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: <202512151349.vlq3mpfniyk3@alvherre.pgsql> References: <202512151349.vlq3mpfniyk3@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Mon, 15 Dec 2025 15:25:22 +0100." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11246.1767609087.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Mon, 05 Jan 2026 11:31:27 +0100 Message-ID: <11247.1767609087@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera wrote: > On 2025-Dec-13, Antonin Houska wrote: > = > > From 6279394135f2b693b6fffd174822509e0a067cbf Mon Sep 17 00:00:00 2001 > > From: Antonin Houska > > Date: Sat, 13 Dec 2025 19:27:18 +0100 > > Subject: [PATCH 4/6] Add CONCURRENTLY option to REPACK command. > = > > diff --git a/src/backend/replication/logical/decode.c b/src/backend/re= plication/logical/decode.c > > index cc03f0706e9..a956892f42f 100644 > > --- a/src/backend/replication/logical/decode.c > > +++ b/src/backend/replication/logical/decode.c > > @@ -472,6 +473,88 @@ heap_decode(LogicalDecodingContext *ctx, XLogReco= rdBuffer *buf) > = > > + /* > > + * Second, skip records which do not contain sufficient information = for > > + * the decoding. > > + * > > + * The problem we solve here is that REPACK CONCURRENTLY generates W= AL > > + * when doing changes in the new table. Those changes should not be = useful > > + * for any other user (such as logical replication subscription) bec= ause > > + * the new table will eventually be dropped (after REPACK CONCURRENT= LY has > > + * assigned its file to the "old table"). > > + */ > > + switch (info) > > + { > > + case XLOG_HEAP_INSERT: > > + { > > + xl_heap_insert *rec; > > + > > + rec =3D (xl_heap_insert *) XLogRecGetData(buf->record); > > + > > + /* > > + * This does happen when 1) raw_heap_insert marks the TOAST > > + * record as HEAP_INSERT_NO_LOGICAL, 2) REPACK CONCURRENTLY > > + * replays inserts performed by other backends. > > + */ > > + if ((rec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE) =3D=3D 0) > > + return; > > + > > + break; > > + } > > + > > + case XLOG_HEAP_HOT_UPDATE: > > + case XLOG_HEAP_UPDATE: > > + { > > + xl_heap_update *rec; > > + > > + rec =3D (xl_heap_update *) XLogRecGetData(buf->record); > > + if ((rec->flags & > > + (XLH_UPDATE_CONTAINS_NEW_TUPLE | > > + XLH_UPDATE_CONTAINS_OLD_TUPLE | > > + XLH_UPDATE_CONTAINS_OLD_KEY)) =3D=3D 0) > > + return; > > + > > + break; > > + } > > + > > + case XLOG_HEAP_DELETE: > > + { > > + xl_heap_delete *rec; > > + > > + rec =3D (xl_heap_delete *) XLogRecGetData(buf->record); > > + if (rec->flags & XLH_DELETE_NO_LOGICAL) > > + return; > > + break; > > + } > > + } > = > I'm confused as to the purpose of this addition. I took this whole > block out, and no tests seem to fail. This is just an optimization, to avoid unnecessary decoding of data change= s that the output plugin would ignore anyway. Note that REPACK (CONCURRENTLY= ) can generate a huge amount of WAL itself. > Moreover, some of the cases that > are being skipped because of this, would already be skipped by code in > DecodeInsert / DecodeUpdate anyway. By checking earlier I tried to avoid calling ReorderBufferProcessXid() unnecessarily. > The case for XLOG_HEAP_DELETE seems > to have no effect (that is, the "return" there never hits for any tests > as far as I can tell.) The current tests do not cover this, but it should be hit by backends performing logical decoding unrelated to REPACK. The typical case is that = WAL sender involved in logical replication reads a DELETE record generated by REPACK (CONCURRENTLY) due to replaying a DELETE statement on the new relat= ion. > The reason I ask is that the line immediately below does this: > = > > ReorderBufferProcessXid(ctx->reorder, xid, buf->origptr); > = > which means the Xid is tracked for snapshot building purposes. Which is > probably important, because of what the comment right below it says: > = > /* > * If we don't have snapshot or we are just fast-forwarding, there is n= o > * point in decoding data changes. However, it's crucial to build the b= ase > * snapshot during fast-forward mode (as is done in > * SnapBuildProcessChange()) because we require the snapshot's xmin whe= n > * determining the candidate catalog_xmin for the replication slot. See > * SnapBuildProcessRunningXacts(). > */ > = > So what happens here is that we would skip processing the Xid of a xlog > record during snapshot-building, on the grounds that it doesn't contain > logical changes. I'm not sure this is okay. I think I missed the fact that SnapBuildProcessChange() relies on ReorderBufferProcessXid() having been called. > If we do indeed need this, > then perhaps it should be done after ReorderBufferProcessXid(). ... and after SnapBuildProcessChange(). Thus the changes being discussed h= ere should be removed from the patch. I'll do that in the next version. Thanks= . -- = Antonin Houska Web: https://www.cybertec-postgresql.com