Re: Block level parallel vacuum

Mahendra Singh Thalor <[email protected]> Fri, 10 Jan 2020 17:24:44 +0530
Newsgroups gmane.comp.db.postgresql.devel.general
Message-ID <CAKYtNAroXD9C5bAiqne1KZV0vpEhfKZqbinH4AW9pDV_V9KYgQ@mail.gmail.com>
On Fri, 10 Jan 2020 at 15:51, Sergei Kornilov <[email protected]> wrote:
>
> Hi
> Thank you for update! I looked again
>
> (vacuum_indexes_leader)
> +               /* Skip the indexes that can be processed by parallel workers */
> +               if (!skip_index)
> +                       continue;
>
> Does the variable name skip_index not confuse here? Maybe rename to something like can_parallel?

I also agree with your point.

>
> Another question about behavior on temporary tables. Use case: the user commands just "vacuum;" to vacuum entire database (and has enough maintenance workers). Vacuum starts fine in parallel, but on first temporary table we hit:
>
> +       if (RelationUsesLocalBuffers(onerel) && params->nworkers >= 0)
> +       {
> +               ereport(WARNING,
> +                               (errmsg("disabling parallel option of vacuum on \"%s\" --- cannot vacuum temporary tables in parallel",
> +                                               RelationGetRelationName(onerel))));
> +               params->nworkers = -1;
> +       }
>
> And therefore we turn off the parallel vacuum for the remaining tables... Can we improve this case?

Good point.
Yes, we should improve this. I tried to fix this.  Attaching a delta
patch that is fixing both the comments.

-- 
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com
v44-0002-delta_Allow-vacuum-command-to-process-indexes-in-parallel.patch (application/octet-stream, 1.6 KB)
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index f12c41f..d4ffd1b 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -2158,11 +2158,12 @@ vacuum_indexes_leader(Relation *Irel, IndexBulkDeleteResult **stats,
 
 	for (i = 0; i < nindexes; i++)
 	{
-		bool		skip_index = (get_indstats(lps->lvshared, i) == NULL ||
-								  skip_parallel_vacuum_index(Irel[i], lps->lvshared));
+		bool		can_parallel = (get_indstats(lps->lvshared, i) == NULL ||
+									skip_parallel_vacuum_index(Irel[i],
+															   lps->lvshared));
 
 		/* Skip the indexes that can be processed by parallel workers */
-		if (!skip_index)
+		if (!can_parallel)
 			continue;
 
 		vacuum_one_index(Irel[i], &(stats[i]), lps->lvshared,
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 6526cc1..a32fe28 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -430,6 +430,7 @@ vacuum(List *relations, VacuumParams *params,
 	PG_TRY();
 	{
 		ListCell   *cur;
+		int			nworkers = params->nworkers;
 
 		in_vacuum = true;
 		VacuumCostActive = (VacuumCostDelay > 0);
@@ -446,6 +447,14 @@ vacuum(List *relations, VacuumParams *params,
 		{
 			VacuumRelation *vrel = lfirst_node(VacuumRelation, cur);
 
+			/*
+			 * Copy the number of workers.  It is possible that we might
+			 * reseted nworkers to -1 to disable parallel vacuum for temp
+			 * tables.
+			 */
+			if (nworkers != params->nworkers)
+				params->nworkers = nworkers;
+
 			if (params->options & VACOPT_VACUUM)
 			{
 				if (!vacuum_rel(vrel->oid, vrel->relation, params))