diff --git a/src/postgres/src/backend/access/transam/parallel.c b/src/postgres/src/backend/access/transam/parallel.c index af0c624d4453..fbebfe22a287 100644 --- a/src/postgres/src/backend/access/transam/parallel.c +++ b/src/postgres/src/backend/access/transam/parallel.c @@ -1280,6 +1280,9 @@ ParallelWorkerMain(Datum main_arg) /* Set flag to indicate that we're initializing a parallel worker. */ InitializingParallelWorker = true; + if (YBIsEnabledInPostgresEnvVar()) + YbSetParallelWorker(); + /* Establish signal handlers. */ pqsignal(SIGTERM, die); BackgroundWorkerUnblockSignals(); diff --git a/src/postgres/src/backend/utils/misc/guc.c b/src/postgres/src/backend/utils/misc/guc.c index acf5c2aac1cf..bc6570c0ae9b 100644 --- a/src/postgres/src/backend/utils/misc/guc.c +++ b/src/postgres/src/backend/utils/misc/guc.c @@ -11595,6 +11595,12 @@ read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size) *srcptr += size; } +void YbSetParallelWorker() +{ + yb_is_parallel_worker = true; + elog(LOG, "yb_is_parallel_worker has been set to true"); +} + /* * RestoreGUCState: * Reads the GUC state at the specified address and updates the GUCs with the diff --git a/src/postgres/src/backend/utils/misc/pg_yb_utils.c b/src/postgres/src/backend/utils/misc/pg_yb_utils.c index d0dd1d019a8f..71e156e45f8e 100644 --- a/src/postgres/src/backend/utils/misc/pg_yb_utils.c +++ b/src/postgres/src/backend/utils/misc/pg_yb_utils.c @@ -4677,7 +4677,13 @@ bool yb_use_tserver_key_auth_check_hook(bool *newval, void **extra, GucSource source) { /* Allow setting yb_use_tserver_key_auth to false */ - if (!(*newval)) + /* + * Parallel workers are created and maintained by postmaster. So physical connections + * can never be of parallel worker type, therefore it makes no sense to restore + * or even do check/assign hooks for ysql connection manager specific guc variables + * on parallel worker process. + */ + if (!(*newval) || yb_is_parallel_worker == true) return true; /* diff --git a/src/postgres/src/backend/utils/misc/yb_ysql_conn_mgr_helper.c b/src/postgres/src/backend/utils/misc/yb_ysql_conn_mgr_helper.c index 7ba33352d52d..3c0c1a7b3539 100644 --- a/src/postgres/src/backend/utils/misc/yb_ysql_conn_mgr_helper.c +++ b/src/postgres/src/backend/utils/misc/yb_ysql_conn_mgr_helper.c @@ -68,6 +68,7 @@ #define YB_CREATE_SHMEM_FLAG 0666 | IPC_EXCL | IPC_CREAT bool yb_is_client_ysqlconnmgr = false; +bool yb_is_parallel_worker = false; enum SESSION_PARAMETER_UPDATE_RST { @@ -797,7 +798,13 @@ yb_is_client_ysqlconnmgr_check_hook(bool *newval, void **extra, GucSource source) { /* Allow setting yb_is_client_ysqlconnmgr as false */ - if (!(*newval)) + /* + * Parallel workers are created and maintained by postmaster. So physical connections + * can never be of parallel worker type, therefore it makes no sense to restore + * or even do check/assign hooks for ysql connection manager specific guc variables + * on parallel worker process. + */ + if (!(*newval) || yb_is_parallel_worker == true) return true; /* Client needs to be connected on unix domain socket */ @@ -821,7 +828,12 @@ yb_is_client_ysqlconnmgr_assign_hook(bool newval, void *extras) { yb_is_client_ysqlconnmgr = newval; - if (yb_is_client_ysqlconnmgr == true) + /* + * Parallel workers are created and maintained by postmaster. So physical connections + * can never be of parallel worker type, therefore it makes no sense to perform any + * ysql connection manager specific operations on it. + */ + if (yb_is_client_ysqlconnmgr == true && !yb_is_parallel_worker) send_oid_info('d', get_database_oid(MyProcPort->database_name, false)); } diff --git a/src/postgres/src/include/utils/guc.h b/src/postgres/src/include/utils/guc.h index 02fb8c17c5be..b059096057cb 100644 --- a/src/postgres/src/include/utils/guc.h +++ b/src/postgres/src/include/utils/guc.h @@ -422,6 +422,8 @@ extern void write_nondefault_variables(GucContext context); extern void read_nondefault_variables(void); #endif +extern void YbSetParallelWorker(); + /* GUC serialization */ extern Size EstimateGUCStateSpace(void); extern void SerializeGUCState(Size maxsize, char *start_address); diff --git a/src/postgres/src/include/yb_ysql_conn_mgr_helper.h b/src/postgres/src/include/yb_ysql_conn_mgr_helper.h index 23117cf45d01..f59b00749c29 100644 --- a/src/postgres/src/include/yb_ysql_conn_mgr_helper.h +++ b/src/postgres/src/include/yb_ysql_conn_mgr_helper.h @@ -35,6 +35,12 @@ */ extern bool yb_is_client_ysqlconnmgr; +/* + * `yb_is_parallel_worker` is used to identify that whether background worker is + * of parallel worker type. +*/ +extern bool yb_is_parallel_worker; + /* TODO (janand): Write a function to read/change yb_logical_client_shmem_key */ extern int yb_logical_client_shmem_key;