diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index 6532240dd1..19267b83b9 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -148,8 +148,8 @@ GetStandbyLimitTime(void) } } -#define STANDBY_INITIAL_WAIT_US 1000 -static int standbyWait_us = STANDBY_INITIAL_WAIT_US; +#define STANDBY_INITIAL_WAIT_MS 1 +static int standbyWait_ms = STANDBY_INITIAL_WAIT_MS; /* * Standby wait logic for ResolveRecoveryConflictWithVirtualXIDs. @@ -171,15 +171,19 @@ WaitExceedsMaxStandbyDelay(void) /* * Sleep a bit (this is essential to avoid busy-waiting). */ - pg_usleep(standbyWait_us); + (void) WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, + standbyWait_ms, + WAIT_EVENT_STANDBY_DELAY); + ResetLatch(MyLatch); /* - * Progressively increase the sleep times, but not to more than 1s, since - * pg_usleep isn't interruptable on some platforms. + * Progressively increase the sleep times, but not to more than 1s + * to keep process in a respectable range. */ - standbyWait_us *= 2; - if (standbyWait_us > 1000000) - standbyWait_us = 1000000; + standbyWait_ms *= 2; + if (standbyWait_ms > 1000) + standbyWait_ms = 1000; return false; } @@ -206,8 +210,8 @@ ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, while (VirtualTransactionIdIsValid(*waitlist)) { - /* reset standbyWait_us for each xact we wait for */ - standbyWait_us = STANDBY_INITIAL_WAIT_US; + /* reset standbyWait_ms for each xact we wait for */ + standbyWait_ms = STANDBY_INITIAL_WAIT_MS; /* wait until the virtual xid is gone */ while (!VirtualXactLock(*waitlist, false)) diff --git a/src/include/pgstat.h b/src/include/pgstat.h index de8225b989..83194db520 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -800,7 +800,8 @@ typedef enum { WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT, WAIT_EVENT_PG_SLEEP, - WAIT_EVENT_RECOVERY_APPLY_DELAY + WAIT_EVENT_RECOVERY_APPLY_DELAY, + WAIT_EVENT_STANDBY_DELAY } WaitEventTimeout; /* ----------