Skip to content

Move CheckPointBuffers to PreCheckPointGuts to save FSM/VM pages on normal shutdown #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
@@ -7215,17 +7215,20 @@ CheckPointReplicationState(void)
* NEON: we use logical records to persist information of about slots, origins, relation map...
* If it is done inside shutdown checkpoint, then Postgres panics: "concurrent write-ahead log activity while database system is shutting down"
* So do it before checkpoint REDO position is determined.
* The same is true for CheckPointBuffers which wallog dirty FSM/VM pages.
*/
static void
PreCheckPointGuts(int flags)
{
if (flags & CHECKPOINT_IS_SHUTDOWN)
{
CheckPointReplicationState();
CheckPointBuffers(flags);

/*
* pgstat_write_statsfile will be called later by before_shmem_exit() hook, but by then it's too late
* to write WAL records. In Neon, pgstat_write_statsfile() writes the pgstats file to the WAL, so we have
* to call it earlier. (The call that happens later is useless, but it doesn't do any harm either)
* to call it earlier. (The call that happens later is useless, but it doesn't do any harm either)
*/
pgstat_write_statsfile();
}
@@ -7251,7 +7254,14 @@ CheckPointGuts(XLogRecPtr checkPointRedo, int flags)
CheckPointSUBTRANS();
CheckPointMultiXact();
CheckPointPredicate();
CheckPointBuffers(flags);
/*
* NEON: Checkpoint buffer will write dirty pages to the disk and Neon SMGR
* wallog FSM/VM pages to persist them at page server.
* Writing to the WAL during shutdown checkpoint cause Postgres panic.
* So do it before in PreCheckPointGuts.
*/
if (!(flags & CHECKPOINT_IS_SHUTDOWN))
CheckPointBuffers(flags);

/* Perform all queued up fsyncs */
TRACE_POSTGRESQL_BUFFER_CHECKPOINT_SYNC_START();