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 1tijdm-001hjE-3v for pgsql-general@arkaria.postgresql.org; Fri, 14 Feb 2025 00:33:10 +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 1tijdj-00H7H3-Nj for pgsql-general@arkaria.postgresql.org; Fri, 14 Feb 2025 00:33:08 +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 1tijdj-00H7Gm-BG for pgsql-general@lists.postgresql.org; Fri, 14 Feb 2025 00:33:08 +0000 Received: from mail-il1-x143.google.com ([2607:f8b0:4864:20::143]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tijdh-000i9k-2A for pgsql-general@lists.postgresql.org; Fri, 14 Feb 2025 00:33:07 +0000 Received: by mail-il1-x143.google.com with SMTP id e9e14a558f8ab-3d03ac846a7so4785195ab.2 for ; Thu, 13 Feb 2025 16:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739493184; x=1740097984; 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=GiGfkFEi6JY6H+pmsO4p6Htm5T/beBkGM7CAZuxXSog=; b=kHSk6NHp0ImuRi4Ijil0K/VDdUBSbOKcmwaxXnnUOGLAhNrDljeVeRaySGvctvgz7/ E4BJoCgsiKPOYLrYLI56n6INLqVsnDqjB27xNd7uffWVp8Dz+nrZmqQnD/SbBbMTynmV S3QJdJee5cp8IPRs9DriO8HduXlQrmgnwsQXDEW3OyOjPDx2qPHV/561alaBJ1cGCBjF yxjzhj/ILEtJK4I2kUwFAETxGoE51kImeObmQ494Si2mFQiqFlDyV3LsbZb7xdiQ/Dq8 mnzaTX51ZQSyQzrsJ/1rGrVB7TkIs+zOu0tzuSuev8ULVuzHwWF25xm4ksGsgSx6H/M0 EmtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739493184; x=1740097984; 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=GiGfkFEi6JY6H+pmsO4p6Htm5T/beBkGM7CAZuxXSog=; b=hXqqvJzDL38YJkNPtj8xuvrTzTtM0rADtLkRDp48nFGA+swCcuZoha2arnyp+CtNHK n6GrQlBdv2aUKWu2QhBrmQu5+Zo/Zs24JQoM7RnWPRcmQghCxuFVq6MD5nd/nU+NdDEJ 1Rzjxsh6DVlK57KpMSYukhzktKJ9pRPAP53SXDEK8+1TOY1yAVnczvRYESiCWYTzGCVF ks+xMC67Pkj2ff+VUqmVKKC3MAxzlps8wb/cSdxGAOYnW8K9kpqwMPjQBnA5nAzjJ8Ni E2PdFoicFZqpWtSMcQwHyAVP6WD6mQH7Y5ZWbZ5KenY9FM5hvd0U+urp4EGHdDjSAA+9 IExQ== X-Forwarded-Encrypted: i=1; AJvYcCVonaS/D/lF4W2xPzv8f2kni479Pnn6VX49AAtIGmxjy/CmCQXwHZf73WvTY8hng0ZlhFGwfdOKDa1LtKqX@lists.postgresql.org X-Gm-Message-State: AOJu0YwmBOAc5l80jKDELzRIJc5SDIEXm9g9Goll96f9+3KuwWipePWZ 9QbpPnPJyTtsFp+ABhydplJey30X5xZFbYGvkV3A9TVthf+C2vQao7NBLrqeqbnQmwcgdxjcYzY sh2lmgZHnhINoTLdUSD1LnJUB2fQ= X-Gm-Gg: ASbGncstoxo/qlsZtVzMr7XB5i7CiiXSLIB1DsHBRMSW1ouOQUnaSQScHiUbLcQAnIa VXJHFGL605AoealOucT57RNBUekzDpt0mXZLRatAII/8xL0r7z+qNEbW/TgefAvo7d4Ai+ZTr X-Google-Smtp-Source: AGHT+IH/BVBBaQBOMcK3PKUkIPSD2qvsLbGQBHWELOPdQI5KJKbpUbb5KGJC8hZPJIj5Dv1jz1trgjBtBRcCyOMn6p4= X-Received: by 2002:a05:6e02:1909:b0:3cf:c17d:5cba with SMTP id e9e14a558f8ab-3d17be19aabmr66546605ab.9.1739493183715; Thu, 13 Feb 2025 16:33:03 -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> <380a6684-86d5-4ef6-9120-820d09c52a2b@aklaver.com> In-Reply-To: <380a6684-86d5-4ef6-9120-820d09c52a2b@aklaver.com> From: Marcelo Fernandes Date: Fri, 14 Feb 2025 13:32:52 +1300 X-Gm-Features: AWEUYZn-grkaG_N6n6vvKysT6NOy6g79JEIk3Ld5yxwWi2UyOQYnjDw5CzIU3_o Message-ID: Subject: Re: Best Approach for Swapping a Table with its Copy To: Adrian Klaver Cc: Dominique Devienne , Greg Sabino Mullane , pgsql-general@lists.postgresql.org 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 On Fri, Feb 14, 2025 at 12:35=E2=80=AFPM Adrian Klaver wrote: > 1) In a previous post you said: > > "Yes, in this scenario the copy is already created, and triggers keep > the copy in sync with the original table." > > In that case the copy will already have TOAST tables associated with it. If we follow the idea behind repack_swap, we would have swapped the oid's o= f the two tables. This means you have to swap the TOAST table in the catalogue as well. Otherwise the new table will be linked to the old TOAST and the old table w= ill be linked to the new TOAST. We want the opposite. > 2) What are the FK relationships and how many? I think that for theoretical purposes we can just say there are "N" FKs. Because no matter how many there are, they need to be updated to point towa= rds the new table. > Also could you just not add the FK's as NOT VALID? That's an interesting compromise I haven't thought of. Thanks. However, ideally I'd like to swap the catalogue entries instead - as that w= ould be a cleaner approach since it wouldn't require dropping old constraints, creating NOT VALID ones, and then optionally validating them later. Regards, - Marcelo