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 1tib6D-000CXU-US for pgsql-general@arkaria.postgresql.org; Thu, 13 Feb 2025 15:25:58 +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 1tib6B-009WSl-VH for pgsql-general@arkaria.postgresql.org; Thu, 13 Feb 2025 15:25:56 +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 1tib6B-009WSc-GV for pgsql-general@lists.postgresql.org; Thu, 13 Feb 2025 15:25:56 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tib6A-000bVp-10 for pgsql-general@lists.postgresql.org; Thu, 13 Feb 2025 15:25:55 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5fc69795ecbso479805eaf.1 for ; Thu, 13 Feb 2025 07:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739460353; x=1740065153; darn=lists.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=0493FHp0S7HPyqIV0fnm9AqudL4o+UuGvb2wIx/jfc4=; b=jGLssaQdTFRH5tCj1VZbtxXwcCs4oGpjIsnHasobyyYVnLdg4uniqvYnrmEPI3YprX jSVI+MCVcxs1lfnhGi4Q7+UngrujzF2bL/hDVhazeAGIuY5zHAWoj0TUCgzKHdU7N8uo RcFkjdOj33leTVoEjU4uJ75kX/539bYzd5lty3ggrTSiYDr5P4NOp0mtRPZCU7CMoe9W sWrUaQyXf2Bdegk3bgP3IfpM4wObdgimctICu4upC/VyFeWSqCCpMjpq3At2Qol6yQgo 5I6Yv2RK59PwkWNJx0jFU5sb7chVMe2eUrdJ3SYa+ZULSwSAuA1PC9Mv0s2BKZy6DVaY /CyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739460353; x=1740065153; h=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=0493FHp0S7HPyqIV0fnm9AqudL4o+UuGvb2wIx/jfc4=; b=ATWt075AVs9TsmUXkGs3vTf/WAp0RJLF/79OD4JFzdurMJN1WhY57Fv3qsDL57Ecg1 5KNREVAi3BCycwBkUODt+K+uJrgm820CVImSYF9fUKm2yqQqDXWCY+bFH2u8/p3V6/6l lRuwo/BNB1lh0xHWaNB2pFrOP3ltuFsHl0heMkG64AcLjWPwlYlzS0H2T9I0g9MtcO6v HTjaPZcCsHmJakRXGcjJLgUru6MJREKZI4WjZcAPFwhPNZyj4KEWeakFSdYHGA006WJn A1+H69FbVWbIgvUbDVa0HAIxYp8IE2B9kZYaFMunBA/fWxbYj4k8VhajstHduBKWZUia dVNw== X-Forwarded-Encrypted: i=1; AJvYcCUCCrlsFXqsEmeujOI+FQejniovp365qaB3a/ZrFtR5aevj+x0yzpnsvMzr8dHHLjlh2TsGM08OCb2oCZXp@lists.postgresql.org X-Gm-Message-State: AOJu0Yz2/URLWB5IXxdFMcB6WNNM9wzMxqUjtCTkORCN3na52x427juP NmqRY3rk4k/UjjQWFvbEVM3WTIkyqhV7gqG2gD0XOT2BF4ijF97Xn23rn2DxhynftupwxUlk5gh bzhJUNjiYN9iyiOXyf/c9smFPYLI= X-Gm-Gg: ASbGncsTDcS4ryy4iO+htrGqFjXcXK1nm1vvW4VT9Ya9vCNeKRQDqHNSWFO7k8LkOAU lAsB+KRAbpziiMqnL8orFfbpd7g3E/BB4W60Fsr0+sdIKxunMQGnPPVvVy+meUWObHsGlKb8qoo Q= X-Google-Smtp-Source: AGHT+IE2RttMKV5rB39DIiYA91h/ej/B/a1T65cd6tawqQMm8tLRHJPssfw7nMVcG31vO0IjkOugIhTU63mK51agPWQ= X-Received: by 2002:a05:6870:8286:b0:2b8:306f:c5b5 with SMTP id 586e51a60fabf-2b8d644be67mr4564700fac.7.1739460353692; Thu, 13 Feb 2025 07:25:53 -0800 (PST) MIME-Version: 1.0 References: <8ac6a1dd-db82-4ea7-8186-0c354d79049f@aklaver.com> <9fa75099-1ee9-43de-ac6e-945841b184eb@aklaver.com> <22406cdf-83f5-4b98-b07e-7827afe97f93@aklaver.com> In-Reply-To: From: Dominique Devienne Date: Thu, 13 Feb 2025 16:25:40 +0100 X-Gm-Features: AWEUYZnvLf8KIHGeEx95Qepfha10EAIO9zNLPhfimjlGzz68Lf7qnRK2kjUj9lw Message-ID: Subject: Re: Best Approach for Swapping a Table with its Copy To: Greg Sabino Mullane Cc: Marcelo Fernandes , Adrian Klaver , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000007b9cb0062e07ac05" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007b9cb0062e07ac05 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 13, 2025 at 4:09=E2=80=AFPM Greg Sabino Mullane wrote: > On Wed, Feb 12, 2025 at 9:02=E2=80=AFPM Marcelo Fernandes > wrote: > >> What I am after is the same, but I seek a deeper understanding of what i= t >> does, and why it does it. For example, it swaps relfilenode. Why? > > > It is surgically replacing all pointers to the old data with pointers to > the new data. Yes, with lots of system catalog shenanigans. > pg_repack is meant to do what vacuum full does, but in a faster way. > Imagine your table is an 18-wheeler truck, with a cab (system catalog > stuff) and a trailer (full of data). We don't want a whole new truck, we > want to change out the trailer. > With VACUUM FULL, you stop all traffic while you pull the truck to the > side of the road and turn it off. A new truck is pulled alongside it, and > everything from the old trailer is unloaded and placed in the new one. Th= e > new trailer is hooked to the cab, and pulls away into the now-moving > traffic. > With pg_repack, you keep driving full speed. A new truck pulls up > alongside your truck, and the new trailer is filled based on the old one. > At the last moment, all the wires are pulled from the old trailer and > hooked to the new trailer. The old trailer is detached and left to crash > into the mutant bikers who have been pursuing you. It's the same cab, but > the trailer (e.g. relfilenodes) has been changed. > It's technically possible to do something similar for your use case, but > it's not trivial. All the cab to trailer wires must be precisely changed. > Everything directly related to the data must be swapped: heap, indexes, > toast. > Thanks for the colorful analogy Greg :). Maybe the better option is to support ALTER TABLE to ADD an exclusion constraint, no? I get that it's not support now. But is it more difficult than the above? And why then? --DD --0000000000007b9cb0062e07ac05 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Feb 13, 2025 at 4:09=E2=80=AFPM G= reg Sabino Mullane <htamfids@gmail= .com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
On Wed, Feb 12, 2025 at 9:02=E2=80=AFPM Marcelo Fernandes <marcefern7@gmail.com<= /a>> wrote:


--0000000000007b9cb0062e07ac05--