Index: doc/src/sgml/catalogs.sgml =================================================================== RCS file: /home/alvherre/cvs/pgsql/doc/src/sgml/catalogs.sgml,v retrieving revision 2.121 diff -c -r2.121 catalogs.sgml *** doc/src/sgml/catalogs.sgml 10 Mar 2006 19:10:46 -0000 2.121 --- doc/src/sgml/catalogs.sgml 2 Apr 2006 17:00:35 -0000 *************** *** 1619,1624 **** --- 1619,1648 ---- + relminxid + xid + + + The minimum transaction ID present in all rows in this table. This + value is used to determine the database-global + pg_database.datminxid value. + + + + + relvacuumxid + xid + + + The transaction ID that was used as cleaning point as of the last vacuum + operation. All rows inserted, updated or deleted in this table by + transactions whose IDs are below this one have been marked as known good + or deleted. This is used to determine the database-global + pg_database.datvacuumxid value. + + + + relacl aclitem[] *************** *** 1990,2010 **** xid ! All rows inserted or deleted by transaction IDs before this one ! have been marked as known committed or known aborted in this database. ! This is used to determine when commit-log space can be recycled. ! datfrozenxid xid All rows inserted by transaction IDs before this one have been relabeled with a permanent (frozen) transaction ID in this ! database. This is useful to check whether a database must be vacuumed ! soon to avoid transaction ID wrap-around problems. --- 2014,2040 ---- xid ! The transaction ID that was used as cleaning point as of the last vacuum ! operation. All rows inserted or deleted by transaction IDs before this one ! have been marked as known good or deleted. This ! is used to determine when commit-log space can be recycled. ! If InvalidTransactionId, then the minimum is unknown and can be ! determined by scanning pg_class.relvacuumxid. ! datminxid xid + The minimum transaction ID present in all tables in this database. All rows inserted by transaction IDs before this one have been relabeled with a permanent (frozen) transaction ID in this ! database. This is useful to check whether a database must be ! vacuumed soon to avoid transaction ID wrap-around problems. ! If InvalidTransactionId, then the minimum is unknown and can be ! determined by scanning pg_class.relminxid. Index: src/backend/access/transam/varsup.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/access/transam/varsup.c,v retrieving revision 1.70 diff -c -r1.70 varsup.c *** src/backend/access/transam/varsup.c 5 Mar 2006 15:58:22 -0000 1.70 --- src/backend/access/transam/varsup.c 20 Mar 2006 04:11:05 -0000 *************** *** 168,178 **** /* * Determine the last safe XID to allocate given the currently oldest ! * datfrozenxid (ie, the oldest XID that might exist in any database * of our cluster). */ void ! SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Name oldest_datname) { TransactionId xidWarnLimit; --- 168,178 ---- /* * Determine the last safe XID to allocate given the currently oldest ! * datminxid (ie, the oldest XID that might exist in any database * of our cluster). */ void ! SetTransactionIdLimit(TransactionId oldest_datminxid, Name oldest_datname) { TransactionId xidWarnLimit; *************** *** 180,195 **** TransactionId xidWrapLimit; TransactionId curXid; ! Assert(TransactionIdIsValid(oldest_datfrozenxid)); /* * The place where we actually get into deep trouble is halfway around ! * from the oldest potentially-existing XID. (This calculation is ! * probably off by one or two counts, because the special XIDs reduce the ! * size of the loop a little bit. But we throw in plenty of slop below, ! * so it doesn't matter.) */ ! xidWrapLimit = oldest_datfrozenxid + (MaxTransactionId >> 1); if (xidWrapLimit < FirstNormalTransactionId) xidWrapLimit += FirstNormalTransactionId; --- 180,195 ---- TransactionId xidWrapLimit; TransactionId curXid; ! Assert(TransactionIdIsValid(oldest_datminxid)); /* * The place where we actually get into deep trouble is halfway around ! * from the oldest existing XID. (This calculation is probably off by one ! * or two counts, because the special XIDs reduce the size of the loop a ! * little bit. But we throw in plenty of slop below, so it doesn't ! * matter.) */ ! xidWrapLimit = oldest_datminxid + (MaxTransactionId >> 1); if (xidWrapLimit < FirstNormalTransactionId) xidWrapLimit += FirstNormalTransactionId; Index: src/backend/catalog/heap.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/catalog/heap.c,v retrieving revision 1.295 diff -c -r1.295 heap.c *** src/backend/catalog/heap.c 5 Mar 2006 15:58:22 -0000 1.295 --- src/backend/catalog/heap.c 2 Apr 2006 18:08:05 -0000 *************** *** 38,43 **** --- 38,44 ---- #include "catalog/indexing.h" #include "catalog/pg_attrdef.h" #include "catalog/pg_constraint.h" + #include "catalog/pg_database.h" #include "catalog/pg_inherits.h" #include "catalog/pg_namespace.h" #include "catalog/pg_statistic.h" *************** *** 568,573 **** --- 569,594 ---- */ new_rel_reltup = new_rel_desc->rd_rel; + /* Initialize relminxid and relvacuumxid */ + if (relkind == RELKIND_RELATION) + { + /* + * Only real tables have Xids stored in them; initialize our known + * values to the minimum Xids that could put tuples in the new table. + */ + new_rel_reltup->relminxid = RecentXmin; + new_rel_reltup->relvacuumxid = RecentXmin; + } + 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: *************** *** 1125,1130 **** --- 1146,1200 ---- } /* + * Invalidate (set to invalid) the datminxid and/or datvacuumxid of a database, + * when we drop the table that has the minimum Xids. + */ + static void + InvalidateDbMinxid(TransactionId relminxid, TransactionId relvacuumxid) + { + Oid dbid = MyDatabaseId; + Relation dbrel; + HeapTuple tuple; + HeapScanDesc scan; + Form_pg_database dbform; + ScanKeyData entry[1]; + + dbrel = heap_open(DatabaseRelationId, RowExclusiveLock); + + /* Must use a heap scan, since there's no syscache for pg_database */ + ScanKeyInit(&entry[0], + ObjectIdAttributeNumber, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(dbid)); + + scan = heap_beginscan(dbrel, SnapshotNow, 1, entry); + + tuple = heap_getnext(scan, ForwardScanDirection); + + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "could not find tuple for database %u", dbid); + + /* Ensure no one does this at the same time */ + LockBuffer(scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE); + + dbform = (Form_pg_database) GETSTRUCT(tuple); + + /* Note we don't actually care if dbform->datminxid is already Invalid */ + if (TransactionIdEquals(dbform->datminxid, relminxid)) + dbform->datminxid = InvalidTransactionId; + + /* ditto */ + if (TransactionIdEquals(dbform->datvacuumxid, relvacuumxid)) + dbform->datvacuumxid = InvalidTransactionId; + + LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); + + heap_endscan(scan); + + heap_close(dbrel, RowExclusiveLock); + } + + /* * heap_drop_with_catalog - removes specified relation from catalogs * * Note that this routine is not responsible for dropping objects that are *************** *** 1153,1158 **** --- 1223,1232 ---- smgrscheduleunlink(rel->rd_smgr, rel->rd_istemp); } + /* Invalidate pg_database.datminxid, if appropiate */ + if ((rel->rd_rel->relkind == RELKIND_RELATION) && (!rel->rd_istemp)) + InvalidateDbMinxid(rel->rd_rel->relminxid, rel->rd_rel->relvacuumxid); + /* * Close relcache entry, but *keep* AccessExclusiveLock on the relation * until transaction commit. This ensures no one else will try to do Index: src/backend/commands/analyze.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/commands/analyze.c,v retrieving revision 1.93 diff -c -r1.93 analyze.c *** src/backend/commands/analyze.c 23 Mar 2006 00:19:28 -0000 1.93 --- src/backend/commands/analyze.c 2 Apr 2006 15:56:26 -0000 *************** *** 424,431 **** { vac_update_relstats(RelationGetRelid(onerel), RelationGetNumberOfBlocks(onerel), ! totalrows, ! hasindex); for (ind = 0; ind < nindexes; ind++) { AnlIndexData *thisdata = &indexdata[ind]; --- 424,434 ---- { vac_update_relstats(RelationGetRelid(onerel), RelationGetNumberOfBlocks(onerel), ! totalrows, hasindex, false, ! InvalidTransactionId, ! InvalidTransactionId, ! NULL, NULL); ! for (ind = 0; ind < nindexes; ind++) { AnlIndexData *thisdata = &indexdata[ind]; *************** *** 435,441 **** vac_update_relstats(RelationGetRelid(Irel[ind]), RelationGetNumberOfBlocks(Irel[ind]), totalindexrows, ! false); } /* report results to the stats collector, too */ --- 438,445 ---- vac_update_relstats(RelationGetRelid(Irel[ind]), RelationGetNumberOfBlocks(Irel[ind]), totalindexrows, ! false, false, InvalidTransactionId, ! InvalidTransactionId, NULL, NULL); } /* report results to the stats collector, too */ Index: src/backend/commands/dbcommands.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/commands/dbcommands.c,v retrieving revision 1.179 diff -c -r1.179 dbcommands.c *** src/backend/commands/dbcommands.c 29 Mar 2006 21:17:38 -0000 1.179 --- src/backend/commands/dbcommands.c 2 Apr 2006 16:46:58 -0000 *************** *** 56,62 **** static bool get_db_info(const char *name, Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, ! TransactionId *dbVacuumXidP, TransactionId *dbFrozenXidP, Oid *dbTablespace); static bool have_createdb_privilege(void); static void remove_dbtablespaces(Oid db_id); --- 56,62 ---- static bool get_db_info(const char *name, Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, ! TransactionId *dbVacuumXidP, TransactionId *dbMinXidP, Oid *dbTablespace); static bool have_createdb_privilege(void); static void remove_dbtablespaces(Oid db_id); *************** *** 77,83 **** bool src_allowconn; Oid src_lastsysoid; TransactionId src_vacuumxid; ! TransactionId src_frozenxid; Oid src_deftablespace; volatile Oid dst_deftablespace; volatile Relation pg_database_rel; --- 77,83 ---- bool src_allowconn; Oid src_lastsysoid; TransactionId src_vacuumxid; ! TransactionId src_minxid; Oid src_deftablespace; volatile Oid dst_deftablespace; volatile Relation pg_database_rel; *************** *** 237,243 **** if (!get_db_info(dbtemplate, &src_dboid, &src_owner, &src_encoding, &src_istemplate, &src_allowconn, &src_lastsysoid, ! &src_vacuumxid, &src_frozenxid, &src_deftablespace)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_DATABASE), errmsg("template database \"%s\" does not exist", dbtemplate))); --- 237,243 ---- if (!get_db_info(dbtemplate, &src_dboid, &src_owner, &src_encoding, &src_istemplate, &src_allowconn, &src_lastsysoid, ! &src_vacuumxid, &src_minxid, &src_deftablespace)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_DATABASE), errmsg("template database \"%s\" does not exist", dbtemplate))); *************** *** 337,349 **** /* * Normally we mark the new database with the same datvacuumxid and ! * datfrozenxid as the source. However, if the source is not allowing * connections then we assume it is fully frozen, and we can set the * current transaction ID as the xid limits. This avoids immediately * starting to generate warnings after cloning template0. */ if (!src_allowconn) ! src_vacuumxid = src_frozenxid = GetCurrentTransactionId(); /* * Preassign OID for pg_database tuple, so that we can compute db path. We --- 337,349 ---- /* * Normally we mark the new database with the same datvacuumxid and ! * datminxid as the source. However, if the source is not allowing * connections then we assume it is fully frozen, and we can set the * current transaction ID as the xid limits. This avoids immediately * starting to generate warnings after cloning template0. */ if (!src_allowconn) ! src_vacuumxid = src_minxid = GetCurrentTransactionId(); /* * Preassign OID for pg_database tuple, so that we can compute db path. We *************** *** 464,470 **** new_record[Anum_pg_database_datconnlimit - 1] = Int32GetDatum(dbconnlimit); new_record[Anum_pg_database_datlastsysoid - 1] = ObjectIdGetDatum(src_lastsysoid); new_record[Anum_pg_database_datvacuumxid - 1] = TransactionIdGetDatum(src_vacuumxid); ! new_record[Anum_pg_database_datfrozenxid - 1] = TransactionIdGetDatum(src_frozenxid); new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_deftablespace); /* --- 464,470 ---- new_record[Anum_pg_database_datconnlimit - 1] = Int32GetDatum(dbconnlimit); new_record[Anum_pg_database_datlastsysoid - 1] = ObjectIdGetDatum(src_lastsysoid); new_record[Anum_pg_database_datvacuumxid - 1] = TransactionIdGetDatum(src_vacuumxid); ! new_record[Anum_pg_database_datminxid - 1] = TransactionIdGetDatum(src_minxid); new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_deftablespace); /* *************** *** 1097,1103 **** get_db_info(const char *name, Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, ! TransactionId *dbVacuumXidP, TransactionId *dbFrozenXidP, Oid *dbTablespace) { Relation relation; --- 1097,1103 ---- get_db_info(const char *name, Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, ! TransactionId *dbVacuumXidP, TransactionId *dbMinXidP, Oid *dbTablespace) { Relation relation; *************** *** 1147,1155 **** /* limit of vacuumed XIDs */ if (dbVacuumXidP) *dbVacuumXidP = dbform->datvacuumxid; ! /* limit of frozen XIDs */ ! if (dbFrozenXidP) ! *dbFrozenXidP = dbform->datfrozenxid; /* default tablespace for this database */ if (dbTablespace) *dbTablespace = dbform->dattablespace; --- 1147,1155 ---- /* limit of vacuumed XIDs */ if (dbVacuumXidP) *dbVacuumXidP = dbform->datvacuumxid; ! /* limit of min XIDs */ ! if (dbMinXidP) ! *dbMinXidP = dbform->datminxid; /* default tablespace for this database */ if (dbTablespace) *dbTablespace = dbform->dattablespace; Index: src/backend/commands/vacuum.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/commands/vacuum.c,v retrieving revision 1.326 diff -c -r1.326 vacuum.c *** src/backend/commands/vacuum.c 31 Mar 2006 23:32:06 -0000 1.326 --- src/backend/commands/vacuum.c 2 Apr 2006 16:04:16 -0000 *************** *** 126,131 **** --- 126,132 ---- Size min_tlen; Size max_tlen; bool hasindex; + TransactionId minxid; /* Minimum Xid present anywhere on table */ /* vtlinks array for tuple chain following - sorted by new_tid */ int num_vtlinks; VTupleLink vtlinks; *************** *** 193,217 **** static int elevel = -1; - static TransactionId OldestXmin; - static TransactionId FreezeLimit; - /* non-export function prototypes */ static List *get_rel_oids(List *relids, const RangeVar *vacrel, ! const char *stmttype); ! static void vac_update_dbstats(Oid dbid, ! TransactionId vacuumXID, ! TransactionId frozenXID); ! static void vac_truncate_clog(TransactionId vacuumXID, ! TransactionId frozenXID); ! static bool vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind); ! static void full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt); static void scan_heap(VRelStats *vacrelstats, Relation onerel, ! VacPageList vacuum_pages, VacPageList fraged_pages); static void repair_frag(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages, VacPageList fraged_pages, ! int nindexes, Relation *Irel); static void move_chain_tuple(Relation rel, Buffer old_buf, Page old_page, HeapTuple old_tup, Buffer dst_buf, Page dst_page, VacPage dst_vacpage, --- 194,217 ---- static int elevel = -1; /* non-export function prototypes */ static List *get_rel_oids(List *relids, const RangeVar *vacrel, ! const char *stmttype); ! static void vac_update_dbxids(Oid dbid, TransactionId prevminXid, ! TransactionId prevvacXid); ! static void vac_truncate_clog(TransactionId minXID); ! static void vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind, ! TransactionId *prevmin, TransactionId *prevvac); ! static void full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, ! TransactionId *relminxid, TransactionId *relvacuumxid); ! static void scan_heap(VRelStats *vacrelstats, Relation onerel, ! VacPageList vacuum_pages, VacPageList fraged_pages, ! TransactionId FreezeLimit, TransactionId OldestXmin); static void repair_frag(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages, VacPageList fraged_pages, ! int nindexes, Relation *Irel, TransactionId OldestXmin); static void move_chain_tuple(Relation rel, Buffer old_buf, Page old_page, HeapTuple old_tup, Buffer dst_buf, Page dst_page, VacPage dst_vacpage, *************** *** 268,280 **** vacuum(VacuumStmt *vacstmt, List *relids) { const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE"; - TransactionId initialOldestXmin = InvalidTransactionId; - TransactionId initialFreezeLimit = InvalidTransactionId; volatile MemoryContext anl_context = NULL; volatile bool all_rels, in_outer_xact, use_own_xacts; List *relations; if (vacstmt->verbose) elevel = INFO; --- 268,282 ---- vacuum(VacuumStmt *vacstmt, List *relids) { const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE"; volatile MemoryContext anl_context = NULL; volatile bool all_rels, in_outer_xact, use_own_xacts; List *relations; + TransactionId prevmin, + prevvac; + TransactionId currmin = InvalidTransactionId, + currvac = InvalidTransactionId; if (vacstmt->verbose) elevel = INFO; *************** *** 352,383 **** */ relations = get_rel_oids(relids, vacstmt->relation, stmttype); - if (vacstmt->vacuum && all_rels) - { - /* - * It's a database-wide VACUUM. - * - * Compute the initially applicable OldestXmin and FreezeLimit XIDs, - * so that we can record these values at the end of the VACUUM. Note - * that individual tables may well be processed with newer values, but - * we can guarantee that no (non-shared) relations are processed with - * older ones. - * - * It is okay to record non-shared values in pg_database, even though - * we may vacuum shared relations with older cutoffs, because only the - * minimum of the values present in pg_database matters. We can be - * sure that shared relations have at some time been vacuumed with - * cutoffs no worse than the global minimum; for, if there is a - * backend in some other DB with xmin = OLDXMIN that's determining the - * cutoff with which we vacuum shared relations, it is not possible - * for that database to have a cutoff newer than OLDXMIN recorded in - * pg_database. - */ - vacuum_set_xid_limits(vacstmt, false, - &initialOldestXmin, - &initialFreezeLimit); - } - /* * Decide whether we need to start/commit our own transactions. * --- 354,359 ---- *************** *** 446,453 **** if (vacstmt->vacuum) { ! if (!vacuum_rel(relid, vacstmt, RELKIND_RELATION)) ! all_rels = false; /* forget about updating dbstats */ } if (vacstmt->analyze) { --- 422,439 ---- if (vacstmt->vacuum) { ! vacuum_rel(relid, vacstmt, RELKIND_RELATION, &prevmin, ! &prevvac); ! ! if (!TransactionIdIsValid(currmin) || ! (TransactionIdIsNormal(prevmin) && ! TransactionIdPrecedes(prevmin, currmin))) ! currmin = prevmin; ! ! if (!TransactionIdIsValid(currvac) || ! (TransactionIdIsNormal(prevvac) && ! TransactionIdPrecedes(prevvac, currvac))) ! currvac = prevvac; } if (vacstmt->analyze) { *************** *** 532,546 **** PrintFreeSpaceMapStatistics(elevel); /* ! * If we completed a database-wide VACUUM without skipping any ! * relations, update the database's pg_database row with info about ! * the transaction IDs used, and try to truncate pg_clog. */ ! if (all_rels) { ! vac_update_dbstats(MyDatabaseId, ! initialOldestXmin, initialFreezeLimit); ! vac_truncate_clog(initialOldestXmin, initialFreezeLimit); } } --- 518,536 ---- PrintFreeSpaceMapStatistics(elevel); /* ! * Skip these steps if the current minxid is InvalidTransactionId. ! * It shouldn't happen on normal operation, but it happens during ! * initdb. */ ! if (TransactionIdIsValid(currmin)) { ! Assert(TransactionIdIsValid(currvac)); ! ! /* Update pg_database.datminxid, if necessary. */ ! vac_update_dbxids(MyDatabaseId, currmin, currvac); ! ! /* Try to truncate pg_clog. */ ! vac_truncate_clog(currvac); } } *************** *** 673,678 **** --- 663,672 ---- * doing ANALYZE, but we always update these stats. This routine works * for both index and heap relation entries in pg_class. * + * relminxid and relvacuumxid are output parameters, and correspond + * to the values in pg_class that existed prior to the execution of + * this vacuum. + * * We violate no-overwrite semantics here by storing new values for the * statistics columns directly into the pg_class tuple that's already on * the page. The reason for this is that if we updated these tuples in *************** *** 686,692 **** */ void vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, ! bool hasindex) { Relation rd; HeapTupleData rtup; --- 680,688 ---- */ void vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, ! bool hasindex, bool update_xids, TransactionId minxid, ! TransactionId vacuumxid, TransactionId *relminxid, ! TransactionId *relvacuumxid) { Relation rd; HeapTupleData rtup; *************** *** 718,723 **** --- 714,731 ---- /* overwrite the existing statistics in the tuple */ pgcform = (Form_pg_class) GETSTRUCT(&rtup); + + /* Set relminxid/relvacuumxid only if asked to */ + if (update_xids) + { + AssertArg(relminxid != NULL && relvacuumxid != NULL); + + *relminxid = pgcform->relminxid; + pgcform->relminxid = minxid; + *relvacuumxid = pgcform->relvacuumxid; + pgcform->relvacuumxid = vacuumxid; + } + pgcform->relpages = (int32) num_pages; pgcform->reltuples = (float4) num_tuples; pgcform->relhasindex = hasindex; *************** *** 748,778 **** /* ! * vac_update_dbstats() -- update statistics for one database * ! * Update the whole-database statistics that are kept in its pg_database ! * row, and the flat-file copy of pg_database. * ! * We violate no-overwrite semantics here by storing new values for the ! * statistics columns directly into the tuple that's already on the page. * As with vac_update_relstats, this avoids leaving dead tuples behind * after a VACUUM. * ! * This routine is shared by full and lazy VACUUM. Note that it is only ! * applied after a database-wide VACUUM operation. */ static void ! vac_update_dbstats(Oid dbid, ! TransactionId vacuumXID, ! TransactionId frozenXID) { ! Relation relation; ! ScanKeyData entry[1]; HeapScanDesc scan; HeapTuple tuple; Form_pg_database dbform; ! relation = heap_open(DatabaseRelationId, RowExclusiveLock); /* Must use a heap scan, since there's no syscache for pg_database */ ScanKeyInit(&entry[0], --- 756,803 ---- /* ! * vac_update_dbxids() -- update the minimum Xid present in one database * ! * Update pg_database's datminxid and datvacuumxid and the flat-file copy ! * of pg_database. * ! * The prevminXid argument (resp. prevvacXid) is the minimum of all the ! * relminxids (resp. relvacuumxid) that the vacuumed table(s) had before ! * this vacuum operation. ! * ! * The Xids are updated to the minimum of all relminxid/relvacuumxid found ! * in pg_class, if this prevminXid/prevvacXid is found to be equal to the ! * current minimum -- that is, one of the processed tables was the one ! * holding the minimum back. ! * ! * Note that it's possible for the data in pg_database to be ! * InvalidTransactionId -- for example, if a table is dropped. This is ! * to cope with the possibility that the dropped table was the one with ! * the minimum. In this case, we need to search the minimum ! * inconditionally. ! * ! * We violate no-overwrite semantics here by storing a new value for the ! * statistic column directly into the tuple that's already on the page. * As with vac_update_relstats, this avoids leaving dead tuples behind * after a VACUUM. * ! * This routine is shared by full and lazy VACUUM. */ static void ! vac_update_dbxids(Oid dbid, TransactionId prevminXid, TransactionId prevvacXid) { ! Relation dbrel; ! ScanKeyData entry[1]; HeapScanDesc scan; HeapTuple tuple; Form_pg_database dbform; + TransactionId prevmin, + prevvac; + + Assert(TransactionIdIsValid(prevminXid)); + Assert(TransactionIdIsValid(prevvacXid)); ! dbrel = heap_open(DatabaseRelationId, RowExclusiveLock); /* Must use a heap scan, since there's no syscache for pg_database */ ScanKeyInit(&entry[0], *************** *** 780,838 **** BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dbid)); ! scan = heap_beginscan(relation, SnapshotNow, 1, entry); tuple = heap_getnext(scan, ForwardScanDirection); if (!HeapTupleIsValid(tuple)) elog(ERROR, "could not find tuple for database %u", dbid); ! /* ensure no one else does this at the same time */ ! LockBuffer(scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE); dbform = (Form_pg_database) GETSTRUCT(tuple); ! /* overwrite the existing statistics in the tuple */ ! dbform->datvacuumxid = vacuumXID; ! dbform->datfrozenxid = frozenXID; ! MarkBufferDirty(scan->rs_cbuf); ! LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); ! /* invalidate the tuple in the cache so we'll see the change in cache */ ! CacheInvalidateHeapTuple(relation, tuple); ! heap_endscan(scan); ! heap_close(relation, RowExclusiveLock); ! /* Mark the flat-file copy of pg_database for update at commit */ ! database_file_update_needed(); } /* * vac_truncate_clog() -- attempt to truncate the commit log * ! * Scan pg_database to determine the system-wide oldest datvacuumxid, ! * and use it to truncate the transaction commit log (pg_clog). ! * Also update the XID wrap limit point maintained by varsup.c. * ! * We also generate a warning if the system-wide oldest datfrozenxid * seems to be in danger of wrapping around. This is a long-in-advance * warning; if we start getting uncomfortably close, GetNewTransactionId * will generate more-annoying warnings, and ultimately refuse to issue * any more new XIDs. * ! * The passed XIDs are simply the ones I just wrote into my pg_database ! * entry. They're used to initialize the "min" calculations. * ! * This routine is shared by full and lazy VACUUM. Note that it is only ! * applied after a database-wide VACUUM operation. */ static void ! vac_truncate_clog(TransactionId vacuumXID, TransactionId frozenXID) { TransactionId myXID = GetCurrentTransactionId(); Relation relation; --- 805,915 ---- BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dbid)); ! scan = heap_beginscan(dbrel, SnapshotNow, 1, entry); tuple = heap_getnext(scan, ForwardScanDirection); if (!HeapTupleIsValid(tuple)) elog(ERROR, "could not find tuple for database %u", dbid); ! /* Ensure no one does this at the same time */ ! LockSharedObject(DatabaseRelationId, dbid, 0, AccessExclusiveLock); dbform = (Form_pg_database) GETSTRUCT(tuple); + prevmin = dbform->datminxid; + prevvac = dbform->datvacuumxid; ! /* ! * If the table we just vacuumed was holding one of the minima back, or any ! * of them was unset, update pg_database. ! */ ! if (!TransactionIdIsValid(prevmin) || ! !TransactionIdIsValid(prevvac) || ! TransactionIdEquals(prevmin, prevminXid) || ! TransactionIdEquals(prevvac, prevvacXid)) ! { ! Relation classRel; ! SysScanDesc classScan; ! HeapTuple classTup; ! TransactionId newMinXid = InvalidTransactionId, ! newVacXid = InvalidTransactionId; ! /* scan pg_class searching for the minimum relminxid */ ! classRel = heap_open(RelationRelationId, AccessShareLock); ! classScan = systable_beginscan(classRel, InvalidOid, false, ! SnapshotNow, 0, NULL); ! while ((classTup = systable_getnext(classScan)) != NULL) ! { ! Form_pg_class classForm; ! classForm = (Form_pg_class) GETSTRUCT(classTup); ! ! /* Only consider normal tables */ ! if (classForm->relkind != RELKIND_RELATION) ! continue; ! ! if (!TransactionIdIsValid(newMinXid) || ! (TransactionIdIsNormal(classForm->relminxid) && ! TransactionIdPrecedes(classForm->relminxid, newMinXid))) ! newMinXid = classForm->relminxid; ! ! if (!TransactionIdIsValid(newVacXid) || ! (TransactionIdIsNormal(classForm->relvacuumxid) && ! TransactionIdPrecedes(classForm->relvacuumxid, newVacXid))) ! newVacXid = classForm->relvacuumxid; ! } ! ! systable_endscan(classScan); ! heap_close(classRel, AccessShareLock); ! ! Assert(TransactionIdIsValid(newMinXid)); ! Assert(TransactionIdIsValid(newVacXid)); ! ! LockBuffer(scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE); ! ! dbform->datminxid = newMinXid; ! dbform->datvacuumxid = newVacXid; ! ! /* invalidate the tuple in the cache and write the buffer */ ! CacheInvalidateHeapTuple(dbrel, tuple); ! MarkBufferDirty(scan->rs_cbuf); ! ! LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); ! ! /* Mark the flat-file copy of pg_database for update at commit */ ! database_file_update_needed(); ! } ! UnlockSharedObject(DatabaseRelationId, dbid, 0, AccessExclusiveLock); ! heap_endscan(scan); ! ! heap_close(dbrel, RowExclusiveLock); } /* * vac_truncate_clog() -- attempt to truncate the commit log * ! * Truncate the transaction commit log (pg_clog) using the minimum ! * Xid found on pg_database. Also update the XID wrap limit point ! * maintained by varsup.c. * ! * We also generate a warning if the system-wide oldest datminxid * seems to be in danger of wrapping around. This is a long-in-advance * warning; if we start getting uncomfortably close, GetNewTransactionId * will generate more-annoying warnings, and ultimately refuse to issue * any more new XIDs. * ! * The passed XID is simply the one I just wrote into my pg_database ! * entry. It's used to initialize the "min" calculation. * ! * This routine is shared by full and lazy VACUUM. */ static void ! vac_truncate_clog(TransactionId minXID) { TransactionId myXID = GetCurrentTransactionId(); Relation relation; *************** *** 840,854 **** HeapTuple tuple; int32 age; NameData oldest_datname; ! bool vacuumAlreadyWrapped = false; ! bool frozenAlreadyWrapped = false; ! /* init oldest_datname to sync with my frozenXID */ namestrcpy(&oldest_datname, get_database_name(MyDatabaseId)); /* ! * Note: the "already wrapped" cases should now be impossible due to the ! * defenses in GetNewTransactionId, but we keep them anyway. */ relation = heap_open(DatabaseRelationId, AccessShareLock); --- 917,932 ---- HeapTuple tuple; int32 age; NameData oldest_datname; ! bool alreadyWrapped = false; ! ! Assert(TransactionIdIsValid(minXID)); ! /* init oldest_datname to sync with my minXID */ namestrcpy(&oldest_datname, get_database_name(MyDatabaseId)); /* ! * Note: the "already wrapped" case should now be impossible due to the ! * defenses in GetNewTransactionId, but we keep it anyway. */ relation = heap_open(DatabaseRelationId, AccessShareLock); *************** *** 863,882 **** if (!dbform->datallowconn) continue; ! if (TransactionIdIsNormal(dbform->datvacuumxid)) ! { ! if (TransactionIdPrecedes(myXID, dbform->datvacuumxid)) ! vacuumAlreadyWrapped = true; ! else if (TransactionIdPrecedes(dbform->datvacuumxid, vacuumXID)) ! vacuumXID = dbform->datvacuumxid; ! } ! if (TransactionIdIsNormal(dbform->datfrozenxid)) { ! if (TransactionIdPrecedes(myXID, dbform->datfrozenxid)) ! frozenAlreadyWrapped = true; ! else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID)) { ! frozenXID = dbform->datfrozenxid; namecpy(&oldest_datname, &dbform->datname); } } --- 941,953 ---- if (!dbform->datallowconn) continue; ! if (TransactionIdIsNormal(dbform->datminxid)) { ! if (TransactionIdPrecedes(myXID, dbform->datminxid)) ! alreadyWrapped = true; ! else if (TransactionIdPrecedes(dbform->datminxid, minXID)) { ! minXID = dbform->datminxid; namecpy(&oldest_datname, &dbform->datname); } } *************** *** 887,911 **** heap_close(relation, AccessShareLock); /* ! * Do not truncate CLOG if we seem to have suffered wraparound already; ! * the computed minimum XID might be bogus. ! */ ! if (vacuumAlreadyWrapped) ! { ! ereport(WARNING, ! (errmsg("some databases have not been vacuumed in over 2 billion transactions"), ! errdetail("You may have already suffered transaction-wraparound data loss."))); ! return; ! } ! ! /* Truncate CLOG to the oldest vacuumxid */ ! TruncateCLOG(vacuumXID); ! ! /* ! * Do not update varsup.c if we seem to have suffered wraparound already; ! * the computed XID might be bogus. */ ! if (frozenAlreadyWrapped) { ereport(WARNING, (errmsg("some databases have not been vacuumed in over 1 billion transactions"), --- 958,967 ---- heap_close(relation, AccessShareLock); /* ! * Do not truncate CLOG or update varsup.c if we seem to have suffered ! * wraparound already; the computed XID might be bogus. */ ! if (alreadyWrapped) { ereport(WARNING, (errmsg("some databases have not been vacuumed in over 1 billion transactions"), *************** *** 913,923 **** return; } /* Update the wrap limit for GetNewTransactionId */ ! SetTransactionIdLimit(frozenXID, &oldest_datname); /* Give warning about impending wraparound problems */ ! age = (int32) (myXID - frozenXID); if (age > (int32) ((MaxTransactionId >> 3) * 3)) ereport(WARNING, (errmsg("database \"%s\" must be vacuumed within %u transactions", --- 969,982 ---- return; } + /* Truncate CLOG to the oldest minxid */ + TruncateCLOG(minXID); + /* Update the wrap limit for GetNewTransactionId */ ! SetTransactionIdLimit(minXID, &oldest_datname); /* Give warning about impending wraparound problems */ ! age = (int32) (myXID - minXID); if (age > (int32) ((MaxTransactionId >> 3) * 3)) ereport(WARNING, (errmsg("database \"%s\" must be vacuumed within %u transactions", *************** *** 939,965 **** /* * vacuum_rel() -- vacuum one heap relation * - * Returns TRUE if we actually processed the relation (or can ignore it - * for some reason), FALSE if we failed to process it due to permissions - * or other reasons. (A FALSE result really means that some data - * may have been left unvacuumed, so we can't update XID stats.) - * * Doing one heap at a time incurs extra overhead, since we need to * check that the heap exists again just before we vacuum it. The * reason that we do this is so that vacuuming can be spread across * many small transactions. Otherwise, two-phase locking would require * us to lock the entire database during one pass of the vacuum cleaner. * * At entry and exit, we are not inside a transaction. */ ! static bool ! vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind) { LOCKMODE lmode; Relation onerel; LockRelId onerelid; Oid toast_relid; - bool result; /* Begin a transaction for vacuuming this relation */ StartTransactionCommand(); --- 998,1022 ---- /* * vacuum_rel() -- vacuum one heap relation * * Doing one heap at a time incurs extra overhead, since we need to * check that the heap exists again just before we vacuum it. The * reason that we do this is so that vacuuming can be spread across * many small transactions. Otherwise, two-phase locking would require * us to lock the entire database during one pass of the vacuum cleaner. * + * prevmin and prevvac are output parameters, and correspond to the values + * in pg_class that existed prior to the execution of this vacuum. + * * At entry and exit, we are not inside a transaction. */ ! static void ! vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind, ! TransactionId *prevmin, TransactionId *prevvac) { LOCKMODE lmode; Relation onerel; LockRelId onerelid; Oid toast_relid; /* Begin a transaction for vacuuming this relation */ StartTransactionCommand(); *************** *** 988,994 **** { StrategyHintVacuum(false); CommitTransactionCommand(); ! return true; /* okay 'cause no data there */ } /* --- 1045,1051 ---- { StrategyHintVacuum(false); CommitTransactionCommand(); ! return; } /* *************** *** 1019,1025 **** relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return false; } /* --- 1076,1082 ---- relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return; } /* *************** *** 1034,1040 **** relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return false; } /* --- 1091,1097 ---- relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return; } /* *************** *** 1049,1055 **** relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return true; /* assume no long-lived data in temp tables */ } /* --- 1106,1112 ---- relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return; /* assume no long-lived data in temp tables */ } /* *************** *** 1074,1084 **** * Do the actual work --- either FULL or "lazy" vacuum */ if (vacstmt->full) ! full_vacuum_rel(onerel, vacstmt); else ! lazy_vacuum_rel(onerel, vacstmt); ! ! result = true; /* did the vacuum */ /* all done with this class, but hold lock until commit */ relation_close(onerel, NoLock); --- 1131,1139 ---- * Do the actual work --- either FULL or "lazy" vacuum */ if (vacstmt->full) ! full_vacuum_rel(onerel, vacstmt, prevmin, prevvac); else ! lazy_vacuum_rel(onerel, vacstmt, prevmin, prevvac); /* all done with this class, but hold lock until commit */ relation_close(onerel, NoLock); *************** *** 1092,1113 **** /* * If the relation has a secondary toast rel, vacuum that too while we * still hold the session lock on the master table. Note however that ! * "analyze" will not get done on the toast table. This is good, because ! * the toaster always uses hardcoded index access and statistics are ! * totally unimportant for toast relations. */ if (toast_relid != InvalidOid) ! { ! if (!vacuum_rel(toast_relid, vacstmt, RELKIND_TOASTVALUE)) ! result = false; /* failed to vacuum the TOAST table? */ ! } /* * Now release the session-level lock on the master table. */ UnlockRelationForSession(&onerelid, lmode); - - return result; } --- 1147,1165 ---- /* * If the relation has a secondary toast rel, vacuum that too while we * still hold the session lock on the master table. Note however that ! * "analyze" will not get done on the toast table. This is good, ! * because the toaster always uses hardcoded index access and ! * statistics are totally unimportant for toast relations. ! * ! * Note we ignore the TOAST table for the "minxid" calculations. */ if (toast_relid != InvalidOid) ! vacuum_rel(toast_relid, vacstmt, RELKIND_TOASTVALUE, NULL, NULL); /* * Now release the session-level lock on the master table. */ UnlockRelationForSession(&onerelid, lmode); } *************** *** 1127,1135 **** * * At entry, we have already established a transaction and opened * and locked the relation. */ static void ! full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt) { VacPageListData vacuum_pages; /* List of pages to vacuum and/or * clean indexes */ --- 1179,1193 ---- * * At entry, we have already established a transaction and opened * and locked the relation. + * + * relminxid and relvacuumxid are output parameters, and correspond + * to the values in pg_class that existed prior to the execution of + * this vacuum. + * */ static void ! full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, TransactionId *relminxid, ! TransactionId *relvacuumxid) { VacPageListData vacuum_pages; /* List of pages to vacuum and/or * clean indexes */ *************** *** 1139,1144 **** --- 1197,1204 ---- int nindexes, i; VRelStats *vacrelstats; + TransactionId FreezeLimit, + OldestXmin; vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared, &OldestXmin, &FreezeLimit); *************** *** 1151,1159 **** vacrelstats->rel_tuples = 0; vacrelstats->hasindex = false; /* scan the heap */ vacuum_pages.num_pages = fraged_pages.num_pages = 0; ! scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages); /* Now open all indexes of the relation */ vac_open_indexes(onerel, AccessExclusiveLock, &nindexes, &Irel); --- 1211,1231 ---- vacrelstats->rel_tuples = 0; vacrelstats->hasindex = false; + /* + * Set initial minimum Xid, which will be updated if a smaller Xid is found + * in the relation. + * + * We use RecentXmin here (the minimum Xid that belongs to a transaction + * that is still open according to our snapshot), because it is the + * earliest transaction that could insert new tuples in the table after our + * VACUUM is done. + */ + vacrelstats->minxid = RecentXmin; + /* scan the heap */ vacuum_pages.num_pages = fraged_pages.num_pages = 0; ! scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages, FreezeLimit, ! OldestXmin); /* Now open all indexes of the relation */ vac_open_indexes(onerel, AccessExclusiveLock, &nindexes, &Irel); *************** *** 1181,1187 **** { /* Try to shrink heap */ repair_frag(vacrelstats, onerel, &vacuum_pages, &fraged_pages, ! nindexes, Irel); vac_close_indexes(nindexes, Irel, NoLock); } else --- 1253,1259 ---- { /* Try to shrink heap */ repair_frag(vacrelstats, onerel, &vacuum_pages, &fraged_pages, ! nindexes, Irel, OldestXmin); vac_close_indexes(nindexes, Irel, NoLock); } else *************** *** 1197,1205 **** /* update shared free space map with final free space info */ vac_update_fsm(onerel, &fraged_pages, vacrelstats->rel_pages); ! /* update statistics in pg_class */ vac_update_relstats(RelationGetRelid(onerel), vacrelstats->rel_pages, ! vacrelstats->rel_tuples, vacrelstats->hasindex); /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, --- 1269,1283 ---- /* update shared free space map with final free space info */ vac_update_fsm(onerel, &fraged_pages, vacrelstats->rel_pages); ! /* ! * Update statistics in pg_class. Note we only want the Xids ! * if this is a plain relation (i.e. not a TOAST table) ! */ vac_update_relstats(RelationGetRelid(onerel), vacrelstats->rel_pages, ! vacrelstats->rel_tuples, vacrelstats->hasindex, ! (onerel->rd_rel->relkind == RELKIND_RELATION), ! vacrelstats->minxid, OldestXmin, relminxid, ! relvacuumxid); /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, *************** *** 1213,1228 **** * This routine sets commit status bits, constructs vacuum_pages (list * of pages we need to compact free space on and/or clean indexes of * deleted tuples), constructs fraged_pages (list of pages with free ! * space that tuples could be moved into), and calculates statistics ! * on the number of live tuples in the heap. */ static void scan_heap(VRelStats *vacrelstats, Relation onerel, ! VacPageList vacuum_pages, VacPageList fraged_pages) { BlockNumber nblocks, blkno; - HeapTupleData tuple; char *relname; VacPage vacpage; BlockNumber empty_pages, --- 1291,1307 ---- * This routine sets commit status bits, constructs vacuum_pages (list * of pages we need to compact free space on and/or clean indexes of * deleted tuples), constructs fraged_pages (list of pages with free ! * space that tuples could be moved into), calculates statistics on the ! * number of live tuples in the heap, and figures out the minimum normal ! * Xid present anywhere on the table. */ static void scan_heap(VRelStats *vacrelstats, Relation onerel, ! VacPageList vacuum_pages, VacPageList fraged_pages, ! TransactionId FreezeLimit, TransactionId OldestXmin) { BlockNumber nblocks, blkno; char *relname; VacPage vacpage; BlockNumber empty_pages, *************** *** 1336,1341 **** --- 1415,1421 ---- { ItemId itemid = PageGetItemId(page, offnum); bool tupgone = false; + HeapTupleData tuple; /* * Collect un-used items too - it's possible to have indexes *************** *** 1477,1482 **** --- 1557,1574 ---- min_tlen = tuple.t_len; if (tuple.t_len > max_tlen) max_tlen = tuple.t_len; + + /* Checks for pg_class.relminxid */ + if (TransactionIdIsNormal(HeapTupleHeaderGetXmin(tuple.t_data)) && + TransactionIdPrecedes(HeapTupleHeaderGetXmin(tuple.t_data), + vacrelstats->minxid)) + vacrelstats->minxid = HeapTupleHeaderGetXmin(tuple.t_data); + + if (TransactionIdIsNormal(HeapTupleHeaderGetXmax(tuple.t_data)) && + TransactionIdPrecedes(HeapTupleHeaderGetXmax(tuple.t_data), + vacrelstats->minxid)) + vacrelstats->minxid = HeapTupleHeaderGetXmax(tuple.t_data); + } } /* scan along page */ *************** *** 1616,1622 **** static void repair_frag(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages, VacPageList fraged_pages, ! int nindexes, Relation *Irel) { TransactionId myXID = GetCurrentTransactionId(); Buffer dst_buffer = InvalidBuffer; --- 1708,1714 ---- static void repair_frag(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages, VacPageList fraged_pages, ! int nindexes, Relation *Irel, TransactionId OldestXmin) { TransactionId myXID = GetCurrentTransactionId(); Buffer dst_buffer = InvalidBuffer; *************** *** 2967,2973 **** /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", --- 3059,3066 ---- /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false, false, InvalidTransactionId, ! InvalidTransactionId, NULL, NULL); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", *************** *** 3035,3041 **** /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", --- 3128,3135 ---- /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false, false, InvalidTransactionId, ! InvalidTransactionId, NULL, NULL); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", Index: src/backend/commands/vacuumlazy.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/commands/vacuumlazy.c,v retrieving revision 1.69 diff -c -r1.69 vacuumlazy.c *** src/backend/commands/vacuumlazy.c 31 Mar 2006 23:32:06 -0000 1.69 --- src/backend/commands/vacuumlazy.c 2 Apr 2006 15:56:28 -0000 *************** *** 42,47 **** --- 42,48 ---- #include "access/genam.h" #include "access/heapam.h" #include "access/xlog.h" + #include "catalog/catalog.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "pgstat.h" *************** *** 72,77 **** --- 73,79 ---- double tuples_deleted; BlockNumber nonempty_pages; /* actually, last nonempty page + 1 */ Size threshold; /* minimum interesting free space */ + TransactionId minxid; /* minimum Xid present anywhere in table */ /* List of TIDs of tuples we intend to delete */ /* NB: this list is ordered by TID address */ int num_dead_tuples; /* current # of entries */ *************** *** 88,100 **** static int elevel = -1; - static TransactionId OldestXmin; - static TransactionId FreezeLimit; - /* non-export function prototypes */ static void lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ! Relation *Irel, int nindexes); static void lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats); static void lazy_scan_index(Relation indrel, LVRelStats *vacrelstats); static void lazy_vacuum_index(Relation indrel, --- 90,100 ---- static int elevel = -1; /* non-export function prototypes */ static void lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ! Relation *Irel, int nindexes, TransactionId FreezeLimit, ! TransactionId OldestXmin); static void lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats); static void lazy_scan_index(Relation indrel, LVRelStats *vacrelstats); static void lazy_vacuum_index(Relation indrel, *************** *** 103,111 **** LVRelStats *vacrelstats); static int lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, int tupindex, LVRelStats *vacrelstats); ! static void lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats); static BlockNumber count_nondeletable_pages(Relation onerel, ! LVRelStats *vacrelstats); static void lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks); static void lazy_record_dead_tuple(LVRelStats *vacrelstats, ItemPointer itemptr); --- 103,112 ---- LVRelStats *vacrelstats); static int lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, int tupindex, LVRelStats *vacrelstats); ! static void lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats, ! TransactionId OldestXmin); static BlockNumber count_nondeletable_pages(Relation onerel, ! LVRelStats *vacrelstats, TransactionId OldestXmin); static void lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks); static void lazy_record_dead_tuple(LVRelStats *vacrelstats, ItemPointer itemptr); *************** *** 122,140 **** * lazy_vacuum_rel() -- perform LAZY VACUUM for one heap relation * * This routine vacuums a single heap, cleans out its indexes, and ! * updates its num_pages and num_tuples statistics. * * At entry, we have already established a transaction and opened * and locked the relation. */ void ! lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt) { LVRelStats *vacrelstats; Relation *Irel; int nindexes; bool hasindex; BlockNumber possibly_freeable; if (vacstmt->verbose) elevel = INFO; --- 123,149 ---- * lazy_vacuum_rel() -- perform LAZY VACUUM for one heap relation * * This routine vacuums a single heap, cleans out its indexes, and ! * updates its relpages and reltuples statistics, as well as the ! * relminxid and relvacuumxid information. * * At entry, we have already established a transaction and opened * and locked the relation. + * + * relminxid and relvacuumxid are output parameters, and correspond + * to the values in pg_class that existed prior to the execution of + * this vacuum. */ void ! lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, TransactionId *relminxid, ! TransactionId *relvacuumxid) { LVRelStats *vacrelstats; Relation *Irel; int nindexes; bool hasindex; BlockNumber possibly_freeable; + TransactionId OldestXmin, + FreezeLimit; if (vacstmt->verbose) elevel = INFO; *************** *** 150,161 **** /* XXX should we scale it up or down? Adjust vacuum.c too, if so */ vacrelstats->threshold = GetAvgFSMRequestSize(&onerel->rd_node); /* Open all indexes of the relation */ vac_open_indexes(onerel, ShareUpdateExclusiveLock, &nindexes, &Irel); hasindex = (nindexes > 0); /* Do the vacuuming */ ! lazy_scan_heap(onerel, vacrelstats, Irel, nindexes); /* Done with indexes */ vac_close_indexes(nindexes, Irel, NoLock); --- 159,181 ---- /* XXX should we scale it up or down? Adjust vacuum.c too, if so */ vacrelstats->threshold = GetAvgFSMRequestSize(&onerel->rd_node); + /* + * Set initial minimum Xid, which will be updated if a smaller Xid is found + * in the relation. + * + * We use RecentXmin here (the minimum Xid that belongs to a transaction + * that is still open according to our snapshot), because it is the + * earliest transaction that could insert new tuples in the table after our + * VACUUM is done. + */ + vacrelstats->minxid = RecentXmin; + /* Open all indexes of the relation */ vac_open_indexes(onerel, ShareUpdateExclusiveLock, &nindexes, &Irel); hasindex = (nindexes > 0); /* Do the vacuuming */ ! lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, FreezeLimit, OldestXmin); /* Done with indexes */ vac_close_indexes(nindexes, Irel, NoLock); *************** *** 169,184 **** possibly_freeable = vacrelstats->rel_pages - vacrelstats->nonempty_pages; if (possibly_freeable >= REL_TRUNCATE_MINIMUM || possibly_freeable >= vacrelstats->rel_pages / REL_TRUNCATE_FRACTION) ! lazy_truncate_heap(onerel, vacrelstats); /* Update shared free space map with final free space info */ lazy_update_fsm(onerel, vacrelstats); /* Update statistics in pg_class */ ! vac_update_relstats(RelationGetRelid(onerel), ! vacrelstats->rel_pages, ! vacrelstats->rel_tuples, ! hasindex); /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, --- 189,205 ---- possibly_freeable = vacrelstats->rel_pages - vacrelstats->nonempty_pages; if (possibly_freeable >= REL_TRUNCATE_MINIMUM || possibly_freeable >= vacrelstats->rel_pages / REL_TRUNCATE_FRACTION) ! lazy_truncate_heap(onerel, vacrelstats, OldestXmin); /* Update shared free space map with final free space info */ lazy_update_fsm(onerel, vacrelstats); /* Update statistics in pg_class */ ! vac_update_relstats(RelationGetRelid(onerel), vacrelstats->rel_pages, ! vacrelstats->rel_tuples, hasindex, ! (onerel->rd_rel->relkind == RELKIND_RELATION), ! vacrelstats->minxid, OldestXmin, relminxid, ! relvacuumxid); /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, *************** *** 193,202 **** * and pages with free space, and calculates statistics on the number * of live tuples in the heap. When done, or when we run low on space * for dead-tuple TIDs, invoke vacuuming of indexes and heap. */ static void lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ! Relation *Irel, int nindexes) { BlockNumber nblocks, blkno; --- 214,227 ---- * and pages with free space, and calculates statistics on the number * of live tuples in the heap. When done, or when we run low on space * for dead-tuple TIDs, invoke vacuuming of indexes and heap. + * + * It also updates the minimum Xid found anywhere on the table, for + * pg_class.relminxid. */ static void lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ! Relation *Irel, int nindexes, TransactionId FreezeLimit, ! TransactionId OldestXmin) { BlockNumber nblocks, blkno; *************** *** 419,424 **** --- 444,463 ---- { num_tuples += 1; hastup = true; + + /* + * If the tuple is alive, we consider it for the "minxid" + * calculations. + */ + if (TransactionIdIsNormal(HeapTupleHeaderGetXmin(tuple.t_data)) && + TransactionIdPrecedes(HeapTupleHeaderGetXmin(tuple.t_data), + vacrelstats->minxid)) + vacrelstats->minxid = HeapTupleHeaderGetXmin(tuple.t_data); + + if (TransactionIdIsNormal(HeapTupleHeaderGetXmax(tuple.t_data)) && + TransactionIdPrecedes(HeapTupleHeaderGetXmax(tuple.t_data), + vacrelstats->minxid)) + vacrelstats->minxid = HeapTupleHeaderGetXmax(tuple.t_data); } } /* scan along page */ *************** *** 643,649 **** vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", --- 682,689 ---- vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false, false, InvalidTransactionId, ! InvalidTransactionId, NULL, NULL); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", *************** *** 722,728 **** vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", --- 762,769 ---- vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false, false, InvalidTransactionId, ! InvalidTransactionId, NULL, NULL); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", *************** *** 743,749 **** * lazy_truncate_heap - try to truncate off any empty pages at the end */ static void ! lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats) { BlockNumber old_rel_pages = vacrelstats->rel_pages; BlockNumber new_rel_pages; --- 784,791 ---- * lazy_truncate_heap - try to truncate off any empty pages at the end */ static void ! lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats, ! TransactionId OldestXmin) { BlockNumber old_rel_pages = vacrelstats->rel_pages; BlockNumber new_rel_pages; *************** *** 784,790 **** * because other backends could have added tuples to these pages whilst we * were vacuuming. */ ! new_rel_pages = count_nondeletable_pages(onerel, vacrelstats); if (new_rel_pages >= old_rel_pages) { --- 826,832 ---- * because other backends could have added tuples to these pages whilst we * were vacuuming. */ ! new_rel_pages = count_nondeletable_pages(onerel, vacrelstats, OldestXmin); if (new_rel_pages >= old_rel_pages) { *************** *** 839,845 **** * Returns number of nondeletable pages (last nonempty page + 1). */ static BlockNumber ! count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats) { BlockNumber blkno; HeapTupleData tuple; --- 881,888 ---- * Returns number of nondeletable pages (last nonempty page + 1). */ static BlockNumber ! count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats, ! TransactionId OldestXmin) { BlockNumber blkno; HeapTupleData tuple; Index: src/backend/libpq/hba.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/libpq/hba.c,v retrieving revision 1.151 diff -c -r1.151 hba.c *** src/backend/libpq/hba.c 6 Mar 2006 17:41:43 -0000 1.151 --- src/backend/libpq/hba.c 20 Mar 2006 04:11:17 -0000 *************** *** 1005,1011 **** * dbname: gets database name (must be of size NAMEDATALEN bytes) * dboid: gets database OID * dbtablespace: gets database's default tablespace's OID ! * dbfrozenxid: gets database's frozen XID * dbvacuumxid: gets database's vacuum XID * * This is not much related to the other functions in hba.c, but we put it --- 1005,1011 ---- * dbname: gets database name (must be of size NAMEDATALEN bytes) * dboid: gets database OID * dbtablespace: gets database's default tablespace's OID ! * dbminxid: gets database's minimum XID * dbvacuumxid: gets database's vacuum XID * * This is not much related to the other functions in hba.c, but we put it *************** *** 1013,1019 **** */ bool read_pg_database_line(FILE *fp, char *dbname, Oid *dboid, ! Oid *dbtablespace, TransactionId *dbfrozenxid, TransactionId *dbvacuumxid) { char buf[MAX_TOKEN]; --- 1013,1019 ---- */ bool read_pg_database_line(FILE *fp, char *dbname, Oid *dboid, ! Oid *dbtablespace, TransactionId *dbminxid, TransactionId *dbvacuumxid) { char buf[MAX_TOKEN]; *************** *** 1036,1042 **** next_token(fp, buf, sizeof(buf)); if (!isdigit((unsigned char) buf[0])) elog(FATAL, "bad data in flat pg_database file"); ! *dbfrozenxid = atoxid(buf); next_token(fp, buf, sizeof(buf)); if (!isdigit((unsigned char) buf[0])) elog(FATAL, "bad data in flat pg_database file"); --- 1036,1042 ---- next_token(fp, buf, sizeof(buf)); if (!isdigit((unsigned char) buf[0])) elog(FATAL, "bad data in flat pg_database file"); ! *dbminxid = atoxid(buf); next_token(fp, buf, sizeof(buf)); if (!isdigit((unsigned char) buf[0])) elog(FATAL, "bad data in flat pg_database file"); Index: src/backend/postmaster/autovacuum.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/postmaster/autovacuum.c,v retrieving revision 1.15 diff -c -r1.15 autovacuum.c *** src/backend/postmaster/autovacuum.c 7 Mar 2006 17:32:22 -0000 1.15 --- src/backend/postmaster/autovacuum.c 20 Mar 2006 04:11:23 -0000 *************** *** 76,82 **** { Oid oid; char *name; ! TransactionId frozenxid; TransactionId vacuumxid; PgStat_StatDBEntry *entry; int32 age; --- 76,82 ---- { Oid oid; char *name; ! TransactionId minxid; TransactionId vacuumxid; PgStat_StatDBEntry *entry; int32 age; *************** *** 344,350 **** { autovac_dbase *tmp = lfirst(cell); bool this_whole_db; ! int32 freeze_age, vacuum_age; /* --- 344,350 ---- { autovac_dbase *tmp = lfirst(cell); bool this_whole_db; ! int32 true_age, vacuum_age; /* *************** *** 357,365 **** * Unlike vacuum.c, we also look at vacuumxid. This is so that * pg_clog can be kept trimmed to a reasonable size. */ ! freeze_age = (int32) (nextXid - tmp->frozenxid); vacuum_age = (int32) (nextXid - tmp->vacuumxid); ! tmp->age = Max(freeze_age, vacuum_age); this_whole_db = (tmp->age > (int32) ((MaxTransactionId >> 3) * 3 - 100000)); --- 357,365 ---- * Unlike vacuum.c, we also look at vacuumxid. This is so that * pg_clog can be kept trimmed to a reasonable size. */ ! true_age = (int32) (nextXid - tmp->minxid); vacuum_age = (int32) (nextXid - tmp->vacuumxid); ! tmp->age = Max(true_age, vacuum_age); this_whole_db = (tmp->age > (int32) ((MaxTransactionId >> 3) * 3 - 100000)); *************** *** 459,465 **** FILE *db_file; Oid db_id; Oid db_tablespace; ! TransactionId db_frozenxid; TransactionId db_vacuumxid; filename = database_getflatfilename(); --- 459,465 ---- FILE *db_file; Oid db_id; Oid db_tablespace; ! TransactionId db_minxid; TransactionId db_vacuumxid; filename = database_getflatfilename(); *************** *** 470,476 **** errmsg("could not open file \"%s\": %m", filename))); while (read_pg_database_line(db_file, thisname, &db_id, ! &db_tablespace, &db_frozenxid, &db_vacuumxid)) { autovac_dbase *db; --- 470,476 ---- errmsg("could not open file \"%s\": %m", filename))); while (read_pg_database_line(db_file, thisname, &db_id, ! &db_tablespace, &db_minxid, &db_vacuumxid)) { autovac_dbase *db; *************** *** 479,485 **** db->oid = db_id; db->name = pstrdup(thisname); ! db->frozenxid = db_frozenxid; db->vacuumxid = db_vacuumxid; /* these get set later: */ db->entry = NULL; --- 479,485 ---- db->oid = db_id; db->name = pstrdup(thisname); ! db->minxid = db_minxid; db->vacuumxid = db_vacuumxid; /* these get set later: */ db->entry = NULL; Index: src/backend/utils/init/flatfiles.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/utils/init/flatfiles.c,v retrieving revision 1.17 diff -c -r1.17 flatfiles.c *** src/backend/utils/init/flatfiles.c 5 Mar 2006 15:58:46 -0000 1.17 --- src/backend/utils/init/flatfiles.c 20 Mar 2006 04:11:28 -0000 *************** *** 163,169 **** /* * write_database_file: update the flat database file * ! * A side effect is to determine the oldest database's datfrozenxid * so we can set or update the XID wrap limit. */ static void --- 163,169 ---- /* * write_database_file: update the flat database file * ! * A side effect is to determine the oldest database's datminxid * so we can set or update the XID wrap limit. */ static void *************** *** 177,183 **** HeapScanDesc scan; HeapTuple tuple; NameData oldest_datname; ! TransactionId oldest_datfrozenxid = InvalidTransactionId; /* * Create a temporary filename to be renamed later. This prevents the --- 177,183 ---- HeapScanDesc scan; HeapTuple tuple; NameData oldest_datname; ! TransactionId oldest_datminxid = InvalidTransactionId; /* * Create a temporary filename to be renamed later. This prevents the *************** *** 208,234 **** char *datname; Oid datoid; Oid dattablespace; ! TransactionId datfrozenxid, ! datvacuumxid; datname = NameStr(dbform->datname); datoid = HeapTupleGetOid(tuple); dattablespace = dbform->dattablespace; ! datfrozenxid = dbform->datfrozenxid; datvacuumxid = dbform->datvacuumxid; /* ! * Identify the oldest datfrozenxid, ignoring databases that are not ! * connectable (we assume they are safely frozen). This must match * the logic in vac_truncate_clog() in vacuum.c. */ if (dbform->datallowconn && ! TransactionIdIsNormal(datfrozenxid)) { ! if (oldest_datfrozenxid == InvalidTransactionId || ! TransactionIdPrecedes(datfrozenxid, oldest_datfrozenxid)) { ! oldest_datfrozenxid = datfrozenxid; namestrcpy(&oldest_datname, datname); } } --- 208,235 ---- char *datname; Oid datoid; Oid dattablespace; ! TransactionId datminxid, ! datvacuumxid; ! datname = NameStr(dbform->datname); datoid = HeapTupleGetOid(tuple); dattablespace = dbform->dattablespace; ! datminxid = dbform->datminxid; datvacuumxid = dbform->datvacuumxid; /* ! * Identify the oldest datminxid, ignoring databases that are not ! * connectable (we assume they are safely frozen). This must match * the logic in vac_truncate_clog() in vacuum.c. */ if (dbform->datallowconn && ! TransactionIdIsNormal(datminxid)) { ! if (oldest_datminxid == InvalidTransactionId || ! TransactionIdPrecedes(datminxid, oldest_datminxid)) { ! oldest_datminxid = datminxid; namestrcpy(&oldest_datname, datname); } } *************** *** 244,257 **** } /* ! * The file format is: "dbname" oid tablespace frozenxid vacuumxid * ! * The xids are not needed for backend startup, but are of use to * autovacuum, and might also be helpful for forensic purposes. */ fputs_quote(datname, fp); fprintf(fp, " %u %u %u %u\n", ! datoid, dattablespace, datfrozenxid, datvacuumxid); } heap_endscan(scan); --- 245,258 ---- } /* ! * The file format is: "dbname" oid tablespace minxid vacuumxid * ! * The minxid is not needed for backend startup, but is of use to * autovacuum, and might also be helpful for forensic purposes. */ fputs_quote(datname, fp); fprintf(fp, " %u %u %u %u\n", ! datoid, dattablespace, datminxid, datvacuumxid); } heap_endscan(scan); *************** *** 272,281 **** tempname, filename))); /* ! * Set the transaction ID wrap limit using the oldest datfrozenxid */ ! if (oldest_datfrozenxid != InvalidTransactionId) ! SetTransactionIdLimit(oldest_datfrozenxid, &oldest_datname); } --- 273,282 ---- tempname, filename))); /* ! * Set the transaction ID wrap limit using the oldest datminxid */ ! if (oldest_datminxid != InvalidTransactionId) ! SetTransactionIdLimit(oldest_datminxid, &oldest_datname); } Index: src/include/access/transam.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/access/transam.h,v retrieving revision 1.57 diff -c -r1.57 transam.h *** src/include/access/transam.h 5 Mar 2006 15:58:53 -0000 1.57 --- src/include/access/transam.h 20 Mar 2006 04:11:40 -0000 *************** *** 123,130 **** /* in transam/varsup.c */ extern TransactionId GetNewTransactionId(bool isSubXact); extern TransactionId ReadNewTransactionId(void); ! extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, ! Name oldest_datname); extern Oid GetNewObjectId(void); #endif /* TRAMSAM_H */ --- 123,130 ---- /* in transam/varsup.c */ extern TransactionId GetNewTransactionId(bool isSubXact); extern TransactionId ReadNewTransactionId(void); ! extern void SetTransactionIdLimit(TransactionId oldest_datminxid, ! Name oldest_datname); extern Oid GetNewObjectId(void); #endif /* TRAMSAM_H */ Index: src/include/catalog/pg_attribute.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/catalog/pg_attribute.h,v retrieving revision 1.120 diff -c -r1.120 pg_attribute.h *** src/include/catalog/pg_attribute.h 5 Mar 2006 15:58:54 -0000 1.120 --- src/include/catalog/pg_attribute.h 20 Mar 2006 04:11:41 -0000 *************** *** 404,410 **** { 1259, {"relhaspkey"}, 16, -1, 1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \ { 1259, {"relhasrules"}, 16, -1, 1, 23, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \ { 1259, {"relhassubclass"},16, -1, 1, 24, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \ ! { 1259, {"relacl"}, 1034, -1, -1, 25, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 } DATA(insert ( 1259 relname 19 -1 NAMEDATALEN 1 0 -1 -1 f p i t f f t 0)); DATA(insert ( 1259 relnamespace 26 -1 4 2 0 -1 -1 t p i t f f t 0)); --- 404,412 ---- { 1259, {"relhaspkey"}, 16, -1, 1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \ { 1259, {"relhasrules"}, 16, -1, 1, 23, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \ { 1259, {"relhassubclass"},16, -1, 1, 24, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \ ! { 1259, {"relminxid"}, 28, -1, 4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \ ! { 1259, {"relvacuumxid"}, 28, -1, 4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \ ! { 1259, {"relacl"}, 1034, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 } DATA(insert ( 1259 relname 19 -1 NAMEDATALEN 1 0 -1 -1 f p i t f f t 0)); DATA(insert ( 1259 relnamespace 26 -1 4 2 0 -1 -1 t p i t f f t 0)); *************** *** 430,436 **** DATA(insert ( 1259 relhaspkey 16 -1 1 22 0 -1 -1 t p c t f f t 0)); DATA(insert ( 1259 relhasrules 16 -1 1 23 0 -1 -1 t p c t f f t 0)); DATA(insert ( 1259 relhassubclass 16 -1 1 24 0 -1 -1 t p c t f f t 0)); ! DATA(insert ( 1259 relacl 1034 -1 -1 25 1 -1 -1 f x i f f f t 0)); DATA(insert ( 1259 ctid 27 0 6 -1 0 -1 -1 f p s t f f t 0)); DATA(insert ( 1259 oid 26 0 4 -2 0 -1 -1 t p i t f f t 0)); DATA(insert ( 1259 xmin 28 0 4 -3 0 -1 -1 t p i t f f t 0)); --- 432,440 ---- DATA(insert ( 1259 relhaspkey 16 -1 1 22 0 -1 -1 t p c t f f t 0)); DATA(insert ( 1259 relhasrules 16 -1 1 23 0 -1 -1 t p c t f f t 0)); DATA(insert ( 1259 relhassubclass 16 -1 1 24 0 -1 -1 t p c t f f t 0)); ! DATA(insert ( 1259 relminxid 28 -1 4 25 0 -1 -1 t p i t f f t 0)); ! DATA(insert ( 1259 relvacuumxid 28 -1 4 26 0 -1 -1 t p i t f f t 0)); ! DATA(insert ( 1259 relacl 1034 -1 -1 27 1 -1 -1 f x i f f f t 0)); DATA(insert ( 1259 ctid 27 0 6 -1 0 -1 -1 f p s t f f t 0)); DATA(insert ( 1259 oid 26 0 4 -2 0 -1 -1 t p i t f f t 0)); DATA(insert ( 1259 xmin 28 0 4 -3 0 -1 -1 t p i t f f t 0)); Index: src/include/catalog/pg_class.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/catalog/pg_class.h,v retrieving revision 1.91 diff -c -r1.91 pg_class.h *** src/include/catalog/pg_class.h 5 Mar 2006 15:58:54 -0000 1.91 --- src/include/catalog/pg_class.h 20 Mar 2006 04:11:42 -0000 *************** *** 74,79 **** --- 74,81 ---- bool relhaspkey; /* has PRIMARY KEY index */ bool relhasrules; /* has associated rules */ bool relhassubclass; /* has derived classes */ + TransactionId relminxid; /* minimum Xid present in table */ + TransactionId relvacuumxid; /* OldestXmin of latest vacuum */ /* * relacl may or may not be present, see note above! *************** *** 83,89 **** /* Size of fixed part of pg_class tuples, not counting relacl or padding */ #define CLASS_TUPLE_SIZE \ ! (offsetof(FormData_pg_class,relhassubclass) + sizeof(bool)) /* ---------------- * Form_pg_class corresponds to a pointer to a tuple with --- 85,91 ---- /* Size of fixed part of pg_class tuples, not counting relacl or padding */ #define CLASS_TUPLE_SIZE \ ! (offsetof(FormData_pg_class,relvacuumxid) + sizeof(TransactionId)) /* ---------------- * Form_pg_class corresponds to a pointer to a tuple with *************** *** 103,110 **** * relacl field. This is a kluge. * ---------------- */ ! #define Natts_pg_class_fixed 24 ! #define Natts_pg_class 25 #define Anum_pg_class_relname 1 #define Anum_pg_class_relnamespace 2 #define Anum_pg_class_reltype 3 --- 105,112 ---- * relacl field. This is a kluge. * ---------------- */ ! #define Natts_pg_class_fixed 26 ! #define Natts_pg_class 27 #define Anum_pg_class_relname 1 #define Anum_pg_class_relnamespace 2 #define Anum_pg_class_reltype 3 *************** *** 129,135 **** #define Anum_pg_class_relhaspkey 22 #define Anum_pg_class_relhasrules 23 #define Anum_pg_class_relhassubclass 24 ! #define Anum_pg_class_relacl 25 /* ---------------- * initial contents of pg_class --- 131,139 ---- #define Anum_pg_class_relhaspkey 22 #define Anum_pg_class_relhasrules 23 #define Anum_pg_class_relhassubclass 24 ! #define Anum_pg_class_relminxid 25 ! #define Anum_pg_class_relvacuumxid 26 ! #define Anum_pg_class_relacl 27 /* ---------------- * initial contents of pg_class *************** *** 139,151 **** * ---------------- */ ! DATA(insert OID = 1247 ( pg_type PGNSP 71 PGUID 0 1247 0 0 0 0 0 f f r 23 0 0 0 0 0 t f f f _null_ )); DESCR(""); ! DATA(insert OID = 1249 ( pg_attribute PGNSP 75 PGUID 0 1249 0 0 0 0 0 f f r 17 0 0 0 0 0 f f f f _null_ )); DESCR(""); ! DATA(insert OID = 1255 ( pg_proc PGNSP 81 PGUID 0 1255 0 0 0 0 0 f f r 18 0 0 0 0 0 t f f f _null_ )); DESCR(""); ! DATA(insert OID = 1259 ( pg_class PGNSP 83 PGUID 0 1259 0 0 0 0 0 f f r 25 0 0 0 0 0 t f f f _null_ )); DESCR(""); #define RELKIND_INDEX 'i' /* secondary index */ --- 143,155 ---- * ---------------- */ ! DATA(insert OID = 1247 ( pg_type PGNSP 71 PGUID 0 1247 0 0 0 0 0 f f r 23 0 0 0 0 0 t f f f 0 0 _null_ )); DESCR(""); ! DATA(insert OID = 1249 ( pg_attribute PGNSP 75 PGUID 0 1249 0 0 0 0 0 f f r 17 0 0 0 0 0 f f f f 0 0 _null_ )); DESCR(""); ! DATA(insert OID = 1255 ( pg_proc PGNSP 81 PGUID 0 1255 0 0 0 0 0 f f r 18 0 0 0 0 0 t f f f 0 0 _null_ )); DESCR(""); ! DATA(insert OID = 1259 ( pg_class PGNSP 83 PGUID 0 1259 0 0 0 0 0 f f r 27 0 0 0 0 0 t f f f 0 0 _null_ )); DESCR(""); #define RELKIND_INDEX 'i' /* secondary index */ Index: src/include/catalog/pg_database.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/catalog/pg_database.h,v retrieving revision 1.40 diff -c -r1.40 pg_database.h *** src/include/catalog/pg_database.h 5 Mar 2006 15:58:54 -0000 1.40 --- src/include/catalog/pg_database.h 2 Apr 2006 16:51:22 -0000 *************** *** 42,49 **** bool datallowconn; /* new connections allowed? */ int4 datconnlimit; /* max connections allowed (-1=no limit) */ Oid datlastsysoid; /* highest OID to consider a system OID */ ! TransactionId datvacuumxid; /* all XIDs before this are vacuumed */ ! TransactionId datfrozenxid; /* all XIDs before this are frozen */ Oid dattablespace; /* default table space for this DB */ text datconfig[1]; /* database-specific GUC (VAR LENGTH) */ aclitem datacl[1]; /* access permissions (VAR LENGTH) */ --- 42,50 ---- bool datallowconn; /* new connections allowed? */ int4 datconnlimit; /* max connections allowed (-1=no limit) */ Oid datlastsysoid; /* highest OID to consider a system OID */ ! TransactionId datvacuumxid; /* all Xids in all tables before this have ! * been marked known-committed or -aborted */ ! TransactionId datminxid; /* no table contains an Xid below this one */ Oid dattablespace; /* default table space for this DB */ text datconfig[1]; /* database-specific GUC (VAR LENGTH) */ aclitem datacl[1]; /* access permissions (VAR LENGTH) */ *************** *** 69,75 **** #define Anum_pg_database_datconnlimit 6 #define Anum_pg_database_datlastsysoid 7 #define Anum_pg_database_datvacuumxid 8 ! #define Anum_pg_database_datfrozenxid 9 #define Anum_pg_database_dattablespace 10 #define Anum_pg_database_datconfig 11 #define Anum_pg_database_datacl 12 --- 70,76 ---- #define Anum_pg_database_datconnlimit 6 #define Anum_pg_database_datlastsysoid 7 #define Anum_pg_database_datvacuumxid 8 ! #define Anum_pg_database_datminxid 9 #define Anum_pg_database_dattablespace 10 #define Anum_pg_database_datconfig 11 #define Anum_pg_database_datacl 12 Index: src/include/commands/vacuum.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/commands/vacuum.h,v retrieving revision 1.63 diff -c -r1.63 vacuum.h *** src/include/commands/vacuum.h 5 Mar 2006 15:58:55 -0000 1.63 --- src/include/commands/vacuum.h 20 Mar 2006 04:11:43 -0000 *************** *** 114,123 **** extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel); extern void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode); ! extern void vac_update_relstats(Oid relid, ! BlockNumber num_pages, ! double num_tuples, ! bool hasindex); extern void vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel, TransactionId *oldestXmin, TransactionId *freezeLimit); --- 114,123 ---- extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel); extern void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode); ! extern void vac_update_relstats(Oid relid, BlockNumber num_pages, ! double num_tuples, bool hasindex, bool update_xids, ! TransactionId minxid, TransactionId vacuumxid, ! TransactionId *relminxid, TransactionId *relvacuumxid); extern void vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel, TransactionId *oldestXmin, TransactionId *freezeLimit); *************** *** 125,131 **** extern void vacuum_delay_point(void); /* in commands/vacuumlazy.c */ ! extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt); /* in commands/analyze.c */ extern void analyze_rel(Oid relid, VacuumStmt *vacstmt); --- 125,132 ---- extern void vacuum_delay_point(void); /* in commands/vacuumlazy.c */ ! extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, ! TransactionId *relminxid, TransactionId *relvacuumxid); /* in commands/analyze.c */ extern void analyze_rel(Oid relid, VacuumStmt *vacstmt); Index: src/include/libpq/hba.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/libpq/hba.h,v retrieving revision 1.42 diff -c -r1.42 hba.h *** src/include/libpq/hba.h 6 Mar 2006 17:41:44 -0000 1.42 --- src/include/libpq/hba.h 20 Mar 2006 04:11:43 -0000 *************** *** 39,46 **** extern void load_role(void); extern int hba_getauthmethod(hbaPort *port); extern int authident(hbaPort *port); ! extern bool read_pg_database_line(FILE *fp, char *dbname, Oid *dboid, ! Oid *dbtablespace, TransactionId *dbfrozenxid, ! TransactionId *dbvacuumxid); #endif /* HBA_H */ --- 39,46 ---- extern void load_role(void); extern int hba_getauthmethod(hbaPort *port); extern int authident(hbaPort *port); ! extern bool read_pg_database_line(FILE *fp, char *dbname, Oid *dboid, ! Oid *dbtablespace, TransactionId *dbminxid, ! TransactionId *dbvacuumxid); #endif /* HBA_H */