Re: In-placre persistance change of a relation

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: stark(dot)cfm(at)gmail(dot)com
Cc: hlinnaka(at)iki(dot)fi, barwick(at)gmail(dot)com, jchampion(at)timescale(dot)com, pryzby(at)telsasoft(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, rjuju123(at)gmail(dot)com, jakub(dot)wartak(at)tomtom(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: In-placre persistance change of a relation
Date: 2023-04-25 07:54:57
Message-ID: 20230425.165457.193946345712188069.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Fri, 17 Mar 2023 15:16:34 +0900 (JST), Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote in
> Mmm. It took longer than I said, but this is the patch set that
> includes all three parts.
>
> 1. "Mark files" to prevent orphan storage files for in-transaction
> created relations after a crash.
>
> 2. In-place persistence change: For ALTER TABLE SET LOGGED/UNLOGGED
> with wal_level minimal, and ALTER TABLE SET UNLOGGED with other
> wal_levels, the commands don't require a file copy for the relation
> storage. ALTER TABLE SET LOGGED with non-minimal wal_level emits
> bulk FPIs instead of a bunch of individual INSERTs.
>
> 3. An extension to ALTER TABLE SET (UN)LOGGED that can handle all
> tables in a tablespace at once.
>
>
> As a side note, I quickly go over the behavior of the mark files
> introduced by the first patch, particularly what happens when deletion
> fails.
>
> (1) The mark file for MAIN fork ("<oid>.u") corresponds to all forks,
> while the mark file for INIT fork ("<oid>_init.u") corresponds to
> INIT fork alone.
>
> (2) The mark file is created just before the the corresponding storage
> file is made. This is always logged in the WAL.
>
> (3) The mark file is deleted after removing the corresponding storage
> file during the commit and rollback. This action is logged in the
> WAL, too. If the deletion fails, an ERROR is output and the
> transaction aborts.
>
> (4) If a crash leaves a mark file behind, server will try to delete it
> after successfully removing the corresponding storage file during
> the subsequent startup that runs a recovery. If deletion fails,
> server leaves the mark file alone with emitting a WARNING. (The
> same behavior for non-mark files.)
>
> (5) If the deletion of the mark file fails, the leftover mark file
> prevents the creation of the corresponding storage file (causing
> an ERROR). The leftover mark files don't result in the removal of
> the wrong files due to that behavior.
>
> (6) The mark file for an INIT fork is created only when ALTER TABLE
> SET UNLOGGED is executed (not for CREATE UNLOGGED TABLE) to signal
> the crash-cleanup code to remove the INIT fork. (Otherwise the
> cleanup code removes the main fork instead. This is the main
> objective of introducing the mark files.)

Rebased.

I fixed some code comments and commit messages. I fixed the wrong
arrangement of some changes among patches. Most importantly, I fixed
the a bug based on a wrong assumption that init-fork is not resides on
shared buffers. Now smgrDoPendingCleanups drops buffer for a init-fork
to be removed.

The new fourth patch is a temporary fix for recently added code, which
will soon be no longer needed.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
v28-0001-Introduce-storage-mark-files.patch text/x-patch 55.6 KB
v28-0002-In-place-table-persistence-change.patch text/x-patch 31.4 KB
v28-0003-New-command-ALTER-TABLE-ALL-IN-TABLESPACE-SET-LO.patch text/x-patch 17.9 KB
v28-0004-Tentative-deletion-of-include.patch text/x-patch 737 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2023-04-25 08:27:59 enhancing plpgsql debug api - hooks on statements errors and function errors
Previous Message torikoshia 2023-04-25 07:38:16 Allow pg_archivecleanup to remove backup history files