Skip to content

Commit 98a4e81

Browse files
committed
Defer restoration of libraries in parallel workers.
Several users of extensions complained of crashes in parallel workers that turned out to be due to syscache access from their _PG_init() functions. Reorder the initialization of parallel workers so that libraries are restored after the caches are initialized, and inside a transaction. This was reported in bug #15350 and elsewhere. We don't consider it to be a bug: extensions shouldn't do that, because then they can't be used in shared_preload_libraries. However, it's a fairly obscure hazard and these extensions worked in practice before parallel query came along. So let's make it work. Later commits might add a warning message and eventually an error. Back-patch to 9.6, where parallel query landed. Author: Thomas Munro Reviewed-by: Amit Kapila Reported-by: Kieran McCusker, Jimmy Discussion: https://postgr.es/m/153512195228.1489.8545997741965926448%40wrigleys.postgresql.org
1 parent 82b7cfa commit 98a4e81

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/backend/access/transam/parallel.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,14 +1118,6 @@ ParallelWorkerMain(Datum main_arg)
11181118
fps->parallel_master_pid))
11191119
return;
11201120

1121-
/*
1122-
* Load libraries that were loaded by original backend. We want to do
1123-
* this before restoring GUCs, because the libraries might define custom
1124-
* variables.
1125-
*/
1126-
libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false);
1127-
RestoreLibraryState(libraryspace);
1128-
11291121
/*
11301122
* Identify the entry point to be called. In theory this could result in
11311123
* loading an additional library, though most likely the entry point is in
@@ -1147,9 +1139,17 @@ ParallelWorkerMain(Datum main_arg)
11471139
*/
11481140
SetClientEncoding(GetDatabaseEncoding());
11491141

1142+
/*
1143+
* Load libraries that were loaded by original backend. We want to do
1144+
* this before restoring GUCs, because the libraries might define custom
1145+
* variables.
1146+
*/
1147+
libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false);
1148+
StartTransactionCommand();
1149+
RestoreLibraryState(libraryspace);
1150+
11501151
/* Restore GUC values from launching backend. */
11511152
gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC, false);
1152-
StartTransactionCommand();
11531153
RestoreGUCState(gucspace);
11541154
CommitTransactionCommand();
11551155

0 commit comments

Comments
 (0)