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

Commitfea9346

Browse files
committed
Don't delete unarchived WAL files during crash recovery.
Bug reported by Jehan-Guillaume (ioguix) de Rorthais. This was introducedwith the change to keep WAL files restored from archive in pg_xlog, in 9.2.
1 parent7b058a2 commitfea9346

File tree

1 file changed

+29
-1
lines changed
  • src/backend/access/transam

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ typedef struct XLogCtlData
418418
* recovery. Protected by info_lck.
419419
*/
420420
boolSharedRecoveryInProgress;
421+
boolSharedInArchiveRecovery;
421422

422423
/*
423424
* SharedHotStandbyActive indicates if we're still in crash or archive
@@ -622,6 +623,7 @@ static void XLogArchiveCleanup(const char *xlog);
622623
staticvoidreadRecoveryCommandFile(void);
623624
staticvoidexitArchiveRecovery(TimeLineIDendTLI,
624625
uint32endLogId,uint32endLogSeg);
626+
staticboolArchiveRecoveryInProgress(void);
625627
staticboolrecoveryStopsHere(XLogRecord*record,bool*includeThis);
626628
staticvoidrecoveryPausesHere(void);
627629
staticvoidSetLatestXTime(TimestampTzxtime);
@@ -3571,7 +3573,7 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
35713573
strspn(xlde->d_name,"0123456789ABCDEF")==24&&
35723574
strcmp(xlde->d_name+8,lastoff+8) <=0)
35733575
{
3574-
if (RecoveryInProgress()||XLogArchiveCheckDone(xlde->d_name))
3576+
if (ArchiveRecoveryInProgress()||XLogArchiveCheckDone(xlde->d_name))
35753577
{
35763578
snprintf(path,MAXPGPATH,XLOGDIR"/%s",xlde->d_name);
35773579

@@ -5289,6 +5291,7 @@ XLOGShmemInit(void)
52895291
*/
52905292
XLogCtl->XLogCacheBlck=XLOGbuffers-1;
52915293
XLogCtl->SharedRecoveryInProgress= true;
5294+
XLogCtl->SharedInArchiveRecovery= false;
52925295
XLogCtl->SharedHotStandbyActive= false;
52935296
XLogCtl->WalWriterSleeping= false;
52945297
XLogCtl->Insert.currpage= (XLogPageHeader) (XLogCtl->pages);
@@ -5680,6 +5683,7 @@ readRecoveryCommandFile(void)
56805683

56815684
/* Enable fetching from archive recovery area */
56825685
InArchiveRecovery= true;
5686+
XLogCtl->SharedInArchiveRecovery= true;
56835687

56845688
/*
56855689
* If user specified recovery_target_timeline, validate it or compute the
@@ -5718,11 +5722,16 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
57185722
{
57195723
charrecoveryPath[MAXPGPATH];
57205724
charxlogpath[MAXPGPATH];
5725+
/* use volatile pointer to prevent code rearrangement */
5726+
volatileXLogCtlData*xlogctl=XLogCtl;
57215727

57225728
/*
57235729
* We are no longer in archive recovery state.
57245730
*/
57255731
InArchiveRecovery= false;
5732+
SpinLockAcquire(&xlogctl->info_lck);
5733+
xlogctl->SharedInArchiveRecovery= false;
5734+
SpinLockRelease(&xlogctl->info_lck);
57265735

57275736
/*
57285737
* Update min recovery point one last time.
@@ -7314,6 +7323,25 @@ RecoveryInProgress(void)
73147323
}
73157324
}
73167325

7326+
/*
7327+
* Are we currently in archive recovery? In the startup process, you can just
7328+
* check InArchiveRecovery variable instead.
7329+
*/
7330+
staticbool
7331+
ArchiveRecoveryInProgress()
7332+
{
7333+
boolresult;
7334+
/* use volatile pointer to prevent code rearrangement */
7335+
volatileXLogCtlData*xlogctl=XLogCtl;
7336+
7337+
/* spinlock is essential on machines with weak memory ordering! */
7338+
SpinLockAcquire(&xlogctl->info_lck);
7339+
result=xlogctl->SharedInArchiveRecovery;
7340+
SpinLockRelease(&xlogctl->info_lck);
7341+
7342+
returnresult;
7343+
}
7344+
73177345
/*
73187346
* Is HotStandby active yet? This is only important in special backends
73197347
* since normal backends won't ever be able to connect until this returns

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp