diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index c168118467..cdaa32e29a 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -1311,14 +1311,6 @@ ParallelWorkerMain(Datum main_arg) fps->parallel_master_pid)) return; - /* - * Load libraries that were loaded by original backend. We want to do - * this before restoring GUCs, because the libraries might define custom - * variables. - */ - libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false); - RestoreLibraryState(libraryspace); - /* * Identify the entry point to be called. In theory this could result in * loading an additional library, though most likely the entry point is in @@ -1341,9 +1333,17 @@ ParallelWorkerMain(Datum main_arg) */ SetClientEncoding(GetDatabaseEncoding()); + /* + * Load libraries that were loaded by original backend. We want to do + * this before restoring GUCs, because the libraries might define custom + * variables. + */ + libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false); + StartTransactionCommand(); + RestoreLibraryState(libraryspace); + /* Restore GUC values from launching backend. */ gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC, false); - StartTransactionCommand(); RestoreGUCState(gucspace); CommitTransactionCommand();