PostgreSQL Source Code  git master
worker_spi.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "postmaster/bgworker.h"
#include "postmaster/interrupt.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lwlock.h"
#include "storage/proc.h"
#include "storage/shmem.h"
#include "access/xact.h"
#include "commands/dbcommands.h"
#include "executor/spi.h"
#include "fmgr.h"
#include "lib/stringinfo.h"
#include "pgstat.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/snapmgr.h"
Include dependency graph for worker_spi.c:

Go to the source code of this file.

Data Structures

struct  worktable
 

Typedefs

typedef struct worktable worktable
 

Functions

 PG_FUNCTION_INFO_V1 (worker_spi_launch)
 
PGDLLEXPORT void worker_spi_main (Datum main_arg) pg_attribute_noreturn()
 
static void initialize_worker_spi (worktable *table)
 
void _PG_init (void)
 
Datum worker_spi_launch (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static int worker_spi_naptime = 10
 
static int worker_spi_total_workers = 2
 
static char * worker_spi_database = NULL
 
static char * worker_spi_role = NULL
 
static uint32 worker_spi_wait_event_main = 0
 

Typedef Documentation

◆ worktable

typedef struct worktable worktable

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 316 of file worker_spi.c.

317 {
318  BackgroundWorker worker;
319 
320  /* get the configuration */
321 
322  /*
323  * These GUCs are defined even if this library is not loaded with
324  * shared_preload_libraries, for worker_spi_launch().
325  */
326  DefineCustomIntVariable("worker_spi.naptime",
327  "Duration between each check (in seconds).",
328  NULL,
330  10,
331  1,
332  INT_MAX,
333  PGC_SIGHUP,
334  0,
335  NULL,
336  NULL,
337  NULL);
338 
339  DefineCustomStringVariable("worker_spi.database",
340  "Database to connect to.",
341  NULL,
343  "postgres",
344  PGC_SIGHUP,
345  0,
346  NULL, NULL, NULL);
347 
348  DefineCustomStringVariable("worker_spi.role",
349  "Role to connect with.",
350  NULL,
352  NULL,
353  PGC_SIGHUP,
354  0,
355  NULL, NULL, NULL);
356 
358  return;
359 
360  DefineCustomIntVariable("worker_spi.total_workers",
361  "Number of workers.",
362  NULL,
364  2,
365  1,
366  100,
368  0,
369  NULL,
370  NULL,
371  NULL);
372 
373  MarkGUCPrefixReserved("worker_spi");
374 
375  /* set up common data for all our workers */
376  memset(&worker, 0, sizeof(worker));
381  sprintf(worker.bgw_library_name, "worker_spi");
382  sprintf(worker.bgw_function_name, "worker_spi_main");
383  worker.bgw_notify_pid = 0;
384 
385  /*
386  * Now fill in worker-specific data, and do the actual registrations.
387  *
388  * bgw_extra can optionally include a database OID, a role OID and a set
389  * of flags. This is left empty here to fallback to the related GUCs at
390  * startup (0 for the bgworker flags).
391  */
392  for (int i = 1; i <= worker_spi_total_workers; i++)
393  {
394  snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi worker %d", i);
395  snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi");
396  worker.bgw_main_arg = Int32GetDatum(i);
397 
398  RegisterBackgroundWorker(&worker);
399  }
400 }
void RegisterBackgroundWorker(BackgroundWorker *worker)
Definition: bgworker.c:939
#define BGW_NEVER_RESTART
Definition: bgworker.h:85
@ BgWorkerStart_RecoveryFinished
Definition: bgworker.h:81
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:60
#define BGWORKER_SHMEM_ACCESS
Definition: bgworker.h:53
#define BGW_MAXLEN
Definition: bgworker.h:86
void DefineCustomStringVariable(const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
Definition: guc.c:5176
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:5237
void DefineCustomIntVariable(const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
Definition: guc.c:5116
@ PGC_POSTMASTER
Definition: guc.h:70
@ PGC_SIGHUP
Definition: guc.h:71
int i
Definition: isn.c:73
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1778
#define sprintf
Definition: port.h:240
#define snprintf
Definition: port.h:238
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
char bgw_function_name[BGW_MAXLEN]
Definition: bgworker.h:97
Datum bgw_main_arg
Definition: bgworker.h:98
char bgw_name[BGW_MAXLEN]
Definition: bgworker.h:91
int bgw_restart_time
Definition: bgworker.h:95
char bgw_type[BGW_MAXLEN]
Definition: bgworker.h:92
BgWorkerStartTime bgw_start_time
Definition: bgworker.h:94
pid_t bgw_notify_pid
Definition: bgworker.h:100
char bgw_library_name[MAXPGPATH]
Definition: bgworker.h:96
static int worker_spi_naptime
Definition: worker_spi.c:54
static char * worker_spi_database
Definition: worker_spi.c:56
static int worker_spi_total_workers
Definition: worker_spi.c:55
static char * worker_spi_role
Definition: worker_spi.c:57

References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_SHMEM_ACCESS, BgWorkerStart_RecoveryFinished, DefineCustomIntVariable(), DefineCustomStringVariable(), i, Int32GetDatum(), MarkGUCPrefixReserved(), PGC_POSTMASTER, PGC_SIGHUP, process_shared_preload_libraries_in_progress, RegisterBackgroundWorker(), snprintf, sprintf, worker_spi_database, worker_spi_naptime, worker_spi_role, and worker_spi_total_workers.

◆ initialize_worker_spi()

static void initialize_worker_spi ( worktable table)
static

Definition at line 73 of file worker_spi.c.

74 {
75  int ret;
76  int ntup;
77  bool isnull;
79 
82  SPI_connect();
84  pgstat_report_activity(STATE_RUNNING, "initializing worker_spi schema");
85 
86  /* XXX could we use CREATE SCHEMA IF NOT EXISTS? */
88  appendStringInfo(&buf, "select count(*) from pg_namespace where nspname = '%s'",
89  table->schema);
90 
91  debug_query_string = buf.data;
92  ret = SPI_execute(buf.data, true, 0);
93  if (ret != SPI_OK_SELECT)
94  elog(FATAL, "SPI_execute failed: error code %d", ret);
95 
96  if (SPI_processed != 1)
97  elog(FATAL, "not a singleton result");
98 
101  1, &isnull));
102  if (isnull)
103  elog(FATAL, "null result");
104 
105  if (ntup == 0)
106  {
107  debug_query_string = NULL;
110  "CREATE SCHEMA \"%s\" "
111  "CREATE TABLE \"%s\" ("
112  " type text CHECK (type IN ('total', 'delta')), "
113  " value integer)"
114  "CREATE UNIQUE INDEX \"%s_unique_total\" ON \"%s\" (type) "
115  "WHERE type = 'total'",
116  table->schema, table->name, table->name, table->name);
117 
118  /* set statement start time */
120 
121  debug_query_string = buf.data;
122  ret = SPI_execute(buf.data, false, 0);
123 
124  if (ret != SPI_OK_UTILITY)
125  elog(FATAL, "failed to create my schema");
126 
127  debug_query_string = NULL; /* rest is not statement-specific */
128  }
129 
130  SPI_finish();
133  debug_query_string = NULL;
135 }
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_IDLE
@ STATE_RUNNING
#define FATAL
Definition: elog.h:41
#define elog(elevel,...)
Definition: elog.h:225
static char * buf
Definition: pg_test_fsync.c:73
const char * debug_query_string
Definition: postgres.c:88
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:385
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:216
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:648
void PopActiveSnapshot(void)
Definition: snapmgr.c:743
uint64 SPI_processed
Definition: spi.c:44
SPITupleTable * SPI_tuptable
Definition: spi.c:45
int SPI_connect(void)
Definition: spi.c:94
int SPI_finish(void)
Definition: spi.c:182
int SPI_execute(const char *src, bool read_only, long tcount)
Definition: spi.c:593
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:1249
#define SPI_OK_UTILITY
Definition: spi.h:85
#define SPI_OK_SELECT
Definition: spi.h:86
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:78
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
TupleDesc tupdesc
Definition: spi.h:25
HeapTuple * vals
Definition: spi.h:26
const char * name
Definition: worker_spi.c:65
const char * schema
Definition: worker_spi.c:64
void StartTransactionCommand(void)
Definition: xact.c:3039
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:913
void CommitTransactionCommand(void)
Definition: xact.c:3137

