From ffa72cd4067b5d31ce6dc6bc2818607425181913 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Tue, 8 Aug 2023 08:08:31 +0000 Subject: [PATCH] Suppress generating WAL records during the upgrade --- src/backend/access/transam/xlog.c | 3 ++- src/backend/postmaster/bgwriter.c | 5 +++-- src/backend/storage/buffer/bufmgr.c | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 60c0b7ec3a..2f1cbc6898 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6555,7 +6555,8 @@ CreateCheckPoint(int flags) if ((flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_FORCE)) == 0) { - if (last_important_lsn == ControlFile->checkPoint) + if (XLogRecPtrIsInvalid(last_important_lsn) || + last_important_lsn == ControlFile->checkPoint) { WALInsertLockRelease(); END_CRIT_SECTION(); diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index caad642ec9..95d88ac8bc 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -276,6 +276,7 @@ BackgroundWriterMain(void) { TimestampTz timeout = 0; TimestampTz now = GetCurrentTimestamp(); + XLogRecPtr last_important = GetLastImportantRecPtr(); timeout = TimestampTzPlusMilliseconds(last_snapshot_ts, LOG_SNAPSHOT_INTERVAL_MS); @@ -287,8 +288,8 @@ BackgroundWriterMain(void) * start of a record, whereas last_snapshot_lsn points just past * the end of the record. */ - if (now >= timeout && - last_snapshot_lsn <= GetLastImportantRecPtr()) + if (now >= timeout && last_snapshot_lsn <= last_important && + !XLogRecPtrIsInvalid(last_important)) { last_snapshot_lsn = LogStandbySnapshot(); last_snapshot_ts = now; diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index df22aaa1c5..db0fc4ef96 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -4588,8 +4588,13 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std) * * We don't check full_page_writes here because that logic is included * when we call XLogInsert() since the value changes dynamically. + * + * XXX: avoid to write WAL if we are in the binary-upgrade mode. Some + * catalogs are read during the upgrade, but it may trigger to generate + * XLOG_FPI_FOR_HINT. It may become the "WAL hole". */ if (XLogHintBitIsNeeded() && + !IsBinaryUpgrade && (pg_atomic_read_u32(&bufHdr->state) & BM_PERMANENT)) { /* -- 2.27.0