60#define SH_PREFIX pgsa_saved_stash_table
61#define SH_ELEMENT_TYPE pgsa_saved_stash
62#define SH_KEY_TYPE char *
64#define SH_HASH_KEY(tb, key) hash_bytes((const unsigned char *) (key), strlen(key))
65#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
66#define SH_SCOPE static inline
107 errmsg(
"pg_stash_advice worker started"));
132 (
errmsg(
"pg_stash_advice worker is already running under PID %d",
276 "pg_stash_advice load",
333 for (p =
filebuf, lineno = 1; *p !=
'\0'; lineno++)
367 errmsg(
"syntax error in file \"%s\" line %u: expected stash name",
374 errmsg(
"syntax error in file \"%s\" line %u: expected end of line",
382 errmsg(
"syntax error in file \"%s\" line %u: duplicate stash name \"%s\"",
396 if (stash_name ==
NULL)
399 errmsg(
"syntax error in file \"%s\" line %u: expected stash name",
407 errmsg(
"syntax error in file \"%s\" line %u: expected query ID",
415 errmsg(
"syntax error in file \"%s\" line %u: expected advice string",
422 errmsg(
"syntax error in file \"%s\" line %u: expected end of line",
430 errmsg(
"syntax error in file \"%s\" line %u: unknown stash \"%s\"",
440 errmsg(
"syntax error in file \"%s\" line %u: invalid query ID \"%s\"",
454 entries[num_entries].
queryId = queryId;
462 errmsg(
"syntax error in file \"%s\" line %u: unrecognized line type",
482 (
errmsg(
"loaded %d advice stashes and %d entries from \"%s\"",
508 "pg_stash_advice dump",
518 errmsg(
"could not open file \"%s\": %m",
wctx.pathname)));
530 if (
wctx.nhash->members == 0)
533 errmsg(
"there are no advice stashes to save"));
550 errmsg(
"could not close file \"%s\": %m",
556 errmsg(
"saved %d advice stashes and %d entries to \"%s\"",
557 (
int)
wctx.nhash->members,
wctx.entries_written,
574 for (
const char *p =
str; *p !=
'\0'; p++)
612 while (*p !=
'\0' && *p !=
'\t')
629 for (
int i = 0;
i < num_entries;
i++)
632 errmsg(
"restoring advice stash entry for \"%s\", query ID %" PRId64,
633 entries[
i].stash_name, entries[
i].queryId));
636 entries[
i].advice_string);
656 errmsg(
"restoring advice stash \"%s\"", s->
name));
701 errmsg(
"syntax error in file \"%s\" line %u: trailing backslash",
707 errmsg(
"syntax error in file \"%s\" line %u: unrecognized escape \"\\%c\"",
751 wctx->entries_written++;
769 errmsg(
"could not write to file \"%s\": %m",
wctx->pathname)));
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
TimestampTz GetCurrentTimestamp(void)
void pgstat_bestart_initial(void)
void pgstat_bestart_final(void)
void BackgroundWorkerUnblockSignals(void)
#define Assert(condition)
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
#define InvalidDsaPointer
void dshash_seq_init(dshash_seq_status *status, dshash_table *hash_table, bool exclusive)
void dshash_seq_term(dshash_seq_status *status)
void * dshash_seq_next(dshash_seq_status *status)
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
#define ereport(elevel,...)
int durable_rename(const char *oldfile, const char *newfile, int elevel)
FILE * AllocateFile(const char *name, const char *mode)
void ProcessConfigFile(GucContext context)
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
volatile sig_atomic_t ShutdownRequestPending
volatile sig_atomic_t ConfigReloadPending
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
MemoryContext CurrentMemoryContext
void * palloc_extended(Size size, int flags)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
void InitializeSessionUserIdStandalone(void)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define ERRCODE_DATA_CORRUPTED
dshash_table * pgsa_entry_dshash
dshash_table * pgsa_stash_dshash
void pgsa_create_stash(char *stash_name)
void pgsa_set_advice_string(char *stash_name, int64 queryId, char *advice_string)
void pgsa_reset_all_stashes(void)
pgsa_shared_state * pgsa_state
int pg_stash_advice_persist_interval
static char buf[DEFAULT_XLOG_SEG_SIZE]
void procsignal_sigusr1_handler(SIGNAL_ARGS)
static void pgsa_detach_shmem(int code, Datum arg)
static pg_noreturn void pgsa_write_error(pgsa_writer_context *wctx)
static char * pgsa_next_tsv_field(char **cursor)
static void pgsa_append_tsv_escaped_string(StringInfo buf, const char *str)
static void pgsa_restore_entries(pgsa_saved_entry *entries, int num_entries)
static void pgsa_unescape_tsv_field(char *str, const char *filename, unsigned lineno)
static void pgsa_read_from_disk(void)
PGDLLEXPORT void pg_stash_advice_worker_main(Datum main_arg)
static void pgsa_restore_stashes(pgsa_saved_stash_table_hash *saved_stashes)
static void pgsa_write_to_disk(void)
static void pgsa_write_entries(pgsa_writer_context *wctx)
static void pgsa_write_stashes(pgsa_writer_context *wctx)
void resetStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
dsa_pointer advice_string
pg_atomic_uint64 change_count
pg_atomic_flag stashes_ready
pgsa_stash_name_table_hash * nhash
#define TimestampTzPlusMilliseconds(tz, ms)
#define PG_WAIT_EXTENSION
#define WL_EXIT_ON_PM_DEATH