mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Fix timing of Startup CLOG and MultiXact during Hot Standby
Patch by me, bug report by Chris Redekop, analysis by Florian Pflug
This commit is contained in:
parent
c2891b46a4
commit
f8409b39d1
@ -489,6 +489,25 @@ StartupCLOG(void)
|
|||||||
*/
|
*/
|
||||||
ClogCtl->shared->latest_page_number = pageno;
|
ClogCtl->shared->latest_page_number = pageno;
|
||||||
|
|
||||||
|
LWLockRelease(CLogControlLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This must be called ONCE at the end of startup/recovery.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
TrimCLOG(void)
|
||||||
|
{
|
||||||
|
TransactionId xid = ShmemVariableCache->nextXid;
|
||||||
|
int pageno = TransactionIdToPage(xid);
|
||||||
|
|
||||||
|
LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Re-Initialize our idea of the latest page number.
|
||||||
|
*/
|
||||||
|
ClogCtl->shared->latest_page_number = pageno;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Zero out the remainder of the current clog page. Under normal
|
* Zero out the remainder of the current clog page. Under normal
|
||||||
* circumstances it should be zeroes already, but it seems at least
|
* circumstances it should be zeroes already, but it seems at least
|
||||||
|
@ -1567,7 +1567,7 @@ StartupMultiXact(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Zero out the remainder of the current members page. See notes in
|
* Zero out the remainder of the current members page. See notes in
|
||||||
* StartupCLOG() for motivation.
|
* TrimCLOG() for motivation.
|
||||||
*/
|
*/
|
||||||
entryno = MXOffsetToMemberEntry(offset);
|
entryno = MXOffsetToMemberEntry(offset);
|
||||||
if (entryno != 0)
|
if (entryno != 0)
|
||||||
|
@ -6410,10 +6410,12 @@ StartupXLOG(void)
|
|||||||
oldestActiveXID = checkPoint.oldestActiveXid;
|
oldestActiveXID = checkPoint.oldestActiveXid;
|
||||||
Assert(TransactionIdIsValid(oldestActiveXID));
|
Assert(TransactionIdIsValid(oldestActiveXID));
|
||||||
|
|
||||||
/* Startup commit log and related stuff */
|
/*
|
||||||
|
* Startup commit log and subtrans only. Other SLRUs are not
|
||||||
|
* maintained during recovery and need not be started yet.
|
||||||
|
*/
|
||||||
StartupCLOG();
|
StartupCLOG();
|
||||||
StartupSUBTRANS(oldestActiveXID);
|
StartupSUBTRANS(oldestActiveXID);
|
||||||
StartupMultiXact();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're beginning at a shutdown checkpoint, we know that
|
* If we're beginning at a shutdown checkpoint, we know that
|
||||||
@ -6914,16 +6916,21 @@ StartupXLOG(void)
|
|||||||
TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
|
TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start up the commit log and related stuff, too. In hot standby mode we
|
* Start up the commit log and subtrans, if not already done for
|
||||||
* did this already before WAL replay.
|
* hot standby.
|
||||||
*/
|
*/
|
||||||
if (standbyState == STANDBY_DISABLED)
|
if (standbyState == STANDBY_DISABLED)
|
||||||
{
|
{
|
||||||
StartupCLOG();
|
StartupCLOG();
|
||||||
StartupSUBTRANS(oldestActiveXID);
|
StartupSUBTRANS(oldestActiveXID);
|
||||||
StartupMultiXact();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform end of recovery actions for any SLRUs that need it.
|
||||||
|
*/
|
||||||
|
StartupMultiXact();
|
||||||
|
TrimCLOG();
|
||||||
|
|
||||||
/* Reload shared-memory state for prepared transactions */
|
/* Reload shared-memory state for prepared transactions */
|
||||||
RecoverPreparedTransactions();
|
RecoverPreparedTransactions();
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "pgstat.h"
|
#include "pgstat.h"
|
||||||
#include "postmaster/autovacuum.h"
|
#include "postmaster/autovacuum.h"
|
||||||
#include "postmaster/postmaster.h"
|
#include "postmaster/postmaster.h"
|
||||||
|
#include "postmaster/startup.h"
|
||||||
#include "replication/walsender.h"
|
#include "replication/walsender.h"
|
||||||
#include "storage/bufmgr.h"
|
#include "storage/bufmgr.h"
|
||||||
#include "storage/fd.h"
|
#include "storage/fd.h"
|
||||||
|
@ -40,6 +40,7 @@ extern Size CLOGShmemSize(void);
|
|||||||
extern void CLOGShmemInit(void);
|
extern void CLOGShmemInit(void);
|
||||||
extern void BootStrapCLOG(void);
|
extern void BootStrapCLOG(void);
|
||||||
extern void StartupCLOG(void);
|
extern void StartupCLOG(void);
|
||||||
|
extern void TrimCLOG(void);
|
||||||
extern void ShutdownCLOG(void);
|
extern void ShutdownCLOG(void);
|
||||||
extern void CheckPointCLOG(void);
|
extern void CheckPointCLOG(void);
|
||||||
extern void ExtendCLOG(TransactionId newestXact);
|
extern void ExtendCLOG(TransactionId newestXact);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user