mirror of
https://github.com/postgres/postgres.git
synced 2025-08-25 20:23:07 +03:00
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user