Re-arrange placement of GetRunningTransactionData() so that
authorSimon Riggs <simon@2ndQuadrant.com>
Fri, 2 Oct 2009 09:50:32 +0000 (10:50 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Fri, 2 Oct 2009 09:50:32 +0000 (10:50 +0100)
it occurs in same place always, whatever mode we are in. Call now occurs after we get REDO pointer for checkpoint yet before we checkpoint and write the checkpoint WAL record.

src/backend/access/transam/xlog.c

index de682f1b57fb97aaaeb667e639adb4c255b54610..cdb43e254b902848cae29918de65254188606bf1 100644 (file)
@@ -7060,14 +7060,6 @@ ShutdownXLOG(int code, Datum arg)
                CreateRestartPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
        else
        {
-               /*
-                * Take a snapshot of running transactions and write this to WAL.
-                * This allows us to reconstruct the state of running transactions
-                * during archive recovery, if required.
-                */
-               if (XLogArchivingActive() && XLogArchiveCommandSet())
-                       GetRunningTransactionData();
-
                /*
                 * If archiving is enabled, rotate the last XLOG file so that all the
                 * remaining records are archived (postmaster wakes up the archiver
@@ -7078,15 +7070,6 @@ ShutdownXLOG(int code, Datum arg)
                        RequestXLogSwitch();
 
                CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
-
-               /*
-                * Take a snapshot of running transactions and write this to WAL.
-                * This allows us to reconstruct the state of running transactions
-                * during archive recovery, if required. We do this even if we are
-                * not archiving, to allow a cold physical backup of the server to
-                * be useful as a read only standby.
-                */
-               GetRunningTransactionData();
        }
        ShutdownCLOG();
        ShutdownSUBTRANS();
@@ -7355,6 +7338,26 @@ CreateCheckPoint(int flags)
         */
        LWLockRelease(WALInsertLock);
 
+       /*
+        * Take a snapshot of running transactions and write this to WAL.
+        * This allows us to reconstruct the state of running transactions
+        * during archive recovery, if required. We do this even if we are
+        * not archiving, to allow a cold physical backup of the server to
+        * be useful as a read only standby.
+        */
+       if (shutdown || (XLogArchivingActive() && XLogArchiveCommandSet()))
+       {
+               /* 
+                * GetRunningTransactionData() inserts WAL records while holding
+                * ProcArrayLock. Make sure we flush WAL first so we reduce the
+                * chance of needing to flush WAL during XLogInsert(), which might
+                * mean we hold ProcArrayLock across an I/O, which could be bad.
+                */
+               if (!shutdown)
+                       XLogBackgroundFlush();
+               GetRunningTransactionData();
+       }
+
        /*
         * If enabled, log checkpoint start.  We postpone this until now so as not
         * to log anything if we decided to skip the checkpoint.
@@ -7553,27 +7556,6 @@ CreateCheckPoint(int flags)
                                                                         CheckpointStats.ckpt_segs_recycled);
 
        LWLockRelease(CheckpointLock);
-
-       /*
-        * Take a snapshot of running transactions and write this to WAL.
-        * This allows us to reconstruct the state of running transactions
-        * during archive recovery, if required. If we aren't archiving,
-        * don't bother.
-        *
-        * If we are shutting down, or Startup process is completing crash
-        * recovery we don't need to write running xact data.
-        */
-       if (!shutdown && XLogArchivingActive() && !RecoveryInProgress())
-       {
-               /* 
-                * GetRunningTransactionData() inserts WAL records while holding
-                * ProcArrayLock. Make sure we flush WAL first so we reduce the
-                * chance of needing to flush WAL during XLogInsert(), which might
-                * mean we hold ProcArrayLock across an I/O, which could be bad.
-                */
-               XLogBackgroundFlush();
-               GetRunningTransactionData();
-       }
 }
 
 /*