summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-03-14 23:49:33 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-03-14 23:49:33 +0000
commit2059a5a1bce6932c52a440b62154e70a0fad5d2b (patch)
tree0b15451420310d1f2081f523375ca66545bc0b41
parente5ecea0d7359b5eff08620dd653515eedc0737b3 (diff)
downloadpostgresql-2059a5a1bce6932c52a440b62154e70a0fad5d2b.tar.gz
Fix inappropriately-timed memory context switch in autovacuum_do_vac_analyze.REL8_3_1
This accidentally failed to fail before 8.3, because the context we were switching back to was long-lived anyway; but it sure looks risky as can be now. Well spotted by Pavan Deolasee.
-rw-r--r--src/backend/postmaster/autovacuum.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 7d861c1d21..411c1cd4eb 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -55,7 +55,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.71.2.2 2008/03/14 17:26:01 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.71.2.3 2008/03/14 23:49:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2602,17 +2602,12 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
BufferAccessStrategy bstrategy)
{
VacuumStmt vacstmt;
+ List *relids;
MemoryContext old_cxt;
+ /* Set up command parameters --- use a local variable instead of palloc */
MemSet(&vacstmt, 0, sizeof(vacstmt));
- /*
- * The list must survive transaction boundaries, so make sure we create it
- * in a long-lived context
- */
- old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
-
- /* Set up command parameters */
vacstmt.type = T_VacuumStmt;
vacstmt.vacuum = dovacuum;
vacstmt.full = false;
@@ -2622,11 +2617,18 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
vacstmt.relation = NULL; /* not used since we pass a relids list */
vacstmt.va_cols = NIL;
+ /*
+ * The list must survive transaction boundaries, so make sure we create it
+ * in a long-lived context
+ */
+ old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
+ relids = list_make1_oid(relid);
+ MemoryContextSwitchTo(old_cxt);
+
/* Let pgstat know what we're doing */
autovac_report_activity(&vacstmt, relid);
- vacuum(&vacstmt, list_make1_oid(relid), bstrategy, for_wraparound, true);
- MemoryContextSwitchTo(old_cxt);
+ vacuum(&vacstmt, relids, bstrategy, for_wraparound, true);
}
/*