aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/vacuum.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/vacuum.c')
-rw-r--r--src/backend/commands/vacuum.c109
1 files changed, 60 insertions, 49 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index dfc03ea461a..23d7996cf53 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.284 2004/07/21 22:31:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.285 2004/07/31 00:45:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -228,14 +228,13 @@ void
vacuum(VacuumStmt *vacstmt)
{
const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE";
- MemoryContext anl_context = NULL;
TransactionId initialOldestXmin = InvalidTransactionId;
TransactionId initialFreezeLimit = InvalidTransactionId;
- bool all_rels,
+ volatile MemoryContext anl_context = NULL;
+ volatile bool all_rels,
in_outer_xact,
use_own_xacts;
List *relations;
- ListCell *cur;
if (vacstmt->verbose)
elevel = INFO;
@@ -267,10 +266,6 @@ vacuum(VacuumStmt *vacstmt)
in_outer_xact = IsInTransactionChain((void *) vacstmt);
}
- /* Turn vacuum cost accounting on or off */
- VacuumCostActive = (VacuumCostNaptime > 0);
- VacuumCostBalance = 0;
-
/*
* Send info about dead objects to the statistics collector
*/
@@ -377,57 +372,76 @@ vacuum(VacuumStmt *vacstmt)
CommitTransactionCommand();
}
- /*
- * Loop to process each selected relation.
- */
- foreach(cur, relations)
+ /* Turn vacuum cost accounting on or off */
+ PG_TRY();
{
- Oid relid = lfirst_oid(cur);
+ ListCell *cur;
- if (vacstmt->vacuum)
- {
- if (!vacuum_rel(relid, vacstmt, RELKIND_RELATION))
- all_rels = false; /* forget about updating dbstats */
- }
- if (vacstmt->analyze)
+ VacuumCostActive = (VacuumCostNaptime > 0);
+ VacuumCostBalance = 0;
+
+ /*
+ * Loop to process each selected relation.
+ */
+ foreach(cur, relations)
{
- MemoryContext old_context = NULL;
+ Oid relid = lfirst_oid(cur);
- /*
- * If using separate xacts, start one for analyze. Otherwise,
- * we can use the outer transaction, but we still need to call
- * analyze_rel in a memory context that will be cleaned up on
- * return (else we leak memory while processing multiple
- * tables).
- */
- if (use_own_xacts)
+ if (vacstmt->vacuum)
{
- StartTransactionCommand();
- SetQuerySnapshot(); /* might be needed for functions
- * in indexes */
+ if (!vacuum_rel(relid, vacstmt, RELKIND_RELATION))
+ all_rels = false; /* forget about updating dbstats */
}
- else
- old_context = MemoryContextSwitchTo(anl_context);
+ if (vacstmt->analyze)
+ {
+ MemoryContext old_context = NULL;
- /*
- * Tell the buffer replacement strategy that vacuum is
- * causing the IO
- */
- StrategyHintVacuum(true);
+ /*
+ * If using separate xacts, start one for analyze. Otherwise,
+ * we can use the outer transaction, but we still need to call
+ * analyze_rel in a memory context that will be cleaned up on
+ * return (else we leak memory while processing multiple
+ * tables).
+ */
+ if (use_own_xacts)
+ {
+ StartTransactionCommand();
+ SetQuerySnapshot(); /* might be needed for functions
+ * in indexes */
+ }
+ else
+ old_context = MemoryContextSwitchTo(anl_context);
+
+ /*
+ * Tell the buffer replacement strategy that vacuum is
+ * causing the IO
+ */
+ StrategyHintVacuum(true);
- analyze_rel(relid, vacstmt);
+ analyze_rel(relid, vacstmt);
- StrategyHintVacuum(false);
+ StrategyHintVacuum(false);
- if (use_own_xacts)
- CommitTransactionCommand();
- else
- {
- MemoryContextSwitchTo(old_context);
- MemoryContextResetAndDeleteChildren(anl_context);
+ if (use_own_xacts)
+ CommitTransactionCommand();
+ else
+ {
+ MemoryContextSwitchTo(old_context);
+ MemoryContextResetAndDeleteChildren(anl_context);
+ }
}
}
}
+ PG_CATCH();
+ {
+ /* Make sure cost accounting is turned off after error */
+ VacuumCostActive = false;
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
+
+ /* Turn off vacuum cost accounting */
+ VacuumCostActive = false;
/*
* Finish up processing.
@@ -475,9 +489,6 @@ vacuum(VacuumStmt *vacstmt)
if (anl_context)
MemoryContextDelete(anl_context);
-
- /* Turn off vacuum cost accounting */
- VacuumCostActive = false;
}
/*