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 1vRCGP-0099Af-0C for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 16:33:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRCGO-003VeW-0O for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 16:33:04 +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 1vRCGN-003VeN-2S for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 16:33:04 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vRCGL-0038Ex-2L for pgsql-hackers@postgresql.org; Thu, 04 Dec 2025 16:33:03 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-37e578d04b5so10812891fa.1 for ; Thu, 04 Dec 2025 08:33:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764865981; x=1765470781; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=EMnYK6MR34+xsmjghK0gHdH7mU4rdeZvCkjcZ0cwu5c=; b=LjpFZ+IxImxxZ6mCcpsEKAOrRjKTM21g6WE7mIImYDs6FX/dpR0WrBhvVveOVppT7e WUiBkcPwct2Go0Ell1pYpj2mHs2X+QI9MHbs35/Xsm+izOzNOByc7xt4CZDJFSzLYDgW zgp4UiLmvi+G4xOEB9yYX9hwqAm5naft032xdGmSk9f3QC3uGJs8feLI3+TFE0l1hLox MCxXFMALH4RMR4WJ4B2ZUxt+yDtk1tmdVLQhR3BId23mC+Z6PS4NFOHwPjE1VjQQvY9x mubKHGDqWszLpMxU3ws7xc92cJctJaIWEcjz4vG6jFBR+PBriUJjPKuimUnUn0V64c8I LsbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764865981; x=1765470781; h=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=EMnYK6MR34+xsmjghK0gHdH7mU4rdeZvCkjcZ0cwu5c=; b=J026GqAkEdS1Dwvqjrc9xkWhb0cWQxJBr7/vFsdGsWkjyOrdS0l9yVKQ0gL2oj5lAA 1k3ZA9WyHrPoL5jzOt4QQNj1Wzr6PRzv5+rhK9m4pkdSvhMFPGaPW9ed/ISw+rLUfhKs JENFvKNG9TAoweOGRSKBCvefvlTOxC2DlTgzX2pEB8g76XUVbM3ycbjB1IpdvzAcW5FX tTRW/0n2hs+jbOcw43uSQohQo3Muf466NPG+cuzmhg4s0iL5eGxi0HsY2HT3700LKsr7 aXDSuMTOxSTS/PzQs/wSJSgEZ6QF58t13GDs87qnEvUVqZLndMm3sWKs6crBQa2+4ATn HUPQ== X-Forwarded-Encrypted: i=1; AJvYcCUvZ5W0lfd2/lLWa6of4/cM2wQFFjbaoXt4UXJoMgVwUNR5QlI+VzXbFIXGZrfq1urhqk+zbl2FCK29NHJe@postgresql.org X-Gm-Message-State: AOJu0Yx9CH8RzW+AhCyNxx2oWOlfwObicfHmPCMBpSuUJMhkV13gHedM Xe93v7Zoor5E440kPT29WRhcshhTzO5+5beKkTOPb/VS1CeFlOqrdSO1b9Wq2XqP+6BTzmGdBaI C+ZIQxOyoxsj6BecDh0K1uRqaOyIAwCw= X-Gm-Gg: ASbGncuO2S2tQu4lU4Ywt7ZOyUvd2g8eKExniKaxTMFj3lBoXSx6/7JXbMZ41SXi1GX AuyCA+LmsjofWaa8aXRSpIftT28Awrr5Lbu9Wwl71FoeA+EQQ8/vI0E9QZzwl+nRDz2Vg20+CM0 /dcizT57AvuN/0xRJacChFFLzUMDfTtZGYbmbU4Zelv1cAshMd82Mt1C6TOZrnt1/2n4yBXopD2 5lQJyzOqtzJi0Sxxkjzphz+d3BmbYnXYlTBRCSXS36AYx6bD4D/4k6jRSWpHoEPUjQrrsEXG7As DoBgnMtVTbAirzvLd1Ykga6XOa8xFB6+DOnBhPW21x6veAxqeJZObLypg0K96I4DnqDZ X-Google-Smtp-Source: AGHT+IFRqstehiLvrT775lC9OAXBqAYY1h6XpvLqR0UGGtNbrLskDv5zRTlsUzuIcbVbkvKFdJOEOi7t4e3mMKEn5S0= X-Received: by 2002:a05:651c:a0b:b0:37b:9cb4:ab5b with SMTP id 38308e7fff4ca-37e6dee385emr11975381fa.32.1764865980381; Thu, 04 Dec 2025 08:33:00 -0800 (PST) MIME-Version: 1.0 References: <202505181556.3n6oiowvntyr@alvherre.pgsql> <5784.1764580169@localhost> <5293.1764837294@localhost> In-Reply-To: <5293.1764837294@localhost> From: Matthias van de Meent Date: Thu, 4 Dec 2025 17:32:48 +0100 X-Gm-Features: AWmQ_bm6-Kx3OZRXdpLwrY4YpJO8TXGb2jiZX1LwZks0GDBFvG6DZfUcD1BwJ2Q Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Antonin Houska Cc: Mihail Nikalayeu , Sergey Sargsyan , alvherre@kurilemu.de, Andres Freund , Michael Paquier , PostgreSQL Hackers , Andrey Borodin , Melanie Plageman Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 4 Dec 2025 at 09:34, Antonin Houska wrote: > > Matthias van de Meent wrote: > > > On Mon, 1 Dec 2025 at 10:09, Antonin Houska wrote: > > > > > > 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. > > > > > > Can you please give me an example of this problem? I understand that two > > > transactions do this > > > > > > T1: RecordTransactionCommit() > > > T2: RecordTransactionCommit() > > > T2: ProcArrayEndTransaction() > > > T1: ProcArrayEndTransaction() > > > > > > but I'm failing to imagine this if both transactions are trying to update the > > > same row. > > > > Correct, it doesn't have anything to do with two transactions updating > > the same row; but instead the same transaction getting applied twice; > > related to issues described in (among others) [0]: > > Logical replication applies transactions in WAL commit order, but > > (normal) snapshots on the primary use the transaction's persistence > > requirements (and procarray lock acquisition) as commit order. > > > > This can cause the snapshot to see T2 as committed before T1, whilst > > logical replication will apply transactions in T1 -> T2 order. This > > can break the exactly-once expectations of commits, because a normal > > snapshot taken between T2 and T1 on the primary (i.e., T2 is > > considered committed, but T1 not) will have T2 already applied. LR > > would have to apply changes of T1, which also implies it'd eventually > > get to T2's commit and apply that too. Alternatively, it'd skip past > > T2 because that's already present in the snapshot, and lose the > > changes that were committed with T1. > > ISTM that what you consider a problem is copying the table using PGPROC-based > snapshot and applying logically decoded commits to the result - is that 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 here on > replaying WAL, not on PGPROC. OK, that's good to know. For reference, do you know where this is documented, explained, or implemented? I'm asking, because the code that I could find didn't seem use any special snapshot (tablesync.c uses `PushActiveSnapshot(GetTransactionSnapshot())`), 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. Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)