aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2018-09-20 14:02:56 +1200
committerThomas Munro <tmunro@postgresql.org>2018-09-20 14:21:32 +1200
commit9d178fb928040f1a5ab5b566f1ec76d7ac554587 (patch)
tree2fcd77f89d2352b013920712bf2b76fa13b0ffdd
parent6449616419c59c3223b3c4f731cefa3d77fac567 (diff)
downloadpostgresql-9d178fb928040f1a5ab5b566f1ec76d7ac554587.tar.gz
postgresql-9d178fb928040f1a5ab5b566f1ec76d7ac554587.zip
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
-rw-r--r--src/backend/access/transam/parallel.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 1d631b72755..a9edf7b9e88 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -1304,14 +1304,6 @@ ParallelWorkerMain(Datum main_arg)
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
* the core backend or in a library we just loaded.
@@ -1333,9 +1325,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();