diff --git a/src/gausskernel/process/postmaster/pgarch.cpp b/src/gausskernel/process/postmaster/pgarch.cpp index 93032cfe..327e823a 100644 --- a/src/gausskernel/process/postmaster/pgarch.cpp +++ b/src/gausskernel/process/postmaster/pgarch.cpp @@ -430,6 +430,15 @@ static void pgarch_MainLoop(void) if (time_to_stop) { continue; } + + /* + * cannot send archive task if we don't acquire an archive slot. + */ + if (t_thrd.slot_cxt.MyReplicationSlot == NULL) { + ereport(LOG, (errmsg("there is no slot to flush, exit the archvier"))); + break; + } + gettimeofday(&curtime, NULL); const long time_diff = TIME_GET_MILLISEC(curtime) - t_thrd.arch.last_arch_time; XLogRecPtr receivePtr; diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index 7a0bfbd2..93f720d0 100755 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -2788,7 +2788,8 @@ static int ServerLoop(void) if (g_instance.pid_cxt.PgArchPID == 0 && !dummyStandbyMode) { obs_slot = getObsReplicationSlot(); if ((XLogArchivingActive() && pmState == PM_RUN) || - ((pmState == PM_RUN || pmState == PM_HOT_STANDBY) && obs_slot != NULL)) { + ((pmState == PM_RUN || pmState == PM_HOT_STANDBY) && obs_slot != NULL && + get_local_dbstate() == NORMAL_STATE)) { g_instance.pid_cxt.PgArchPID = pgarch_start(); } } @@ -5420,7 +5421,8 @@ static void reaper(SIGNAL_ARGS) if (g_instance.pid_cxt.PgArchPID == 0 && !dummyStandbyMode) { obs_slot = getObsReplicationSlot(); if ((XLogArchivingActive() && pmState == PM_RUN) || - ((pmState == PM_RUN || pmState == PM_HOT_STANDBY) && obs_slot != NULL)) { + ((pmState == PM_RUN || pmState == PM_HOT_STANDBY) && obs_slot != NULL && + get_local_dbstate() == NORMAL_STATE)) { g_instance.pid_cxt.PgArchPID = pgarch_start(); } }