1313 *
1414 *
1515 * IDENTIFICATION
16- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.366 2008/03/10 02:04:08 tgl Exp $
16+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.367 2008/03/14 17:25:58 alvherre Exp $
1717 *
1818 *-------------------------------------------------------------------------
1919 */
@@ -209,7 +209,8 @@ static BufferAccessStrategy vac_strategy;
209209static List * get_rel_oids (List * relids , const RangeVar * vacrel ,
210210 const char * stmttype );
211211static void vac_truncate_clog (TransactionId frozenXID );
212- static void vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind );
212+ static void vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind ,
213+ bool for_wraparound );
213214static void full_vacuum_rel (Relation onerel , VacuumStmt * vacstmt );
214215static void scan_heap (VRelStats * vacrelstats , Relation onerel ,
215216 VacPageList vacuum_pages , VacPageList fraged_pages );
@@ -263,6 +264,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
263264 * relation OIDs to be processed, and vacstmt->relation is ignored.
264265 * (The non-NIL case is currently only used by autovacuum.)
265266 *
267+ * for_wraparound is used by autovacuum to let us know when it's forcing
268+ * a vacuum for wraparound, which should not be auto-cancelled.
269+ *
266270 * bstrategy is normally given as NULL, but in autovacuum it can be passed
267271 * in to use the same buffer strategy object across multiple vacuum() calls.
268272 *
@@ -274,7 +278,7 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
274278 */
275279void
276280vacuum (VacuumStmt * vacstmt , List * relids ,
277- BufferAccessStrategy bstrategy , bool isTopLevel )
281+ BufferAccessStrategy bstrategy , bool for_wraparound , bool isTopLevel )
278282{
279283 const char * stmttype = vacstmt -> vacuum ? "VACUUM" : "ANALYZE" ;
280284 volatile MemoryContext anl_context = NULL ;
@@ -421,7 +425,7 @@ vacuum(VacuumStmt *vacstmt, List *relids,
421425 Oid relid = lfirst_oid (cur );
422426
423427 if (vacstmt -> vacuum )
424- vacuum_rel (relid , vacstmt , RELKIND_RELATION );
428+ vacuum_rel (relid , vacstmt , RELKIND_RELATION , for_wraparound );
425429
426430 if (vacstmt -> analyze )
427431 {
@@ -966,7 +970,8 @@ vac_truncate_clog(TransactionId frozenXID)
966970 * At entry and exit, we are not inside a transaction.
967971 */
968972static void
969- vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind )
973+ vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind ,
974+ bool for_wraparound )
970975{
971976 LOCKMODE lmode ;
972977 Relation onerel ;
@@ -999,13 +1004,19 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
9991004 * contents of other tables is arguably broken, but we won't break it
10001005 * here by violating transaction semantics.)
10011006 *
1007+ * We also set the VACUUM_FOR_WRAPAROUND flag, which is passed down
1008+ * by autovacuum; it's used to avoid cancelling a vacuum that was
1009+ * invoked in an emergency.
1010+ *
10021011 * Note: this flag remains set until CommitTransaction or
10031012 * AbortTransaction. We don't want to clear it until we reset
10041013 * MyProc->xid/xmin, else OldestXmin might appear to go backwards,
10051014 * which is probably Not Good.
10061015 */
10071016 LWLockAcquire (ProcArrayLock , LW_EXCLUSIVE );
10081017 MyProc -> vacuumFlags |= PROC_IN_VACUUM ;
1018+ if (for_wraparound )
1019+ MyProc -> vacuumFlags |= PROC_VACUUM_FOR_WRAPAROUND ;
10091020 LWLockRelease (ProcArrayLock );
10101021 }
10111022
@@ -1147,7 +1158,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
11471158 * totally unimportant for toast relations.
11481159 */
11491160 if (toast_relid != InvalidOid )
1150- vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE );
1161+ vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE , for_wraparound );
11511162
11521163 /*
11531164 * Now release the session-level lock on the master table.
0 commit comments