|
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"
|
@@ -914,7 +915,23 @@ InitPostgres(const char *in_dbname, Oid dboid,
|
914 | 915 | {
|
915 | 916 | InitializeSessionUserId(username, useroid,
|
916 | 917 | (flags & INIT_PG_OVERRIDE_ROLE_LOGIN) != 0);
|
917 |
| - am_superuser = superuser(); |
| 918 | + |
| 919 | + /* |
| 920 | + * In a parallel worker, set am_superuser based on the |
| 921 | + * authenticated user ID, not the current role. This is pretty |
| 922 | + * dubious but it matches our historical behavior. Note that this |
| 923 | + * value of am_superuser is used only for connection-privilege |
| 924 | + * checks here and in CheckMyDatabase (we won't reach |
| 925 | + * process_startup_options in a background worker). |
| 926 | + * |
| 927 | + * In other cases, there's been no opportunity for the current |
| 928 | + * role to diverge from the authenticated user ID yet, so we can |
| 929 | + * just rely on superuser() and avoid an extra catalog lookup. |
| 930 | + */ |
| 931 | + if (InitializingParallelWorker) |
| 932 | + am_superuser = superuser_arg(GetAuthenticatedUserId()); |
| 933 | + else |
| 934 | + am_superuser = superuser(); |
918 | 935 | }
|
919 | 936 | }
|
920 | 937 | else
|
|
0 commit comments