From 4658f72d6a1e4a9e0e91fa45e787a3ec186d3176 Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Wed, 5 Aug 2026 15:21:09 +0200 Subject: [PATCH 1/2] Propagate extension-script state to parallel workers creating_extension and CurrentExtensionObject are backend-local, so a parallel worker doing work for a CREATE/ALTER EXTENSION script (for example, executing a parallel-safe function's body) behaved as though no script were in progress. No visible effect on its own; preparation for the following commit. --- src/backend/access/transam/parallel.c | 9 +++++++++ src/backend/commands/extension.c | 24 ++++++++++++++++++++++++ src/include/commands/extension.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 17fcd246b0c..c5f67b2f992 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -26,6 +26,7 @@ #include "catalog/pg_enum.h" #include "catalog/storage.h" #include "commands/async.h" +#include "commands/extension.h" #include "commands/vacuum.h" #include "executor/execParallel.h" #include "libpq/libpq.h" @@ -90,9 +91,11 @@ typedef struct FixedParallelState Oid current_user_id; Oid temp_namespace_id; Oid temp_toast_namespace_id; + Oid current_extension_object; int sec_context; bool session_user_is_superuser; bool role_is_superuser; + bool creating_extension; PGPROC *parallel_leader_pgproc; pid_t parallel_leader_pid; ProcNumber parallel_leader_proc_number; @@ -348,6 +351,8 @@ InitializeParallelDSM(ParallelContext *pcxt) fps->role_is_superuser = current_role_is_superuser; GetTempNamespaceState(&fps->temp_namespace_id, &fps->temp_toast_namespace_id); + GetExtensionCreationState(&fps->creating_extension, + &fps->current_extension_object); fps->parallel_leader_pgproc = MyProc; fps->parallel_leader_pid = MyProcPid; fps->parallel_leader_proc_number = MyProcNumber; @@ -1534,6 +1539,10 @@ ParallelWorkerMain(Datum main_arg) SetTempNamespaceState(fps->temp_namespace_id, fps->temp_toast_namespace_id); + /* Restore extension-script state, so the worker matches the leader. */ + SetExtensionCreationState(fps->creating_extension, + fps->current_extension_object); + /* Restore uncommitted enums. */ uncommittedenumsspace = shm_toc_lookup(toc, PARALLEL_KEY_UNCOMMITTEDENUMS, false); diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index f7e7395c173..4e3b4494759 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -1509,6 +1509,30 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, SetUserIdAndSecContext(save_userid, save_sec_context); } +/* + * GetExtensionCreationState - report the current extension-script state + * + * Used by the parallel-query machinery to carry creating_extension and + * CurrentExtensionObject to workers, so a worker sees the same + * extension-script state as the leader. + */ +void +GetExtensionCreationState(bool *creating, Oid *extensionObject) +{ + *creating = creating_extension; + *extensionObject = CurrentExtensionObject; +} + +/* + * SetExtensionCreationState - restore extension-script state in a worker + */ +void +SetExtensionCreationState(bool creating, Oid extensionObject) +{ + creating_extension = creating; + CurrentExtensionObject = extensionObject; +} + /* * Find or create an ExtensionVersionInfo for the specified version name * diff --git a/src/include/commands/extension.h b/src/include/commands/extension.h index 7a76bdebcfa..8eaec2d4f68 100644 --- a/src/include/commands/extension.h +++ b/src/include/commands/extension.h @@ -32,6 +32,9 @@ extern PGDLLIMPORT char *Extension_control_path; extern PGDLLIMPORT bool creating_extension; extern PGDLLIMPORT Oid CurrentExtensionObject; +extern void GetExtensionCreationState(bool *creating, Oid *extensionObject); +extern void SetExtensionCreationState(bool creating, Oid extensionObject); + extern ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt); -- 2.47.3