]> granicus.if.org Git - postgresql/commitdiff
Fix timing of Startup CLOG and MultiXact during Hot Standby
authorSimon Riggs <simon@2ndQuadrant.com>
Wed, 2 Nov 2011 08:07:44 +0000 (08:07 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Wed, 2 Nov 2011 08:07:44 +0000 (08:07 +0000)
Patch by me, bug report by Chris Redekop, analysis by Florian Pflug

src/backend/access/transam/clog.c
src/backend/access/transam/multixact.c
src/backend/access/transam/xlog.c
src/backend/utils/init/postinit.c
src/include/access/clog.h

index ee645f7bd472ee394ace23f9461318b611e57514..6a2bf83362f4213c6ddf534cd0c4e13969576b51 100644 (file)
@@ -489,6 +489,25 @@ StartupCLOG(void)
         */
        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
         * circumstances it should be zeroes already, but it seems at least
index 1d159bc89cb65838d19772dc36af46b1ed608360..c1c8ba52da30e02457af163a883a5b31da7760a6 100644 (file)
@@ -1567,7 +1567,7 @@ StartupMultiXact(void)
 
        /*
         * Zero out the remainder of the current members page.  See notes in
-        * StartupCLOG() for motivation.
+        * TrimCLOG() for motivation.
         */
        entryno = MXOffsetToMemberEntry(offset);
        if (entryno != 0)
index a6aee9eb30c53fd661d1ae694f2f16771090ae5b..bf57b3bf49e08635340d5e7b278d5d76e4460bb5 100644 (file)
@@ -6410,10 +6410,12 @@ StartupXLOG(void)
                                oldestActiveXID = checkPoint.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();
                        StartupSUBTRANS(oldestActiveXID);
-                       StartupMultiXact();
 
                        /*
                         * If we're beginning at a shutdown checkpoint, we know that
@@ -6914,16 +6916,21 @@ StartupXLOG(void)
        TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
 
        /*
-        * Start up the commit log and related stuff, too. In hot standby mode we
-        * did this already before WAL replay.
+        * Start up the commit log and subtrans, if not already done for
+        * hot standby.
         */
        if (standbyState == STANDBY_DISABLED)
        {
                StartupCLOG();
                StartupSUBTRANS(oldestActiveXID);
-               StartupMultiXact();
        }
 
+       /*
+        * Perform end of recovery actions for any SLRUs that need it.
+        */
+       StartupMultiXact();
+       TrimCLOG();
+
        /* Reload shared-memory state for prepared transactions */
        RecoverPreparedTransactions();
 
index 94f92dd7343af74c37b7efe9f5f57a44f42c3d9e..0fda55af0fcc560988d8715d3c43a87aaf912dc0 100644 (file)
@@ -36,6 +36,7 @@
 #include "pgstat.h"
 #include "postmaster/autovacuum.h"
 #include "postmaster/postmaster.h"
+#include "postmaster/startup.h"
 #include "replication/walsender.h"
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
index 7a8918e0fc56975043faa65b0a5ef28a39d37ccf..691430c97ca191a870e00cd0115b82f1e7ac125e 100644 (file)
@@ -40,6 +40,7 @@ extern Size CLOGShmemSize(void);
 extern void CLOGShmemInit(void);
 extern void BootStrapCLOG(void);
 extern void StartupCLOG(void);
+extern void TrimCLOG(void);
 extern void ShutdownCLOG(void);
 extern void CheckPointCLOG(void);
 extern void ExtendCLOG(TransactionId newestXact);