29 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
30 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/pgstat.stat"
31 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/pgstat.tmp"
34 #define PG_STAT_TMP_DIR "pg_stat_tmp"
37 #define PgStat_Kind uint32
40 #define PGSTAT_KIND_MIN 1
41 #define PGSTAT_KIND_MAX 256
44 #define PGSTAT_KIND_INVALID 0
47 #define PGSTAT_KIND_DATABASE 1
48 #define PGSTAT_KIND_RELATION 2
49 #define PGSTAT_KIND_FUNCTION 3
50 #define PGSTAT_KIND_REPLSLOT 4
51 #define PGSTAT_KIND_SUBSCRIPTION 5
54 #define PGSTAT_KIND_ARCHIVER 6
55 #define PGSTAT_KIND_BGWRITER 7
56 #define PGSTAT_KIND_CHECKPOINTER 8
57 #define PGSTAT_KIND_IO 9
58 #define PGSTAT_KIND_SLRU 10
59 #define PGSTAT_KIND_WAL 11
61 #define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE
62 #define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL
63 #define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1)
68 #define PGSTAT_KIND_CUSTOM_MIN 128
69 #define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX
70 #define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1)
77 #define PGSTAT_KIND_EXPERIMENTAL 128
270 #define PGSTAT_FILE_FORMAT_ID 0x01A5BCAF
318 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
328 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
342 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
591 #define pgstat_count_buffer_read_time(n) \
592 (pgStatBlockReadTime += (n))
593 #define pgstat_count_buffer_write_time(n) \
594 (pgStatBlockWriteTime += (n))
595 #define pgstat_count_conn_active_time(n) \
596 (pgStatActiveTime += (n))
597 #define pgstat_count_conn_txn_idle_time(n) \
598 (pgStatTransactionIdleTime += (n))
643 #define pgstat_should_count_relation(rel) \
644 (likely((rel)->pgstat_info != NULL) ? true : \
645 ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
649 #define pgstat_count_heap_scan(rel) \
651 if (pgstat_should_count_relation(rel)) \
652 (rel)->pgstat_info->counts.numscans++; \
654 #define pgstat_count_heap_getnext(rel) \
656 if (pgstat_should_count_relation(rel)) \
657 (rel)->pgstat_info->counts.tuples_returned++; \
659 #define pgstat_count_heap_fetch(rel) \
661 if (pgstat_should_count_relation(rel)) \
662 (rel)->pgstat_info->counts.tuples_fetched++; \
664 #define pgstat_count_index_scan(rel) \
666 if (pgstat_should_count_relation(rel)) \
667 (rel)->pgstat_info->counts.numscans++; \
669 #define pgstat_count_index_tuples(rel, n) \
671 if (pgstat_should_count_relation(rel)) \
672 (rel)->pgstat_info->counts.tuples_returned += (n); \
674 #define pgstat_count_buffer_read(rel) \
676 if (pgstat_should_count_relation(rel)) \
677 (rel)->pgstat_info->counts.blocks_fetched++; \
679 #define pgstat_count_buffer_hit(rel) \
681 if (pgstat_should_count_relation(rel)) \
682 (rel)->pgstat_info->counts.blocks_hit++; \
#define CONFLICT_NUM_TYPES
#define BACKEND_NUM_TYPES
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
void pgstat_drop_function(Oid proid)
#define PGSTAT_KIND_CUSTOM_MAX
void pgstat_drop_subscription(Oid subid)
struct PgStat_TableStatus PgStat_TableStatus
void pgstat_update_parallel_workers_stats(PgStat_Counter workers_to_launch, PgStat_Counter workers_launched)
void pgstat_reset_replslot(const char *name)
instr_time pgstat_prepare_io_time(bool track_io_guc)
static bool pgstat_is_kind_builtin(PgStat_Kind kind)
void AtPrepare_PgStat(void)
int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items)
void pgstat_copy_relation_stats(Relation dst, Relation src)
void pgstat_unlink_relation(Relation rel)
struct PgStat_CheckpointerStats PgStat_CheckpointerStats
void pgstat_reset_slru(const char *)
void pgstat_count_slru_page_exists(int slru_idx)
void pgstat_create_subscription(Oid subid)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt)
void pgstat_count_slru_page_read(int slru_idx)
void pgstat_count_heap_update(Relation rel, bool hot, bool newpage)
@ PGSTAT_FETCH_CONSISTENCY_NONE
@ PGSTAT_FETCH_CONSISTENCY_CACHE
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo)
void StatsShmemInit(void)
void pgstat_reset_counters(void)
void pgstat_report_subscription_conflict(Oid subid, ConflictType type)
struct PgStat_StatSubEntry PgStat_StatSubEntry
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
void AtEOXact_PgStat(bool isCommit, bool parallel)
int pgstat_get_slru_index(const char *name)
void pgstat_count_slru_page_hit(int slru_idx)
bool pgstat_tracks_io_bktype(BackendType bktype)
void pgstat_report_subscription_error(Oid subid, bool is_apply_error)
void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
void pgstat_report_autovac(Oid dboid)
static bool pgstat_is_kind_custom(PgStat_Kind kind)
struct PgStat_TableCounts PgStat_TableCounts
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
void pgstat_report_connect(Oid dboid)
void pgstat_initialize(void)
struct PgStat_BackendSubEntry PgStat_BackendSubEntry
void pgstat_assoc_relation(Relation rel)
void pgstat_count_slru_page_zeroed(int slru_idx)
long pgstat_report_stat(bool force)
struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
void pgstat_count_slru_truncate(int slru_idx)
void pgstat_report_checksum_failure(void)
void pgstat_reset_of_kind(PgStat_Kind kind)
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
struct PgStat_SLRUStats PgStat_SLRUStats
PGDLLIMPORT int pgstat_fetch_consistency
struct PgStat_BktypeIO PgStat_BktypeIO
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
#define IOCONTEXT_NUM_TYPES
void pgstat_before_server_shutdown(int code, Datum arg)
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
#define PGSTAT_KIND_CUSTOM_MIN
void pgstat_report_deadlock(void)
void pgstat_acquire_replslot(struct ReplicationSlot *slot)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
const char * pgstat_get_io_object_name(IOObject io_object)
void pgstat_report_recovery_conflict(int reason)
void pgstat_force_next_flush(void)
void pgstat_create_function(Oid proid)
void pgstat_count_slru_page_written(int slru_idx)
struct PgStat_ArchiverStats PgStat_ArchiverStats
PGDLLIMPORT PgStat_Counter pgStatActiveTime
#define PGSTAT_KIND_BUILTIN_MAX
PgStat_SLRUStats * pgstat_fetch_slru(void)
void pgstat_clear_snapshot(void)
const char * pgstat_get_slru_name(int slru_idx)
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
Size StatsShmemSize(void)
void pgstat_create_relation(Relation rel)
void PostPrepare_PgStat(void)
PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
struct PgStat_FunctionCounts PgStat_FunctionCounts
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
struct PgStat_PendingWalStats PgStat_PendingWalStats
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
void pgstat_report_wal(bool force)
PGDLLIMPORT int pgstat_track_functions
void pgstat_count_heap_delete(Relation rel)
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
struct PgStat_StatDBEntry PgStat_StatDBEntry
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
PgStat_IO * pgstat_fetch_stat_io(void)
void pgstat_restore_stats(XLogRecPtr redo)
void pgstat_count_slru_flush(int slru_idx)
PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
void pgstat_report_checkpointer(void)
void AtEOSubXact_PgStat(bool isCommit, int nestDepth)
struct PgStat_WalStats PgStat_WalStats
void pgstat_create_replslot(struct ReplicationSlot *slot)
void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
PgStat_WalStats * pgstat_fetch_stat_wal(void)
void pgstat_drop_database(Oid databaseid)
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
struct PgStat_BgWriterStats PgStat_BgWriterStats
struct PgStat_StatTabEntry PgStat_StatTabEntry
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
void pgstat_count_truncate(Relation rel)
void pgstat_drop_replslot(struct ReplicationSlot *slot)
PGDLLIMPORT bool pgstat_track_counts
void pgstat_drop_relation(Relation rel)
#define PGSTAT_KIND_BUILTIN_MIN
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)
const char * pgstat_get_io_context_name(IOContext io_context)
void pgstat_discard_stats(void)
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
void pgstat_report_bgwriter(void)
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)
void pgstat_report_archiver(const char *xlog, bool failed)
#define IOOBJECT_NUM_TYPES
struct PgStat_TableXactStatus PgStat_TableXactStatus
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
PGDLLIMPORT SessionEndType pgStatSessionEndCause
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op)
void pgstat_init_relation(Relation rel)
PGDLLIMPORT PgStat_PendingWalStats PendingWalStats
struct PgStat_IO PgStat_IO
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 apply_error_count
PgStat_Counter sync_error_count
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
PgStat_Counter buf_written_clean
PgStat_Counter maxwritten_clean
TimestampTz stat_reset_timestamp
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_Counter restartpoints_requested
PgStat_Counter write_time
PgStat_Counter num_requested
PgStat_Counter num_performed
PgStat_Counter restartpoints_timed
PgStat_Counter restartpoints_performed
PgStat_Counter buffers_written
TimestampTz stat_reset_timestamp
PgStat_Counter slru_written
PgStat_FunctionCounts * fs
instr_time save_f_total_time
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
TimestampTz stat_reset_timestamp
PgStat_Counter wal_buffers_full
instr_time wal_write_time
PgStat_Counter blocks_read
PgStat_Counter blocks_exists
TimestampTz stat_reset_timestamp
PgStat_Counter blocks_zeroed
PgStat_Counter blocks_written
PgStat_Counter blocks_hit
PgStat_Counter blk_write_time
PgStat_Counter xact_rollback
PgStat_Counter conflict_startup_deadlock
PgStat_Counter conflict_lock
PgStat_Counter tuples_updated
PgStat_Counter parallel_workers_to_launch
PgStat_Counter tuples_inserted
TimestampTz stat_reset_timestamp
PgStat_Counter conflict_snapshot
PgStat_Counter sessions_fatal
TimestampTz last_checksum_failure
PgStat_Counter tuples_returned
PgStat_Counter blk_read_time
PgStat_Counter parallel_workers_launched
PgStat_Counter xact_commit
TimestampTz last_autovac_time
PgStat_Counter temp_bytes
PgStat_Counter session_time
PgStat_Counter blocks_hit
PgStat_Counter temp_files
PgStat_Counter sessions_abandoned
PgStat_Counter active_time
PgStat_Counter blocks_fetched
PgStat_Counter conflict_bufferpin
PgStat_Counter idle_in_transaction_time
PgStat_Counter conflict_logicalslot
PgStat_Counter tuples_deleted
PgStat_Counter sessions_killed
PgStat_Counter tuples_fetched
PgStat_Counter checksum_failures
PgStat_Counter conflict_tablespace
PgStat_Counter total_time
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
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
TimestampTz stat_reset_timestamp
PgStat_Counter vacuum_count
PgStat_Counter tuples_fetched
PgStat_Counter ins_since_vacuum
PgStat_Counter blocks_hit
PgStat_Counter mod_since_analyze
TimestampTz last_autovacuum_time
PgStat_Counter analyze_count
PgStat_Counter tuples_deleted
PgStat_Counter tuples_hot_updated
PgStat_Counter tuples_updated
PgStat_Counter live_tuples
PgStat_Counter autovacuum_count
TimestampTz last_analyze_time
PgStat_Counter dead_tuples
PgStat_Counter autoanalyze_count
PgStat_Counter blocks_fetched
PgStat_Counter tuples_returned
TimestampTz last_autoanalyze_time
PgStat_Counter tuples_inserted
PgStat_Counter tuples_newpage_updated
TimestampTz last_vacuum_time
PgStat_Counter blocks_hit
PgStat_Counter tuples_hot_updated
PgStat_Counter tuples_returned
PgStat_Counter tuples_inserted
PgStat_Counter delta_live_tuples
PgStat_Counter changed_tuples
PgStat_Counter tuples_updated
PgStat_Counter blocks_fetched
PgStat_Counter tuples_fetched
PgStat_Counter tuples_newpage_updated
PgStat_Counter delta_dead_tuples
PgStat_Counter tuples_deleted
PgStat_TableCounts counts
struct PgStat_TableXactStatus * trans
struct PgStat_TableXactStatus * next
PgStat_Counter deleted_pre_truncdrop
PgStat_TableStatus * parent
PgStat_Counter tuples_inserted
PgStat_Counter tuples_updated
PgStat_Counter inserted_pre_truncdrop
PgStat_Counter tuples_deleted
struct PgStat_TableXactStatus * upper
PgStat_Counter updated_pre_truncdrop
PgStat_Counter wal_buffers_full
PgStat_Counter wal_write_time
TimestampTz stat_reset_timestamp
PgStat_Counter wal_sync_time
PgStat_Counter wal_records