@@ -1269,7 +1269,8 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
1269
1269
* changes because we'd be updating the old data that we're about to throw
1270
1270
* away. Because the real work being done here for a mapped relation is
1271
1271
* just to change the relation map settings, it's all right to not update
1272
- * the pg_class rows in this case.
1272
+ * the pg_class rows in this case. The most important changes will instead
1273
+ * performed later, in finish_heap_swap() itself.
1273
1274
*/
1274
1275
if (!target_is_pg_class )
1275
1276
{
@@ -1504,6 +1505,40 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
1504
1505
reindex_flags |= REINDEX_REL_CHECK_CONSTRAINTS ;
1505
1506
reindex_relation (OIDOldHeap , reindex_flags );
1506
1507
1508
+ /*
1509
+ * If the relation being rebuild is pg_class, swap_relation_files()
1510
+ * couldn't update pg_class's own pg_class entry (check comments in
1511
+ * swap_relation_files()), thus relfrozenxid was not updated. That's
1512
+ * annoying because a potential reason for doing a VACUUM FULL is a
1513
+ * imminent or actual anti-wraparound shutdown. So, now that we can
1514
+ * access the new relation using it's indices, update
1515
+ * relfrozenxid. pg_class doesn't have a toast relation, so we don't need
1516
+ * to update the corresponding toast relation. Not that there's little
1517
+ * point moving all relfrozenxid updates here since swap_relation_files()
1518
+ * needs to write to pg_class for non-mapped relations anyway.
1519
+ */
1520
+ if (OIDOldHeap == RelationRelationId )
1521
+ {
1522
+ Relation relRelation ;
1523
+ HeapTuple reltup ;
1524
+ Form_pg_class relform ;
1525
+
1526
+ relRelation = heap_open (RelationRelationId , RowExclusiveLock );
1527
+
1528
+ reltup = SearchSysCacheCopy1 (RELOID , ObjectIdGetDatum (OIDOldHeap ));
1529
+ if (!HeapTupleIsValid (reltup ))
1530
+ elog (ERROR , "cache lookup failed for relation %u" , OIDOldHeap );
1531
+ relform = (Form_pg_class ) GETSTRUCT (reltup );
1532
+
1533
+ relform -> relfrozenxid = frozenXid ;
1534
+ relform -> relminmxid = cutoffMulti ;
1535
+
1536
+ simple_heap_update (relRelation , & reltup -> t_self , reltup );
1537
+ CatalogUpdateIndexes (relRelation , reltup );
1538
+
1539
+ heap_close (relRelation , RowExclusiveLock );
1540
+ }
1541
+
1507
1542
/* Destroy new heap with old filenode */
1508
1543
object .classId = RelationRelationId ;
1509
1544
object .objectId = OIDNewHeap ;
0 commit comments