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 1vRGUR-00Aatd-32 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 21:03:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRGUR-004sOJ-0B for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 21:03:51 +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 1vRGUQ-004sOB-2L for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 21:03:51 +0000 Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vRGUO-003ALV-2m for pgsql-hackers@postgresql.org; Thu, 04 Dec 2025 21:03:50 +0000 Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-4edb8d6e98aso134161cf.0 for ; Thu, 04 Dec 2025 13:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764882226; x=1765487026; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y54EanF/jfopfY/BdnFfBoCFLPX1PCzBumXCkvcSjNc=; b=NyHVcIrsoCY8X7YRzPypziIW8/ToWktFACl9EjRF+ZkTxOd9JitPIeZFpTBBKHNO60 XQOgMNzfwNPYqjOJhw2IZEZOhXRYqjMYpTytVyzPve9l7gSs9IjV+/zuto8T79XuHPvj gAJ71j5Gr/w0GkDDOCy2yzW6ZCG0+gUnbxQgXIxbI24aE/c+9jxrwNSr3jiugvmlC1o3 D/lmI0GM4mFr/OPwUsafBwQRBy3M4bxGD470aTttWtLQcwqdMDe0WETtrTAcrItWmthl 6ul0C+lIQzbHU1nqUPq6EUTwZ+yJajcsUCPpaz6wJk5XZBv9STFVbZjtQeZiMvWcH5M8 t5rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764882226; x=1765487026; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=y54EanF/jfopfY/BdnFfBoCFLPX1PCzBumXCkvcSjNc=; b=VNesg+Jh/FhiW/Dx1wqNcd4xDMyRjHHjuI5Kjc2fZ7ofInISFXebeItldKzjmWNT6r GY6e31qYrg5H50I0MUvAvM7OfnPzZ2amSpHV7KAnLL9HoAOd31kEMRpNT0+J0sU6Cqq8 1lLszFoMxbWuy4awlezULKyrAnfk5NeXV6a/OCvMDJ0gpoF14rt8vM2zWaIn1bwfxIJI YzSmZ1rYQuqlH69ue9ji4VraXphiE2A0RBwhY2Dw1iwoaiQyeC9gq4ifY1z28He+RAag HtjJG+EoQFMu5O/9bDCBPLIvMY1RorOJr7p3UGborFndINxwjViY1F86xQPetnlFZTjx xuOQ== X-Gm-Message-State: AOJu0YxjDOKo9G0HDZCEUAAIbWJx14lU9dGG3pYcfXbzThqVaFXuZZys Lm/BUvY000BcPKqAc5fiO4QAB2u/aUeSbE3dvhnpCWmezD/2xEqmhys32IZY8PTQx2hnuVmJIf0 Zw7waWzb9qy5lBmzEaUI2k+DPhj94IClD8sdj2AHSGwqIlDgcJLPfC3V1 X-Gm-Gg: ASbGncv/mooSkeAryDQJ97HmriLnyOsBN119/4/+HeQI+keSEFL1y9tok1yYWzvMG2O oZAkDRlCOrRcYA1DHwIFo9K9n5ZGkot1irk1tyA3j2d2BQVSm9Q25eZEdhpRw+iNTvMdDsSa4B4 p67s9lSTLo9NWbPqa/6tpajKsMI7IIsxIai8xH2LeEytkYAsn0N8xph7wg4pNHr+R8BR+H2OPgE Yip6nyhlBjiAOZtku2vAPFVhitvNYleYkrBj1XbnKTLwFSiqMA7e7kiaS/xIUi9XWPwo0VD X-Google-Smtp-Source: AGHT+IFDtM+1njF1aEGd+8HPuGUbU2GVGSlh069xJNv9TWLop4R/WVKvVi0f7nNdYzkwBY5Hn+IR7aILHyJYCKMCKAg= X-Received: by 2002:a05:622a:1b87:b0:4b7:aa51:116a with SMTP id d75a77b69052e-4f030e63877mr2316531cf.4.1764882224646; Thu, 04 Dec 2025 13:03:44 -0800 (PST) MIME-Version: 1.0 References: <202505181556.3n6oiowvntyr@alvherre.pgsql> <5784.1764580169@localhost> <5293.1764837294@localhost> <120851.1764875744@localhost> In-Reply-To: <120851.1764875744@localhost> From: Hannu Krosing Date: Thu, 4 Dec 2025 22:03:33 +0100 X-Gm-Features: AWmQ_bloLIysDdfNcNXdQ5zYnL1NtwLq-wvDvkJNsV81RDip1F3djZgCmPcXaEg Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: PostgreSQL Hackers Cc: Antonin Houska , Matthias van de Meent , Mihail Nikalayeu , Sergey Sargsyan , alvherre@kurilemu.de, Andres Freund , Michael Paquier , Andrey Borodin , Melanie Plageman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I just sent a small patch for logical decoding to pgsql-hackers@ exposing to logical decoding old and new tuple ids and a boolean telling if an UPDATE is HOT. Feel free to test if this helps here as well On Thu, Dec 4, 2025 at 8:15=E2=80=AFPM Antonin Houska wrot= e: > > Matthias van de Meent wrote: > > > On Thu, 4 Dec 2025 at 09:34, Antonin Houska wrote: > > > > > > ISTM that what you consider a problem is copying the table using PGPR= OC-based > > > snapshot and applying logically decoded commits to the result - is th= at what > > > you mean? > > > > Correct. > > > > > In fact, LR (and also REPACK) uses snapshots generated by the logical= decoding > > > system. The information on running/committed transactions is based he= re on > > > replaying WAL, not on PGPROC. > > > > OK, that's good to know. For reference, do you know where this is > > documented, explained, or implemented? > > All my knowledge of these things is from source code. > > > I'm asking, because the code that I could find didn't seem use any > > special snapshot (tablesync.c uses > > `PushActiveSnapshot(GetTransactionSnapshot())`), > > My understanding is that this is what happens on the subscription side. S= ome > lines above that however, walrcv_create_slot(..., CRS_USE_SNAPSHOT, ...) = is > called which in turn calls CreateReplicationSlot(..., CRS_USE_SNAPSHOT, .= ..) > on the publication side and it sets that snapshot for the transaction on = the > remote (publication) side: > > else if (snapshot_action =3D=3D CRS_USE_SNAPSHOT) > { > Snapshot snap; > > snap =3D SnapBuildInitialSnapshot(ctx->snapshot_builder); > RestoreTransactionSnapshot(snap, MyProc); > } > > > and the other > > reference to LR's snapshots (snapbuild.c, and inside > > `GetTransactionSnapshot()`) explicitly said that its snapshots are > > only to be used for catalog lookups, never for general-purpose > > queries. > > I think the reason is that snapbuild.c only maintains snapshots for catal= og > scans, because in logical decoding you only need to scan catalog tables. = This > is especially to find out which tuple descriptor was valid when particula= r > data change (INSERT / UPDATE / DELETE) was WAL-logged - the output plugin > needs the correct version of tuple descriptor to deform each tuple. Howev= er > there is no need to scan non-catalog tables: as long as wal_level=3Dlogic= al, the > WAL records contains all the information needed for logical replication > (including key values). So snapbuild.c only keeps track of transactions t= hat > modify system catalog and uses this information to create the snapshots. > > A special case is if you pass need_full_snapshot=3Dtrue to > CreateInitDecodingContext(). In this case the snapshot builder tracks com= mits > of all transactions, but only does so until SNAPBUILD_CONSISTENT state is > reached. Thus, just before the actual decoding starts, you can get a snap= shot > to scan even non-catalog tables (SnapBuildInitialSnapshot() creates that,= like > in the code above). (For REPACK, I'm trying to teach snapbuild.c recogniz= e > that transaction changed one particular non-catalog table, so it can buil= d > snapshots to scan this one table anytime.) > > Another reason not to use those snapshots for non-catalog tables is that > snapbuild.c creates snapshots of the kind SNAPSHOT_HISTORIC_MVCC. If you = used > this for non-catalog tables, HeapTupleSatisfiesHistoricMVCC() would be us= ed > for visibility checks instead of HeapTupleSatisfiesMVCC(). The latter can > handle tuples surviving from older version of postgres, but the earlier > cannot: > > /* Used by pre-9.0 binary upgrades */ > if (tuple->t_infomask & HEAP_MOVED_OFF) > > No such tuples should appear in the catalog because initdb always creates= it > from scratch. > > For LR, SnapBuildInitialSnapshot() takes care of the conversion from > SNAPSHOT_HISTORIC_MVCC to SNAPSHOT_MVCC. > > -- > Antonin Houska > Web: https://www.cybertec-postgresql.com > >