90 elog(
FATAL,
"SPI_execute failed: error code %d", ret);
106 "CREATE SCHEMA \"%s\" "
107 "CREATE TABLE \"%s\" ("
108 " type text CHECK (type IN ('total', 'delta')), "
110 "CREATE UNIQUE INDEX \"%s_unique_total\" ON \"%s\" (type) "
111 "WHERE type = 'total'",
121 elog(
FATAL,
"failed to create my schema");
152 memcpy(&dboid, p,
sizeof(
Oid));
154 memcpy(&roleoid, p,
sizeof(
Oid));
156 memcpy(&flags, p,
sizeof(
bits32));
172 elog(
LOG,
"%s initialized with %s.%s",
188 "WITH deleted AS (DELETE "
190 "WHERE type = 'delta' RETURNING value), "
191 "total AS (SELECT coalesce(sum(value), 0) as sum "
194 "SET value = %s.value + total.sum "
195 "FROM total WHERE type = 'total' "
196 "RETURNING %s.value",
264 elog(
FATAL,
"cannot select from table %s.%s: error code %d",
276 elog(
LOG,
"%s: count in %s.%s is now %d",
313 "Duration between each check (in seconds).",
326 "Database to connect to.",
335 "Role to connect with.",
347 "Number of workers.",
362 memset(&worker, 0,
sizeof(worker));
408 memset(&worker, 0,
sizeof(worker));
425 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
426 errmsg(
"flags array must be one-dimensional")));
430 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
431 errmsg(
"flags array must not contain nulls")));
436 for (
i = 0;
i < nelems;
i++)
440 if (strcmp(optname,
"ALLOWCONN") == 0)
442 else if (strcmp(optname,
"ROLELOGINCHECK") == 0)
446 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
447 errmsg(
"incorrect flag value found in array")));
465 memcpy(p, &dboid,
sizeof(
Oid));
467 memcpy(p, &roleoid,
sizeof(
Oid));
469 memcpy(p, &flags,
sizeof(
bits32));
478 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
479 errmsg(
"could not start background process"),
480 errhint(
"More details may be available in the server log.")));
483 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
484 errmsg(
"cannot start background processes without postmaster"),
485 errhint(
"Kill all remaining database processes and restart the database.")));
Oid get_role_oid(const char *rolname, bool missing_ok)
#define PG_GETARG_ARRAYTYPE_P(n)
bool array_contains_nulls(ArrayType *array)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
void pgstat_report_activity(BackendState state, const char *cmd_str)
void RegisterBackgroundWorker(BackgroundWorker *worker)
BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, uint32 flags)
void BackgroundWorkerUnblockSignals(void)
void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
#define BGW_NEVER_RESTART
#define BGWORKER_BYPASS_ROLELOGINCHECK
@ BgWorkerStart_RecoveryFinished
#define BGWORKER_BACKEND_DATABASE_CONNECTION
#define BGWORKER_BYPASS_ALLOWCONN
#define BGWORKER_SHMEM_ACCESS
#define TextDatumGetCString(d)
#define Assert(condition)
#define pg_attribute_noreturn()
#define OidIsValid(objectId)
Oid get_database_oid(const char *dbname, bool missing_ok)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
void ProcessConfigFile(GucContext context)
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)
void MarkGUCPrefixReserved(const char *className)
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)
volatile sig_atomic_t ConfigReloadPending
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
#define WL_EXIT_ON_PM_DEATH
char * pstrdup(const char *in)
#define CHECK_FOR_INTERRUPTS()
bool process_shared_preload_libraries_in_progress
long pgstat_report_stat(bool force)
pqsigfunc pqsignal(int signo, pqsigfunc func)
const char * debug_query_string
static int64 DatumGetInt64(Datum X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
BackgroundWorker * MyBgworkerEntry
const char * quote_identifier(const char *ident)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
SPITupleTable * SPI_tuptable
int SPI_execute(const char *src, bool read_only, long tcount)
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
#define SPI_OK_UPDATE_RETURNING
void resetStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void initStringInfo(StringInfo str)
char bgw_function_name[BGW_MAXLEN]
char bgw_name[BGW_MAXLEN]
char bgw_type[BGW_MAXLEN]
BgWorkerStartTime bgw_start_time
char bgw_extra[BGW_EXTRALEN]
char bgw_library_name[MAXPGPATH]
uint32 WaitEventExtensionNew(const char *wait_event_name)
static int worker_spi_naptime
static void initialize_worker_spi(worktable *table)
PGDLLEXPORT void worker_spi_main(Datum main_arg) pg_attribute_noreturn()
Datum worker_spi_launch(PG_FUNCTION_ARGS)
static uint32 worker_spi_wait_event_main
static char * worker_spi_database
static int worker_spi_total_workers
struct worktable worktable
static char * worker_spi_role
PG_FUNCTION_INFO_V1(worker_spi_launch)
void StartTransactionCommand(void)
void SetCurrentStatementStartTimestamp(void)
void CommitTransactionCommand(void)