PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
worker_spi.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "postmaster/bgworker.h"
#include "postmaster/interrupt.h"
#include "storage/latch.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 pg_noreturn void worker_spi_main (Datum main_arg)
 
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 302 of file worker_spi.c.

303{
304 BackgroundWorker worker;
305
306 /* get the configuration */
307
308 /*
309 * These GUCs are defined even if this library is not loaded with
310 * shared_preload_libraries, for worker_spi_launch().
311 */
312 DefineCustomIntVariable("worker_spi.naptime",
313 "Duration between each check (in seconds).",
314 NULL,
316 10,
317 1,
318 INT_MAX,
320 0,
321 NULL,
322 NULL,
323 NULL);
324
325 DefineCustomStringVariable("worker_spi.database",
326 "Database to connect to.",
327 NULL,
329 "postgres",
331 0,
332 NULL, NULL, NULL);
333
334 DefineCustomStringVariable("worker_spi.role",
335 "Role to connect with.",
336 NULL,
338 NULL,
340 0,
341 NULL, NULL, NULL);
342
344 return;
345
346 DefineCustomIntVariable("worker_spi.total_workers",
347 "Number of workers.",
348 NULL,
350 2,
351 1,
352 100,
354 0,
355 NULL,
356 NULL,
357 NULL);
358
359 MarkGUCPrefixReserved("worker_spi");
360
361 /* set up common data for all our workers */
362 memset(&worker, 0, sizeof(worker));
367 sprintf(worker.bgw_library_name, "worker_spi");
368 sprintf(worker.bgw_function_name, "worker_spi_main");
369 worker.bgw_notify_pid = 0;
370
371 /*
372 * Now fill in worker-specific data, and do the actual registrations.
373 *
374 * bgw_extra can optionally include a database OID, a role OID and a set
375 * of flags. This is left empty here to fallback to the related GUCs at
376 * startup (0 for the bgworker flags).
377 */
378 for (int i = 1; i <= worker_spi_total_workers; i++)
379 {
380 snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi worker %d", i);
381 snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi");
382 worker.bgw_main_arg = Int32GetDatum(i);
383
385 }
386}
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:5218
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:5279
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:5158
@ PGC_POSTMASTER
Definition: guc.h:74
@ PGC_SIGHUP
Definition: guc.h:75
int i
Definition: isn.c:74
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1837
#define sprintf
Definition: port.h:241
#define snprintf
Definition: port.h:239
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217
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:50
static char * worker_spi_database
Definition: worker_spi.c:52
static int worker_spi_total_workers
Definition: worker_spi.c:51
static char * worker_spi_role
Definition: worker_spi.c:53

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 69 of file worker_spi.c.

70{
71 int ret;
72 int ntup;
73 bool isnull;
75
80 pgstat_report_activity(STATE_RUNNING, "initializing worker_spi schema");
81
82 /* XXX could we use CREATE SCHEMA IF NOT EXISTS? */
84 appendStringInfo(&buf, "select count(*) from pg_namespace where nspname = '%s'",
85 table->schema);
86
88 ret = SPI_execute(buf.data, true, 0);
89 if (ret != SPI_OK_SELECT)
90 elog(FATAL, "SPI_execute failed: error code %d", ret);
91
92 if (SPI_processed != 1)
93 elog(FATAL, "not a singleton result");
94
97 1, &isnull));
98 if (isnull)
99 elog(FATAL, "null result");
100
101 if (ntup == 0)
102 {
103 debug_query_string = NULL;
106 "CREATE SCHEMA \"%s\" "
107 "CREATE TABLE \"%s\" ("
108 " type text CHECK (type IN ('total', 'delta')), "
109 " value integer)"
110 "CREATE UNIQUE INDEX \"%s_unique_total\" ON \"%s\" (type) "
111 "WHERE type = 'total'",
112 table->schema, table->name, table->name, table->name);
113
114 /* set statement start time */
116
117 debug_query_string = buf.data;
118 ret = SPI_execute(buf.data, false, 0);
119
120 if (ret != SPI_OK_UTILITY)
121 elog(FATAL, "failed to create my schema");
122
123 debug_query_string = NULL; /* rest is not statement-specific */
124 }
125
126 SPI_finish();
129 debug_query_string = NULL;
131}
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:72
const char * debug_query_string
Definition: postgres.c:88
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:390
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:271
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:669
void PopActiveSnapshot(void)
Definition: snapmgr.c:762
uint64 SPI_processed
Definition: spi.c:44
SPITupleTable * SPI_tuptable
Definition: spi.c:45
int SPI_connect(void)
Definition: spi.c:95
int SPI_finish(void)
Definition: spi.c:183
int SPI_execute(const char *src, bool read_only, long tcount)
Definition: spi.c:597
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:1253
#define SPI_OK_UTILITY
Definition: spi.h:85
#define SPI_OK_SELECT
Definition: spi.h:86
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:126
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
TupleDesc tupdesc
Definition: spi.h:25
HeapTuple * vals
Definition: spi.h:26
const char * name
Definition: worker_spi.c:61
const char * schema
Definition: worker_spi.c:60
void StartTransactionCommand(void)
Definition: xact.c:3059
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:914
void CommitTransactionCommand(void)
Definition: xact.c:3157

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 392 of file worker_spi.c.

