diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 91e6f6ea18..36414973e2 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -60,12 +60,6 @@ */ int BgWriterDelay = 200; -/* - * Multiplier to apply to BgWriterDelay when we decide to hibernate. - * (Perhaps this needs to be configurable?) - */ -#define HIBERNATE_FACTOR 50 - /* * Interval in which standby snapshots are logged into the WAL stream, in * milliseconds. @@ -335,7 +329,7 @@ BackgroundWriterMain(void) /* Sleep ... */ (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - BgWriterDelay * HIBERNATE_FACTOR, + HIBERNATE_DELAY_MS, WAIT_EVENT_BGWRITER_HIBERNATE); /* Reset the notification request in case we timed out */ StrategyNotifyBgWriter(-1); diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index beb46dcb55..08ab783c1f 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -70,14 +70,6 @@ int WalWriterDelay = 200; int WalWriterFlushAfter = 128; -/* - * Number of do-nothing loops before lengthening the delay time, and the - * multiplier to apply to WalWriterDelay when we do decide to hibernate. - * (Perhaps these need to be configurable?) - */ -#define LOOPS_UNTIL_HIBERNATE 50 -#define HIBERNATE_FACTOR 25 - /* Prototypes for private functions */ static void HandleWalWriterInterrupts(void); @@ -225,8 +217,6 @@ WalWriterMain(void) */ for (;;) { - long cur_timeout; - /* * Advertise whether we might hibernate in this cycle. We do this * before resetting the latch to ensure that any async commits will @@ -266,14 +256,18 @@ WalWriterMain(void) * sleep time so as to reduce the server's idle power consumption. */ if (left_till_hibernate > 0) - cur_timeout = WalWriterDelay; /* in ms */ - else - cur_timeout = WalWriterDelay * HIBERNATE_FACTOR; + { + (void) WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, + WalWriterDelay, /* in ms */ + WAIT_EVENT_WAL_WRITER_MAIN); + continue; + } (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - cur_timeout, - WAIT_EVENT_WAL_WRITER_MAIN); + HIBERNATE_DELAY_MS, + WAIT_EVENT_WAL_WRITER_HIBERNATE); } } diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c index 92f24a6c9b..b4eaba737f 100644 --- a/src/backend/utils/activity/wait_event.c +++ b/src/backend/utils/activity/wait_event.c @@ -245,6 +245,9 @@ pgstat_get_wait_activity(WaitEventActivity w) case WAIT_EVENT_WAL_WRITER_MAIN: event_name = "WalWriterMain"; break; + case WAIT_EVENT_WAL_WRITER_HIBERNATE: + event_name = "WalWriterHibernate"; + break; /* no default case, so that compiler will warn */ } diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h index 68ab740f16..f0a86ede3a 100644 --- a/src/include/storage/latch.h +++ b/src/include/storage/latch.h @@ -140,6 +140,11 @@ typedef struct Latch WL_SOCKET_CONNECTED | \ WL_SOCKET_CLOSED) +/* Hibernation */ +#define HIBERNATE_DELAY_SEC 60 +#define HIBERNATE_DELAY_MS (1000L * HIBERNATE_DELAY_SEC) +#define LOOPS_UNTIL_HIBERNATE 50 + typedef struct WaitEvent { int pos; /* position in the event data structure */ diff --git a/src/include/utils/wait_event.h b/src/include/utils/wait_event.h index 6f2d5612e0..d8a77eabd1 100644 --- a/src/include/utils/wait_event.h +++ b/src/include/utils/wait_event.h @@ -46,7 +46,8 @@ typedef enum WAIT_EVENT_SYSLOGGER_MAIN, WAIT_EVENT_WAL_RECEIVER_MAIN, WAIT_EVENT_WAL_SENDER_MAIN, - WAIT_EVENT_WAL_WRITER_MAIN + WAIT_EVENT_WAL_WRITER_MAIN, + WAIT_EVENT_WAL_WRITER_HIBERNATE } WaitEventActivity; /* ----------