Index: doc/src/sgml/catalogs.sgml =================================================================== RCS file: /home/alvherre/cvs/pgsql/doc/src/sgml/catalogs.sgml,v retrieving revision 2.122 diff -c -r2.122 catalogs.sgml *** doc/src/sgml/catalogs.sgml 2 May 2006 22:25:09 -0000 2.122 --- doc/src/sgml/catalogs.sgml 5 May 2006 01:54:38 -0000 *************** *** 1633,1638 **** --- 1633,1662 ---- + 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[] *************** *** 2004,2024 **** 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. --- 2028,2054 ---- 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/heap/heapam.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/access/heap/heapam.c,v retrieving revision 1.211 diff -c -r1.211 heapam.c *** src/backend/access/heap/heapam.c 31 Mar 2006 23:32:05 -0000 1.211 --- src/backend/access/heap/heapam.c 8 May 2006 02:15:20 -0000 *************** *** 51,61 **** --- 51,72 ---- #include "storage/procarray.h" #include "utils/inval.h" #include "utils/relcache.h" + #include "utils/syscache.h" static XLogRecPtr log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from, Buffer newbuf, HeapTuple newtup, bool move); + /* + * There are some situations in which we want to acquire strong locks on + * relations, but we know there is no need to unfreeze them; for example, + * during VACUUM. Any such caller sets this variable to true, which turns + * heap_unfreeze into a no-op. + * + * It's advisable to do this in a PG_TRY block so that it won't "forget" to + * reset the variable in case of error. + */ + bool disable_heap_unfreeze = false; /* ---------------------------------------------------------------- * heap support routines *************** *** 2673,2678 **** --- 2684,2813 ---- return HeapTupleMayBeUpdated; } + /* + * heap_unfreeze + * Mark a table as no longer frozen in pg_class. + * + * This routine updates the pg_class.relminxid column so that it no longer + * appears as frozen. + */ + void + heap_unfreeze(Relation rel) + { + Relation classRel; + Form_pg_class classForm; + HeapTuple tuple; + HeapTupleData rtup; + Oid relid = RelationGetRelid(rel); + Buffer buffer; + TransactionId unfreezeXid; + + /* early exit if somebody decided to disable us */ + if (disable_heap_unfreeze) + return; + + /* + * Under normal conditions, we should have a snapshot already, but in some + * cases there may not be one. Getting a snapshot guarantees we will have + * a valid RecentXmin to use. + */ + if (!TransactionIdIsValid(RecentXmin)) + ActiveSnapshot = CopySnapshot(GetTransactionSnapshot()); + Assert(TransactionIdIsValid(RecentXmin)); + + PG_TRY(); + { + /* Disable ourselves so that we don't recurse on unfreezing pg_class */ + disable_heap_unfreeze = true; + classRel = heap_open(RelationRelationId, RowExclusiveLock); + } + PG_CATCH(); + { + disable_heap_unfreeze = false; + PG_RE_THROW(); + } + PG_END_TRY(); + disable_heap_unfreeze = false; + + tuple = SearchSysCache(RELOID, + ObjectIdGetDatum(relid), + 0, 0, 0); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for relation %u", relid); + + rtup.t_self = tuple->t_self; + if (!heap_fetch(classRel, SnapshotNow, &rtup, &buffer, false, NULL)) + elog(ERROR, "pg_class entry for relid %u vanished during unfreezing", + relid); + ReleaseSysCache(tuple); + + /* + * XXX -- is there a race condition here? I don't think so, because we + * are holding the affected relation with a nonzero reference count. + */ + + /* Ensure no one does this at the same time */ + LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + + /* NO EREPORT(ERROR) from here till changes are logged */ + START_CRIT_SECTION(); + + classForm = (Form_pg_class) GETSTRUCT(&rtup); + classForm->relminxid = RecentXmin; + + MarkBufferDirty(buffer); + + /* XLOG stuff */ + if (!rel->rd_istemp) + { + xl_heap_unfreeze xlrec; + XLogRecData rdata[2]; + XLogRecPtr recptr; + + xlrec.target.node = classRel->rd_node; + xlrec.target.tid = rtup.t_self; + xlrec.target_xid = RecentXmin; + + rdata[0].data = (char *) &xlrec; + rdata[0].len = SizeOfHeapUnfreeze; + rdata[0].buffer = InvalidBuffer; + rdata[0].next = &(rdata[1]); + + rdata[1].data = NULL; + rdata[1].len = 0; + rdata[1].buffer = buffer; + rdata[1].buffer_std = true; + rdata[1].next = NULL; + + recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_UNFREEZE, rdata); + + PageSetLSN(BufferGetPage(buffer), recptr); + PageSetTLI(BufferGetPage(buffer), ThisTimeLineID); + } + + END_CRIT_SECTION(); + + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + + /* + * Mark tuple for invalidation from system caches at next command + * boundary. We have to do this before releasing the buffer because we + * need to look at the contents of the tuple. + */ + CacheInvalidateHeapTuple(classRel, &rtup); + + /* Release the buffer */ + ReleaseBuffer(buffer); + + heap_close(classRel, RowExclusiveLock); + + /* + * Increment our own command counter to get the inval message, so that we + * don't unfreeze this relation again. + */ + CommandCounterIncrement(); + } + /* ---------------- * heap_markpos - mark scan position * ---------------- *************** *** 3329,3334 **** --- 3464,3517 ---- UnlockReleaseBuffer(buffer); } + static void + heap_xlog_unfreeze(XLogRecPtr lsn, XLogRecord *record) + { + xl_heap_unfreeze *xlrec = (xl_heap_unfreeze *) XLogRecGetData(record); + Relation reln; + Form_pg_class classForm; + Buffer buffer; + Page page; + OffsetNumber offnum; + ItemId lp = NULL; + HeapTupleData tup; + + if (record->xl_info & XLR_BKP_BLOCK_1) + return; + + reln = XLogOpenRelation(xlrec->target.node); + buffer = XLogReadBuffer(reln, + ItemPointerGetBlockNumber(&(xlrec->target.tid)), + false); + if (!BufferIsValid(buffer)) + return; + page = (Page) BufferGetPage(buffer); + + if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */ + { + UnlockReleaseBuffer(buffer); + return; + } + + offnum = ItemPointerGetOffsetNumber(&(xlrec->target.tid)); + if (PageGetMaxOffsetNumber(page) >= offnum) + lp = PageGetItemId(page, offnum); + + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsUsed(lp)) + elog(PANIC, "heap_xlog_unfreeze: invalid lp"); + + tup.t_data = (HeapTupleHeader) PageGetItem(page, lp); + + classForm = (Form_pg_class) GETSTRUCT(&tup); + + classForm->relminxid = xlrec->target_xid; + + PageSetLSN(page, lsn); + PageSetTLI(page, ThisTimeLineID); + MarkBufferDirty(buffer); + UnlockReleaseBuffer(buffer); + } + void heap_redo(XLogRecPtr lsn, XLogRecord *record) { *************** *** 3349,3354 **** --- 3532,3539 ---- heap_xlog_newpage(lsn, record); else if (info == XLOG_HEAP_LOCK) heap_xlog_lock(lsn, record); + else if (info == XLOG_HEAP_UNFREEZE) + heap_xlog_unfreeze(lsn, record); else elog(PANIC, "heap_redo: unknown op code %u", info); } *************** *** 3442,3447 **** --- 3627,3644 ---- appendStringInfo(buf, "%u ", xlrec->locking_xid); out_target(buf, &(xlrec->target)); } + else if (info == XLOG_HEAP_UNFREEZE) + { + xl_heap_unfreeze *xlrec = (xl_heap_unfreeze *) rec; + + appendStringInfo(buf, "unfreeze: rel %u/%u/%u; tuple %u/%u, xid %u", + xlrec->target.node.spcNode, + xlrec->target.node.dbNode, + xlrec->target.node.relNode, + ItemPointerGetBlockNumber(&(xlrec->target.tid)), + ItemPointerGetOffsetNumber(&(xlrec->target.tid)), + xlrec->target_xid); + } else appendStringInfo(buf, "UNKNOWN"); } 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 5 May 2006 01:54:38 -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.298 diff -c -r1.298 heap.c *** src/backend/catalog/heap.c 30 Apr 2006 01:08:06 -0000 1.298 --- src/backend/catalog/heap.c 5 May 2006 01:54:38 -0000 *************** *** 568,573 **** --- 568,594 ---- */ 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 + * 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: 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 5 May 2006 01:54:38 -0000 *************** *** 424,431 **** { vac_update_relstats(RelationGetRelid(onerel), RelationGetNumberOfBlocks(onerel), ! totalrows, ! hasindex); for (ind = 0; ind < nindexes; ind++) { AnlIndexData *thisdata = &indexdata[ind]; --- 424,433 ---- { vac_update_relstats(RelationGetRelid(onerel), RelationGetNumberOfBlocks(onerel), ! totalrows, hasindex, ! InvalidTransactionId, ! InvalidTransactionId); ! for (ind = 0; ind < nindexes; ind++) { AnlIndexData *thisdata = &indexdata[ind]; *************** *** 434,441 **** totalindexrows = ceil(thisdata->tupleFract * totalrows); vac_update_relstats(RelationGetRelid(Irel[ind]), RelationGetNumberOfBlocks(Irel[ind]), ! totalindexrows, ! false); } /* report results to the stats collector, too */ --- 436,443 ---- totalindexrows = ceil(thisdata->tupleFract * totalrows); vac_update_relstats(RelationGetRelid(Irel[ind]), RelationGetNumberOfBlocks(Irel[ind]), ! totalindexrows, false, InvalidTransactionId, ! InvalidTransactionId); } /* 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.181 diff -c -r1.181 dbcommands.c *** src/backend/commands/dbcommands.c 4 May 2006 16:07:29 -0000 1.181 --- src/backend/commands/dbcommands.c 8 May 2006 02:02:18 -0000 *************** *** 46,51 **** --- 46,52 ---- #include "utils/flatfiles.h" #include "utils/fmgroids.h" #include "utils/guc.h" + #include "utils/inval.h" #include "utils/lsyscache.h" #include "utils/syscache.h" *************** *** 55,61 **** 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 ---- 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); *************** *** 76,82 **** bool src_allowconn; Oid src_lastsysoid; TransactionId src_vacuumxid; ! TransactionId src_frozenxid; Oid src_deftablespace; volatile Oid dst_deftablespace; 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; Relation pg_database_rel; *************** *** 228,234 **** if (!get_db_info(dbtemplate, ShareLock, &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", --- 229,235 ---- if (!get_db_info(dbtemplate, ShareLock, &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", *************** *** 328,340 **** /* * 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(); /* * Check for db name conflict. This is just to give a more friendly --- 329,341 ---- /* * 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(); /* * Check for db name conflict. This is just to give a more friendly *************** *** 367,373 **** 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); /* --- 368,374 ---- 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); /* *************** *** 1050,1055 **** --- 1051,1145 ---- */ } + /* + * UnfreezeDatabase + * Unfreezes a database + * + * Unfreezing a database is to set datminxid to a current normal Xid. + * Currently, we do this anytime somebody connects to a database that is + * currently marked as frozen (datminxid = FrozenTransactionId). + * + * NB --- this is called early during backend initialization. + */ + void + UnfreezeDatabase(HeapTuple dbtuple, TransactionId unfreezeXid) + { + Form_pg_database dbForm; + HeapTupleData rtup; + Relation dbRel; + Buffer buffer; + xl_dbase_unfreeze_rec xlrec; + XLogRecData rdata[1]; + XLogRecPtr recptr; + bool need_inval = true; + + dbForm = (Form_pg_database) GETSTRUCT(dbtuple); + + Assert(TransactionIdEquals(dbForm->datminxid, FrozenTransactionId)); + dbRel = heap_open(DatabaseRelationId, RowExclusiveLock); + + rtup.t_self = dbtuple->t_self; + if (!heap_fetch(dbRel, SnapshotNow, &rtup, &buffer, false, NULL)) + elog(ERROR, + "pg_database entry for database %u vanished during unfreezing", + HeapTupleGetOid(dbtuple)); + + /* Ensure no one does this at the same time */ + LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + + /* return quickly if somebody else did it */ + if (!TransactionIdEquals(dbForm->datminxid, FrozenTransactionId)) + { + need_inval = false; + goto unfreeze_done; + } + + /* NO EREPORT(ERROR) from here till changes are logged */ + START_CRIT_SECTION(); + + dbForm = (Form_pg_database) GETSTRUCT(&rtup); + dbForm->datminxid = unfreezeXid; + + MarkBufferDirty(buffer); + + /* XLOG stuff */ + xlrec.db_rel = dbRel->rd_node; + xlrec.item = rtup.t_self; + xlrec.target_xid = unfreezeXid; + + rdata[0].data = (char *) &xlrec; + rdata[0].len = sizeof(xl_dbase_unfreeze_rec); + rdata[0].buffer = InvalidBuffer; + rdata[0].next = &(rdata[1]); + + rdata[1].data = NULL; + rdata[1].len = 0; + rdata[1].buffer = buffer; + rdata[1].buffer_std = true; + rdata[1].next = NULL; + + recptr = XLogInsert(RM_DBASE_ID, XLOG_DBASE_UNFREEZE, rdata); + + PageSetLSN(BufferGetPage(buffer), recptr); + PageSetTLI(BufferGetPage(buffer), ThisTimeLineID); + + END_CRIT_SECTION(); + + unfreeze_done: + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + + /* + * Mark tuple for invalidation from system caches at next command + * boundary. We have to do this before releasing the buffer because we + * need to look at the contents of the tuple. + */ + if (need_inval) + CacheInvalidateHeapTuple(dbRel, &rtup); + + ReleaseBuffer(buffer); + + heap_close(dbRel, RowExclusiveLock); + } /* * Helper functions *************** *** 1066,1072 **** Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, ! TransactionId *dbVacuumXidP, TransactionId *dbFrozenXidP, Oid *dbTablespace) { bool result = false; --- 1156,1162 ---- Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, ! TransactionId *dbVacuumXidP, TransactionId *dbMinXidP, Oid *dbTablespace) { bool result = false; *************** *** 1155,1163 **** /* 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; --- 1245,1253 ---- /* limit of vacuumed XIDs */ if (dbVacuumXidP) *dbVacuumXidP = dbform->datvacuumxid; ! /* limit of existent XIDs */ ! if (dbMinXidP) ! *dbMinXidP = dbform->datminxid; /* default tablespace for this database */ if (dbTablespace) *dbTablespace = dbform->dattablespace; *************** *** 1396,1401 **** --- 1486,1538 ---- (errmsg("could not remove database directory \"%s\"", dst_path))); } + else if (info == XLOG_DBASE_UNFREEZE) + { + xl_dbase_unfreeze_rec *xlrec; + Relation rel; + Buffer buffer; + Page page; + OffsetNumber offnum; + ItemId lp = NULL; + HeapTupleData tup; + Form_pg_database dbForm; + + if (record->xl_info & XLR_BKP_BLOCK_1) + return; + + xlrec = (xl_dbase_unfreeze_rec *) XLogRecGetData(record); + + rel = XLogOpenRelation(xlrec->db_rel); + buffer = XLogReadBuffer(rel, + ItemPointerGetBlockNumber(&(xlrec->item)), + false); + if (!BufferIsValid(buffer)) + return; + page = (Page) BufferGetPage(buffer); + + if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */ + { + UnlockReleaseBuffer(buffer); + return; + } + + offnum = ItemPointerGetOffsetNumber(&(xlrec->item)); + if (PageGetMaxOffsetNumber(page) >= offnum) + lp = PageGetItemId(page, offnum); + + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsUsed(lp)) + elog(PANIC, "dbase_redo: invalid lp in database unfreeze"); + + tup.t_data = (HeapTupleHeader) PageGetItem(page, lp); + + dbForm = (Form_pg_database) GETSTRUCT(&tup); + dbForm->datminxid = xlrec->target_xid; + + PageSetLSN(page, lsn); + PageSetTLI(page, ThisTimeLineID); + MarkBufferDirty(buffer); + UnlockReleaseBuffer(buffer); + } else elog(PANIC, "dbase_redo: unknown op code %u", info); } *************** *** 1420,1425 **** --- 1557,1573 ---- appendStringInfo(buf, "drop db: dir %u/%u", xlrec->db_id, xlrec->tablespace_id); } + else if (info == XLOG_DBASE_UNFREEZE) + { + xl_dbase_unfreeze_rec *xlrec = (xl_dbase_unfreeze_rec *) rec; + + appendStringInfo(buf, "unfreeze db: %u/%u/%u %u/%u to %u", + xlrec->db_rel.spcNode, xlrec->db_rel.dbNode, + xlrec->db_rel.relNode, + ItemPointerGetBlockNumber(&(xlrec->item)), + ItemPointerGetOffsetNumber(&(xlrec->item)), + xlrec->target_xid); + } else appendStringInfo(buf, "UNKNOWN"); } Index: src/backend/commands/vacuum.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/commands/vacuum.c,v retrieving revision 1.329 diff -c -r1.329 vacuum.c *** src/backend/commands/vacuum.c 3 May 2006 22:45:26 -0000 1.329 --- src/backend/commands/vacuum.c 8 May 2006 02:24:43 -0000 *************** *** 127,132 **** --- 127,133 ---- 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; *************** *** 194,218 **** 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, --- 195,216 ---- 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 *vacuumXID, ! TransactionId *minXID); static void vac_truncate_clog(TransactionId vacuumXID, ! TransactionId minXID); ! static void 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, ! 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,275 **** 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, --- 266,271 ---- *************** *** 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. * --- 348,353 ---- *************** *** 438,443 **** --- 408,423 ---- VacuumCostBalance = 0; /* + * During vacuum, we are going to lock the relation with a writer's + * lock, but if it's already frozen, we won't do any writing on it, so + * disable the unfreezing for the duration of this VACUUM operation. + * However, if this a FULL vacuum, we may mark some tuples with our + * Xid even if the table is frozen, so skip this step. + */ + if (!vacstmt->full) + disable_heap_unfreeze = true; + + /* * Loop to process each selected relation. */ foreach(cur, relations) *************** *** 445,454 **** Oid relid = lfirst_oid(cur); if (vacstmt->vacuum) ! { ! if (!vacuum_rel(relid, vacstmt, RELKIND_RELATION)) ! all_rels = false; /* forget about updating dbstats */ ! } if (vacstmt->analyze) { MemoryContext old_context = NULL; --- 425,432 ---- Oid relid = lfirst_oid(cur); if (vacstmt->vacuum) ! vacuum_rel(relid, vacstmt, RELKIND_RELATION); ! if (vacstmt->analyze) { MemoryContext old_context = NULL; *************** *** 493,504 **** --- 471,486 ---- { /* Make sure cost accounting is turned off after error */ VacuumCostActive = false; + /* reenable heap unfreezing too */ + disable_heap_unfreeze = false; PG_RE_THROW(); } PG_END_TRY(); /* Turn off vacuum cost accounting */ VacuumCostActive = false; + /* reenable heap unfreezing too */ + disable_heap_unfreeze = false; /* * Finish up processing. *************** *** 524,529 **** --- 506,514 ---- if (vacstmt->vacuum) { + TransactionId vacuumXID, + minXID; + /* * If it was a database-wide VACUUM, print FSM usage statistics (we * don't make you be superuser to see these). *************** *** 531,547 **** if (all_rels) 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); ! } } /* --- 516,526 ---- if (all_rels) PrintFreeSpaceMapStatistics(elevel); ! /* Update pg_database.datminxid */ ! vac_update_dbxids(MyDatabaseId, &vacuumXID, &minXID); ! ! /* Try to truncate pg_clog. */ ! vac_truncate_clog(vacuumXID, minXID); } /* *************** *** 686,692 **** */ void vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, ! bool hasindex) { Relation rd; HeapTupleData rtup; --- 665,672 ---- */ void vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, ! bool hasindex, TransactionId minxid, ! TransactionId vacuumxid) { Relation rd; HeapTupleData rtup; *************** *** 718,723 **** --- 698,706 ---- /* overwrite the existing statistics in the tuple */ pgcform = (Form_pg_class) GETSTRUCT(&rtup); + + pgcform->relminxid = minxid; + pgcform->relvacuumxid = vacuumxid; pgcform->relpages = (int32) num_pages; pgcform->reltuples = (float4) num_tuples; pgcform->relhasindex = hasindex; *************** *** 748,786 **** /* ! * 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]; ! SysScanDesc scan; HeapTuple tuple; - Buffer buf; Form_pg_database dbform; ! relation = heap_open(DatabaseRelationId, RowExclusiveLock); ScanKeyInit(&entry[0], ObjectIdAttributeNumber, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dbid)); ! scan = systable_beginscan(relation, DatabaseOidIndexId, true, SnapshotNow, 1, entry); tuple = systable_getnext(scan); --- 731,844 ---- /* ! * 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 Xids are updated to the minimum of all ! * relminxid/relvacuumxid found in pg_class. Both values are also ! * returned in vacuumXID and minXID. * ! * 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 *vacuumXID, TransactionId *minXID) { ! ScanKeyData entry[1]; HeapTuple tuple; Form_pg_database dbform; + Relation relation; + SysScanDesc scan; + HeapTuple classTup; + TransactionId newMinXid = InvalidTransactionId, + newVacXid = InvalidTransactionId; + + /* + * We must seqscan pg_class to find the minimum Xids, because there + * is no index that can help us here. + */ + relation = heap_open(RelationRelationId, AccessShareLock); + + scan = systable_beginscan(relation, InvalidOid, false, + SnapshotNow, 0, NULL); + + while ((classTup = systable_getnext(scan)) != NULL) + { + Form_pg_class classForm; + + classForm = (Form_pg_class) GETSTRUCT(classTup); + + /* + * Only consider heap and TOAST tables (anything else should have + * InvalidTransactionId in both fields anyway.) + */ + if (classForm->relkind != RELKIND_RELATION && + classForm->relkind != RELKIND_TOASTVALUE) + continue; + + /* + * Consider only normal Xids. This means in particular we avoid + * setting the minimum to FrozenTransactionId here. If all tables + * turn out to be frozen, we will exit the loop with the value set + * to InvalidTransactionId. + */ + if (TransactionIdIsNormal(classForm->relminxid) && + (!TransactionIdIsValid(newMinXid) || + TransactionIdPrecedes(classForm->relminxid, newMinXid))) + newMinXid = classForm->relminxid; + + /* ditto */ + if (TransactionIdIsNormal(classForm->relvacuumxid) && + (!TransactionIdIsValid(newVacXid) || + TransactionIdPrecedes(classForm->relvacuumxid, newVacXid))) + newVacXid = classForm->relvacuumxid; + } + + /* we're done with pg_class */ + systable_endscan(scan); + heap_close(relation, AccessShareLock); + + /* + * If we got InvalidTransactionId, then all tables must be frozen. As + * a special protection, we only allow a database to be wholly marked as + * "frozen" if this is a standalone backend. Otherwise, some other + * backend may be modifying a table behind our back, so couldn't safely + * assume that the database is truly frozen. So if we detect that all + * tables are frozen but we're running on a regular backend, fall back to + * storing RecentXmin in datminxid and datvacuumxid (the minimum Xid which + * could be unfreezing a table simultaneously.) + */ + if (!TransactionIdIsValid(newMinXid)) + newMinXid = IsPostmasterEnvironment ? RecentXmin : FrozenTransactionId; + if (!TransactionIdIsValid(newVacXid)) + newVacXid = IsPostmasterEnvironment ? RecentXmin : FrozenTransactionId; + + /* Now fetch the pg_database tuple we need to update. */ + PG_TRY(); + { + /* XXX Describe why we do this */ + disable_heap_unfreeze = true; + relation = heap_open(DatabaseRelationId, RowExclusiveLock); + } + PG_CATCH(); + { + disable_heap_unfreeze = false; + PG_RE_THROW(); + } + PG_END_TRY(); ! disable_heap_unfreeze = false; ScanKeyInit(&entry[0], ObjectIdAttributeNumber, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dbid)); ! scan = systable_beginscan(relation, InvalidOid, false, SnapshotNow, 1, entry); tuple = systable_getnext(scan); *************** *** 788,823 **** if (!HeapTupleIsValid(tuple)) elog(ERROR, "could not find tuple for database %u", dbid); ! if (scan->irel) ! buf = scan->iscan->xs_cbuf; ! else ! buf = scan->scan->rs_cbuf; /* ensure no one else does this at the same time */ ! LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); ! dbform = (Form_pg_database) GETSTRUCT(tuple); ! /* overwrite the existing statistics in the tuple */ ! dbform->datvacuumxid = vacuumXID; ! dbform->datfrozenxid = frozenXID; ! MarkBufferDirty(buf); ! LockBuffer(buf, BUFFER_LOCK_UNLOCK); ! /* invalidate the tuple in the cache so we'll see the change in cache */ ! CacheInvalidateHeapTuple(relation, tuple); systable_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 * --- 846,886 ---- if (!HeapTupleIsValid(tuple)) elog(ERROR, "could not find tuple for database %u", dbid); ! dbform = (Form_pg_database) GETSTRUCT(tuple); /* ensure no one else does this at the same time */ ! LockBuffer(scan->scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE); ! elog(NOTICE, "previous state: datminxid %u, datvacuumxid %u, newMinXid %u," ! " newVacXid %u", ! dbform->datminxid, dbform->datvacuumxid, newMinXid, newVacXid); ! if (TransactionIdPrecedes(dbform->datminxid, newMinXid) || ! TransactionIdEquals(newMinXid, FrozenTransactionId)) ! dbform->datminxid = newMinXid; ! if (TransactionIdPrecedes(dbform->datvacuumxid, newVacXid) || ! TransactionIdEquals(newVacXid, FrozenTransactionId)) ! dbform->datvacuumxid = newVacXid; ! elog(NOTICE, "final state: datminxid %u, datvacuumxid %u, newMinXid %u," ! " newVacXid %u", ! dbform->datminxid, dbform->datvacuumxid, newMinXid, newVacXid); ! MarkBufferDirty(scan->scan->rs_cbuf); ! /* invalidate the tuple in the cache and write the buffer */ ! CacheInvalidateHeapTuple(relation, tuple); ! LockBuffer(scan->scan->rs_cbuf, BUFFER_LOCK_UNLOCK); ! /* Mark the flat-file copy of pg_database for update at commit */ ! database_file_update_needed(); systable_endscan(scan); heap_close(relation, RowExclusiveLock); ! *minXID = newMinXid; ! *vacuumXID = newVacXid; } /* * vac_truncate_clog() -- attempt to truncate the commit log * *************** *** 834,844 **** * 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; --- 897,906 ---- * 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. */ static void ! vac_truncate_clog(TransactionId vacuumXID, TransactionId minXID) { TransactionId myXID = GetCurrentTransactionId(); Relation relation; *************** *** 847,855 **** 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)); /* --- 909,920 ---- int32 age; NameData oldest_datname; bool vacuumAlreadyWrapped = false; ! bool minAlreadyWrapped = false; ! ! Assert(TransactionIdIsValid(vacuumXID)); ! Assert(TransactionIdIsValid(minXID)); ! /* init oldest_datname to sync with my minXID */ namestrcpy(&oldest_datname, get_database_name(MyDatabaseId)); /* *************** *** 876,888 **** 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 ---- else if (TransactionIdPrecedes(dbform->datvacuumxid, vacuumXID)) vacuumXID = dbform->datvacuumxid; } ! if (TransactionIdIsNormal(dbform->datminxid)) { ! if (TransactionIdPrecedes(myXID, dbform->datminxid)) ! minAlreadyWrapped = true; ! else if (TransactionIdPrecedes(dbform->datminxid, minXID)) { ! minXID = dbform->datminxid; namecpy(&oldest_datname, &dbform->datname); } } *************** *** 911,917 **** * 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"), --- 976,982 ---- * Do not update varsup.c if we seem to have suffered wraparound already; * the computed XID might be bogus. */ ! if (minAlreadyWrapped) { ereport(WARNING, (errmsg("some databases have not been vacuumed in over 1 billion transactions"), *************** *** 920,929 **** } /* 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", --- 985,994 ---- } /* 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", *************** *** 945,955 **** /* * 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 --- 1010,1015 ---- *************** *** 958,971 **** * * 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(); --- 1018,1030 ---- * * At entry and exit, we are not inside a transaction. */ ! static void vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind) { LOCKMODE lmode; Relation onerel; LockRelId onerelid; Oid toast_relid; /* Begin a transaction for vacuuming this relation */ StartTransactionCommand(); *************** *** 994,1008 **** { StrategyHintVacuum(false); CommitTransactionCommand(); ! return true; /* okay 'cause no data there */ } /* * Determine the type of lock we want --- hard exclusive lock for a FULL ! * vacuum, but just ShareUpdateExclusiveLock for concurrent vacuum. Either ! * way, we can be sure that no other backend is vacuuming the same table. */ ! lmode = vacstmt->full ? AccessExclusiveLock : ShareUpdateExclusiveLock; /* * Open the class, get an appropriate lock on it, and check permissions. --- 1053,1069 ---- { StrategyHintVacuum(false); CommitTransactionCommand(); ! return; } /* * Determine the type of lock we want --- hard exclusive lock for a FULL ! * vacuum, ExclusiveLock for VACUUM FREEZE, but just ! * ShareUpdateExclusiveLock for concurrent vacuum. Either way, we can be ! * sure that no other backend is vacuuming the same table. */ ! lmode = vacstmt->full ? AccessExclusiveLock : ! vacstmt->freeze ? ExclusiveLock : ShareUpdateExclusiveLock; /* * Open the class, get an appropriate lock on it, and check permissions. *************** *** 1025,1031 **** relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return false; } /* --- 1086,1092 ---- relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return; } /* *************** *** 1040,1046 **** relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return false; } /* --- 1101,1107 ---- relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return; } /* *************** *** 1055,1061 **** relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return true; /* assume no long-lived data in temp tables */ } /* --- 1116,1122 ---- relation_close(onerel, lmode); StrategyHintVacuum(false); CommitTransactionCommand(); ! return; /* assume no long-lived data in temp tables */ } /* *************** *** 1084,1091 **** 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); --- 1145,1150 ---- *************** *** 1098,1119 **** /* * 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; } --- 1157,1173 ---- /* * 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) ! vacuum_rel(toast_relid, vacstmt, RELKIND_TOASTVALUE); /* * Now release the session-level lock on the master table. */ UnlockRelationForSession(&onerelid, lmode); } *************** *** 1145,1150 **** --- 1199,1206 ---- int nindexes, i; VRelStats *vacrelstats; + TransactionId FreezeLimit, + OldestXmin; vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared, &OldestXmin, &FreezeLimit); *************** *** 1157,1165 **** 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); --- 1213,1233 ---- vacrelstats->rel_tuples = 0; vacrelstats->hasindex = false; + /* + * Set initial minimum Xid, which will be updated if a smaller Xid is found + * in the relation by scan_heap. + * + * 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); *************** *** 1187,1193 **** { /* Try to shrink heap */ repair_frag(vacrelstats, onerel, &vacuum_pages, &fraged_pages, ! nindexes, Irel); vac_close_indexes(nindexes, Irel, NoLock); } else --- 1255,1261 ---- { /* Try to shrink heap */ repair_frag(vacrelstats, onerel, &vacuum_pages, &fraged_pages, ! nindexes, Irel, OldestXmin); vac_close_indexes(nindexes, Irel, NoLock); } else *************** *** 1205,1211 **** /* 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, --- 1273,1280 ---- /* update statistics in pg_class */ vac_update_relstats(RelationGetRelid(onerel), vacrelstats->rel_pages, ! vacrelstats->rel_tuples, vacrelstats->hasindex, ! vacrelstats->minxid, OldestXmin); /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, *************** *** 1219,1234 **** * 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, --- 1288,1304 ---- * 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, *************** *** 1342,1347 **** --- 1412,1418 ---- { ItemId itemid = PageGetItemId(page, offnum); bool tupgone = false; + HeapTupleData tuple; /* * Collect un-used items too - it's possible to have indexes *************** *** 1483,1488 **** --- 1554,1571 ---- 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 */ *************** *** 1622,1628 **** 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; --- 1705,1711 ---- 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; *************** *** 2965,2971 **** /* 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", --- 3048,3054 ---- /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false, InvalidTransactionId, InvalidTransactionId); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", *************** *** 3034,3040 **** /* 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", --- 3117,3123 ---- /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), stats->num_pages, stats->num_index_tuples, ! false, InvalidTransactionId, InvalidTransactionId); 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.70 diff -c -r1.70 vacuumlazy.c *** src/backend/commands/vacuumlazy.c 2 May 2006 22:25:10 -0000 1.70 --- src/backend/commands/vacuumlazy.c 5 May 2006 01:54:38 -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_vacuum_index(Relation indrel, IndexBulkDeleteResult **stats, --- 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_vacuum_index(Relation indrel, IndexBulkDeleteResult **stats, *************** *** 104,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); 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); --- 104,113 ---- 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,128 **** * 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. --- 123,130 ---- * 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. *************** *** 135,146 **** --- 137,164 ---- int nindexes; bool hasindex; BlockNumber possibly_freeable; + TransactionId OldestXmin, + FreezeLimit; if (vacstmt->verbose) elevel = INFO; else elevel = DEBUG2; + /* + * We can skip vacuuming a frozen table, since we know nobody has touched + * it since the last VACUUM. XXX Do it only in regular backends though, + * just to make sure we won't be skipping vacuums in standalone backends + * due to strange sinval behavior. + */ + if (onerel->rd_rel->relminxid == FrozenTransactionId && IsUnderPostmaster) + { + elog(LOG, "skipping VACUUM to frozen relation \"%s\"", + RelationGetRelationName(onerel)); + + return; + } + vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared, &OldestXmin, &FreezeLimit); *************** *** 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); --- 168,201 ---- /* 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 by lazy_scan_heap. + * + * In VACUUM FREEZE, we use FrozenTransactionId here. This is safe + * because we acquired ExclusiveLock above, so no one can be inserting + * newer tuples in pages earlier to those we have scanned. If there's any + * tuple whose Xid we can't change, the lower bound will be raised. + * + * In the non-FREEZE case, 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 concurrently insert + * new tuples in the table. + * + * The FREEZE case doesn't have an equivalent in VACUUM FULL because FULL + * in combination with FREEZE is verboten. + */ + if (vacstmt->freeze) + vacrelstats->minxid = FrozenTransactionId; + else + 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, --- 209,223 ---- 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, ! vacrelstats->minxid, OldestXmin); /* 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; --- 232,245 ---- * 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; *************** *** 408,413 **** --- 451,470 ---- { 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 */ *************** *** 668,676 **** /* 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", --- 725,732 ---- /* now update statistics in pg_class */ vac_update_relstats(RelationGetRelid(indrel), ! stats->num_pages, stats->num_index_tuples, ! false, InvalidTransactionId, InvalidTransactionId); ereport(elevel, (errmsg("index \"%s\" now contains %.0f row versions in %u pages", *************** *** 691,697 **** * 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; --- 747,754 ---- * 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; *************** *** 732,738 **** * 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) { --- 789,795 ---- * 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) { *************** *** 787,793 **** * Returns number of nondeletable pages (last nonempty page + 1). */ static BlockNumber ! count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats) { BlockNumber blkno; HeapTupleData tuple; --- 844,851 ---- * 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 5 May 2006 01:54:38 -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.18 diff -c -r1.18 autovacuum.c *** src/backend/postmaster/autovacuum.c 3 May 2006 22:45:26 -0000 1.18 --- src/backend/postmaster/autovacuum.c 5 May 2006 01:54:39 -0000 *************** *** 77,83 **** { Oid oid; char *name; ! TransactionId frozenxid; TransactionId vacuumxid; PgStat_StatDBEntry *entry; int32 age; --- 77,83 ---- { Oid oid; char *name; ! TransactionId minxid; TransactionId vacuumxid; PgStat_StatDBEntry *entry; int32 age; *************** *** 345,351 **** { autovac_dbase *tmp = lfirst(cell); bool this_whole_db; ! int32 freeze_age, vacuum_age; /* --- 345,351 ---- { autovac_dbase *tmp = lfirst(cell); bool this_whole_db; ! int32 true_age, vacuum_age; /* *************** *** 358,366 **** * 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)); --- 358,366 ---- * 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)); *************** *** 451,457 **** FILE *db_file; Oid db_id; Oid db_tablespace; ! TransactionId db_frozenxid; TransactionId db_vacuumxid; filename = database_getflatfilename(); --- 451,457 ---- FILE *db_file; Oid db_id; Oid db_tablespace; ! TransactionId db_minxid; TransactionId db_vacuumxid; filename = database_getflatfilename(); *************** *** 462,468 **** 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; --- 462,468 ---- 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; *************** *** 471,477 **** db->oid = db_id; db->name = pstrdup(thisname); ! db->frozenxid = db_frozenxid; db->vacuumxid = db_vacuumxid; /* these get set later: */ db->entry = NULL; --- 471,477 ---- 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/storage/lmgr/lmgr.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/storage/lmgr/lmgr.c,v retrieving revision 1.83 diff -c -r1.83 lmgr.c *** src/backend/storage/lmgr/lmgr.c 4 May 2006 16:07:29 -0000 1.83 --- src/backend/storage/lmgr/lmgr.c 5 May 2006 14:07:48 -0000 *************** *** 15,20 **** --- 15,21 ---- #include "postgres.h" + #include "access/heapam.h" #include "access/subtrans.h" #include "access/transam.h" #include "access/xact.h" *************** *** 53,58 **** --- 54,67 ---- LOCKTAG tag; LockAcquireResult res; + /* + * If the relation was frozen and somebody tries to lock it for more than + * a simple SELECT, unfreeze it. + */ + if (relation->rd_rel->relminxid == FrozenTransactionId && + lockmode > AccessShareLock) + heap_unfreeze(relation); + SET_LOCKTAG_RELATION(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); *************** *** 89,94 **** --- 98,111 ---- LOCKTAG tag; LockAcquireResult res; + /* + * If the relation was frozen and somebody tries to lock it for more than + * a simple SELECT, unfreeze it. + */ + if (relation->rd_rel->relminxid == FrozenTransactionId && + lockmode > AccessShareLock) + heap_unfreeze(relation); + SET_LOCKTAG_RELATION(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); Index: src/backend/utils/init/flatfiles.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/utils/init/flatfiles.c,v retrieving revision 1.18 diff -c -r1.18 flatfiles.c *** src/backend/utils/init/flatfiles.c 4 May 2006 16:07:29 -0000 1.18 --- src/backend/utils/init/flatfiles.c 5 May 2006 01:54:39 -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/backend/utils/init/postinit.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/backend/utils/init/postinit.c,v retrieving revision 1.167 diff -c -r1.167 postinit.c *** src/backend/utils/init/postinit.c 4 May 2006 18:51:36 -0000 1.167 --- src/backend/utils/init/postinit.c 8 May 2006 02:04:26 -0000 *************** *** 24,29 **** --- 24,30 ---- #include "catalog/pg_authid.h" #include "catalog/pg_database.h" #include "catalog/pg_tablespace.h" + #include "commands/dbcommands.h" #include "libpq/hba.h" #include "mb/pg_wchar.h" #include "miscadmin.h" *************** *** 193,198 **** --- 194,210 ---- PGC_BACKEND, PGC_S_DEFAULT); /* + * If the database is marked as frozen, unfreeze it to make sure we won't + * leave non-vacuumed tuples hidden behind a frozen pg_database entry. + * + * This is more paranoid than it needs to be -- if we had a way of + * declaring a session as being guaranteed-read-only, we could skip doing + * this for such sessions. In the meantime, be safe. + */ + if (TransactionIdEquals(dbform->datminxid, FrozenTransactionId)) + UnfreezeDatabase(tup, GetCurrentTransactionId()); + + /* * Lastly, set up any database-specific configuration variables. */ if (IsUnderPostmaster) Index: src/bin/initdb/initdb.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/bin/initdb/initdb.c,v retrieving revision 1.114 diff -c -r1.114 initdb.c *** src/bin/initdb/initdb.c 21 Mar 2006 17:54:28 -0000 1.114 --- src/bin/initdb/initdb.c 7 May 2006 04:59:58 -0000 *************** *** 184,189 **** --- 184,190 ---- static void setup_schema(void); static void vacuum_db(void); static void make_template0(void); + static void freeze_template0(void); static void make_postgres(void); static void trapsig(int signum); static void check_ok(void); *************** *** 2014,2019 **** --- 2015,2054 ---- } /* + * freeze template0 + * + * Note that this routine connects to template0, not template1 like all the + * rest. + */ + static void + freeze_template0(void) + { + PG_CMD_DECL; + char **line; + static char *template_freeze[] = { + "VACUUM FREEZE;\n", + NULL + }; + + fputs(_("freezing template0 ... "), stdout); + fflush(stdout); + + snprintf(cmd, sizeof(cmd), + "\"%s\" %s template0 >%s", + backend_exec, backend_options, + DEVNULL); + + PG_CMD_OPEN; + + for (line = template_freeze; *line; line++) + PG_CMD_PUTS(*line); + + PG_CMD_CLOSE; + + check_ok(); + } + + /* * copy template1 to postgres */ static void *************** *** 2946,2951 **** --- 2981,2988 ---- make_template0(); + freeze_template0(); + make_postgres(); if (authwarning != NULL) Index: src/include/access/heapam.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/access/heapam.h,v retrieving revision 1.110 diff -c -r1.110 heapam.h *** src/include/access/heapam.h 24 Apr 2006 22:24:58 -0000 1.110 --- src/include/access/heapam.h 5 May 2006 14:05:37 -0000 *************** *** 122,127 **** --- 122,129 ---- /* heapam.c */ + extern bool disable_heap_unfreeze; + typedef enum { LockTupleShared, *************** *** 168,173 **** --- 170,176 ---- Buffer *buffer, ItemPointer ctid, TransactionId *update_xmax, CommandId cid, LockTupleMode mode, bool nowait); + extern void heap_unfreeze(Relation rel); extern Oid simple_heap_insert(Relation relation, HeapTuple tup); extern void simple_heap_delete(Relation relation, ItemPointer tid); Index: src/include/access/htup.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/access/htup.h,v retrieving revision 1.81 diff -c -r1.81 htup.h *** src/include/access/htup.h 5 Mar 2006 15:58:53 -0000 1.81 --- src/include/access/htup.h 5 May 2006 01:54:39 -0000 *************** *** 444,450 **** #define XLOG_HEAP_CLEAN 0x40 #define XLOG_HEAP_NEWPAGE 0x50 #define XLOG_HEAP_LOCK 0x60 ! /* opcode 0x70 still free */ #define XLOG_HEAP_OPMASK 0x70 /* * When we insert 1st item on new page in INSERT/UPDATE --- 444,450 ---- #define XLOG_HEAP_CLEAN 0x40 #define XLOG_HEAP_NEWPAGE 0x50 #define XLOG_HEAP_LOCK 0x60 ! #define XLOG_HEAP_UNFREEZE 0x70 #define XLOG_HEAP_OPMASK 0x70 /* * When we insert 1st item on new page in INSERT/UPDATE *************** *** 545,548 **** --- 545,557 ---- #define SizeOfHeapLock (offsetof(xl_heap_lock, shared_lock) + sizeof(bool)) + /* This is what we need to know about unfreeze */ + typedef struct xl_heap_unfreeze + { + xl_heaptid target; /* pg_class tuple id of unfrozen rel */ + TransactionId target_xid; /* unfreezing TransactionId */ + } xl_heap_unfreeze; + + #define SizeOfHeapUnfreeze (offsetof(xl_heap_unfreeze, target_xid) + sizeof(TransactionId)) + #endif /* HTUP_H */ 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 5 May 2006 01:54:39 -0000 *************** *** 123,129 **** /* 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); --- 123,129 ---- /* 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); 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 5 May 2006 01:54:39 -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 5 May 2006 01:54:39 -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 5 May 2006 01:54:39 -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/dbcommands.h =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/include/commands/dbcommands.h,v retrieving revision 1.45 diff -c -r1.45 dbcommands.h *** src/include/commands/dbcommands.h 24 Mar 2006 04:32:13 -0000 1.45 --- src/include/commands/dbcommands.h 7 May 2006 07:28:22 -0000 *************** *** 14,25 **** --- 14,28 ---- #ifndef DBCOMMANDS_H #define DBCOMMANDS_H + #include "access/htup.h" #include "access/xlog.h" #include "nodes/parsenodes.h" + #include "storage/itemptr.h" /* XLOG stuff */ #define XLOG_DBASE_CREATE 0x00 #define XLOG_DBASE_DROP 0x10 + #define XLOG_DBASE_UNFREEZE 0x20 typedef struct xl_dbase_create_rec_old { *************** *** 52,63 **** --- 55,75 ---- Oid tablespace_id; } xl_dbase_drop_rec; + typedef struct xl_dbase_unfreeze_rec + { + /* Records unfreezing a database */ + RelFileNode db_rel; + ItemPointerData item; + TransactionId target_xid; + } xl_dbase_unfreeze_rec; + extern void createdb(const CreatedbStmt *stmt); extern void dropdb(const char *dbname, bool missing_ok); extern void RenameDatabase(const char *oldname, const char *newname); extern void AlterDatabase(AlterDatabaseStmt *stmt); extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt); extern void AlterDatabaseOwner(const char *dbname, Oid newOwnerId); + extern void UnfreezeDatabase(HeapTuple dbtuple, TransactionId unfreezeXid); extern Oid get_database_oid(const char *dbname); extern char *get_database_name(Oid dbid); 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 5 May 2006 01:54:39 -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,122 ---- 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, ! TransactionId minxid, TransactionId vacuumxid); extern void vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel, TransactionId *oldestXmin, TransactionId *freezeLimit); 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 5 May 2006 01:54:39 -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 */