> diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
> index bd626a16363..6d4a34257fb 100644
> --- a/src/backend/postmaster/autovacuum.c
> +++ b/src/backend/postmaster/autovacuum.c
> @@ -3327,7 +3327,15 @@ relation_needs_vacanalyze(Oid relid,
> anltuples, anlthresh, scores->anl,
> scores->xid, scores->mxid);
>
> - pfree(tabentry);
> + /*
> + * Avoid leaking pgstat entries until the end of autovacuum. Elsewhere,
> + * we let the commit/abort machinery take care of freeing it. While
> + * autovacuum workers set stats_fetch_consistency to "none", it might be
> + * set to a different value in other processes, so we can't safely free it
> + * here for them.
> + */
> + if (AmAutoVacuumWorkerProcess())
> + pfree(tabentry);
> }
This works too, but v1-0001 is more generalized and we don't have to
care about who the caller is when deciding to free or not.
--
Sami