Re: PoC: Simplify recovery after dropping a table by LOGGING the restore LSN

From: Salma Elsayed <salmasayed182003(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Kirk Wolak <wolakk(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Nikolay Samokhvalov <samokhvalov(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Subject: Re: PoC: Simplify recovery after dropping a table by LOGGING the restore LSN
Date: 2026-11-06 18:52:53
Message-ID: CANBEAPFzwpUcDcSyN=P2Mg7kqTP3Jx8YkPAVMOR2aK+XeM0ZKw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thanks for the reviews.

On Sun, Nov 1, 2026 at 4:27 PM Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:

> == GUC name (bikeshedding) ==
> I don't think we should spend too much time on this right now, but I
> thought I should mention it for later.
>
I agree, we can change it later.

> == wal_level minimal ==
>
> The lsn is being logged also when the cluster is set to wal_level =
> minimal. The docs say "The minimal level generates the least WAL volume.
> It logs no row information for permanent relations in transactions that
> create or rewrite them." [1]
>
I added an XLogIsNeeded() check to RegisterDropOrTruncateTable, so
nothing is logged when wal_level is minimal. I also added your test
and a note in the docs.

> == errhint in AtEOXact_DropOrTruncateTable (nit) ==
>
> The two branches in "if (info->is_truncate) can be simplified into a
> single ereport call, e.g.
>
Done.

On Thu, Nov 5, 2026 at 12:17 AM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
> DROP TABLE also has a similar loss window as DROP DATABASE: if the
> backend dies with kill -9 / immediate shutdown with a committed DROP
> TABLE waiting for synchronous replication.
> (create table; alter system set
> synchronous_standby_names='nosuchstandby'; drop table; kill)
>
Yes, I was able to reproduce this.

> Logging in RecordTransactionCommit right after END_CRIT_SECTION could
> be a better choice that would fix this, and could work without
> XactLastCommitStart?
>
I moved the logging into RecordTransactionCommit, right after
END_CRIT_SECTION. It uses a local commit_lsn, so XactLastCommitStart
is removed, and AtEOXact_DropOrTruncateTable now only frees the list.

With this change, the LSN is logged before the kill in your scenario,
and recovering to that LSN brings the table back.

v13 attached.

Thanks,
Salma Elsayed

Attachment Content-Type Size
v13-0001-Log-the-recovery-LSN-of-dropped-and-truncated-ta.patch application/x-patch 30.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-11-06 18:59:14 Re: Reject access to unlogged tables in contrib modules
Previous Message Greg Burd 2026-11-06 18:48:04 Re: UNDO with FILEOPS, and the FLUX table AM