393{
395 Oid dboid = PG_GETARG_OID(1);
396 Oid roleoid = PG_GETARG_OID(2);
397 BackgroundWorker worker;
399 BgwHandleStatus status;
400 pid_t pid;
401 char *p;
402 bits32 flags = 0;
404 Size ndim;
405 int nelems;
406 Datum *datum_flags;
407
408 memset(&worker, 0, sizeof(worker));
413 sprintf(worker.bgw_library_name, "worker_spi");
414 sprintf(worker.bgw_function_name, "worker_spi_main");
415 snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi dynamic worker %d", i);
416 snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi dynamic");
417 worker.bgw_main_arg = Int32GetDatum(i);
418 /* set bgw_notify_pid so that we can use WaitForBackgroundWorkerStartup */
419 worker.bgw_notify_pid = MyProcPid;
420
421 /* extract flags, if any */
422 ndim = ARR_NDIM(arr);
423 if (ndim > 1)
425 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
426 errmsg("flags array must be one-dimensional")));
427
428 if (array_contains_nulls(arr))
430 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
431 errmsg("flags array must not contain nulls")));
432
433 Assert(ARR_ELEMTYPE(arr) == TEXTOID);
434 deconstruct_array_builtin(arr, TEXTOID, &datum_flags, NULL, &nelems);
435
436 for (i = 0; i < nelems; i++)
437 {
438 char *optname = TextDatumGetCString(datum_flags[i]);
439
440 if (strcmp(optname, "ALLOWCONN") == 0)
442 else if (strcmp(optname, "ROLELOGINCHECK") == 0)
444 else
446 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
447 errmsg("incorrect flag value found in array")));
448 }
449
450 /*
451 * Register database and role to use for the worker started in bgw_extra.
452 * If none have been provided, this will fall back to the GUCs at startup.
453 */
454 if (!OidIsValid(dboid))
456
457 /*
458 * worker_spi_role is NULL by default, so this gives to worker_spi_main()
459 * an invalid OID in this case.
460 */
461 if (!OidIsValid(roleoid) && worker_spi_role)
462 roleoid = get_role_oid(worker_spi_role, false);
463
464 p = worker.bgw_extra;
465 memcpy(p, &dboid, sizeof(Oid));
466 p += sizeof(Oid);
467 memcpy(p, &roleoid, sizeof(Oid));
468 p += sizeof(Oid);
469 memcpy(p, &flags, sizeof(bits32));
470
471 if (!RegisterDynamicBackgroundWorker(&worker, &handle))
473
474 status = WaitForBackgroundWorkerStartup(handle, &pid);
475
476 if (status == BGWH_STOPPED)
478 (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
479 errmsg("could not start background process"),
480 errhint("More details may be available in the server log.")));
481 if (status == BGWH_POSTMASTER_DIED)
483 (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
484 errmsg("cannot start background processes without postmaster"),
485 errhint("Kill all remaining database processes and restart the database.")));
486 Assert(status == BGWH_STARTED);
487
488 PG_RETURN_INT32(pid);
489}
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5536
#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
uint32 bits32
Definition: c.h:511
int32_t int32
Definition: c.h:498
#define OidIsValid(objectId)
Definition: c.h:746
size_t Size
Definition: c.h:576
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:3141
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
Assert(PointerIsAligned(start, uint64))
uintptr_t Datum
Definition: postgres.h:69
unsigned int Oid
Definition: postgres_ext.h:30
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 134 of file worker_spi.c.

