From: Simon Riggs Date: Fri, 2 Oct 2009 09:50:32 +0000 (+0100) Subject: Re-arrange placement of GetRunningTransactionData() so that X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=5c2993f2e0f4999c54bb68a7b261ed51de53ef99;p=users%2Fsimon%2Fpostgres.git Re-arrange placement of GetRunningTransactionData() so that 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. --- diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index de682f1b57..cdb43e254b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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(); - } } /*