Skip to content

Commit 82b3776

Browse files
committed
Fix a problem with parallel workers being unable to restore role.
check_role() tries to verify that the user has permission to become the requested role, but this is inappropriate in a parallel worker, which needs to exactly recreate the master's authorization settings. So skip the check in that case. This fixes a bug in commit 924bcf4.
1 parent 6de6d96 commit 82b3776

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/backend/access/transam/parallel.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ int ParallelWorkerNumber = -1;
9696
/* Is there a parallel message pending which we need to receive? */
9797
bool ParallelMessagePending = false;
9898

99+
/* Are we initializing a parallel worker? */
100+
bool InitializingParallelWorker = false;
101+
99102
/* Pointer to our fixed parallel state. */
100103
static FixedParallelState *MyFixedParallelState;
101104

@@ -815,6 +818,9 @@ ParallelWorkerMain(Datum main_arg)
815818
char *tstatespace;
816819
StringInfoData msgbuf;
817820

821+
/* Set flag to indicate that we're initializing a parallel worker. */
822+
InitializingParallelWorker = true;
823+
818824
/* Establish signal handlers. */
819825
pqsignal(SIGTERM, die);
820826
BackgroundWorkerUnblockSignals();
@@ -942,6 +948,7 @@ ParallelWorkerMain(Datum main_arg)
942948
* We've initialized all of our state now; nothing should change
943949
* hereafter.
944950
*/
951+
InitializingParallelWorker = false;
945952
EnterParallelMode();
946953

947954
/*

src/backend/commands/variable.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ctype.h>
2020

2121
#include "access/htup_details.h"
22+
#include "access/parallel.h"
2223
#include "access/xact.h"
2324
#include "access/xlog.h"
2425
#include "catalog/pg_authid.h"
@@ -877,9 +878,12 @@ check_role(char **newval, void **extra, GucSource source)
877878
ReleaseSysCache(roleTup);
878879

879880
/*
880-
* Verify that session user is allowed to become this role
881+
* Verify that session user is allowed to become this role, but
882+
* skip this in parallel mode, where we must blindly recreate the
883+
* parallel leader's state.
881884
*/
882-
if (!is_member_of_role(GetSessionUserId(), roleid))
885+
if (!InitializingParallelWorker &&
886+
!is_member_of_role(GetSessionUserId(), roleid))
883887
{
884888
GUC_check_errcode(ERRCODE_INSUFFICIENT_PRIVILEGE);
885889
GUC_check_errmsg("permission denied to set role \"%s\"",

src/include/access/parallel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct ParallelContext
4848

4949
extern bool ParallelMessagePending;
5050
extern int ParallelWorkerNumber;
51+
extern bool InitializingParallelWorker;
5152

5253
#define IsParallelWorker() (ParallelWorkerNumber >= 0)
5354

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy