*/
PG_TRY();
{
+ /* Use PortalContext for any per-table allocations */
+ MemoryContextSwitchTo(PortalContext);
+
/* have at it */
- MemoryContextSwitchTo(TopTransactionContext);
autovacuum_do_vac_analyze(tab, bstrategy);
/*
}
PG_END_TRY();
+ /* Make sure we're back in AutovacMemCxt */
+ MemoryContextSwitchTo(AutovacMemCxt);
+
did_vacuum = true;
/* the PGXACT flags are reset at the next end of transaction */
continue;
if (workitem->avw_active)
continue;
+ if (workitem->avw_database != MyDatabaseId)
+ continue;
/* claim this one, and release lock while performing it */
workitem->avw_active = true;
perform_work_item(workitem);
/*
- * Check for config changes before acquiring lock for further
- * jobs.
+ * Check for config changes before acquiring lock for further jobs.
*/
CHECK_FOR_INTERRUPTS();
if (got_SIGHUP)
/*
* Save the relation name for a possible error message, to avoid a catalog
* lookup in case of an error. If any of these return NULL, then the
- * relation has been dropped since last we checked; skip it. Note: they
- * must live in a long-lived memory context because we call vacuum and
- * analyze in different transactions.
+ * relation has been dropped since last we checked; skip it.
*/
+ Assert(CurrentMemoryContext == AutovacMemCxt);
cur_relname = get_rel_name(workitem->avw_relation);
cur_nspname = get_namespace_name(get_rel_namespace(workitem->avw_relation));
autovac_report_workitem(workitem, cur_nspname, cur_datname);
+ /* clean up memory before each work item */
+ MemoryContextResetAndDeleteChildren(PortalContext);
+
/*
* We will abort the current work item if something errors out, and
* continue with the next one; in particular, this happens if we are
*/
PG_TRY();
{
- /* have at it */
- MemoryContextSwitchTo(TopTransactionContext);
+ /* Use PortalContext for any per-work-item allocations */
+ MemoryContextSwitchTo(PortalContext);
+ /* have at it */
switch (workitem->avw_type)
{
case AVW_BRINSummarizeRange:
}
PG_END_TRY();
+ /* Make sure we're back in AutovacMemCxt */
+ MemoryContextSwitchTo(AutovacMemCxt);
+
/* We intentionally do not set did_vacuum here */
/* be tidy */