References appendStringInfo(), buf, CommitTransactionCommand(), DatumGetInt64(), debug_query_string, elog, FATAL, GetTransactionSnapshot(), initStringInfo(), worktable::name, pgstat_report_activity(), PopActiveSnapshot(), PushActiveSnapshot(), resetStringInfo(), worktable::schema, SetCurrentStatementStartTimestamp(), SPI_connect(), SPI_execute(), SPI_finish(), SPI_getbinval(), SPI_OK_SELECT, SPI_OK_UTILITY, SPI_processed, SPI_tuptable, StartTransactionCommand(), STATE_IDLE, STATE_RUNNING, SPITupleTable::tupdesc, and SPITupleTable::vals.

Referenced by worker_spi_main().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( worker_spi_launch  )

◆ worker_spi_launch()

Datum worker_spi_launch ( PG_FUNCTION_ARGS  )

Definition at line 406 of file worker_spi.c.

407 {
408  int32 i = PG_GETARG_INT32(0);
409  Oid dboid = PG_GETARG_OID(1);
410  Oid roleoid = PG_GETARG_OID(2);
411  BackgroundWorker worker;
412  BackgroundWorkerHandle *handle;
413  BgwHandleStatus status;
414  pid_t pid;
415  char *p;
416  bits32 flags = 0;
418  Size ndim;
419  int nelems;
420  Datum *datum_flags;
421 
422  memset(&worker, 0, sizeof(worker));
427  sprintf(worker.bgw_library_name, "worker_spi");
428  sprintf(worker.bgw_function_name, "worker_spi_main");
429  snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi dynamic worker %d", i);
430  snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi dynamic");
431  worker.bgw_main_arg = Int32GetDatum(i);
432  /* set bgw_notify_pid so that we can use WaitForBackgroundWorkerStartup */
433  worker.bgw_notify_pid = MyProcPid;
434 
435  /* extract flags, if any */
436  ndim = ARR_NDIM(arr);
437  if (ndim > 1)
438  ereport(ERROR,
439  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
440  errmsg("flags array must be one-dimensional")));
441 
442  if (array_contains_nulls(arr))
443  ereport(ERROR,
444  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
445  errmsg("flags array must not contain nulls")));
446 
447  Assert(ARR_ELEMTYPE(arr) == TEXTOID);
448  deconstruct_array_builtin(arr, TEXTOID, &datum_flags, NULL, &nelems);
449 
450  for (i = 0; i < nelems; i++)
451  {
452  char *optname = TextDatumGetCString(datum_flags[i]);
453 
454  if (strcmp(optname, "ALLOWCONN") == 0)
455  flags |= BGWORKER_BYPASS_ALLOWCONN;
456  else if (strcmp(optname, "ROLELOGINCHECK") == 0)
458  else
459  ereport(ERROR,
460  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
461  errmsg("incorrect flag value found in array")));
462  }
463 
464  /*
465  * Register database and role to use for the worker started in bgw_extra.
466  * If none have been provided, this will fall back to the GUCs at startup.
467  */
468  if (!OidIsValid(dboid))
469  dboid = get_database_oid(worker_spi_database, false);
470 
471  /*
472  * worker_spi_role is NULL by default, so this gives to worker_spi_main()
473  * an invalid OID in this case.
474  */
475  if (!OidIsValid(roleoid) && worker_spi_role)
476  roleoid = get_role_oid(worker_spi_role, false);
477 
478  p = worker.bgw_extra;
479  memcpy(p, &dboid, sizeof(Oid));
480  p += sizeof(Oid);
481  memcpy(p, &roleoid, sizeof(Oid));
482  p += sizeof(Oid);
483  memcpy(p, &flags, sizeof(bits32));
484 
485  if (!RegisterDynamicBackgroundWorker(&worker, &handle))
486  PG_RETURN_NULL();
487 
488  status = WaitForBackgroundWorkerStartup(handle, &pid);
489 
490  if (status == BGWH_STOPPED)
491  ereport(ERROR,
492  (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
493  errmsg("could not start background process"),
494  errhint("More details may be available in the server log.")));
495  if (status == BGWH_POSTMASTER_DIED)
496  ereport(ERROR,
497  (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
498  errmsg("cannot start background processes without postmaster"),
499  errhint("Kill all remaining database processes and restart the database.")));
500  Assert(status == BGWH_STARTED);
501 
502  PG_RETURN_INT32(pid);
503 }
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5554
#define ARR_NDIM(a)
Definition: array.h:290
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:263
#define ARR_ELEMTYPE(a)
Definition: array.h:292
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3767
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3697
BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1212
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
Definition: bgworker.c:1045
#define BGWORKER_BYPASS_ROLELOGINCHECK
Definition: bgworker.h:157
BgwHandleStatus
Definition: bgworker.h:104
@ BGWH_POSTMASTER_DIED
Definition: bgworker.h:108
@ BGWH_STARTED
Definition: bgworker.h:105
@ BGWH_STOPPED
Definition: bgworker.h:107
#define BGWORKER_BYPASS_ALLOWCONN
Definition: bgworker.h:156
#define TextDatumGetCString(d)
Definition: builtins.h:98
signed int int32
Definition: c.h:496
#define Assert(condition)
Definition: c.h:849
uint32 bits32
Definition: c.h:514
#define OidIsValid(objectId)
Definition: c.h:766
size_t Size
Definition: c.h:596
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:3140
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int MyProcPid
Definition: globals.c:46
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
char bgw_extra[BGW_EXTRALEN]
Definition: bgworker.h:99

