From e2a5a5fbd51d3c30ff4ebc79e320d23e89d9e624 Mon Sep 17 00:00:00 2001 From: Haoyu Huang Date: Mon, 15 Sep 2025 22:02:43 +0000 Subject: [PATCH 1/2] c --- src/backend/access/transam/xlog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 31c6b3cde05..bd7dbee4712 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -10156,10 +10156,18 @@ CreateRestartPoint(int flags) ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); LWLockRelease(ControlFileLock); + // Flush dirty buffers. + CheckPointBuffers(flags); } return false; } + if (flags & CHECKPOINT_IS_SHUTDOWN) + { + // Flush dirty buffers. + CheckPointBuffers(flags); + } + /* * Update the shared RedoRecPtr so that the startup process can calculate * the number of segments replayed since last restartpoint, and request a From e5bac9c3bf1d21aa7f5a8e04be3e5ccf03dd9afb Mon Sep 17 00:00:00 2001 From: Haoyu Huang Date: Tue, 16 Sep 2025 21:33:59 +0000 Subject: [PATCH 2/2] c --- src/backend/access/transam/xlog.c | 13 ++++++++----- src/include/access/xlog.h | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index bd7dbee4712..9e0f14dd57b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -129,6 +129,7 @@ restore_running_xacts_callback_t restore_running_xacts_callback; set_lwlsn_db_hook_type set_lwlsn_db_hook = NULL; set_lwlsn_relation_hook_type set_lwlsn_relation_hook = NULL; set_max_lwlsn_hook_type set_max_lwlsn_hook = NULL; +flush_dirty_buffers_hook_type flush_dirty_buffers_hook = NULL; /* * Number of WAL insertion locks to use. A higher value allows more insertions @@ -10156,16 +10157,18 @@ CreateRestartPoint(int flags) ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); LWLockRelease(ControlFileLock); - // Flush dirty buffers. - CheckPointBuffers(flags); + + if (flush_dirty_buffers_hook) + { + flush_dirty_buffers_hook(flags); + } } return false; } - if (flags & CHECKPOINT_IS_SHUTDOWN) + if (flush_dirty_buffers_hook) { - // Flush dirty buffers. - CheckPointBuffers(flags); + flush_dirty_buffers_hook(flags); } /* diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 098dc35037b..7e46fce7c4e 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -373,6 +373,9 @@ extern set_lwlsn_db_hook_type set_lwlsn_db_hook; extern set_lwlsn_relation_hook_type set_lwlsn_relation_hook; extern set_max_lwlsn_hook_type set_max_lwlsn_hook; +typedef void (*flush_dirty_buffers_hook_type)(int flags); +extern flush_dirty_buffers_hook_type flush_dirty_buffers_hook; + extern XLogRecPtr GetRedoStartLsn(void); extern bool PromoteIsTriggered(void);