Skip to content

Commit 4873c96

Browse files
committed
Fix inappropriately-timed memory context switch in autovacuum_do_vac_analyze.
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.
1 parent 4844529 commit 4873c96

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.73 2008/03/14 17:25:58 alvherre Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.74 2008/03/14 23:49:28 tgl Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -2602,17 +2602,12 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
26022602
BufferAccessStrategy bstrategy)
26032603
{
26042604
VacuumStmt vacstmt;
2605+
List *relids;
26052606
MemoryContext old_cxt;
26062607

2608+
/* Set up command parameters --- use a local variable instead of palloc */
26072609
MemSet(&vacstmt, 0, sizeof(vacstmt));
26082610

2609-
/*
2610-
* The list must survive transaction boundaries, so make sure we create it
2611-
* in a long-lived context
2612-
*/
2613-
old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
2614-
2615-
/* Set up command parameters */
26162611
vacstmt.type = T_VacuumStmt;
26172612
vacstmt.vacuum = dovacuum;
26182613
vacstmt.full = false;
@@ -2622,11 +2617,18 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
26222617
vacstmt.relation = NULL; /* not used since we pass a relids list */
26232618
vacstmt.va_cols = NIL;
26242619

2620+
/*
2621+
* The list must survive transaction boundaries, so make sure we create it
2622+
* in a long-lived context
2623+
*/
2624+
old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
2625+
relids = list_make1_oid(relid);
2626+
MemoryContextSwitchTo(old_cxt);
2627+
26252628
/* Let pgstat know what we're doing */
26262629
autovac_report_activity(&vacstmt, relid);
26272630

2628-
vacuum(&vacstmt, list_make1_oid(relid), bstrategy, for_wraparound, true);
2629-
MemoryContextSwitchTo(old_cxt);
2631+
vacuum(&vacstmt, relids, bstrategy, for_wraparound, true);
26302632
}
26312633

26322634
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy