diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 194a1207be..7c39903249 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -1430,13 +1430,18 @@ ParallelWorkerMain(Datum main_arg) * variables. */ libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false); - StartTransactionCommand(); RestoreLibraryState(libraryspace); - /* Restore GUC values from launching backend. */ + /* + * Restore GUC values from launching backend. We want to do this without + * starting a transaction as some GUC check hook functions require catalog + * access. It may be unsafe to access the catalogs as, for example, + * reading buffer to load a catalog page may require writing dirty buffers + * and we don't want to do that until I/O related GUCs such as fsync are + * correctly set. + */ gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC, false); RestoreGUCState(gucspace); - CommitTransactionCommand(); /* Crank up a transaction state appropriate to a parallel worker. */ tstatespace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_STATE, false); diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c index c361bb2079..a52ed5fa75 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -813,6 +813,14 @@ check_session_authorization(char **newval, void **extra, GucSource source) if (!IsTransactionState()) { + /* + * If we're a parallel worker being started up, there's no need to + * verify the role exists. We'll end up running the same snapshot as + * the leader process anyway so the role must exist. + */ + if (InitializingParallelWorker) + return true; + /* * Can't do catalog lookups, so fail. The result of this is that * session_authorization cannot be set in postgresql.conf, which seems