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 1wBBo1-000pAO-2U for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 13:21:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wBBny-00C0pz-27 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 13:21: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 1wBBny-00C0pq-15 for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 13:21:51 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wBBnw-00000000MJe-2rKn for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 13:21:50 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-43b983bb07eso1282659f8f.0 for ; Fri, 10 Apr 2026 06:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1775827307; x=1776432107; darn=lists.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=rHXW/KeI0xdfIwdky1IIClxDkY2mvvodA51JFLMvvq8=; b=ksS+pS2EuzVIEnYCOWjaa/3LRBs7qdIJUrPkO+J8gEuYYlITz1Twa/4XjPmhiOPR/2 qtR4xCIBhUkcsfHeXU+S2HUy6W49VmPbG5paYMqIBPNBmLfqejtcSzDe2cW69R7E1CNR ghttGF+ir5tONeoT3aY6VMg4gR+VXUV1w0LDL/YAijmz81ygZxnG1MD110rmD8ay3/A0 HMT7IuArAagOW820IBxplZkOR2neXEtqoqMMzo4q/f6aMRMxrjfNKQOLADX/BmNeKPwk OYehwFLbp9BrYNplaWzPfgpjrAdaawFsc09DkFgZcOnsvpLz4GWmPTIKUfXU+Dkcs8eG 0Tfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775827307; x=1776432107; 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=rHXW/KeI0xdfIwdky1IIClxDkY2mvvodA51JFLMvvq8=; b=WJWoOzAbJGZfyGZMrn/riNnNO08BC4Pd5pEgpkKQV178i/0RhsB7GmRNzua12yFagh At/7rjFQ8+lUlCFghMy17VX27naCeewJA31f7L7/L/5S5M7+Gdn2Nw6k4GW6/OpH8KR9 ufborVXzCOc8dDlhnUI5gp/Euuu1pm6nxS6VjBGnvGaTS/BgcsnogzKVgH31pxwMkwlL Nh1CF4QNvvrJClX/DjVdh9rlXX4ThIqisflNfBk7yLtFEsprBBRGOXbM1Nuj7N8nkWK+ ENXcf0e5eRsuhBp4/C4LLoTkNZyuigAOG/Ekp1CVunAuEAGKI3R2TctQ1l/8xeCnFYJd My1g== X-Forwarded-Encrypted: i=1; AJvYcCXSaxyUZUzoyteRET7+WW/lt3k/xJx+kWkJtTMz6eSl7hsO05Dg941WDQbZebuLonMMuBOnoMrifFlcFwm5@lists.postgresql.org X-Gm-Message-State: AOJu0YzL24HTbQmvVzzzsx+JVWAX6lWZpXvJfgFFbXi1PW5pbiXbhUPO QGSdURUDRjk9+21l5Fpd1CnxVAd2je/n5lerFYdt3qzzOnCScpC1s4OzG1aOOsE2z0o= X-Gm-Gg: AeBDievjlWZrbhN0KTKpgNXYwTCOFCiY3Z2LKvXjFmTX92zWtzBQ166l3YlaOSDQRKJ VVdYaeKKbgDXcLyT9kgK18p8mh7zcc85fAFmRF/JbdrqTRaNcOUEX7ZVVyv5dPWzQAK2Ho2MlkA rAGPpqBgfGi5fcKPx2iH1G698gk4z7WGNBSoz4SmX6Irlzf7uNXezgrslb6OiMRuBv35PILkTL7 4yPoOSY/cq3P+arlzDQV8If490hj3YRs4l5H8i01oU/c9kPi6IKtbTgAEq0StBgHRQjZeXXzK2K U2FrAdwScfbmiQXtzDnwkK8rXHPCxWTb9NQsBkrQpuuIsSZgyG3KyoIX3/CTjTxQM7De19hO+PN O2jIlNYQun9CnEpFkSJye9O9F+qs5yVykgi+i1n/D3gmHgNt38l8t1QEuzSDl3Upri8A1BdkUOy +mLiEZJVlf0akaMOSfmRZFAORU/rEyTVWYMkII X-Received: by 2002:a5d:5849:0:b0:43b:45a0:9df8 with SMTP id ffacd0b85a97d-43d642be552mr5072338f8f.35.1775827306764; Fri, 10 Apr 2026 06:21:46 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e468d0sm7388966f8f.18.2026.04.10.06.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2026 06:21:46 -0700 (PDT) From: Antonin Houska To: "Zhijie Hou (Fujitsu)" cc: Alvaro Herrera , Amit Kapila , "Hayato Kuroda (Fujitsu)" , Srinath Reddy Sadipiralla , Mihail Nikalayeu , Matthias van de Meent , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: References: <202604072027.gazfa2zt2l2j@alvherre.pgsql> Comments: In-reply-to "Zhijie Hou (Fujitsu)" message dated "Fri, 10 Apr 2026 10:53:53 -0000." 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: <125084.1775827305.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 10 Apr 2026 15:21:45 +0200 Message-ID: <125085.1775827305@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Zhijie Hou (Fujitsu) wrote: > When testing REPACK concurrently, I noticed that all WALs are retained f= rom > the moment REPACK begins copying data to the new table until the command > finishes replaying concurrent changes on the new table and stops the rep= ack > decoding worker. > = > I understand the reason: the REPACK command itself starts a long-running > transaction, and logical decoding does not advance restart_lsn beyond th= e > oldest running transaction's start position. As a result, slot.restart_l= sn > remains unchanged, preventing the checkpointer from recycling WALs. I think you're right, sorry for the omission. > However, since REPACK can run for a long time (hours or even days), I'd = like > to confirm whether this is expected behavior or if we plan to improve it > in the future ? And additionally, Yes, it will be improved. I have a draft patch for it, will rebase and pos= t it soon. The plan is to: 1) preserve the original xmin/xmax of the tuples when we insert them into = the new heap. Thus, besides achieving MVCC safety, we won't need XID assigned = for most of the time. 2) do catalog changes in separate transactions - XID needed here, but thes= e transactions take very short time. 3) use a single snapshot only for limited number of tuples/pages. When mor= e data needs to be copied, a new snapshot is built, supposedly with higher ->xmin than the prevous one. > IIUC, REPACK without using concurrent option does not have this issue. It does not have the WAL recycling issue because it does not need to read WAL. However it also runs in a long transaction. Even though it does not n= eed XID for the actual heap rewriting, it gets one at the moment it locks the table using AccessExclusiveLock (which is at the very beginning). > Given that we do not restart a REPACK, I think the repack decoding worke= r > should be able to advance restart_lsn each time after writing changes > (similar to how a physical slot behaves). To illustrate this, I've writt= en > a patch (attached) that implements this approach, and it works fine for = me. LGTM, thanks! > BTW, catalog_xmin also won't advance, but that seems not a big issue as > the REPACK transaction itself also holds a snapshot that retains catalog= tuples, > so advancing catalog_xmin wouldn't change the situation anyway. The snapshot "resetting" (mentioned above) should fix this problem too. -- = Antonin Houska Web: https://www.cybertec-postgresql.com