diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index a47eba6..1f425d5 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -37,6 +37,12 @@
 
 
 /*
+ * Hook function to control the number of parallel workers that can
+ * be generated for a parallel query.
+ */
+number_of_parallel_workers_hook_type number_of_parallel_workers_hook;
+
+/*
  * We don't want to waste a lot of memory on an error queue which, most of
  * the time, will process only a handful of small messages.  However, it is
  * desirable to make it large enough that a typical ErrorResponse can be sent
@@ -436,9 +442,10 @@ LaunchParallelWorkers(ParallelContext *pcxt)
 	BackgroundWorker worker;
 	int			i;
 	bool		any_registrations_failed = false;
+	int 		nworkers = pcxt->nworkers;
 
 	/* Skip this if we have no workers. */
-	if (pcxt->nworkers == 0)
+	if (nworkers == 0)
 		return;
 
 	/* We need to be a lock group leader. */
@@ -462,6 +469,8 @@ LaunchParallelWorkers(ParallelContext *pcxt)
 	worker.bgw_notify_pid = MyProcPid;
 	memset(&worker.bgw_extra, 0, BGW_EXTRALEN);
 
+	if (number_of_parallel_workers_hook)
+		nworkers = Min(nworkers, number_of_parallel_workers_hook(nworkers));
 	/*
 	 * Start workers.
 	 *
@@ -470,7 +479,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
 	 * fails.  It wouldn't help much anyway, because registering the worker in
 	 * no way guarantees that it will start up and initialize successfully.
 	 */
-	for (i = 0; i < pcxt->nworkers; ++i)
+	for (i = 0; i < nworkers; ++i)
 	{
 		memcpy(worker.bgw_extra, &i, sizeof(int));
 		if (!any_registrations_failed &&
diff --git a/src/include/access/parallel.h b/src/include/access/parallel.h
index 2f8f36f..f587447 100644
--- a/src/include/access/parallel.h
+++ b/src/include/access/parallel.h
@@ -21,6 +21,9 @@
 #include "storage/shm_toc.h"
 
 typedef void (*parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc);
+typedef int (*number_of_parallel_workers_hook_type)(int nworkers);
+
+extern PGDLLIMPORT number_of_parallel_workers_hook_type number_of_parallel_workers_hook;
 
 typedef struct ParallelWorkerInfo
 {