References ARR_ELEMTYPE, ARR_NDIM, array_contains_nulls(), Assert, BackgroundWorker::bgw_extra, BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWH_POSTMASTER_DIED, BGWH_STARTED, BGWH_STOPPED, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_BYPASS_ALLOWCONN, BGWORKER_BYPASS_ROLELOGINCHECK, BGWORKER_SHMEM_ACCESS, BgWorkerStart_RecoveryFinished, deconstruct_array_builtin(), ereport, errcode(), errhint(), errmsg(), ERROR, get_database_oid(), get_role_oid(), i, Int32GetDatum(), MyProcPid, OidIsValid, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_INT32, PG_RETURN_NULL, RegisterDynamicBackgroundWorker(), snprintf, sprintf, TextDatumGetCString, WaitForBackgroundWorkerStartup(), worker_spi_database, and worker_spi_role.

◆ worker_spi_main()

void worker_spi_main ( Datum  main_arg)

Definition at line 138 of file worker_spi.c.

139 {
140  int index = DatumGetInt32(main_arg);
141  worktable *table;
143  char name[20];
144  Oid dboid;
145  Oid roleoid;
146  char *p;
147  bits32 flags = 0;
148 
149  table = palloc(sizeof(worktable));
150  sprintf(name, "schema%d", index);
151  table->schema = pstrdup(name);
152  table->name = pstrdup("counted");
153 
154  /* fetch database and role OIDs, these are set for a dynamic worker */
156  memcpy(&dboid, p, sizeof(Oid));
157  p += sizeof(Oid);
158  memcpy(&roleoid, p, sizeof(Oid));
159  p += sizeof(Oid);
160  memcpy(&flags, p, sizeof(bits32));
161 
162  /* Establish signal handlers before unblocking signals. */
164  pqsignal(SIGTERM, die);
165 
166  /* We're now ready to receive signals */
168 
169  /* Connect to our database */
170  if (OidIsValid(dboid))
171  BackgroundWorkerInitializeConnectionByOid(dboid, roleoid, flags);
172  else
174  worker_spi_role, flags);
175 
176  /*
177  * Disable parallel query for workers started with
178  * BGWORKER_BYPASS_ALLOWCONN or BGWORKER_BYPASS_ROLELOGINCHECK so as these
179  * don't attempt connections using a database or a role that may not allow
180  * that.
181  */
183  SetConfigOption("max_parallel_workers_per_gather", "0",
185 
186  elog(LOG, "%s initialized with %s.%s",
187  MyBgworkerEntry->bgw_name, table->schema, table->name);
188  initialize_worker_spi(table);
189 
190  /*
191  * Quote identifiers passed to us. Note that this must be done after
192  * initialize_worker_spi, because that routine assumes the names are not
193  * quoted.
194  *
195  * Note some memory might be leaked here.
196  */
197  table->schema = quote_identifier(table->schema);
198  table->name = quote_identifier(table->name);
199 
202  "WITH deleted AS (DELETE "
203  "FROM %s.%s "
204  "WHERE type = 'delta' RETURNING value), "
205  "total AS (SELECT coalesce(sum(value), 0) as sum "
206  "FROM deleted) "
207  "UPDATE %s.%s "
208  "SET value = %s.value + total.sum "
209  "FROM total WHERE type = 'total' "
210  "RETURNING %s.value",
211  table->schema, table->name,
212  table->schema, table->name,
213  table->name,
214  table->name);
215 
216  /*
217  * Main loop: do this until SIGTERM is received and processed by
218  * ProcessInterrupts.
219  */
220  for (;;)
221  {
222  int ret;
223 
224  /* First time, allocate or get the custom wait event */
227 
228  /*
229  * Background workers mustn't call usleep() or any direct equivalent:
230  * instead, they may wait on their process latch, which sleeps as
231  * necessary, but is awakened if postmaster dies. That way the
232  * background process goes away immediately in an emergency.
233  */
234  (void) WaitLatch(MyLatch,
236  worker_spi_naptime * 1000L,
239 
241 
242  /*
243  * In case of a SIGHUP, just reload the configuration.
244  */
246  {
247  ConfigReloadPending = false;
249  }
250 
251  /*
252  * Start a transaction on which we can run queries. Note that each
253  * StartTransactionCommand() call should be preceded by a
254  * SetCurrentStatementStartTimestamp() call, which sets both the time
255  * for the statement we're about the run, and also the transaction
256  * start time. Also, each other query sent to SPI should probably be
257  * preceded by SetCurrentStatementStartTimestamp(), so that statement
258  * start time is always up to date.
259  *
260  * The SPI_connect() call lets us run queries through the SPI manager,
261  * and the PushActiveSnapshot() call creates an "active" snapshot
262  * which is necessary for queries to have MVCC data to work on.
263  *
264  * The pgstat_report_activity() call makes our activity visible
265  * through the pgstat views.
266  */
269  SPI_connect();
271  debug_query_string = buf.data;
273 
274  /* We can now execute queries via SPI */
275  ret = SPI_execute(buf.data, false, 0);
276 
277  if (ret != SPI_OK_UPDATE_RETURNING)
278  elog(FATAL, "cannot select from table %s.%s: error code %d",
279  table->schema, table->name, ret);
280 
281  if (SPI_processed > 0)
282  {
283  bool isnull;
284  int32 val;
285 
288  1, &isnull));
289  if (!isnull)
290  elog(LOG, "%s: count in %s.%s is now %d",
292  table->schema, table->name, val);
293  }
294 
295  /*
296  * And finish our transaction.
297  */
298  SPI_finish();
301  debug_query_string = NULL;
302  pgstat_report_stat(true);
304  }
305 
306  /* Not reachable */
307 }
void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, uint32 flags)
Definition: bgworker.c:852
void BackgroundWorkerUnblockSignals(void)
Definition: bgworker.c:926
void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)
Definition: bgworker.c:886
#define LOG
Definition: elog.h:31
struct Latch * MyLatch
Definition: globals.c:62
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4290
@ PGC_S_OVERRIDE
Definition: guc.h:119
@ PGC_USERSET
Definition: guc.h:75
void ProcessConfigFile(GucContext context)
long val
Definition: informix.c:689
volatile sig_atomic_t ConfigReloadPending
Definition: interrupt.c:27
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:61
void ResetLatch(Latch *latch)
Definition: latch.c:724
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:517
#define WL_TIMEOUT
Definition: latch.h:130
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:132
#define WL_LATCH_SET
Definition: latch.h:127
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void * palloc(Size size)
Definition: mcxt.c:1317
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
#define die(msg)
long pgstat_report_stat(bool force)
Definition: pgstat.c:660
pqsigfunc pqsignal(int signo, pqsigfunc func)
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:181
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12840
#define SPI_OK_UPDATE_RETURNING
Definition: spi.h:94
Definition: type.h:95
uint32 WaitEventExtensionNew(const char *wait_event_name)
Definition: wait_event.c:164
const char * name
#define SIGHUP
Definition: win32_port.h:168
static void initialize_worker_spi(worktable *table)
Definition: worker_spi.c:73
static uint32 worker_spi_wait_event_main
Definition: worker_spi.c:60

