13
13
*
14
14
*
15
15
* 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 $
17
17
*
18
18
*-------------------------------------------------------------------------
19
19
*/
@@ -209,7 +209,8 @@ static BufferAccessStrategy vac_strategy;
209
209
static List * get_rel_oids (List * relids , const RangeVar * vacrel ,
210
210
const char * stmttype );
211
211
static 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 );
213
214
static void full_vacuum_rel (Relation onerel , VacuumStmt * vacstmt );
214
215
static void scan_heap (VRelStats * vacrelstats , Relation onerel ,
215
216
VacPageList vacuum_pages , VacPageList fraged_pages );
@@ -263,6 +264,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
263
264
* relation OIDs to be processed, and vacstmt->relation is ignored.
264
265
* (The non-NIL case is currently only used by autovacuum.)
265
266
*
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
+ *
266
270
* bstrategy is normally given as NULL, but in autovacuum it can be passed
267
271
* in to use the same buffer strategy object across multiple vacuum() calls.
268
272
*
@@ -274,7 +278,7 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
274
278
*/
275
279
void
276
280
vacuum (VacuumStmt * vacstmt , List * relids ,
277
- BufferAccessStrategy bstrategy , bool isTopLevel )
281
+ BufferAccessStrategy bstrategy , bool for_wraparound , bool isTopLevel )
278
282
{
279
283
const char * stmttype = vacstmt -> vacuum ? "VACUUM" : "ANALYZE" ;
280
284
volatile MemoryContext anl_context = NULL ;
@@ -421,7 +425,7 @@ vacuum(VacuumStmt *vacstmt, List *relids,
421
425
Oid relid = lfirst_oid (cur );
422
426
423
427
if (vacstmt -> vacuum )
424
- vacuum_rel (relid , vacstmt , RELKIND_RELATION );
428
+ vacuum_rel (relid , vacstmt , RELKIND_RELATION , for_wraparound );
425
429
426
430
if (vacstmt -> analyze )
427
431
{
@@ -966,7 +970,8 @@ vac_truncate_clog(TransactionId frozenXID)
966
970
* At entry and exit, we are not inside a transaction.
967
971
*/
968
972
static 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 )
970
975
{
971
976
LOCKMODE lmode ;
972
977
Relation onerel ;
@@ -999,13 +1004,19 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
999
1004
* contents of other tables is arguably broken, but we won't break it
1000
1005
* here by violating transaction semantics.)
1001
1006
*
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
+ *
1002
1011
* Note: this flag remains set until CommitTransaction or
1003
1012
* AbortTransaction. We don't want to clear it until we reset
1004
1013
* MyProc->xid/xmin, else OldestXmin might appear to go backwards,
1005
1014
* which is probably Not Good.
1006
1015
*/
1007
1016
LWLockAcquire (ProcArrayLock , LW_EXCLUSIVE );
1008
1017
MyProc -> vacuumFlags |= PROC_IN_VACUUM ;
1018
+ if (for_wraparound )
1019
+ MyProc -> vacuumFlags |= PROC_VACUUM_FOR_WRAPAROUND ;
1009
1020
LWLockRelease (ProcArrayLock );
1010
1021
}
1011
1022
@@ -1147,7 +1158,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
1147
1158
* totally unimportant for toast relations.
1148
1159
*/
1149
1160
if (toast_relid != InvalidOid )
1150
- vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE );
1161
+ vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE , for_wraparound );
1151
1162
1152
1163
/*
1153
1164
* Now release the session-level lock on the master table.
0 commit comments