13
13
*
14
14
*
15
15
* IDENTIFICATION
16
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.364 2008/02/11 19:14:30 tgl Exp $
16
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.364.2.1 2008/03/14 17:26:00 alvherre Exp $
17
17
*
18
18
*-------------------------------------------------------------------------
19
19
*/
@@ -208,7 +208,8 @@ static BufferAccessStrategy vac_strategy;
208
208
static List * get_rel_oids (List * relids , const RangeVar * vacrel ,
209
209
const char * stmttype );
210
210
static void vac_truncate_clog (TransactionId frozenXID );
211
- static void vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind );
211
+ static void vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind ,
212
+ bool for_wraparound );
212
213
static void full_vacuum_rel (Relation onerel , VacuumStmt * vacstmt );
213
214
static void scan_heap (VRelStats * vacrelstats , Relation onerel ,
214
215
VacPageList vacuum_pages , VacPageList fraged_pages );
@@ -262,6 +263,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
262
263
* relation OIDs to be processed, and vacstmt->relation is ignored.
263
264
* (The non-NIL case is currently only used by autovacuum.)
264
265
*
266
+ * for_wraparound is used by autovacuum to let us know when it's forcing
267
+ * a vacuum for wraparound, which should not be auto-cancelled.
268
+ *
265
269
* bstrategy is normally given as NULL, but in autovacuum it can be passed
266
270
* in to use the same buffer strategy object across multiple vacuum() calls.
267
271
*
@@ -273,7 +277,7 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
273
277
*/
274
278
void
275
279
vacuum (VacuumStmt * vacstmt , List * relids ,
276
- BufferAccessStrategy bstrategy , bool isTopLevel )
280
+ BufferAccessStrategy bstrategy , bool for_wraparound , bool isTopLevel )
277
281
{
278
282
const char * stmttype = vacstmt -> vacuum ? "VACUUM" : "ANALYZE" ;
279
283
volatile MemoryContext anl_context = NULL ;
@@ -420,7 +424,7 @@ vacuum(VacuumStmt *vacstmt, List *relids,
420
424
Oid relid = lfirst_oid (cur );
421
425
422
426
if (vacstmt -> vacuum )
423
- vacuum_rel (relid , vacstmt , RELKIND_RELATION );
427
+ vacuum_rel (relid , vacstmt , RELKIND_RELATION , for_wraparound );
424
428
425
429
if (vacstmt -> analyze )
426
430
{
@@ -965,7 +969,8 @@ vac_truncate_clog(TransactionId frozenXID)
965
969
* At entry and exit, we are not inside a transaction.
966
970
*/
967
971
static void
968
- vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind )
972
+ vacuum_rel (Oid relid , VacuumStmt * vacstmt , char expected_relkind ,
973
+ bool for_wraparound )
969
974
{
970
975
LOCKMODE lmode ;
971
976
Relation onerel ;
@@ -998,13 +1003,19 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
998
1003
* contents of other tables is arguably broken, but we won't break it
999
1004
* here by violating transaction semantics.)
1000
1005
*
1006
+ * We also set the VACUUM_FOR_WRAPAROUND flag, which is passed down
1007
+ * by autovacuum; it's used to avoid cancelling a vacuum that was
1008
+ * invoked in an emergency.
1009
+ *
1001
1010
* Note: this flag remains set until CommitTransaction or
1002
1011
* AbortTransaction. We don't want to clear it until we reset
1003
1012
* MyProc->xid/xmin, else OldestXmin might appear to go backwards,
1004
1013
* which is probably Not Good.
1005
1014
*/
1006
1015
LWLockAcquire (ProcArrayLock , LW_EXCLUSIVE );
1007
1016
MyProc -> vacuumFlags |= PROC_IN_VACUUM ;
1017
+ if (for_wraparound )
1018
+ MyProc -> vacuumFlags |= PROC_VACUUM_FOR_WRAPAROUND ;
1008
1019
LWLockRelease (ProcArrayLock );
1009
1020
}
1010
1021
@@ -1137,7 +1148,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
1137
1148
* totally unimportant for toast relations.
1138
1149
*/
1139
1150
if (toast_relid != InvalidOid )
1140
- vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE );
1151
+ vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE , for_wraparound );
1141
1152
1142
1153
/*
1143
1154
* Now release the session-level lock on the master table.
0 commit comments