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 1tjoO6-00DdM1-K3 for pgsql-general@arkaria.postgresql.org; Sun, 16 Feb 2025 23:49:26 +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 1tjoO4-00Bfm1-Q8 for pgsql-general@arkaria.postgresql.org; Sun, 16 Feb 2025 23:49:24 +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.94.2) (envelope-from ) id 1tjoO4-00Bfls-CB for pgsql-general@lists.postgresql.org; Sun, 16 Feb 2025 23:49:24 +0000 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tjoO1-001Erh-2j for pgsql-general@lists.postgresql.org; Sun, 16 Feb 2025 23:49:24 +0000 Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-3cfc8772469so12204585ab.3 for ; Sun, 16 Feb 2025 15:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739749760; x=1740354560; 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=ETShSUBea0gf6ugLxF0V0nZy/PHQ1kKZyfrt/wdD/Lo=; b=DdpapSDtco887Thc/XFAT6DO2cUsP0YAFZ56xGAFxDPCRHqXiPglZnO4+d5mLn14he CDvm82FszTdB/2nMM0aaEig56gjNqk+4sa7SIjAPZAnH3veQSuqBaZs7g2UPN0G7vmns Un1aR3iRgew1o3K6tpNpi2MG6rwHb/nzInDItXK/b0r4ZPA1cd4hHwiDTfUfslf0dEnq pexXa8uyc85kFgowJ7XwoLOP1Q3EmBXWDgElsXuyb96SisKR6fz5WY20QS+CYH3ZT2fG eio/zCIQH2BI1EDQWhLrWKTgNDwXH5N9VhTDcrR5wO7pHC8PwHt2tR9jufzeUjSs1rBV 6woA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739749760; x=1740354560; 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=ETShSUBea0gf6ugLxF0V0nZy/PHQ1kKZyfrt/wdD/Lo=; b=rjATq7L7BIRzuqpMm8NGNDg2mh3QVJez2W181NADn1BLZ/jt5cL2Pj7napnkQDY5Ob n3peu/hnzce1luHTgjv5x1/aZsrcM7n5yGlrqoIBB6Abpgq6P4dUCICsMCO4O116gA3D s5YutESDd5n/CcV00WeCuT0mFBTVYX9aMaTtacNdt2qZwJsU/ApgQ9h264+edTSxUzKX 72gjxRJnHtsApVHJcvrDfV6ma3M+b4i1pnV+g3wDeJqbpnvz1Bvk39E53OrqHh0hhGL9 jBJnsfIyoUt5fCqnJIHg6fPAfeOLHEDjQ4/kaKvxlXyVTUPoIFIcWQ8WGkgAlSl3IRaI sLsw== X-Forwarded-Encrypted: i=1; AJvYcCWj8PsIl8zyshw04sxQh+bqElgrfnS9tjZwxYyYc0P1+J8kiL/PoHktZInYcfejNDuTrTXYp7BhrkIBZpjy@lists.postgresql.org X-Gm-Message-State: AOJu0Yww1+jL8HF8yrPlPtc2N9MnYt6QXRsJ5koKEd/ps3mJcszFAU9L Qb7ETGSb43VirBdUlQxfTWD6KXFJkZOG32HzDWZC39MOC2YugPPrYd8TNqd0lc5lqc/RXz2mQEF ifU9v/BA9uu5YcY3W/HK5Wxlmxfatx1D/ X-Gm-Gg: ASbGncth7/NYNUZ48CVp1IYyBHMVWWyvJK7rZ0AxJQhTrvsK3FAXQjHwLyaQXyRRa7f UohbtVkzicr2ju3eFCqUmGsMAV9zlD/AP7kpigqCKMHqThUrshrV0BkFbPHd9/xXrAcoAor6Uh2 qcJMDq5S2wWUWefu1F2Zl/xVj66+4nUR0= X-Google-Smtp-Source: AGHT+IHVHbucW+c7guMCpVdTMU82E4tvEq4YOUeWMpDF6tXEOBp1wGJQ0v9Jf3/fVpZBoZvITMAC07z1Q2uxU/5Plb8= X-Received: by 2002:a05:6e02:1fed:b0:3cf:fa94:c7d with SMTP id e9e14a558f8ab-3d2807fe341mr52062645ab.9.1739749759664; Sun, 16 Feb 2025 15:49:19 -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> <94e1205e-8ddf-403b-8477-02d7939f2905@aklaver.com> In-Reply-To: From: Greg Sabino Mullane Date: Sun, 16 Feb 2025 18:48:43 -0500 X-Gm-Features: AWEUYZlQKm4-f6nJ4LUSWliYugfmSjhYPtThs3h52rNYDt21PP3NtWJMQX2BUcI Message-ID: Subject: Re: Best Approach for Swapping a Table with its Copy To: Marcelo Fernandes Cc: Adrian Klaver , Dominique Devienne , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000006c4816062e4b0eea" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006c4816062e4b0eea Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Feb 16, 2025 at 5:58=E2=80=AFPM Marcelo Fernandes wrote: > - The foreign keys are not being updated to point to the new table. > You started out okay with your test script, but the pg_depend bit needs work. I would recommend examining that table closely until you have a really good understanding of how it works - both on the objid and refobjid side. Create and modify tables and see how the pg_depend entries change. Hint: Try it with and without foreign keys. https://www.postgresql.org/docs/current/catalog-pg-depend.html > - pg_repack seems to update relcache entries. I am not sure how to do tha= t > with SQL. Yes, as I mentioned upthread, the safest thing will probably be a restart. Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support --0000000000006c4816062e4b0eea Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Feb 16, 2025 at 5:58=E2=80=AFPM M= arcelo Fernandes <marcefern7@gma= il.com> wrote:
- The foreign keys are n= ot being updated to point to the new table.

=
You started out okay with=C2=A0your test script, but the pg_depend bit= needs work. I would recommend examining that table closely until you have = a really good understanding=C2=A0of how it works - both on the objid and re= fobjid side. Create and modify tables and see how the pg_depend entries cha= nge. Hint: Try it with=C2=A0and without foreign=C2=A0keys.

=C2=A0
- pg_repack seems to update relcache entries. I am not sure how to do that = with SQL.

Yes, as I mentioned upthread, the= safest thing will probably be a restart.

Ch= eers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support

--0000000000006c4816062e4b0eea--