diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index e09bdb20b0d9d56056a858989a652ad0de10a435..9c7428f5d6c6efdf4ca274001c1c384f4856c7dc 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -96,6 +96,9 @@ int			ParallelWorkerNumber = -1;
 /* Is there a parallel message pending which we need to receive? */
 bool		ParallelMessagePending = false;
 
+/* Are we initializing a parallel worker? */
+bool		InitializingParallelWorker = false;
+
 /* Pointer to our fixed parallel state. */
 static FixedParallelState *MyFixedParallelState;
 
@@ -815,6 +818,9 @@ ParallelWorkerMain(Datum main_arg)
 	char	   *tstatespace;
 	StringInfoData msgbuf;
 
+	/* Set flag to indicate that we're initializing a parallel worker. */
+	InitializingParallelWorker = true;
+
 	/* Establish signal handlers. */
 	pqsignal(SIGTERM, die);
 	BackgroundWorkerUnblockSignals();
@@ -942,6 +948,7 @@ ParallelWorkerMain(Datum main_arg)
 	 * We've initialized all of our state now; nothing should change
 	 * hereafter.
 	 */
+	InitializingParallelWorker = false;
 	EnterParallelMode();
 
 	/*
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 2d0a44effe797e7f3d0c297dd5efb7989743b0dc..16c122a22bc7f1916cd5b2a1f84fb622e380cc23 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -19,6 +19,7 @@
 #include <ctype.h>
 
 #include "access/htup_details.h"
+#include "access/parallel.h"
 #include "access/xact.h"
 #include "access/xlog.h"
 #include "catalog/pg_authid.h"
@@ -877,9 +878,12 @@ check_role(char **newval, void **extra, GucSource source)
 		ReleaseSysCache(roleTup);
 
 		/*
-		 * Verify that session user is allowed to become this role
+		 * Verify that session user is allowed to become this role, but
+		 * skip this in parallel mode, where we must blindly recreate the
+		 * parallel leader's state.
 		 */
-		if (!is_member_of_role(GetSessionUserId(), roleid))
+		if (!InitializingParallelWorker &&
+			!is_member_of_role(GetSessionUserId(), roleid))
 		{
 			GUC_check_errcode(ERRCODE_INSUFFICIENT_PRIVILEGE);
 			GUC_check_errmsg("permission denied to set role \"%s\"",
diff --git a/src/include/access/parallel.h b/src/include/access/parallel.h
index b029c1e88317fecb43916231bc22ccdea9d3f085..44f0616cb86547fbe96ca5e164a9fe51ac00f1b0 100644
--- a/src/include/access/parallel.h
+++ b/src/include/access/parallel.h
@@ -48,6 +48,7 @@ typedef struct ParallelContext
 
 extern bool ParallelMessagePending;
 extern int	ParallelWorkerNumber;
+extern bool InitializingParallelWorker;
 
 #define		IsParallelWorker()		(ParallelWorkerNumber >= 0)