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 1vREnv-00AGpO-2d for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 19:15: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 1vREnu-004KGC-27 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 19:15:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vREnu-004KG4-0f for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 19:15:50 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vREnr-0039Rd-0T for pgsql-hackers@postgresql.org; Thu, 04 Dec 2025 19:15:49 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-64180bd67b7so1780514a12.0 for ; Thu, 04 Dec 2025 11:15:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1764875746; x=1765480546; darn=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=kjaxpwFrgBl8cVEeH1P67HFUgXrPBCYIoZrLr1y1giM=; b=nnuHSzpe3FrGlUWZcdSTXVv3goL76lzxqaqkSlpjxvmXpepVDCtbl1Pc0URNhzztwn q6CcYK1G5xOz6c8dc+mwZmfdQDQrtmeSPZjZjbtfw+H0MPBH6M+C8I/hGT8Oqw4R/HBT D/gErP7Imwi37sZfCccsPoEOAYFR024iSb8crVMytv8JV2FqwaLGMAaO3ZYaFtNaHauB 7rbuQtINOEhb933UlKdVYRJtp5ePPOtQc17481a9OmzMahm6YuEDmHmRhSKuNtl9J9LB d+pmTGpJTt+KTDKt8YY01CBtF5qEjx1P9nCXQ9L/5Z2+G/VujJqGjUl7kncsAgjRND9L uQcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764875746; x=1765480546; 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=kjaxpwFrgBl8cVEeH1P67HFUgXrPBCYIoZrLr1y1giM=; b=B/1hV2SWVfZxYizzbax75HndOWxcR4mHAG6YaecvkH6ifd2aolha01CE1GFSurVaeK OnJdNy/xqZeoXsXla4xUYUue+LXCVJXJrYMnDdlYHx6X4/f1mVMhWppgLo4CS+JUlF8I NHxHQzajM6OvbfQhMUCABeOCnbNji7RV4mBksz1x7z/8qErZ1zBxVmll1+sYm+oDIhf4 WyDdCbNT5oHu/U1vxySLtcOl2xzxQ0PfoLzpl1FpnI6Hvg0JqKoesRXdZu8iteP2HQNM iL51nYbmsTXdjZcoq5oUb+ss/m2GUpnkopZC0zMhRfI1OpWfksj6UxpP5yXb1I0JmdFd gDzg== X-Forwarded-Encrypted: i=1; AJvYcCUcN3I4fwiCm01GDBqHJL1qLbwux6O8Ke7+624u6LgbUGFoj6DJlGxGqTr3t4Lg0gup3vBVCTSb7kYio/Ip@postgresql.org X-Gm-Message-State: AOJu0YwRx7eUT5jcJIoEqjJBdAFoxF5hjovzRRJar3PGF8eWgkOVj8tC JkNf+h8zqXS29uhPSenY0RFYoHPSpfeIFl6UAbqI8e4xtz+8LH0wQHxej9VBHnYxyTY= X-Gm-Gg: ASbGncsMT+GTXcVHm4mtaXvjauxHQPPuMb4tg9O1v0jhlW4CvUgyKrkZ24HxT0Wnne6 OEAkKYb1FiMe4h4W6k5O3j3zFOpyzOvW9WJMW8hdZOqldgeZE+gxn89jHBXcTDfX7oEiyt6H8/s ZFQGcgITO0KzV0OzcYdXjG2OVhtHLMQCkjLqHB7el3Xscf6wckO1JE4GhwIlFm95x3YU4s2EuoQ le7wW4/ekhKdYTDZ+5nu/tNeZFzX4Xw4TgTzjoA7GfUNVuAKMVJsWB8+Pu4P6wmCxW0ui+esGI5 NzsGAWb9pnH/fOdK1keG9ySENUwj3oKRtpaPp2isFxxEtLm2E4mKiCzIBG4TeRtufu8j5If36fe jumgz1O6Z3yJCi2EAXsBf/c0mnycgPDnyucEBwv2FiXU4xvAKpzngHf/beE12cY07UA/M36MUJR F/2ptKLOqCGc7cd4XwOoNg9o/Q X-Google-Smtp-Source: AGHT+IEj9Sp5WfS7fgsV63j1hRvp8KLWBxGpdhZT7n9IfdtLINnR7Xmp3XZMA/ZRpOMMxURXhNqt6Q== X-Received: by 2002:a17:907:86a7:b0:b73:6d56:f3ff with SMTP id a640c23a62f3a-b79dbea4561mr752656566b.20.1764875746104; Thu, 04 Dec 2025 11:15:46 -0800 (PST) Received: from localhost (109-81-168-246.rct.o2.cz. [109.81.168.246]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b79f445968asm205700466b.3.2025.12.04.11.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 11:15:45 -0800 (PST) From: Antonin Houska To: Matthias van de Meent cc: Mihail Nikalayeu , Sergey Sargsyan , alvherre@kurilemu.de, Andres Freund , Michael Paquier , PostgreSQL Hackers , Andrey Borodin , Melanie Plageman Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements In-reply-to: References: <202505181556.3n6oiowvntyr@alvherre.pgsql> <5784.1764580169@localhost> <5293.1764837294@localhost> Comments: In-reply-to Matthias van de Meent message dated "Thu, 04 Dec 2025 17:32:48 +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: <120850.1764875744.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Thu, 04 Dec 2025 20:15:44 +0100 Message-ID: <120851.1764875744@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 PGPRO= C-based > > snapshot and applying logically decoded commits to the result - is tha= t 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 her= e 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. So= me lines above that however, walrcv_create_slot(..., CRS_USE_SNAPSHOT, ...) i= s called which in turn calls CreateReplicationSlot(..., CRS_USE_SNAPSHOT, ..= .) on the publication side and it sets that snapshot for the transaction on t= he 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 catalo= g scans, because in logical decoding you only need to scan catalog tables. T= his is especially to find out which tuple descriptor was valid when particular data change (INSERT / UPDATE / DELETE) was WAL-logged - the output plugin needs the correct version of tuple descriptor to deform each tuple. Howeve= r there is no need to scan non-catalog tables: as long as wal_level=3Dlogica= l, the WAL records contains all the information needed for logical replication (including key values). So snapbuild.c only keeps track of transactions th= at 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 comm= its of all transactions, but only does so until SNAPBUILD_CONSISTENT state is reached. Thus, just before the actual decoding starts, you can get a snaps= hot to scan even non-catalog tables (SnapBuildInitialSnapshot() creates that, = like in the code above). (For REPACK, I'm trying to teach snapbuild.c recognize that transaction changed one particular non-catalog table, so it can build 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 u= sed this for non-catalog tables, HeapTupleSatisfiesHistoricMVCC() would be use= d 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