From 1695dce1825ea8687f6c32ccc2a243a5de37be9f Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 19 Oct 2026 14:25:57 -0400 Subject: [PATCH 1/2] Update minRecoveryPoint before removing files in drop redo Replay of DROP DATABASE and DROP TABLESPACE removed files before updating minRecoveryPoint. A standby restarted after that could reach consistency too early and then fail replaying older WAL that touches the removed files. Call XLogFlush() first, as xact_redo_commit() does. Reported-by: azure young Discussion: https://postgr.es/m/18258-1e2fd3058dda84b0@postgresql.org --- src/backend/commands/dbcommands.c | 6 ++++++ src/backend/commands/tablespace.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 7e3fc59eafd..969baee98df 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -3471,6 +3471,12 @@ dbase_redo(XLogReaderState *record) /* Close all smgr fds in all backends. */ WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_SMGRRELEASE)); + /* + * Update minimum recovery point to cover this record before removing + * the files, like xact_redo_commit() does for dropped relations. + */ + XLogFlush(record->EndRecPtr); + for (i = 0; i < xlrec->ntablespaces; i++) { dst_path = GetDatabasePath(xlrec->db_id, xlrec->tablespace_ids[i]); diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index 7c40176b7b9..ac47b37d9aa 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -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 -- 2.37.1 (Apple Git-137.1)