postgresql获得max_parallel_workers是否能添加的状态(小试牛刀)

#include "postgres.h"
#include "miscadmin.h"
#include "fmgr.h"
#include <string.h>
#include "postmaster/bgworker.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

PG_FUNCTION_INFO_V1(get_worker_processes_status);

Datum
get_worker_processes_status(PG_FUNCTION_ARGS)
{

int32    i = PG_GETARG_INT32(0);
BackgroundWorker worker;
BackgroundWorkerHandle *handle;
BgwHandleStatus status;

text* greeting;
text* towhom;
char greet[] = "False";
int greetlen;
int towhomlen;

greetlen = strlen(greet);
towhomlen = VARSIZE(towhom) - VARHDRSZ;

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");
snprintf(worker.bgw_name, BGW_MAXLEN, "worker %d", i);
worker.bgw_main_arg = Int32GetDatum(i);
worker.bgw_notify_pid = MyProcPid;

towhomlen = VARSIZE(towhom) - VARHDRSZ;
greeting = (text*)palloc(greetlen + towhomlen);
VARATT_SIZEP(greeting) = greetlen + towhomlen + VARHDRSZ;

strncpy(VARDATA(greeting), greet, greetlen);
strncpy(VARDATA(greeting) + greetlen,
VARDATA(towhom),
towhomlen);

if (!RegisterDynamicBackgroundWorker(&worker, &handle))
{
PG_RETURN_TEXT_P(greeting);
}


}

 

 

上一篇:PHP constant() 函数


下一篇:C++ -string method - find, replace, size, append