summaryrefslogtreecommitdiff
path: root/src/backend/commands/vacuum.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-08-31 02:23:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-08-31 02:23:23 +0000
commit25ec228ef760eb91c094cc3b6dea7257cc22ffb5 (patch)
tree59d9d82fa2a61c1c27174d9b2f462536a7db39ee /src/backend/commands/vacuum.c
parente1cc64197bd3a8d6fd5e4ca6830d514130f2737f (diff)
Track the current XID wrap limit (or more accurately, the oldest unfrozen
XID) in checkpoint records. This eliminates the need to recompute the value from scratch during database startup, which is one of the two remaining reasons for the flatfile code to exist. It should also simplify life for hot-standby operation. To avoid bloating the checkpoint records unreasonably, I switched from tracking the oldest database by name to tracking it by OID. This turns out to save cycles in general (everywhere but the warning-generating paths, which we hardly care about) and also helps us deal with the case that the oldest database got dropped instead of being vacuumed. The prior coding might go for a long time without updating the wrap limit in that case, which is bad because it might result in a lot of useless autovacuum activity.
Diffstat (limited to 'src/backend/commands/vacuum.c')
-rw-r--r--src/backend/commands/vacuum.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 1058bd2d312..d2b3105e028 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.390 2009/08/24 02:18:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.391 2009/08/31 02:23:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -895,8 +895,9 @@ vac_update_datfrozenxid(void)
/*
* If we were able to advance datfrozenxid, mark the flat-file copy of
* pg_database for update at commit, and see if we can truncate pg_clog.
+ * Also force update if the shared XID-wrap-limit info is stale.
*/
- if (dirty)
+ if (dirty || !TransactionIdLimitIsValid())
{
database_file_update_needed();
vac_truncate_clog(newFrozenXid);
@@ -916,7 +917,7 @@ vac_update_datfrozenxid(void)
*
* This routine is shared by full and lazy VACUUM. Note that it's
* only invoked when we've managed to change our DB's datfrozenxid
- * entry.
+ * entry, or we found that the shared XID-wrap-limit info is stale.
*/
static void
vac_truncate_clog(TransactionId frozenXID)
@@ -925,11 +926,11 @@ vac_truncate_clog(TransactionId frozenXID)
Relation relation;
HeapScanDesc scan;
HeapTuple tuple;
- NameData oldest_datname;
+ Oid oldest_datoid;
bool frozenAlreadyWrapped = false;
- /* init oldest_datname to sync with my frozenXID */
- namestrcpy(&oldest_datname, get_database_name(MyDatabaseId));
+ /* init oldest_datoid to sync with my frozenXID */
+ oldest_datoid = MyDatabaseId;
/*
* Scan pg_database to compute the minimum datfrozenxid
@@ -958,7 +959,7 @@ vac_truncate_clog(TransactionId frozenXID)
else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID))
{
frozenXID = dbform->datfrozenxid;
- namecpy(&oldest_datname, &dbform->datname);
+ oldest_datoid = HeapTupleGetOid(tuple);
}
}
@@ -987,7 +988,7 @@ vac_truncate_clog(TransactionId frozenXID)
* Update the wrap limit for GetNewTransactionId. Note: this function
* will also signal the postmaster for an(other) autovac cycle if needed.
*/
- SetTransactionIdLimit(frozenXID, &oldest_datname);
+ SetTransactionIdLimit(frozenXID, oldest_datoid);
}