|
22 | 22 | #include "access/genam.h"
|
23 | 23 | #include "access/heapam.h"
|
24 | 24 | #include "access/htup_details.h"
|
| 25 | +#include "access/parallel.h" |
25 | 26 | #include "access/session.h"
|
26 | 27 | #include "access/tableam.h"
|
27 | 28 | #include "access/xact.h"
|
@@ -875,7 +876,23 @@ InitPostgres(const char *in_dbname, Oid dboid,
|
875 | 876 | {
|
876 | 877 | InitializeSessionUserId(username, useroid,
|
877 | 878 | (flags & INIT_PG_OVERRIDE_ROLE_LOGIN) != 0);
|
878 |
| - am_superuser = superuser(); |
| 879 | + |
| 880 | + /* |
| 881 | + * In a parallel worker, set am_superuser based on the |
| 882 | + * authenticated user ID, not the current role. This is pretty |
| 883 | + * dubious but it matches our historical behavior. Note that this |
| 884 | + * value of am_superuser is used only for connection-privilege |
| 885 | + * checks here and in CheckMyDatabase (we won't reach |
| 886 | + * process_startup_options in a background worker). |
| 887 | + * |
| 888 | + * In other cases, there's been no opportunity for the current |
| 889 | + * role to diverge from the authenticated user ID yet, so we can |
| 890 | + * just rely on superuser() and avoid an extra catalog lookup. |
| 891 | + */ |
| 892 | + if (InitializingParallelWorker) |
| 893 | + am_superuser = superuser_arg(GetAuthenticatedUserId()); |
| 894 | + else |
| 895 | + am_superuser = superuser(); |
879 | 896 | }
|
880 | 897 | }
|
881 | 898 | else
|
|
0 commit comments