From f80c086d9b428363c7d77fac0a2135e509703c8c Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Thu, 9 Dec 2021 02:08:13 +0000 Subject: [PATCH v2] Skip control file db state updation during end-of-recovery checkpoint While the database is performing end-of-recovery checkpoint, the control file gets updated with db state as "shutting down" in CreateCheckPoint and at the end it sets it back to "shut down" for a brief moment and then finally to "in production". Intead, let the db state be in DB_IN_CRASH_RECOVERY which then changes to DB_IN_PRODUCTION. --- src/backend/access/transam/xlog.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d894af310a..b4a2746cae 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -9112,6 +9112,10 @@ CreateCheckPoint(int flags) /* * An end-of-recovery checkpoint is really a shutdown checkpoint, just * issued at a different time. + * + * Note that for an end-of-recovery checkpoint, the database state in + * the control file will not be updated within this function, it will + * still be the previous state i.e., "in crash recovery". */ if (flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY)) shutdown = true; @@ -9137,7 +9141,7 @@ CreateCheckPoint(int flags) */ START_CRIT_SECTION(); - if (shutdown) + if (flags & CHECKPOINT_IS_SHUTDOWN) { LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); ControlFile->state = DB_SHUTDOWNING; @@ -9406,7 +9410,7 @@ CreateCheckPoint(int flags) * Update the control file. */ LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); - if (shutdown) + if (flags & CHECKPOINT_IS_SHUTDOWN) ControlFile->state = DB_SHUTDOWNED; ControlFile->checkPoint = ProcLastRecPtr; ControlFile->checkPointCopy = checkPoint; -- 2.25.1