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

Commitc9cc7e0

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 parent8e6c8da commitc9cc7e0

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
@@ -433,6 +433,7 @@ typedef struct XLogCtlData
433433
* recovery. Protected by info_lck.
434434
*/
435435
boolSharedRecoveryInProgress;
436+
boolSharedInArchiveRecovery;
436437

437438
/*
438439
* SharedHotStandbyActive indicates if we're still in crash or archive
@@ -619,6 +620,7 @@ static bool bgwriterLaunched = false;
619620

620621
staticvoidreadRecoveryCommandFile(void);
621622
staticvoidexitArchiveRecovery(TimeLineIDendTLI,XLogSegNoendLogSegNo);
623+
staticboolArchiveRecoveryInProgress(void);
622624
staticboolrecoveryStopsHere(XLogRecord*record,bool*includeThis);
623625
staticvoidrecoveryPausesHere(void);
624626
staticvoidSetLatestXTime(TimestampTzxtime);
@@ -2923,7 +2925,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr endptr)
29232925
strspn(xlde->d_name,"0123456789ABCDEF")==24&&
29242926
strcmp(xlde->d_name+8,lastoff+8) <=0)
29252927
{
2926-
if (RecoveryInProgress()||XLogArchiveCheckDone(xlde->d_name))
2928+
if (ArchiveRecoveryInProgress()||XLogArchiveCheckDone(xlde->d_name))
29272929
{
29282930
snprintf(path,MAXPGPATH,XLOGDIR"/%s",xlde->d_name);
29292931

@@ -3869,6 +3871,7 @@ XLOGShmemInit(void)
38693871
*/
38703872
XLogCtl->XLogCacheBlck=XLOGbuffers-1;
38713873
XLogCtl->SharedRecoveryInProgress= true;
3874+
XLogCtl->SharedInArchiveRecovery= false;
38723875
XLogCtl->SharedHotStandbyActive= false;
38733876
XLogCtl->WalWriterSleeping= false;
38743877
XLogCtl->Insert.currpage= (XLogPageHeader) (XLogCtl->pages);
@@ -4262,6 +4265,7 @@ readRecoveryCommandFile(void)
42624265

42634266
/* Enable fetching from archive recovery area */
42644267
InArchiveRecovery= true;
4268+
XLogCtl->SharedInArchiveRecovery= true;
42654269

42664270
/*
42674271
* If user specified recovery_target_timeline, validate it or compute the
@@ -4300,11 +4304,16 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
43004304
{
43014305
charrecoveryPath[MAXPGPATH];
43024306
charxlogpath[MAXPGPATH];
4307+
/* use volatile pointer to prevent code rearrangement */
4308+
volatileXLogCtlData*xlogctl=XLogCtl;
43034309

43044310
/*
43054311
* We are no longer in archive recovery state.
43064312
*/
43074313
InArchiveRecovery= false;
4314+
SpinLockAcquire(&xlogctl->info_lck);
4315+
xlogctl->SharedInArchiveRecovery= false;
4316+
SpinLockRelease(&xlogctl->info_lck);
43084317

43094318
/*
43104319
* Update min recovery point one last time.
@@ -6101,6 +6110,25 @@ RecoveryInProgress(void)
61016110
}
61026111
}
61036112

6113+
/*
6114+
* Are we currently in archive recovery? In the startup process, you can just
6115+
* check InArchiveRecovery variable instead.
6116+
*/
6117+
staticbool
6118+
ArchiveRecoveryInProgress()
6119+
{
6120+
boolresult;
6121+
/* use volatile pointer to prevent code rearrangement */
6122+
volatileXLogCtlData*xlogctl=XLogCtl;
6123+
6124+
/* spinlock is essential on machines with weak memory ordering! */
6125+
SpinLockAcquire(&xlogctl->info_lck);
6126+
result=xlogctl->SharedInArchiveRecovery;
6127+
SpinLockRelease(&xlogctl->info_lck);
6128+
6129+
returnresult;
6130+
}
6131+
61046132
/*
61056133
* Is HotStandby active yet? This is only important in special backends
61066134
* since normal backends won't ever be able to connect until this returns

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp