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 1tiSrH-00GIpj-Aq for pgsql-general@arkaria.postgresql.org; Thu, 13 Feb 2025 06:37:59 +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 1tiSrD-002yOD-Ik for pgsql-general@arkaria.postgresql.org; Thu, 13 Feb 2025 06:37: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 1tiSrD-002yO5-7J for pgsql-general@lists.postgresql.org; Thu, 13 Feb 2025 06:37:55 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tiSrB-000Wvw-2N for pgsql-general@lists.postgresql.org; Thu, 13 Feb 2025 06:37:54 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5dec996069aso798755a12.2 for ; Wed, 12 Feb 2025 22:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1739428672; x=1740033472; darn=lists.postgresql.org; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=w5cgL35W0iWkoBDJ5arkXwXkfXZGdwzruWHSUby8UTs=; b=enkl1Ma5PyJ1X8NFcKIvN7OMvNs2SKt1I02DcH9kkP5+34zIJhA9po82utSqhw5xX2 Ph5VDA3NYQUQZYSGF2kh6vwSJmHfkSii+0sA014bDDZjFhJ88ENi9G3aBN86TrFbzSm+ 9XDLJIZfZac8oA6djM7HytNGjOLqbhdisCOmnuLyJILXn8fg++xGBBfXA5Xeo4UqSd2y DxIkACl/Udb0qQ8csZSSKWD0w3B8ZUwXT2YPv7KOKa5TCnhPvwk4+lZj6XyIpr5FQCnO qn8izFJhuWxpqCCPNCeZIleL6QkH620uQnYj+j/Pfpt+wFBYW22ohM/jhTrDH4R4F95q LLPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739428672; x=1740033472; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=w5cgL35W0iWkoBDJ5arkXwXkfXZGdwzruWHSUby8UTs=; b=DykHm6AHif7W3Y4IHYdO8UvGkxIHG47Qdrp1qyhP2sNDtaZQJ82+opmndhSam8k8SP l5m6B4mZGIhSNvK96KijIKEpItOjeGCYBOg+yUELWx4qYEEKdd8LchliI2gocDJQWPye U/BEcmh+udIOahsCq0aZkjHn+/OrBR94pwEXesg/GPV63OGUdZyjm8ntZFdKNQIJZZA9 vf1Bh4c2PY7gifPbRiNG7kfIZyjGOhTlFE6ar2OcPzR59+J1Srt/thm1b8JpVMOG8AWC t8bAJkdCvcECDYAMKINlfigQWRmWXiE/yyDB3hseN1C4DjI6qd7BHuSfYs+BUvam3yOq jXrQ== X-Gm-Message-State: AOJu0YwBlx89BPGucrZOm7ZzJ31A6kXD/X+XzNnt8jTO4u9rUnwWONIg MfcKqWPUqQyO17wcO146isicjTjO+YOAcc94ufcyOLc+FPAzMgN+mmgNqkq0njx0bJefMeNxZBz xFp53oLSaw9mgqBKC9ztUlHEoHHnSNuQdssh4CuXqFZ0IGBtrJYeu1Oyt0pm4XwDt X-Gm-Gg: ASbGncsBHbT9RtpkwvANsggHwjoEyVGwHEiRPlevL9H88arBHe9HVQWTi7xeNm2niVc HnxnyI1QxdJTJyJAqa/pF/y4desGl0W2HxknBslKsP62ETZ1uUvv4b5lH+f+8inbxOuYu65n6nQ 2EN+ACpKSKgB7VxcAwuw7m2oW27mk1OuxxrxV1gADmUi21iPJtjXSrCkGd88g+3W41gWi9SOpSK cCHNYTbMgx5S3y5WTjO1jhTd5QEvuNkfo6AgveEa9Hz/naIClb7UDWWrASefFI0KhBt81s5+Wlf uIInjM5nofZVxTYBIAZcIu8RrzFIJHuhxTs+ X-Google-Smtp-Source: AGHT+IGLuuHk0GYuH0zG8cnHln9LSUmZG8Um7xUYu7VGnZbALUTGkGqmhouePnWetuxl75XD/aglQQ== X-Received: by 2002:a17:907:6091:b0:ab6:58bc:715b with SMTP id a640c23a62f3a-ab7f34ac990mr609562966b.55.1739428671957; Wed, 12 Feb 2025 22:37:51 -0800 (PST) Received: from localhost.localdomain ([2001:871:255:52d3:3ac8:61ab:b634:342]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aba5339db80sm64682766b.149.2025.02.12.22.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2025 22:37:51 -0800 (PST) Message-ID: Subject: Re: Best Approach for Swapping a Table with its Copy From: Laurenz Albe To: Marcelo Fernandes , Adrian Klaver Cc: pgsql-general@lists.postgresql.org Date: Thu, 13 Feb 2025 07:37:50 +0100 In-Reply-To: References: <8ac6a1dd-db82-4ea7-8186-0c354d79049f@aklaver.com> <9fa75099-1ee9-43de-ac6e-945841b184eb@aklaver.com> User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2025-02-13 at 11:04 +1300, Marcelo Fernandes wrote: > > I am not seeing how this can be done without some outage for that table. > > Swapping tables without an outage is possible. Yes, but only if you are willing to write C code that runs inside the database server. That way, you can do anything (and cause arbitrary damage). The big challenge here would be to do the swap in a safe way. How do you intend to guarantee that the foreign keys are valid without a table scan? How do you handle concurrent data modifications? Yours, Laurenz Albe -- *E-Mail Disclaimer* Der Inhalt dieser E-Mail ist ausschliesslich fuer den bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen. *CONFIDENTIALITY NOTICE & DISCLAIMER *This message and any attachment are confidential and may be privileged or otherwise protected from disclosure and solely for the use of the person(s) or entity to whom it is intended. If you have received this message in error and are not the intended recipient, please notify the sender immediately and delete this message and any attachment from your system. If you are not the intended recipient, be advised that any use of this message is prohibited and may be unlawful, and you must not copy this message or attachment or disclose the contents to any other person.