135{
136 int index = DatumGetInt32(main_arg);
137 worktable *table;
139 char name[20];
140 Oid dboid;
141 Oid roleoid;
142 char *p;
143 bits32 flags = 0;
144
145 table = palloc(sizeof(worktable));
146 sprintf(name, "schema%d", index);
147 table->schema = pstrdup(name);
148 table->name = pstrdup("counted");
149
150 /* fetch database and role OIDs, these are set for a dynamic worker */
152 memcpy(&dboid, p, sizeof(Oid));
153 p += sizeof(Oid);
154 memcpy(&roleoid, p, sizeof(Oid));
155 p += sizeof(Oid);
156 memcpy(&flags, p, sizeof(bits32));
157
158 /* Establish signal handlers before unblocking signals. */
160 pqsignal(SIGTERM, die);
161
162 /* We're now ready to receive signals */
164
165 /* Connect to our database */
166 if (OidIsValid(dboid))
167 BackgroundWorkerInitializeConnectionByOid(dboid, roleoid, flags);
168 else
170 worker_spi_role, flags);
171
172 elog(LOG, "%s initialized with %s.%s",
173 MyBgworkerEntry->bgw_name, table->schema, table->name);
175
176 /*
177 * Quote identifiers passed to us. Note that this must be done after
178 * initialize_worker_spi, because that routine assumes the names are not
179 * quoted.
180 *
181 * Note some memory might be leaked here.
182 */
183 table->schema = quote_identifier(table->schema);
184 table->name = quote_identifier(table->name);
185
188 "WITH deleted AS (DELETE "
189 "FROM %s.%s "
190 "WHERE type = 'delta' RETURNING value), "
191 "total AS (SELECT coalesce(sum(value), 0) as sum "
192 "FROM deleted) "
193 "UPDATE %s.%s "
194 "SET value = %s.value + total.sum "
195 "FROM total WHERE type = 'total' "
196 "RETURNING %s.value",
197 table->schema, table->name,
198 table->schema, table->name,
199 table->name,
200 table->name);
201
202 /*
203 * Main loop: do this until SIGTERM is received and processed by
204 * ProcessInterrupts.
205 */
206 for (;;)
207 {
208 int ret;
209
210 /* First time, allocate or get the custom wait event */
213
214 /*
215 * Background workers mustn't call usleep() or any direct equivalent:
216 * instead, they may wait on their process latch, which sleeps as
217 * necessary, but is awakened if postmaster dies. That way the
218 * background process goes away immediately in an emergency.
219 */
220 (void) WaitLatch(MyLatch,
222 worker_spi_naptime * 1000L,
225
227
228 /*
229 * In case of a SIGHUP, just reload the configuration.
230 */
232 {
233 ConfigReloadPending = false;
235 }
236
237 /*
238 * Start a transaction on which we can run queries. Note that each
239 * StartTransactionCommand() call should be preceded by a
240 * SetCurrentStatementStartTimestamp() call, which sets both the time
241 * for the statement we're about the run, and also the transaction
242 * start time. Also, each other query sent to SPI should probably be
243 * preceded by SetCurrentStatementStartTimestamp(), so that statement
244 * start time is always up to date.
245 *
246 * The SPI_connect() call lets us run queries through the SPI manager,
247 * and the PushActiveSnapshot() call creates an "active" snapshot
248 * which is necessary for queries to have MVCC data to work on.
249 *
250 * The pgstat_report_activity() call makes our activity visible
251 * through the pgstat views.
252 */
255 SPI_connect();
257 debug_query_string = buf.data;
259
260 /* We can now execute queries via SPI */
261 ret = SPI_execute(buf.data, false, 0);
262
263 if (ret != SPI_OK_UPDATE_RETURNING)
264 elog(FATAL, "cannot select from table %s.%s: error code %d",
265 table->schema, table->name, ret);
266
267 if (SPI_processed > 0)
268 {
269 bool isnull;
270 int32 val;
271
274 1, &isnull));
275 if (!isnull)
276 elog(LOG, "%s: count in %s.%s is now %d",
278 table->schema, table->name, val);
279 }
280
281 /*
282 * And finish our transaction.
283 */
284 SPI_finish();
287 debug_query_string = NULL;
288 pgstat_report_stat(true);
290 }
291
292 /* Not reachable */
293}
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 ProcessConfigFile(GucContext context)
Definition: guc-file.l:120
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:372
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:172
char * pstrdup(const char *in)
Definition: mcxt.c:1699
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:691
#define pqsignal
Definition: port.h:521
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:199
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:13019
#define SPI_OK_UPDATE_RETURNING
Definition: spi.h:94
Definition: type.h:96
uint32 WaitEventExtensionNew(const char *wait_event_name)
Definition: wait_event.c:163
const char * name
#define WL_TIMEOUT
Definition: waiteventset.h:37
#define WL_EXIT_ON_PM_DEATH
Definition: waiteventset.h:39
#define WL_LATCH_SET
Definition: waiteventset.h:34
#define SIGHUP
Definition: win32_port.h:158
static void initialize_worker_spi(worktable *table)
Definition: worker_spi.c:69
static uint32 worker_spi_wait_event_main
Definition: worker_spi.c:56

References appendStringInfo(), BackgroundWorkerInitializeConnection(), BackgroundWorkerInitializeConnectionByOid(), BackgroundWorkerUnblockSignals(), BackgroundWorker::bgw_extra, BackgroundWorker::bgw_name, 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_SIGHUP, pgstat_report_activity(), pgstat_report_stat(), PopActiveSnapshot(), pqsignal, ProcessConfigFile(), pstrdup(), PushActiveSnapshot(), quote_identifier(), ResetLatch(), worktable::schema, 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 43 of file worker_spi.c.

◆ worker_spi_database

char* worker_spi_database = NULL
static

Definition at line 52 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 50 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 53 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 51 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 56 of file worker_spi.c.

Referenced by worker_spi_main().