@@ -84,6 +84,9 @@ static const char *spawn_partitions_bgw= "SpawnPartitionsWorker";
84
84
static const char * concurrent_part_bgw = "ConcurrentPartWorker" ;
85
85
86
86
87
+ /* Used for preventing spawn bgw recursion trouble */
88
+ static bool am_spawn_bgw = false;
89
+
87
90
/*
88
91
* Estimate amount of shmem needed for concurrent partitioning.
89
92
*/
@@ -312,6 +315,11 @@ create_partitions_for_value_bg_worker(Oid relid, Datum value, Oid value_type)
312
315
SpawnPartitionArgs * bgw_args ;
313
316
Oid child_oid = InvalidOid ;
314
317
318
+ if (am_spawn_bgw )
319
+ ereport (ERROR ,
320
+ (errmsg ("Attempt to spawn partition using bgw from bgw spawning partitions" ),
321
+ errhint ("Probably init_callback has INSERT to its table?" )));
322
+
315
323
/* Create a dsm segment for the worker to pass arguments */
316
324
segment = create_partitions_bg_worker_segment (relid ,value ,value_type );
317
325
segment_handle = dsm_segment_handle (segment );
@@ -363,6 +371,8 @@ bgw_main_spawn_partitions(Datum main_arg)
363
371
/* We're now ready to receive signals */
364
372
BackgroundWorkerUnblockSignals ();
365
373
374
+ am_spawn_bgw = true;
375
+
366
376
/* Create resource owner */
367
377
CurrentResourceOwner = ResourceOwnerCreate (NULL ,spawn_partitions_bgw );
368
378