summaryrefslogtreecommitdiff
path: root/src/backend/catalog
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2006-07-10 16:20:52 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2006-07-10 16:20:52 +0000
commitd4cef0aa2a55fafbd9ce2783c1eb9e0157c6781e (patch)
tree321bcb690f559b2b87fe51b3fe094d9776ce690a /src/backend/catalog
parente627c9b9a6aff106adba0c486c385a53eedf6c90 (diff)
downloadpostgresql-d4cef0aa2a55fafbd9ce2783c1eb9e0157c6781e.tar.gz
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.
Diffstat (limited to 'src/backend/catalog')
-rw-r--r--src/backend/catalog/heap.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 7ba0e7ef26..67b5a27836 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -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: