@@ -85,29 +85,33 @@ void executor_worker_main(Datum arg)
85
85
86
86
CurrentResourceOwner = ResourceOwnerCreate (NULL , "pgpro_scheduler_executor" );
87
87
init_worker_mem_ctx ("ExecutorMemoryContext" );
88
+ pqsignal (SIGTERM , handle_sigterm );
89
+ pqsignal (SIGHUP , worker_spi_sighup );
90
+ /* must be called before connection initialization otherwise infint wait
91
+ * could happend if bgworker starts while one of 7th critical tables
92
+ * being locked
93
+ */
94
+ BackgroundWorkerUnblockSignals ();
88
95
89
96
seg = dsm_attach (DatumGetInt32 (arg ));
90
97
if (seg == NULL )
91
98
ereport (ERROR ,
92
99
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
93
100
errmsg ("executor unable to map dynamic shared memory segment" )));
94
101
shared = dsm_segment_address (seg );
95
- parent = BackendPidGetProc (MyBgworkerEntry -> bgw_notify_pid );
96
102
97
103
if (shared -> status != SchdExecutorInit )
98
104
{
99
105
ereport (ERROR ,
100
106
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
101
107
errmsg ("executor corrupted dynamic shared memory segment" )));
102
108
}
109
+ BackgroundWorkerInitializeConnection (shared -> database , NULL );
103
110
111
+ parent = BackendPidGetProc (MyBgworkerEntry -> bgw_notify_pid );
104
112
SetConfigOption ("application_name" , "pgp-s executor" , PGC_USERSET , PGC_S_SESSION );
105
113
pgstat_report_activity (STATE_RUNNING , "initialize" );
106
- BackgroundWorkerInitializeConnection (shared -> database , NULL );
107
114
108
- pqsignal (SIGTERM , handle_sigterm );
109
- pqsignal (SIGHUP , worker_spi_sighup );
110
- BackgroundWorkerUnblockSignals ();
111
115
112
116
worker_jobs_limit = read_worker_job_limit ();
113
117
@@ -667,6 +671,10 @@ void at_executor_worker_main(Datum arg)
667
671
668
672
CurrentResourceOwner = ResourceOwnerCreate (NULL , "pgpro_scheduler_at_executor" );
669
673
init_worker_mem_ctx ("ExecutorMemoryContext" );
674
+ pqsignal (SIGTERM , handle_sigterm );
675
+ pqsignal (SIGHUP , worker_spi_sighup );
676
+ BackgroundWorkerUnblockSignals ();
677
+
670
678
seg = dsm_attach (DatumGetInt32 (arg ));
671
679
if (seg == NULL )
672
680
ereport (ERROR ,
@@ -683,13 +691,9 @@ void at_executor_worker_main(Datum arg)
683
691
}
684
692
shared -> start_at = GetCurrentTimestamp ();
685
693
694
+ BackgroundWorkerInitializeConnection (shared -> database , NULL );
686
695
SetConfigOption ("application_name" , "pgp-s at executor" , PGC_USERSET , PGC_S_SESSION );
687
696
pgstat_report_activity (STATE_RUNNING , "initialize" );
688
- BackgroundWorkerInitializeConnection (shared -> database , NULL );
689
-
690
- pqsignal (SIGTERM , handle_sigterm );
691
- pqsignal (SIGHUP , worker_spi_sighup );
692
- BackgroundWorkerUnblockSignals ();
693
697
694
698
695
699
while (1 )
0 commit comments