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

Commit7ff23c6

Browse files
committed
Run checkpointer and bgwriter in crash recovery.
Start up the checkpointer and bgwriter during crash recovery (except in--single mode), as we do for replication. This wasn't done back incommitcdd46c7 out of caution. Now it seems like a better idea to makethe environment as similar as possible in both cases. There may also besome performance advantages.Reviewed-by: Robert Haas <robertmhaas@gmail.com>Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>Tested-by: Jakub Wartak <Jakub.Wartak@tomtom.com>Discussion:https://postgr.es/m/CA%2BhUKGJ8NRsqgkZEnsnRc2MFROBV-jCnacbYvtpptK2A9YYp9Q%40mail.gmail.com
1 parent8b1de88 commit7ff23c6

File tree

6 files changed

+22
-65
lines changed

6 files changed

+22
-65
lines changed

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,6 @@ boolreachedConsistency = false;
869869

870870
staticboolInRedo= false;
871871

872-
/* Have we launched bgwriter during recovery? */
873-
staticboolbgwriterLaunched= false;
874-
875872
/* For WALInsertLockAcquire/Release functions */
876873
staticintMyLockNo=0;
877874
staticboolholdingAllLocks= false;
@@ -7311,25 +7308,15 @@ StartupXLOG(void)
73117308
/* Also ensure XLogReceiptTime has a sane value */
73127309
XLogReceiptTime=GetCurrentTimestamp();
73137310

7311+
/* Allow ProcSendSignal() to find us, for buffer pin wakeups. */
7312+
PublishStartupProcessInformation();
7313+
73147314
/*
73157315
* Let postmaster know we've started redo now, so that it can launch
7316-
* checkpointer to perform restartpoints. We don't bother during
7317-
* crash recovery as restartpoints can only be performed during
7318-
* archive recovery. And we'd like to keep crash recovery simple, to
7319-
* avoid introducing bugs that could affect you when recovering after
7320-
* crash.
7321-
*
7322-
* After this point, we can no longer assume that we're the only
7323-
* process in addition to postmaster! Also, fsync requests are
7324-
* subsequently to be handled by the checkpointer, not locally.
7316+
* the archiver if necessary.
73257317
*/
7326-
if (ArchiveRecoveryRequested&&IsUnderPostmaster)
7327-
{
7328-
PublishStartupProcessInformation();
7329-
EnableSyncRequestForwarding();
7318+
if (IsUnderPostmaster)
73307319
SendPostmasterSignal(PMSIGNAL_RECOVERY_STARTED);
7331-
bgwriterLaunched= true;
7332-
}
73337320

73347321
/*
73357322
* Allow read-only connections immediately if we're consistent
@@ -7903,7 +7890,7 @@ StartupXLOG(void)
79037890
* after we're fully out of recovery mode and already accepting
79047891
* queries.
79057892
*/
7906-
if (bgwriterLaunched)
7893+
if (ArchiveRecoveryRequested&&IsUnderPostmaster)
79077894
{
79087895
if (LocalPromoteIsTriggered)
79097896
{
@@ -7927,7 +7914,11 @@ StartupXLOG(void)
79277914
CHECKPOINT_WAIT);
79287915
}
79297916
else
7930-
CreateCheckPoint(CHECKPOINT_END_OF_RECOVERY |CHECKPOINT_IMMEDIATE);
7917+
{
7918+
RequestCheckpoint(CHECKPOINT_END_OF_RECOVERY |
7919+
CHECKPOINT_IMMEDIATE |
7920+
CHECKPOINT_WAIT);
7921+
}
79317922
}
79327923

79337924
if (ArchiveRecoveryRequested)
@@ -12182,7 +12173,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1218212173
* Request a restartpoint if we've replayed too much xlog since the
1218312174
* last one.
1218412175
*/
12185-
if (bgwriterLaunched)
12176+
if (ArchiveRecoveryRequested&&IsUnderPostmaster)
1218612177
{
1218712178
if (XLogCheckpointNeeded(readSegNo))
1218812179
{

‎src/backend/postmaster/bgwriter.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
*
1313
* As of Postgres 9.2 the bgwriter no longer handles checkpoints.
1414
*
15-
* The bgwriter is started by the postmaster as soon as the startup subprocess
16-
* finishes, or as soon as recovery begins if we are doing archive recovery.
17-
* It remains alive until the postmaster commands it to terminate.
1815
* Normal termination is by SIGTERM, which instructs the bgwriter to exit(0).
1916
* Emergency termination is by SIGQUIT; like any backend, the bgwriter will
2017
* simply abort and exit on SIGQUIT.

‎src/backend/postmaster/checkpointer.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
* fill WAL segments; the checkpointer itself doesn't watch for the
1111
* condition.)
1212
*
13-
* The checkpointer is started by the postmaster as soon as the startup
14-
* subprocess finishes, or as soon as recovery begins if we are doing archive
15-
* recovery. It remains alive until the postmaster commands it to terminate.
1613
* Normal termination is by SIGUSR2, which instructs the checkpointer to
1714
* execute a shutdown checkpoint and then exit(0). (All backends must be
1815
* stopped before SIGUSR2 is issued!) Emergency termination is by SIGQUIT;

‎src/backend/postmaster/postmaster.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,12 @@ PostmasterMain(int argc, char *argv[])
14031403
*/
14041404
AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS,PM_STATUS_STARTING);
14051405

