aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2011-02-16 19:29:37 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2011-02-16 19:29:37 +0000
commitbca8b7f16a3e720794cb0afbdb3733be4f8d9c2c (patch)
tree4d2e650f058ffa99af77f9068bf64a223de17246 /src/backend/storage/ipc
parent65076269ea54a8cd6e39f066a208c7d13aceac0a (diff)
downloadpostgresql-bca8b7f16a3e720794cb0afbdb3733be4f8d9c2c.tar.gz
postgresql-bca8b7f16a3e720794cb0afbdb3733be4f8d9c2c.zip
Hot Standby feedback for avoidance of cleanup conflicts on standby.
Standby optionally sends back information about oldestXmin of queries which is then checked and applied to the WALSender's proc->xmin. GetOldestXmin() is modified slightly to agree with GetSnapshotData(), so that all backends on primary include WALSender within their snapshots. Note this does nothing to change the snapshot xmin on either master or standby. Feedback piggybacks on the standby reply message. vacuum_defer_cleanup_age is no longer used on standby, though parameter still exists on primary, since some use cases still exist. Simon Riggs, review comments from Fujii Masao, Heikki Linnakangas, Robert Haas
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/procarray.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 8b36df4759f..2473881e8fb 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -1034,7 +1034,9 @@ GetOldestXmin(bool allDbs, bool ignoreVacuum)
if (ignoreVacuum && (proc->vacuumFlags & PROC_IN_VACUUM))
continue;
- if (allDbs || proc->databaseId == MyDatabaseId)
+ if (allDbs ||
+ proc->databaseId == MyDatabaseId ||
+ proc->databaseId == 0) /* include WalSender */
{
/* Fetch xid just once - see GetNewTransactionId */
TransactionId xid = proc->xid;
@@ -1066,28 +1068,35 @@ GetOldestXmin(bool allDbs, bool ignoreVacuum)
*/
TransactionId kaxmin = KnownAssignedXidsGetOldestXmin();
+ LWLockRelease(ProcArrayLock);
+
if (TransactionIdIsNormal(kaxmin) &&
TransactionIdPrecedes(kaxmin, result))
result = kaxmin;
}
+ else
+ {
+ /*
+ * No other information needed, so release the lock immediately.
+ */
+ LWLockRelease(ProcArrayLock);
- LWLockRelease(ProcArrayLock);
-
- /*
- * Compute the cutoff XID, being careful not to generate a "permanent"
- * XID.
- *
- * vacuum_defer_cleanup_age provides some additional "slop" for the
- * benefit of hot standby queries on slave servers. This is quick and
- * dirty, and perhaps not all that useful unless the master has a
- * predictable transaction rate, but it's what we've got. Note that we
- * are assuming vacuum_defer_cleanup_age isn't large enough to cause
- * wraparound --- so guc.c should limit it to no more than the
- * xidStopLimit threshold in varsup.c.
- */
- result -= vacuum_defer_cleanup_age;
- if (!TransactionIdIsNormal(result))
- result = FirstNormalTransactionId;
+ /*
+ * Compute the cutoff XID, being careful not to generate a "permanent"
+ * XID. We need do this only on the primary, never on standby.
+ *
+ * vacuum_defer_cleanup_age provides some additional "slop" for the
+ * benefit of hot standby queries on slave servers. This is quick and
+ * dirty, and perhaps not all that useful unless the master has a
+ * predictable transaction rate, but it's what we've got. Note that we
+ * are assuming vacuum_defer_cleanup_age isn't large enough to cause
+ * wraparound --- so guc.c should limit it to no more than the
+ * xidStopLimit threshold in varsup.c.
+ */
+ result -= vacuum_defer_cleanup_age;
+ if (!TransactionIdIsNormal(result))
+ result = FirstNormalTransactionId;
+ }
return result;
}