Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a2f783

Browse files
committed
Disable STARTUP_PROGRESS_TIMEOUT in standby mode.
In standby mode, we don't actually report progress of recovery,but up until now, startup_progress_timeout_handler() neverthelessgot called every log_startup_progress_interval seconds. That'san unnecessary expense, so avoid it.Report by Thomas Munro. Patch by Bharath Rupireddy, reviewed bySimon Riggs, Thomas Munro, and me. Back-patch to v15, wherethe problem was introduced.Discussion:https://www.postgresql.org/message-id/CA%2BhUKGKCHSffAj8zZJKJvNX7ygnQFxVD6wm1d-2j3fVw%2BMafPQ%40mail.gmail.com
1 parent0ae4e49 commit8a2f783

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

‎src/backend/access/transam/xlogrecovery.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static bool recoveryStopAfter;
385385
/* prototypes for local functions */
386386
staticvoidApplyWalRecord(XLogReaderState*xlogreader,XLogRecord*record,TimeLineID*replayTLI);
387387

388+
staticvoidEnableStandbyMode(void);
388389
staticvoidreadRecoverySignalFile(void);
389390
staticvoidvalidateRecoveryParameters(void);
390391
staticboolread_backup_label(XLogRecPtr*checkPointLoc,
@@ -469,6 +470,24 @@ XLogRecoveryShmemInit(void)
469470
ConditionVariableInit(&XLogRecoveryCtl->recoveryNotPausedCV);
470471
}
471472

473+
/*
474+
* A thin wrapper to enable StandbyMode and do other preparatory work as
475+
* needed.
476+
*/
477+
staticvoid
478+
EnableStandbyMode(void)
479+
{
480+
StandbyMode= true;
481+
482+
/*
483+
* To avoid server log bloat, we don't report recovery progress in a
484+
* standby as it will always be in recovery unless promoted. We disable
485+
* startup progress timeout in standby mode to avoid calling
486+
* startup_progress_timeout_handler() unnecessarily.
487+
*/
488+
disable_startup_progress_timeout();
489+
}
490+
472491
/*
473492
* Prepare the system for WAL recovery, if needed.
474493
*
@@ -602,7 +621,7 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
602621
*/
603622
InArchiveRecovery= true;
604623
if (StandbyModeRequested)
605-
StandbyMode= true;
624+
EnableStandbyMode();
606625

607626
/*
608627
* When a backup_label file is present, we want to roll forward from
@@ -739,7 +758,7 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
739758
{
740759
InArchiveRecovery= true;
741760
if (StandbyModeRequested)
742-
StandbyMode= true;
761+
EnableStandbyMode();
743762
}
744763

745764
/* Get the last valid checkpoint record. */
@@ -3117,7 +3136,7 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
31173136
(errmsg_internal("reached end of WAL in pg_wal, entering archive recovery")));
31183137
InArchiveRecovery= true;
31193138
if (StandbyModeRequested)
3120-
StandbyMode= true;
3139+
EnableStandbyMode();
31213140

31223141
SwitchIntoArchiveRecovery(xlogreader->EndRecPtr,replayTLI);
31233142
minRecoveryPoint=xlogreader->EndRecPtr;

‎src/backend/postmaster/startup.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,27 +314,51 @@ startup_progress_timeout_handler(void)
314314
startup_progress_timer_expired= true;
315315
}
316316

317+
void
318+
disable_startup_progress_timeout(void)
319+
{
320+
/* Feature is disabled. */
321+
if (log_startup_progress_interval==0)
322+
return;
323+
324+
disable_timeout(STARTUP_PROGRESS_TIMEOUT, false);
325+
startup_progress_timer_expired= false;
326+
}
327+
317328
/*
318329
* Set the start timestamp of the current operation and enable the timeout.
319330
*/
320331
void
321-
begin_startup_progress_phase(void)
332+
enable_startup_progress_timeout(void)
322333
{
323334
TimestampTzfin_time;
324335

325336
/* Feature is disabled. */
326337
if (log_startup_progress_interval==0)
327338
return;
328339

329-
disable_timeout(STARTUP_PROGRESS_TIMEOUT, false);
330-
startup_progress_timer_expired= false;
331340
startup_progress_phase_start_time=GetCurrentTimestamp();
332341
fin_time=TimestampTzPlusMilliseconds(startup_progress_phase_start_time,
333342
log_startup_progress_interval);
334343
enable_timeout_every(STARTUP_PROGRESS_TIMEOUT,fin_time,
335344
log_startup_progress_interval);
336345
}
337346

347+
/*
348+
* A thin wrapper to first disable and then enable the startup progress
349+
* timeout.
350+
*/
351+
void
352+
begin_startup_progress_phase(void)
353+
{
354+
/* Feature is disabled. */
355+
if (log_startup_progress_interval==0)
356+
return;
357+
358+
disable_startup_progress_timeout();
359+
enable_startup_progress_timeout();
360+
}
361+
338362
/*
339363
* Report whether startup progress timeout has occurred. Reset the timer flag
340364
* if it did, set the elapsed time to the out parameters and return true,

‎src/include/postmaster/startup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern void PostRestoreCommand(void);
3232
externboolIsPromoteSignaled(void);
3333
externvoidResetPromoteSignaled(void);
3434

35+
externvoidenable_startup_progress_timeout(void);
36+
externvoiddisable_startup_progress_timeout(void);
3537
externvoidbegin_startup_progress_phase(void);
3638
externvoidstartup_progress_timeout_handler(void);
3739
externboolhas_startup_progress_timeout_expired(long*secs,int*usecs);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp