@@ -84,6 +84,9 @@ static const char *spawn_partitions_bgw= "SpawnPartitionsWorker";
8484static const char * concurrent_part_bgw = "ConcurrentPartWorker" ;
8585
8686
87+ /* Used for preventing spawn bgw recursion trouble */
88+ static bool am_spawn_bgw = false;
89+
8790/*
8891 * Estimate amount of shmem needed for concurrent partitioning.
8992 */
@@ -312,6 +315,11 @@ create_partitions_for_value_bg_worker(Oid relid, Datum value, Oid value_type)
312315SpawnPartitionArgs * bgw_args ;
313316Oid child_oid = InvalidOid ;
314317
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+
315323/* Create a dsm segment for the worker to pass arguments */
316324segment = create_partitions_bg_worker_segment (relid ,value ,value_type );
317325segment_handle = dsm_segment_handle (segment );
@@ -363,6 +371,8 @@ bgw_main_spawn_partitions(Datum main_arg)
363371/* We're now ready to receive signals */
364372BackgroundWorkerUnblockSignals ();
365373
374+ am_spawn_bgw = true;
375+
366376/* Create resource owner */
367377CurrentResourceOwner = ResourceOwnerCreate (NULL ,spawn_partitions_bgw );
368378