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 1vQ1AJ-005vZI-2Y for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Dec 2025 10:29:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vQ1AI-001yKe-0A for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Dec 2025 10:29:54 +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 1vQ1AH-001yKV-1v for pgsql-hackers@lists.postgresql.org; Mon, 01 Dec 2025 10:29:54 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vQ1AF-002YZB-1G for pgsql-hackers@postgresql.org; Mon, 01 Dec 2025 10:29:53 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-42b3669ca3dso1682798f8f.0 for ; Mon, 01 Dec 2025 02:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1764584990; x=1765189790; darn=postgresql.org; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gF9/zxFnvITdvFz4lGPRTjZstcFahIo6F60es5UuFxY=; b=Zyr6KC3bGbL036IiipTJXkJypJt3ZUolHAubLP6SLFt8HoF0ZnN785mjFPyR/iNM+n uMg6Efh/qqm7WI2mDO0nlYmBknDhbnVMWwslgxZdjgC3ughH0hkrcNbAYhht+dEnL1OI fxZt3QHt1BaMeerwR5a1kWLEIyMqKjMdt2Mkt1+95xS9X0wptMnGrzvC/a1ctCkdwPz3 NUbao18nKtQiedI459ipve4MYz1R+87TiccQx6eqtWZ9BpGvCQF3WDUIAaOnkZZMffWo jSxC4DTMt+hQTaAa0wSVyRlEoY5hlA7wmWRUPnjILqONbOiW4ZdkZQzmIUjrphf2HrfJ jfiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764584990; x=1765189790; h=message-id:date:content-transfer-encoding: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=gF9/zxFnvITdvFz4lGPRTjZstcFahIo6F60es5UuFxY=; b=SlbTGQqqbWAkZGSwQ7kQA0zAxXCxjWPyXP+s6VBu5HFGGg/eq5K4xSov09qFMbiK/x RRfrJa4ztn9yuHvkFgA969MnnQNR5+wffS5GFCpWRAxy4GQ3mLfNiOu3asfc5WMgzCni fV01kSdcTguhtNtTrf9SF1ZGA1WwiGKtGtP3T2WzgZpvqfhDUfKwDITWGkKhBmpZ7NXh uhNVXmfe98PnS0kM1Zmt+/DOCO/dD0T87E+8EXIp0Z0gQVoi79BvMSWcaqzsFq4KBHpk vS5Z6e1oOy9pKohL7jae8MIAN4iO9w4fH3v6xXMZwFY+w/rVW2uqEquBiWVT7HIAM67r z5Mw== X-Forwarded-Encrypted: i=1; AJvYcCUGsLEOyCIrdY8fwA4ybAzzxcx4iq2codnFLayPAFkx459nfJ4YEeK3omdl1x0xcd+qFU9m9uSSja2n5OTX@postgresql.org X-Gm-Message-State: AOJu0Yw+EPFsisW187IiqVK3XatW3PXlzONz5tJd20WI4GZZ84v0caPN qSQBNb+oRRYID/42F4j9MVq15sBWwSTxi4Zn3ThsKOEK/HEvJrtMRzUfwEH3ccawlqg= X-Gm-Gg: ASbGnct1TfwLmwIVKVle47nrF0aHAi74pyhZ9256LDnWgjiHScxJvXFuTGWAzdAh4zw IlPoHIYpl5zr16rfFPig5zTHG8TH8XLPCY4rF40z52UpdSBfiw1LEUyRJtuqJQOkfhgsQIa1l8X h6hVs2OmPeJgSa/waZJieteGqC6doSAIZCiBJfGj4EtNDNB3uvrXr9FmAq2wWIpcmA+L6RGiF/X MSTO+zRBDYMH6ws0tfxywGmtG7EF4ZZ2M3tF2B5EThRYtAadKaLXmw7aUhlZsLONJd+UVYbkFNL DCkpQVWzYGB4GbRz7G7UAWmc6yhU+gYN/qdEFipLmTBW+rXIvJaJFoYMBAyuw1ngscIeI/PLKuN AUwY1ByyoZ1yOijkGUj1hTD0V3mdc9IGteA4P7rYZil5OOe+Q736za4iODxfAZkbLi6WZVMExI2 5+Ev10AWfd40ghYppB1kFOK4jB X-Google-Smtp-Source: AGHT+IGvHNa/4JQz67JiJEo3W+inGGK07w+TGNIuKhHxP8cP+eXoZr7lQ9j0PVKG2GIztqw5/C2AXw== X-Received: by 2002:a5d:5d12:0:b0:42b:2e39:6d45 with SMTP id ffacd0b85a97d-42cc1cbd047mr41802963f8f.15.1764584990436; Mon, 01 Dec 2025 02:29:50 -0800 (PST) Received: from localhost (109-81-168-246.rct.o2.cz. [109.81.168.246]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1ca7880asm25841185f8f.31.2025.12.01.02.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 02:29:49 -0800 (PST) From: Antonin Houska To: Hannu Krosing cc: Matthias van de Meent , 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> Comments: In-reply-to Hannu Krosing message dated "Fri, 28 Nov 2025 19:05:12 +0100." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 01 Dec 2025 11:29:49 +0100 Message-ID: <8010.1764584989@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hannu Krosing wrote: > On Fri, Nov 28, 2025 at 6:58=E2=80=AFPM Hannu Krosing = wrote: > > > > On Fri, Nov 28, 2025 at 5:58=E2=80=AFPM Matthias van de Meent > > wrote: > > > > > ... > > > I'm a bit worried, though, that LR may lose updates due to commit > > > order differences between WAL and PGPROC. I don't know how that's > > > handled in logical decoding, and can't find much literature about it > > > in the repo either. > > > > Now the reference to logical decoding made me think that maybe to real > > fix for CIC would be to leverage logical decoding for the 2nd pass of > > CIC and not worry about in-page visibilities at all. >=20 > And if we are concerned about having possibly to scan more WAL than we > would have had to scan the table, we can start a > tuple-to-index-collector immediately after starting the CIC. >=20 > For extra efficiency gains the collector itself should have two phases >=20 > 1. While the first pass of CIC is collecting the visible tuple for > index the logical decoding collector also collects any new tuples > added after the CIC start. > 2. When the first pass collection finishes, it also gets the indexes > collected so far by the logical decoding collectoir and adds them to > the first set before the sorting and creating the index. >=20 > 3. once the initial index is created, the CIC just gets whatever else > was collected after 2. and adds these to the index The core problem here is that the snapshot you need for the first pass restricts VACUUM on all tables in the database. The same problem exists for REPACK (CONCURRENTLY) and we haven't resolved it yet. With logical replication, we cannot really use multiple snapshots as Mihail= is proposing elsewhere in the thread, because the logical decoding system only generates the snapshot for non-catalog tables once (LR uses that snapshot f= or the initial table synchronization). Only snapshots for system catalog tables are then built as the WAL decoding progresses. It can be worked around by considering regular table as catalog during the processing, but it currently introduces quite some overhead: https://www.postgresql.org/message-id/178741.1743514291%40localhost Perhaps we could enhance the logical decoding so that it gathers the information needed to build snapshots (AFAICS it's mostly about the XLOG_HEAP2_NEW_CID record) not only for catalog tables, but also for particular non-catalog table(s). However, for these non-catalog tables, the actual snapshot build should only take place when the snapshot is actually needed. (For catalog tables, each data change triggers the build of a new snapshot.) So in general I agree with what you say elsewhere in the thread that it mig= ht be worth to enhance the logical decoding a bit. Transient enabling of the decoding, only for specific tables (i.e. not requiring wal_level=3Dlogical), is another problem. I proposed a patch for = that, but not sure it has been reviewed yet: https://www.postgresql.org/message-id/152010.1751307725%40localhost (See the 0007 part.) --=20 Antonin Houska Web: https://www.cybertec-postgresql.com