References appendStringInfo(), BackgroundWorkerInitializeConnection(), BackgroundWorkerInitializeConnectionByOid(), BackgroundWorkerUnblockSignals(), BackgroundWorker::bgw_extra, BackgroundWorker::bgw_name, BGWORKER_BYPASS_ALLOWCONN, BGWORKER_BYPASS_ROLELOGINCHECK, buf, CHECK_FOR_INTERRUPTS, CommitTransactionCommand(), ConfigReloadPending, DatumGetInt32(), debug_query_string, die, elog, FATAL, GetTransactionSnapshot(), initialize_worker_spi(), initStringInfo(), LOG, MyBgworkerEntry, MyLatch, name, worktable::name, OidIsValid, palloc(), PGC_S_OVERRIDE, PGC_SIGHUP, PGC_USERSET, pgstat_report_activity(), pgstat_report_stat(), PopActiveSnapshot(), pqsignal(), ProcessConfigFile(), pstrdup(), PushActiveSnapshot(), quote_identifier(), ResetLatch(), worktable::schema, SetConfigOption(), SetCurrentStatementStartTimestamp(), SIGHUP, SignalHandlerForConfigReload(), SPI_connect(), SPI_execute(), SPI_finish(), SPI_getbinval(), SPI_OK_UPDATE_RETURNING, SPI_processed, SPI_tuptable, sprintf, StartTransactionCommand(), STATE_IDLE, STATE_RUNNING, SPITupleTable::tupdesc, val, SPITupleTable::vals, WaitEventExtensionNew(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_TIMEOUT, worker_spi_database, worker_spi_naptime, worker_spi_role, and worker_spi_wait_event_main.

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 47 of file worker_spi.c.

◆ worker_spi_database

char* worker_spi_database = NULL
static

Definition at line 56 of file worker_spi.c.

Referenced by _PG_init(), worker_spi_launch(), and worker_spi_main().

◆ worker_spi_naptime

int worker_spi_naptime = 10
static

Definition at line 54 of file worker_spi.c.

Referenced by _PG_init(), and worker_spi_main().

◆ worker_spi_role

char* worker_spi_role = NULL
static

Definition at line 57 of file worker_spi.c.

Referenced by _PG_init(), worker_spi_launch(), and worker_spi_main().

◆ worker_spi_total_workers

int worker_spi_total_workers = 2
static

Definition at line 55 of file worker_spi.c.

Referenced by _PG_init().

◆ worker_spi_wait_event_main

uint32 worker_spi_wait_event_main = 0
static

Definition at line 60 of file worker_spi.c.

Referenced by worker_spi_main().