Relation NewHeap,
OldHeap,
OldIndex;
+ Relation relRelation;
+ HeapTuple reltup;
+ Form_pg_class relform;
TupleDesc oldTupDesc;
TupleDesc newTupDesc;
int natts;
double num_tuples = 0,
tups_vacuumed = 0,
tups_recently_dead = 0;
+ BlockNumber num_pages;
int elevel = verbose ? INFO : DEBUG2;
PGRUsage ru0;
/* Reset rd_toastoid just to be tidy --- it shouldn't be looked at again */
NewHeap->rd_toastoid = InvalidOid;
+ num_pages = RelationGetNumberOfBlocks(NewHeap);
+
/* Log what we did */
ereport(elevel,
(errmsg("\"%s\": found %.0f removable, %.0f nonremovable row versions in %u pages",
index_close(OldIndex, NoLock);
heap_close(OldHeap, NoLock);
heap_close(NewHeap, NoLock);
+
+ /* Update pg_class to reflect the correct values of pages and tuples. */
+ relRelation = heap_open(RelationRelationId, RowExclusiveLock);
+
+ reltup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(OIDNewHeap));
+ if (!HeapTupleIsValid(reltup))
+ elog(ERROR, "cache lookup failed for relation %u", OIDNewHeap);
+ relform = (Form_pg_class) GETSTRUCT(reltup);
+
+ relform->relpages = num_pages;
+ relform->reltuples = num_tuples;
+
+ /* Don't update the stats for pg_class. See swap_relation_files. */
+ if (OIDOldHeap != RelationRelationId)
+ CatalogTupleUpdate(relRelation, &reltup->t_self, reltup);
+ else
+ CacheInvalidateRelcacheByTuple(reltup);
+
+ /* Clean up. */
+ heap_freetuple(reltup);
+ heap_close(relRelation, RowExclusiveLock);
+
+ /* Make the update visible */
+ CommandCounterIncrement();
}
/*