src/test/modules/worker_spi/worker_spi.c
void
_PG_init(void)
{
	BackgroundWorker worker;

	/* get the configuration */
	DefineCustomIntVariable("worker_spi.naptime",
							"Duration between each check (in seconds).",
							NULL,
							&worker_spi_naptime,
							10,
							1,
							INT_MAX,
							PGC_SIGHUP,
							0,
							NULL,
							NULL,
							NULL);

	if (!process_shared_preload_libraries_in_progress)
		return;

	DefineCustomIntVariable("worker_spi.total_workers",
							"Number of workers.",
							NULL,
							&worker_spi_total_workers,
							2,
							1,
							100,
							PGC_POSTMASTER,
							0,
							NULL,
							NULL,
							NULL);

	DefineCustomStringVariable("worker_spi.database",
							   "Database to connect to.",
							   NULL,
							   &worker_spi_database,
							   "postgres",
							   PGC_POSTMASTER,
							   0,
							   NULL, NULL, NULL);

	EmitWarningsOnPlaceholders("worker_spi");

	/* set up common data for all our workers */
	memset(&worker, 0, sizeof(worker));
	worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
		BGWORKER_BACKEND_DATABASE_CONNECTION;
	worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
	worker.bgw_restart_time = BGW_NEVER_RESTART;
	sprintf(worker.bgw_library_name, "worker_spi");
	sprintf(worker.bgw_function_name, "worker_spi_main");
	worker.bgw_notify_pid = 0;

	/*
	 * Now fill in worker-specific data, and do the actual registrations.
	 */
	for (int i = 1; i <= worker_spi_total_workers; i++)
	{
		snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi worker %d", i);
		snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi");
		worker.bgw_main_arg = Int32GetDatum(i);

		RegisterBackgroundWorker(&worker);
	}
}
/*
 * Entrypoint of this module.
 *
 * We register more than one worker process here, to demonstrate how that can
 * be done.
 */
Entrypoint of this module.
We register more than one worker process here, to demonstrate how that can
be done.
Entrypoint of this module . We register more than one worker process here to demonstrate how that can be done .
void
_PG_init(void)
{
	BackgroundWorker worker;
	DefineCustomIntVariable("worker_spi.naptime",
							"Duration between each check (in seconds).",
							NULL,
							&worker_spi_naptime,
							10,
							1,
							INT_MAX,
							PGC_SIGHUP,
							0,
							NULL,
							NULL,
							NULL);
	if (!process_shared_preload_libraries_in_progress)
		return;
	DefineCustomIntVariable("worker_spi.total_workers",
							"Number of workers.",
							NULL,
							&worker_spi_total_workers,
							2,
							1,
							100,
							PGC_POSTMASTER,
							0,
							NULL,
							NULL,
							NULL);
	DefineCustomStringVariable("worker_spi.database",
							   "Database to connect to.",
							   NULL,
							   &worker_spi_database,
							   "postgres",
							   PGC_POSTMASTER,
							   0,
							   NULL, NULL, NULL);
	EmitWarningsOnPlaceholders("worker_spi");
	memset(&worker, 0, sizeof(worker));
	worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
		BGWORKER_BACKEND_DATABASE_CONNECTION;
	worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
	worker.bgw_restart_time = BGW_NEVER_RESTART;
	sprintf(worker.bgw_library_name, "worker_spi");
	sprintf(worker.bgw_function_name, "worker_spi_main");
	worker.bgw_notify_pid = 0;
	for (int i = 1; i <= worker_spi_total_workers; i++)
	{
		snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi worker %d", i);
		snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi");
		worker.bgw_main_arg = Int32GetDatum(i);
		RegisterBackgroundWorker(&worker);
	}
}
void _PG_init ( void ) { BackgroundWorker worker ; DefineCustomIntVariable ( " " , " " , NULL , & worker_spi_naptime , 10 , 1 , INT_MAX , PGC_SIGHUP , 0 , NULL , NULL , NULL ) ; if ( ! process_shared_preload_libraries_in_progress ) return ; DefineCustomIntVariable ( " " , " " , NULL , & worker_spi_total_workers , 2 , 1 , 100 , PGC_POSTMASTER , 0 , NULL , NULL , NULL ) ; DefineCustomStringVariable ( " " , " " , NULL , & worker_spi_database , " " , PGC_POSTMASTER , 0 , NULL , NULL , NULL ) ; EmitWarningsOnPlaceholders ( " " ) ; memset ( & worker , 0 , sizeof ( worker ) ) ; worker . bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION ; worker . bgw_start_time = BgWorkerStart_RecoveryFinished ; worker . bgw_restart_time = BGW_NEVER_RESTART ; sprintf ( worker . bgw_library_name , " " ) ; sprintf ( worker . bgw_function_name , " " ) ; worker . bgw_notify_pid = 0 ; for ( int i = 1 ; i <= worker_spi_total_workers ; i ++ ) { snprintf ( worker . bgw_name , BGW_MAXLEN , " " , i ) ; snprintf ( worker . bgw_type , BGW_MAXLEN , " " ) ; worker . bgw_main_arg = Int32GetDatum ( i ) ; RegisterBackgroundWorker ( & worker ) ; } }
Entrypoint of this module.
Entrypoint of this module .
/* get the configuration */ /* set up common data for all our workers */ /*
	 * Now fill in worker-specific data, and do the actual registrations.
	 */