mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
Improve vacuum code to track minimum Xids per table instead of per database.
To this end, add a couple of columns to pg_class, relminxid and relvacuumxid, based on which we calculate the pg_database columns after each vacuum. We now force all databases to be vacuumed, even template ones. A backend noticing too old a database (meaning pg_database.datminxid is in danger of falling behind Xid wraparound) will signal the postmaster, which in turn will start an autovacuum iteration to process the offending database. In principle this is only there to cope with frozen (non-connectable) databases without forcing users to set them to connectable, but it could force regular user database to go through a database-wide vacuum at any time. Maybe we should warn users about this somehow. Of course the real solution will be to use autovacuum all the time ;-) There are some additional improvements we could have in this area: for example the vacuum code could be smarter about not updating pg_database for each table when called by autovacuum, and do it only once the whole autovacuum iteration is done. I updated the system catalogs documentation, but I didn't modify the maintenance section. Also having some regression tests for this would be nice but it's not really a very straightforward thing to do. Catalog version bumped due to system catalog changes.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.305 2006/07/08 20:45:38 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.306 2006/07/10 16:20:49 alvherre Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -597,6 +597,8 @@ InsertPgClassTuple(Relation pg_class_desc,
|
||||
values[Anum_pg_class_relhaspkey - 1] = BoolGetDatum(rd_rel->relhaspkey);
|
||||
values[Anum_pg_class_relhasrules - 1] = BoolGetDatum(rd_rel->relhasrules);
|
||||
values[Anum_pg_class_relhassubclass - 1] = BoolGetDatum(rd_rel->relhassubclass);
|
||||
values[Anum_pg_class_relminxid - 1] = TransactionIdGetDatum(rd_rel->relminxid);
|
||||
values[Anum_pg_class_relvacuumxid - 1] = TransactionIdGetDatum(rd_rel->relvacuumxid);
|
||||
/* start out with empty permissions */
|
||||
nulls[Anum_pg_class_relacl - 1] = 'n';
|
||||
if (reloptions != (Datum) 0)
|
||||
@@ -644,6 +646,35 @@ AddNewRelationTuple(Relation pg_class_desc,
|
||||
*/
|
||||
new_rel_reltup = new_rel_desc->rd_rel;
|
||||
|
||||
/* Initialize relminxid and relvacuumxid */
|
||||
if (relkind == RELKIND_RELATION ||
|
||||
relkind == RELKIND_TOASTVALUE)
|
||||
{
|
||||
/*
|
||||
* Only real tables have Xids stored in them; initialize our known
|
||||
* value to the minimum Xid that could put tuples in the new table.
|
||||
*/
|
||||
if (!IsBootstrapProcessingMode())
|
||||
{
|
||||
new_rel_reltup->relminxid = RecentXmin;
|
||||
new_rel_reltup->relvacuumxid = RecentXmin;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_rel_reltup->relminxid = FirstNormalTransactionId;
|
||||
new_rel_reltup->relvacuumxid = FirstNormalTransactionId;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Other relations will not have Xids in them, so set the initial value
|
||||
* to InvalidTransactionId.
|
||||
*/
|
||||
new_rel_reltup->relminxid = InvalidTransactionId;
|
||||
new_rel_reltup->relvacuumxid = InvalidTransactionId;
|
||||
}
|
||||
|
||||
switch (relkind)
|
||||
{
|
||||
case RELKIND_RELATION:
|
||||
|
Reference in New Issue
Block a user