89 elog(
FATAL,
"SPI_execute failed: error code %d", ret);
105 "CREATE SCHEMA \"%s\" "
106 "CREATE TABLE \"%s\" ("
107 " type text CHECK (type IN ('total', 'delta')), "
109 "CREATE UNIQUE INDEX \"%s_unique_total\" ON \"%s\" (type) "
110 "WHERE type = 'total'",
120 elog(
FATAL,
"failed to create my schema");
155 elog(
LOG,
"%s initialized with %s.%s",
171 "WITH deleted AS (DELETE "
173 "WHERE type = 'delta' RETURNING value), "
174 "total AS (SELECT coalesce(sum(value), 0) as sum "
177 "SET value = %s.value + total.sum "
178 "FROM total WHERE type = 'total' "
179 "RETURNING %s.value",
243 elog(
FATAL,
"cannot select from table %s.%s: error code %d",
255 elog(
LOG,
"%s: count in %s.%s is now %d",
287 "Duration between each check (in seconds).",
303 "Number of workers.",
316 "Database to connect to.",
327 memset(&worker, 0,
sizeof(worker));
361 memset(&worker, 0,
sizeof(worker));
381 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
382 errmsg(
"could not start background process"),
383 errhint(
"More details may be available in the server log.")));
386 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
387 errmsg(
"cannot start background processes without postmaster"),
388 errhint(
"Kill all remaining database processes and restart the database.")));
void pgstat_report_activity(BackendState state, const char *cmd_str)
void RegisterBackgroundWorker(BackgroundWorker *worker)
BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
#define BGW_NEVER_RESTART
@ BgWorkerStart_RecoveryFinished
#define BGWORKER_BACKEND_DATABASE_CONNECTION
#define BGWORKER_SHMEM_ACCESS
#define pg_attribute_noreturn()
elog(ERROR, "%s: %s", p2, msg)
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 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)
void ProcessConfigFile(GucContext context)
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
Assert(fmt[strlen(fmt) - 1] !='\n')
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)
void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, uint32 flags)
void BackgroundWorkerUnblockSignals(void)
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_library_name[BGW_MAXLEN]
#define PG_WAIT_EXTENSION
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 char * worker_spi_database
static int worker_spi_total_workers
struct worktable worktable
PG_FUNCTION_INFO_V1(worker_spi_launch)
void StartTransactionCommand(void)
void SetCurrentStatementStartTimestamp(void)
void CommitTransactionCommand(void)