BUG #18258: The redo of the drop db wal needs to forward the Min Recovery Point
The following bug has been logged on the website:
Bug reference: 18258
Logged by: azure young
Email address: azurezhao8369@gmail.com
PostgreSQL version: 16.1
Operating system: linux
Description:
The redo of the drop db log needs to promptly advance the Min Recovery Point
(MRP).
because if the drop db wal is redone but the MRP is not advanced,
it means that the MRP is before the drop db, but the DB directory is
deleted.
If the standby restarts at this time and redoes,
for the directory does not exist,
there will be an invalid page related to this directory.
When it reaches the MRP, it triggers a consistency check, which will fail
and panic.
Hi,
I found this bug on Noah's wanted list [1]https://wiki.postgresql.org/wiki/User:Nmisch/Wanted, so here is a patch. I can
reproduce it on master. If the standby restarts after replaying the
drop record, it reaches consistency too early and then fails with:
PANIC: WAL contains references to invalid pages
DROP TABLESPACE and ALTER DATABASE SET TABLESPACE have the same gap.
The patch calls XLogFlush() before the files are removed, like
xact_redo_commit() does. The new TAP test fails without the fix and
passes with it.
Thanks,
Shihao
Attachments:
t72279_2v1-0002-Add-test-for-minRecoveryPoint-after-drop-redo.patchapplication/octet-stream; name=v1-0002-Add-test-for-minRecoveryPoint-after-drop-redo.patchDownload+71-1
v1-0001-Update-minRecoveryPoint-before-removing-files-in-dro.patchapplication/octet-stream; name=v1-0001-Update-minRecoveryPoint-before-removing-files-in-dro.patchDownload+9-1
On Mon, Nov 09, 2026 at 10:29:45PM -0500, shihao zhong wrote:
DROP TABLESPACE and ALTER DATABASE SET TABLESPACE have the same gap.
The patch calls XLogFlush() before the files are removed, like
xact_redo_commit() does. The new TAP test fails without the fix and
passes with it.
@@ -1555,6 +1555,9 @@ tblspc_redo(XLogReaderState *record)
/* Close all smgr fds in all backends. */
WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_SMGRRELEASE));
+ /* Update minimum recovery point first, as in dbase_redo() */
+ XLogFlush(record->EndRecPtr);
+
/*
* If we issued a WAL record for a drop tablespace it implies that
* there were no files in it at all when the DROP was done. That means
Hmm. You may be right here. I would bet that this area of the code
has already been discussed regarding this problem, but perhaps my
fuzzy memories are failing me. Did you do a search of the mailing
lists regarding that?
I was wondering if this is worth the cycles spent on to begin with,
but we already have a 033_replay_tsp_drops.pl that serves this exact
purpose, so perhaps we do.
--
Michael
Hi Michael,
Did you do a search of the mailing
lists regarding that?
Thanks for looking. Yes, I searched. The closest is a 2009 review [1]/messages/by-id/4B1B8824.2070808@enterprisedb.com
where Heikki said an XLogFlush() in dbase_redo() did not help, because
his concern was the window after the commit record.
That became the ForceSyncCommit() flush in xact_redo_commit(), so
the window between the drop record and its commit was never covered.
Thanks,
Shihao