Re: Best Approach for Swapping a Table with its Copy - Mailing list pgsql-general

From Marcelo Fernandes
Subject Re: Best Approach for Swapping a Table with its Copy
Date
Msg-id CAM2F1VONo8M9gcybhmf8-CdmRUC2QrFGZkZLYF-+uLZuhRKaxQ@mail.gmail.com
Whole thread Raw
In response to Re: Best Approach for Swapping a Table with its Copy  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Best Approach for Swapping a Table with its Copy
Re: Best Approach for Swapping a Table with its Copy
List pgsql-general
On Thu, Feb 13, 2025 at 10:40 AM Adrian Klaver
<adrian.klaver@aklaver.com> wrote:
> Do you know this will not fail on the existing data?

Yes, all the current data in the original table respects the constraint.

> Do you have room for a complete copy of the table?

Yes, in this scenario the copy is already created, and triggers keep the copy
in sync with the original table.

> I am not seeing how this can be done without some outage for that table.

Swapping tables without an outage is possible. I believe that this something
involved in the process repacking a table when using pg_repack as it relies on
copying the whole table and then swapping it for the original.

My main question is "How?". I know that the pg_repack involves swapping the
relfilenode values and something about TOAST tables, but I am not super
acquainted with pg_repack code or debugging tools to verify precisely what it
does.

> What sort of time frame is acceptable?

The scan phase in this table is very slow, on top of it the exclusion
constraint needs to create the underlying index to service the constraint.

Anything that takes more than 10s in this system is prohibitive, in this sense
creating the constraint without having a table copy is not viable for the size
of this table.

Regards,



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Best Approach for Swapping a Table with its Copy
Next
From: Ben Hancock
Date:
Subject: Re: psql command line editing