37 #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var))))
39 #define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
41 #define PG_STAT_GET_RELENTRY_INT64(stat) \
43 CppConcat(pg_stat_get_,stat)(PG_FUNCTION_ARGS) \
45 Oid relid = PG_GETARG_OID(0); \
47 PgStat_StatTabEntry *tabentry; \
49 if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
52 result = (int64) (tabentry->stat); \
54 PG_RETURN_INT64(result); \
111 #define PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat) \
113 CppConcat(pg_stat_get_,stat)(PG_FUNCTION_ARGS) \
115 Oid relid = PG_GETARG_OID(0); \
116 TimestampTz result; \
117 PgStat_StatTabEntry *tabentry; \
119 if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
122 result = tabentry->stat; \
127 PG_RETURN_TIMESTAMPTZ(result); \
157 #define PG_STAT_GET_FUNCENTRY_FLOAT8_MS(stat) \
159 CppConcat(pg_stat_get_function_,stat)(PG_FUNCTION_ARGS) \
161 Oid funcid = PG_GETARG_OID(0); \
163 PgStat_StatFuncEntry *funcentry; \
165 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL) \
167 result = ((double) funcentry->stat) / 1000.0; \
168 PG_RETURN_FLOAT8(result); \
231 #define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
253 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
254 errmsg(
"invalid command name: \"%s\"", cmd)));
259 for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
307 #define PG_STAT_GET_ACTIVITY_COLS 31
316 for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
324 const char *wait_event_type = NULL;
325 const char *wait_event = NULL;
367 char *clipped_activity;
396 pfree(clipped_activity);
488 memset(&zero_clientaddr, 0,
sizeof(zero_clientaddr));
490 sizeof(zero_clientaddr)) == 0)
501 char remote_host[NI_MAXHOST];
502 char remote_port[NI_MAXSERV];
505 remote_host[0] =
'\0';
506 remote_port[0] =
'\0';
509 remote_host,
sizeof(remote_host),
510 remote_port,
sizeof(remote_port),
511 NI_NUMERICHOST | NI_NUMERICSERV);
554 const char *bgw_type;
595 nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] =
true;
710 #define PG_STAT_GET_SUBXACT_COLS 2
747 const char *activity;
748 char *clipped_activity;
752 activity =
"<backend information not available>";
754 activity =
"<insufficient privilege>";
756 activity =
"<command string not enabled>";
762 pfree(clipped_activity);
773 const char *wait_event_type = NULL;
776 wait_event_type =
"<backend information not available>";
778 wait_event_type =
"<insufficient privilege>";
782 if (!wait_event_type)
794 const char *wait_event = NULL;
797 wait_event =
"<backend information not available>";
799 wait_event =
"<insufficient privilege>";
886 char remote_host[NI_MAXHOST];
896 memset(&zero_clientaddr, 0,
sizeof(zero_clientaddr));
898 sizeof(zero_clientaddr)) == 0)
910 remote_host[0] =
'\0';
913 remote_host,
sizeof(remote_host),
915 NI_NUMERICHOST | NI_NUMERICSERV);
931 char remote_port[NI_MAXSERV];
941 memset(&zero_clientaddr, 0,
sizeof(zero_clientaddr));
943 sizeof(zero_clientaddr)) == 0)
957 remote_port[0] =
'\0';
961 remote_port,
sizeof(remote_port),
962 NI_NUMERICHOST | NI_NUMERICSERV);
980 for (
idx = 1;
idx <= tot_backends;
idx++)
992 #define PG_STAT_GET_DBENTRY_INT64(stat) \
994 CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
996 Oid dbid = PG_GETARG_OID(0); \
998 PgStat_StatDBEntry *dbentry; \
1000 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
1003 result = (int64) (dbentry->stat); \
1005 PG_RETURN_INT64(result); \
1153 #define PG_STAT_GET_DBENTRY_FLOAT8_MS(stat) \
1155 CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
1157 Oid dbid = PG_GETARG_OID(0); \
1159 PgStat_StatDBEntry *dbentry; \
1161 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
1164 result = ((double) dbentry->stat) / 1000.0; \
1166 PG_RETURN_FLOAT8(result); \
1309 elog(
ERROR,
"unrecognized IOOp value: %d", io_op);
1336 elog(
ERROR,
"unrecognized IOOp value: %d", io_op);
1340 static inline double
1343 return val_ms * (double) 0.001;
1424 bktype_stats->
counts[io_obj][io_context][io_op];
1429 nulls[op_idx] =
true;
1438 bktype_stats->
times[io_obj][io_context][io_op];
1443 nulls[time_idx] =
true;
1461 #define PG_STAT_GET_WAL_COLS 9
1487 TIMESTAMPTZOID, -1, 0);
1525 #define PG_STAT_GET_SLRU_COLS 9
1566 #define PG_STAT_GET_XACT_RELENTRY_INT64(stat) \
1568 CppConcat(pg_stat_get_xact_,stat)(PG_FUNCTION_ARGS) \
1570 Oid relid = PG_GETARG_OID(0); \
1572 PgStat_TableStatus *tabentry; \
1574 if ((tabentry = find_tabstat_entry(relid)) == NULL) \
1577 result = (int64) (tabentry->counts.stat); \
1579 PG_RETURN_INT64(result); \
1618 result +=
trans->tuples_inserted;
1639 result +=
trans->tuples_updated;
1660 result +=
trans->tuples_deleted;
1677 #define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(stat) \
1679 CppConcat(pg_stat_get_xact_function_,stat)(PG_FUNCTION_ARGS) \
1681 Oid funcid = PG_GETARG_OID(0); \
1682 PgStat_FunctionCounts *funcentry; \
1684 if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
1686 PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->stat)); \
1750 if (strcmp(target,
"archiver") == 0)
1752 else if (strcmp(target,
"bgwriter") == 0)
1761 else if (strcmp(target,
"io") == 0)
1763 else if (strcmp(target,
"recovery_prefetch") == 0)
1765 else if (strcmp(target,
"wal") == 0)
1769 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1770 errmsg(
"unrecognized reset target: \"%s\"", target),
1771 errhint(
"Target must be \"archiver\", \"bgwriter\", \"io\", \"recovery_prefetch\", or \"wal\".")));
1805 char *target = NULL;
1822 char *target = NULL;
1852 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1853 errmsg(
"invalid subscription OID %u", subid)));
1865 bool nulls[7] = {0};
1875 TIMESTAMPTZOID, -1, 0);
1881 TIMESTAMPTZOID, -1, 0);
1883 TIMESTAMPTZOID, -1, 0);
1929 #define PG_STAT_GET_REPLICATION_SLOT_COLS 10
1959 TIMESTAMPTZOID, -1, 0);
2000 #define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
2020 TIMESTAMPTZOID, -1, 0);
2027 subentry = &allzero;
Datum idx(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
#define PGSTAT_NUM_PROGRESS_PARAM
@ PROGRESS_COMMAND_ANALYZE
@ PROGRESS_COMMAND_CLUSTER
@ PROGRESS_COMMAND_CREATE_INDEX
@ PROGRESS_COMMAND_VACUUM
@ PROGRESS_COMMAND_BASEBACKUP
int pgstat_fetch_stat_numbackends(void)
LocalPgBackendStatus * pgstat_get_local_beentry_by_index(int idx)
PgBackendStatus * pgstat_get_beentry_by_backend_id(BackendId beid)
LocalPgBackendStatus * pgstat_get_local_beentry_by_backend_id(BackendId beid)
char * pgstat_clip_activity(const char *raw_activity)
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_IDLEINTRANSACTION
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define OidIsValid(objectId)
bool IsSharedRelation(Oid relationId)
elog(ERROR, "%s: %s", p2, msg)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Datum Int64GetDatum(int64 X)
Datum Float8GetDatum(float8 X)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_FLOAT8(x)
#define PG_RETURN_INT64(x)
#define DirectFunctionCall1(func, arg1)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_BOOL(x)
#define PG_GETARG_TEXT_P(n)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Datum int4in(PG_FUNCTION_ARGS)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
if(TABLE==NULL||TABLE_index==NULL)
pid_t GetLeaderApplyWorkerPid(pid_t pid)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define BACKEND_NUM_TYPES
const char * GetBackendTypeDesc(BackendType backendType)
void namestrcpy(Name name, const char *str)
void clean_ipv6_addr(int addr_family, char *addr)
Datum inet_in(PG_FUNCTION_ARGS)
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
void pgstat_reset_counters(void)
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
void pgstat_reset_of_kind(PgStat_Kind kind)
void pgstat_force_next_flush(void)
void pgstat_clear_snapshot(void)
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
@ PGSTAT_KIND_SUBSCRIPTION
@ PGSTAT_KIND_CHECKPOINTER
#define IOCONTEXT_NUM_TYPES
#define IOOBJECT_NUM_TYPES
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)
bool pgstat_tracks_io_bktype(BackendType bktype)
const char * pgstat_get_io_object_name(IOObject io_object)
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
PgStat_IO * pgstat_fetch_stat_io(void)
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
const char * pgstat_get_io_context_name(IOContext io_context)
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
void pgstat_reset_replslot(const char *name)
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
void pgstat_reset_slru(const char *name)
PgStat_SLRUStats * pgstat_fetch_slru(void)
const char * pgstat_get_slru_name(int slru_idx)
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
PgStat_WalStats * pgstat_fetch_stat_wal(void)
#define PG_STAT_GET_XACT_RELENTRY_INT64(stat)
Datum pg_stat_get_progress_info(PG_FUNCTION_ARGS)
Datum pg_stat_get_snapshot_timestamp(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
Datum pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS)
Datum pg_stat_get_db_stat_reset_time(PG_FUNCTION_ARGS)
#define PG_STAT_GET_WAL_COLS
Datum pg_stat_get_wal(PG_FUNCTION_ARGS)
Datum pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
Datum pg_stat_reset_replication_slot(PG_FUNCTION_ARGS)
Datum pg_stat_get_checkpoint_sync_time(PG_FUNCTION_ARGS)
#define UINT32_ACCESS_ONCE(var)
Datum pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS)
Datum pg_stat_get_activity(PG_FUNCTION_ARGS)
Datum pg_stat_get_slru(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_start(PG_FUNCTION_ARGS)
Datum pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS)
Datum pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS)
Datum pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS)
Datum pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
#define PG_STAT_GET_SLRU_COLS
#define PG_STAT_GET_DBENTRY_INT64(stat)
Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
static double pg_stat_us_to_ms(PgStat_Counter val_ms)
#define PG_STAT_GET_ACTIVITY_COLS
static io_stat_col pgstat_get_io_time_index(IOOp io_op)
Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS(stat)
Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
Datum pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS)
Datum pg_stat_reset_subscription_stats(PG_FUNCTION_ARGS)
Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS)
Datum pg_stat_reset_slru(PG_FUNCTION_ARGS)
Datum pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
static io_stat_col pgstat_get_io_op_index(IOOp io_op)
Datum pg_stat_have_stats(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS
Datum pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
Datum pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
Datum pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
Datum pg_stat_get_io(PG_FUNCTION_ARGS)
#define PG_STAT_GET_DBENTRY_FLOAT8_MS(stat)
Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
Datum pg_stat_reset(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
#define PG_STAT_GET_SUBXACT_COLS
#define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(stat)
#define PG_STAT_GET_RELENTRY_INT64(stat)
Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat)
#define PG_STAT_GET_PROGRESS_COLS
#define HAS_PGSTAT_PERMISSIONS(role)
Datum pg_stat_get_buf_fsync_backend(PG_FUNCTION_ARGS)
Datum pg_stat_get_archiver(PG_FUNCTION_ARGS)
Datum pg_stat_reset_shared(PG_FUNCTION_ARGS)
Datum pg_stat_force_next_flush(PG_FUNCTION_ARGS)
Datum pg_stat_reset_single_table_counters(PG_FUNCTION_ARGS)
Datum pg_stat_get_bgwriter_stat_reset_time(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS)
Datum pg_stat_get_xact_tuples_updated(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
Datum pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
Datum pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS)
Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
Datum pg_stat_reset_single_function_counters(PG_FUNCTION_ARGS)
Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
Datum pg_backend_pid(PG_FUNCTION_ARGS)
#define PG_STAT_GET_REPLICATION_SLOT_COLS
int pg_strcasecmp(const char *s1, const char *s2)
static Datum PointerGetDatum(const void *X)
static Datum TransactionIdGetDatum(TransactionId X)
static Datum UInt64GetDatum(uint64 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
PGPROC * BackendPidGetProc(int pid)
PGPROC * AuxiliaryPidGetProc(int pid)
MemoryContext multi_call_memory_ctx
TransactionId backend_xid
PgBackendStatus backendStatus
int backend_subxact_count
TransactionId backend_xmin
bool backend_subxact_overflowed
char gss_princ[NAMEDATALEN]
char ssl_version[NAMEDATALEN]
char ssl_cipher[NAMEDATALEN]
char ssl_client_dn[NAMEDATALEN]
char ssl_client_serial[NAMEDATALEN]
char ssl_issuer_dn[NAMEDATALEN]
BackendType st_backendType
TimestampTz st_state_start_timestamp
TimestampTz st_proc_start_timestamp
PgBackendGSSStatus * st_gssstatus
TimestampTz st_activity_start_timestamp
ProgressCommandType st_progress_command
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
PgBackendSSLStatus * st_sslstatus
TimestampTz st_xact_start_timestamp
Oid st_progress_command_target
TimestampTz last_failed_timestamp
TimestampTz stat_reset_timestamp
TimestampTz last_archived_timestamp
char last_failed_wal[MAX_XFN_CHARS+1]
PgStat_Counter failed_count
PgStat_Counter archived_count
char last_archived_wal[MAX_XFN_CHARS+1]
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
TimestampTz stat_reset_timestamp
PgStat_Counter conflict_startup_deadlock
PgStat_Counter conflict_lock
TimestampTz stat_reset_timestamp
PgStat_Counter conflict_snapshot
TimestampTz last_checksum_failure
PgStat_Counter conflict_bufferpin
PgStat_Counter conflict_logicalslot
PgStat_Counter checksum_failures
PgStat_Counter conflict_tablespace
TimestampTz stat_reset_timestamp
PgStat_Counter stream_count
PgStat_Counter total_txns
PgStat_Counter total_bytes
PgStat_Counter spill_txns
PgStat_Counter stream_txns
PgStat_Counter spill_count
PgStat_Counter stream_bytes
PgStat_Counter spill_bytes
PgStat_Counter apply_error_count
PgStat_Counter sync_error_count
TimestampTz stat_reset_timestamp
PgStat_Counter tuples_inserted
PgStat_Counter tuples_updated
PgStat_Counter tuples_deleted
PgStat_TableCounts counts
struct PgStat_TableXactStatus * trans
PgStat_Counter wal_buffers_full
PgStat_Counter wal_write_time
TimestampTz stat_reset_timestamp
PgStat_Counter wal_sync_time
PgStat_Counter wal_records
Tuplestorestate * setResult
struct sockaddr_storage addr
#define TransactionIdIsValid(xid)
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
static Datum TimestampTzGetDatum(TimestampTz X)
#define PG_RETURN_TIMESTAMPTZ(x)
char * text_to_cstring(const text *t)
text * cstring_to_text(const char *s)
const char * pgstat_get_wait_event(uint32 wait_event_info)
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
bool DataChecksumsEnabled(void)
void XLogPrefetchResetStats(void)
static zic_t trans[TZ_MAX_LEAPS]