Subject: Re: [Feature Request] INSERT FROZEN to Optimize Large Cold Data Imports and Migrations

From: Tom Lane <[email-masked]>
Date: Thu, 13 Feb 2025 10:08:44 -0500

=?UTF-8?Q?S=C3=A9bastien?= <[email-masked]> writes:
> Implementation details:

>    - A new INSERT FROZEN option could be introduced, similar to COPY FREEZE,
>    allowing direct insertion of tuples in a frozen state.
>    - This would likely require changes in heap storage logic to ensure
>    tuples are written with a frozen XID at insert time.
>    - Consideration should be given to transaction semantics and WAL logging
>    to ensure consistency and crash recovery integrity.

That last is exactly why this won't happen.  A frozen tuple would be
considered committed and visible the instant it appears in the table,
thus completely breaking both atomicity and integrity of the
transaction.

There has been work going on recently to reduce the impact of freezing
massive amounts of data by spreading the work more effectively [1].
I don't say that that particular commit has completely solved the
problem, but I think that continued effort in that direction is more
likely to yield usable results than what you're suggesting.

BTW, this might or might not be usable in your particular workflow,
but: there have long been some optimizations for data load into a
table created in the same transaction.  The idea there is that if the
transaction rolls back, the table will never have been visible to any
other transaction at all, so that maintaining atomicity/integrity of
its contents is moot.

			regards, tom lane

[1] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=052026c9b

---

From: Sébastien <[email-masked]>
Date: Thu, 13 Feb 2025 17:37:46 +0100

Thank you for your answer TOM.
I'd like to have this option only for initial loading of huge amounts of
data, where atomicity consistency is needed at all. Maybe an option on
startup command just for initial import mode, would be nice.

I had huge problems on server 3 weeks after a 6 TB migration from other DB.
I think it's sad to rewrite all data twice.

Le jeu. 13 févr. 2025 à 16:08, Tom Lane <[email-masked]> a écrit :

> [1]
> https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=052026c9b
>

-- 
Sébastien Caunes
+33 6 7 229 229 7

---

From: Greg Sabino Mullane <[email-masked]>
Date: Fri, 14 Feb 2025 11:39:41 -0500

On Fri, Feb 14, 2025 at 1:41 AM Sébastien <[email-masked]> wrote:

> I had huge problems on server 3 weeks after a 6 TB migration from other
> DB. I think it's sad to rewrite all data twice.
>

You could always COPY FREEZE into a new table, then move any remaining
rows, and finally rename the tables. Should be a win if the majority of the
table is newly-imported data. Another thing you might look at is increasing
your three week forced freeze window by adjusting params and/or decreasing
the number of transactions your cluster is using. (granted, still the same
overall write volume). You could also do manual vacuum freezes at a time
better for you (since you mention autovac is doing this at
unpredictable times).

Cheers,
Greg

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