1406+
/* Start bgwriter and checkpointer so they can help with recovery */
1407+
if (CheckpointerPID==0)
1408+
CheckpointerPID=StartCheckpointer();
1409+
if (BgWriterPID==0)
1410+
BgWriterPID=StartBackgroundWriter();
1411+
14061412
/*
14071413
* We're ready to rock and roll...
14081414
*/
@@ -1765,7 +1771,7 @@ ServerLoop(void)
17651771
* fails, we'll just try again later. Likewise for the checkpointer.
17661772
*/
17671773
if (pmState==PM_RUN||pmState==PM_RECOVERY||
1768-
pmState==PM_HOT_STANDBY)
1774+
pmState==PM_HOT_STANDBY||pmState==PM_STARTUP)
17691775
{
17701776
if (CheckpointerPID==0)
17711777
CheckpointerPID=StartCheckpointer();
@@ -5161,15 +5167,6 @@ sigusr1_handler(SIGNAL_ARGS)
51615167
FatalError= false;
51625168
AbortStartTime=0;
51635169

5164-
/*
5165-
* Crank up the background tasks. It doesn't matter if this fails,
5166-
* we'll just try again later.
5167-
*/
5168-
Assert(CheckpointerPID==0);
5169-
CheckpointerPID=StartCheckpointer();
5170-
Assert(BgWriterPID==0);
5171-
BgWriterPID=StartBackgroundWriter();
5172-
51735170
/*
51745171
* Start the archiver if we're responsible for (re-)archiving received
51755172
* files.

‎src/backend/storage/sync/sync.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ InitSync(void)
129129
{
130130
/*
131131
* Create pending-operations hashtable if we need it. Currently, we need
132-
* it if we are standalone (not under a postmaster) or if we are a startup
133-
*orcheckpointer auxiliary process.
132+
* it if we are standalone (not under a postmaster) or if we are a
133+
* checkpointer auxiliary process.
134134
*/
135-
if (!IsUnderPostmaster||AmStartupProcess()||AmCheckpointerProcess())
135+
if (!IsUnderPostmaster||AmCheckpointerProcess())
136136
{
137137
HASHCTLhash_ctl;
138138

@@ -589,27 +589,3 @@ RegisterSyncRequest(const FileTag *ftag, SyncRequestType type,
589589

590590
returnret;
591591
}
592-
593-
/*
594-
* In archive recovery, we rely on checkpointer to do fsyncs, but we will have
595-
* already created the pendingOps during initialization of the startup
596-
* process. Calling this function drops the local pendingOps so that
597-
* subsequent requests will be forwarded to checkpointer.
598-
*/
599-
void
600-
EnableSyncRequestForwarding(void)
601-
{
602-
/* Perform any pending fsyncs we may have queued up, then drop table */
603-
if (pendingOps)
604-
{
605-
ProcessSyncRequests();
606-
hash_destroy(pendingOps);
607-
}
608-
pendingOps=NULL;
609-
610-
/*
611-
* We should not have any pending unlink requests, since mdunlink doesn't
612-
* queue unlink requests when isRedo.
613-
*/
614-
Assert(pendingUnlinks==NIL);
615-
}

‎src/include/storage/sync.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ extern void SyncPreCheckpoint(void);
6060
externvoidSyncPostCheckpoint(void);
6161
externvoidProcessSyncRequests(void);
6262
externvoidRememberSyncRequest(constFileTag*ftag,SyncRequestTypetype);
63-
externvoidEnableSyncRequestForwarding(void);
6463
externboolRegisterSyncRequest(constFileTag*ftag,SyncRequestTypetype,
6564
boolretryOnError);
6665

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp