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.94.2) (envelope-from ) id 1ukj6i-006EVC-3K for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Aug 2025 12:55:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ukj6e-003OvD-Aw for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Aug 2025 12:55:28 +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.94.2) (envelope-from ) id 1ukj6e-003Ov4-0v for pgsql-hackers@lists.postgresql.org; Sat, 09 Aug 2025 12:55:28 +0000 Received: from mail-ua1-x92c.google.com ([2607:f8b0:4864:20::92c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ukj6b-001Ynp-0H for pgsql-hackers@lists.postgresql.org; Sat, 09 Aug 2025 12:55:27 +0000 Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-88dc7abaf5cso928220241.3 for ; Sat, 09 Aug 2025 05:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754744125; x=1755348925; darn=lists.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=uFDGKaLTDgFMev2vFWUd/i4uD696ybOWMEmXPnpmcFA=; b=CUajRSA/mqiuoeSpcZTvg1GfKG23mTDdAgWL+4wUUXcQpUIIRCIbyALuC67evvZjKL H1ST66a5L5lJL4+yhSeGG82/98SbEGYm/RAJE/bnluuzNoFEnG6akL9uGUrbfw+tBpPO wsMFDWIg01QsXVLb5hGJGMaXO+mdRUF4MmOrjUCEI3fUGgm9TmfN9KiqnjeA06EPCXcj rIhFMC1s2XN7G/1N5yMx+EUpkDvvShCWoN+1qJBd3BXI02J5gjVhurd7tHNG6cJYLiK6 PcFe4HGkYpE7D4lAzq8avAcHV8SfUfVoFhqOE4lwzd9M9R0VPVsmYCauFiGKlqXWckjJ FcqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754744125; x=1755348925; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uFDGKaLTDgFMev2vFWUd/i4uD696ybOWMEmXPnpmcFA=; b=Ax6Sn+Ha2Cw+VXUnt8skz+GKhMy+qOkjfGCBH5vbGFKED0zKkbIPcwczyBhXhvayp4 zg1TBOr875xujFGMBCh0BJAkw0fGOVYI5otjIk8nhISdbQAllSEd8AyLevecdFdEQk66 4OCiggrvzcivJeQyWyt6s5EK0YQT/9kjqr43AtCGVasHLiAfDfM1oJ9IFcPlXZ5D6hhW fs71hQYkCSiklp/n4CnOckh+cubrvvp6qWdrG4XX1+/dTOXqlam91mDPBT9sELJA90E/ kgNs1Cp4KX5VOqTlSGThS2/Ts4Qr+ksJxj1RsrKxb+5NgEfAPUaeBoXYGprsCsvLmiv+ UTrQ== X-Forwarded-Encrypted: i=1; AJvYcCWyZbbv2k+MR+k7ihB5q6Lf7+eipxjF2HjyAyTPnYEwglAK5dESUSyDHcnGVHNgeEane9FOHv465EKjQHAL@lists.postgresql.org X-Gm-Message-State: AOJu0YxgZyBsTn9qFvgIvucBXwKAdOXZv2mjpUoxuaiFp5H4ZZdZ1RNN 6MCadeUc1ocYiIUYxqmiHQ+1PU9zxnxRB1s01J2MfCCTR/N5DswnVFMYIdV5fidUmIOpHltOCLx eAWIa2ls2871Q84d1MFgUlawObE0wt1A= X-Gm-Gg: ASbGnctPSjjlyCHNW8SOjY4OAzYYtcFWrIA7FvtODDBtMDdktUgffaG5VCK22qYztyc L7DEnIYzGTjqtnMuYcsxdRc405kxwqHYex31kIwFY48fsgmlkzupzp1znzXdmIYAm7j3TLxSxJ5 GUGfnItUWA7MeiOjYJzUzoqtyfWQ1L/Ek9ltmwrGrDd+hygCbQhLhN/2QWmfh5RGowwuw3JKQ76 zIkh7k= X-Google-Smtp-Source: AGHT+IF1zTTiRs8Ir8fmUwc8kdC1Xhd7yLuLQcwpNq1jLjGtVQDo1eQrasoMbjpYwaCkDg2Ef4rph5ej4JDmQlqxnjQ= X-Received: by 2002:a05:6122:468d:b0:530:72da:d13d with SMTP id 71dfb90a1353d-53a52d2198fmr2331599e0c.1.1754744125011; Sat, 09 Aug 2025 05:55:25 -0700 (PDT) MIME-Version: 1.0 References: <202507311650.3a44mqyi3xnw@alvherre.pgsql> In-Reply-To: From: Mihail Nikalayeu Date: Sat, 9 Aug 2025 14:55:00 +0200 X-Gm-Features: Ac12FXypbaq0RALCQh6zNnJRbXdpVkwiANel6bU37TDiFb1V2aGHmfsf9tSjU5o Message-ID: Subject: Re: Adding REPACK [concurrently] To: Fujii Masao Cc: Alvaro Herrera , Robert Treat , Pg Hackers , Antonin Houska 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 Hello! One more thing - I think build_new_indexes and index_concurrently_create_copy are very close in semantics, so it might be a good idea to refactor them a bit. I=E2=80=99m still concerned about MVCC-related issues. For multiple applications, this is a dealbreaker, because in some cases correctness is a higher priority than availability. Possible options: 1) Terminate connections with old snapshots. Add a flag to terminate all connections with snapshots during the ExclusiveLock period for the swap. From the application=E2=80=99s perspecti= ve, this is not a big deal - it's similar to a primary switch. We would also need to prevent new snapshots from being taken during the swap transaction, so a short exclusive lock on ProcArrayLock would also be required. 2) MVCC-safe two-phase approach (inspired by CREATE INDEX). - copy the data from T1 to the new table T2. - apply the log. - take a table-exclusive lock on T1 - apply the log again. - instead of swapping, mark the T2 as a kind of shadow table - any transaction applying changes to T1 must also apply them to T2, while reads still use T1 as the source of truth. - commit (and record the transaction ID as XID1). - at this point, all changes are applied to both tables with the same XIDs because of the "shadow table" mechanism. - wait until older snapshots no longer treat XID1 as uncommitted. - now the tables are identical from the MVCC perspective. - take an exclusive lock on both T1 and T2. - perform the swap and drop T1. - commit. This is more complex and would require implementing some sort of "shadow table" mechanism, so it might not be worth the effort. Option 1 feels more appealing to me. If others think this is a good idea, I might try implementing a proof of concept. Best regards, Mikhail