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"
214#define PGSTAT_FILE_FORMAT_ID 0x01A5BCB7
279#define IOOBJECT_NUM_TYPES (IOOBJECT_WAL + 1)
290#define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
316#define IOOP_NUM_TYPES (IOOP_WRITE + 1)
318#define pgstat_is_ioop_tracked_in_bytes(io_op) \
319 (((unsigned int) (io_op)) < IOOP_NUM_TYPES && \
320 ((unsigned int) (io_op)) >= IOOP_EXTEND)
620#define pgstat_count_buffer_read_time(n) \
621 (pgStatBlockReadTime += (n))
622#define pgstat_count_buffer_write_time(n) \
623 (pgStatBlockWriteTime += (n))
624#define pgstat_count_conn_active_time(n) \
625 (pgStatActiveTime += (n))
626#define pgstat_count_conn_txn_idle_time(n) \
627 (pgStatTransactionIdleTime += (n))
673#define pgstat_should_count_relation(rel) \
674 (likely((rel)->pgstat_info != NULL) ? true : \
675 ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
679#define pgstat_count_heap_scan(rel) \
681 if (pgstat_should_count_relation(rel)) \
682 (rel)->pgstat_info->counts.numscans++; \
684#define pgstat_count_heap_getnext(rel) \
686 if (pgstat_should_count_relation(rel)) \
687 (rel)->pgstat_info->counts.tuples_returned++; \
689#define pgstat_count_heap_fetch(rel) \
691 if (pgstat_should_count_relation(rel)) \
692 (rel)->pgstat_info->counts.tuples_fetched++; \
694#define pgstat_count_index_scan(rel) \
696 if (pgstat_should_count_relation(rel)) \
697 (rel)->pgstat_info->counts.numscans++; \
699#define pgstat_count_index_tuples(rel, n) \
701 if (pgstat_should_count_relation(rel)) \
702 (rel)->pgstat_info->counts.tuples_returned += (n); \
704#define pgstat_count_buffer_read(rel) \
706 if (pgstat_should_count_relation(rel)) \
707 (rel)->pgstat_info->counts.blocks_fetched++; \
709#define pgstat_count_buffer_hit(rel) \
711 if (pgstat_should_count_relation(rel)) \
712 (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)
void pgstat_create_backend(ProcNumber procnum)
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)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
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_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples, TimestampTz starttime)
void pgstat_unlink_relation(Relation rel)
struct PgStat_CheckpointerStats PgStat_CheckpointerStats
void pgstat_reset_slru(const char *)
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
void pgstat_count_slru_page_exists(int slru_idx)
void pgstat_create_subscription(Oid subid)
void pgstat_count_slru_page_read(int slru_idx)
void pgstat_count_heap_update(Relation rel, bool hot, bool newpage)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt, uint64 bytes)
@ PGSTAT_FETCH_CONSISTENCY_NONE
@ PGSTAT_FETCH_CONSISTENCY_CACHE
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
bool pgstat_tracks_backend_bktype(BackendType bktype)
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)
PgStat_IO * pgstat_fetch_stat_io(void)
struct PgStat_StatSubEntry PgStat_StatSubEntry
void AtEOXact_PgStat(bool isCommit, bool parallel)
int pgstat_get_slru_index(const char *name)
PgStat_SLRUStats * pgstat_fetch_slru(void)
void pgstat_count_slru_page_hit(int slru_idx)
struct PgStat_PendingIO PgStat_PendingIO
const char * pgstat_get_io_context_name(IOContext io_context)
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
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)
struct PgStat_TableCounts PgStat_TableCounts
void pgstat_prepare_report_checksum_failure(Oid dboid)
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter, TimestampTz starttime)
void pgstat_report_connect(Oid dboid)
void pgstat_initialize(void)
struct PgStat_BackendSubEntry PgStat_BackendSubEntry
void pgstat_count_backend_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
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_reset_of_kind(PgStat_Kind kind)
const char * pgstat_get_io_object_name(IOObject io_object)
struct PgStat_SLRUStats PgStat_SLRUStats
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
PGDLLIMPORT int pgstat_fetch_consistency
struct PgStat_BktypeIO PgStat_BktypeIO
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
#define IOCONTEXT_NUM_TYPES
void pgstat_before_server_shutdown(int code, Datum arg)
void pgstat_report_deadlock(void)
void pgstat_acquire_replslot(struct ReplicationSlot *slot)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
void pgstat_report_recovery_conflict(int reason)
void pgstat_force_next_flush(void)
void pgstat_create_function(Oid proid)
const char * pgstat_get_slru_name(int slru_idx)
void pgstat_count_slru_page_written(int slru_idx)
struct PgStat_ArchiverStats PgStat_ArchiverStats
PGDLLIMPORT PgStat_Counter pgStatActiveTime
void pgstat_clear_snapshot(void)
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
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
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
void pgstat_report_wal(bool force)
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)
PGDLLIMPORT int pgstat_track_functions
void pgstat_count_heap_delete(Relation rel)
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
struct PgStat_Backend PgStat_Backend
void pgstat_restore_stats(void)
struct PgStat_StatDBEntry PgStat_StatDBEntry
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
void pgstat_count_slru_flush(int slru_idx)
PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
PgStat_Backend * pgstat_fetch_stat_backend_by_pid(int pid, BackendType *bktype)
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)
void pgstat_drop_database(Oid databaseid)
void pgstat_count_backend_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time io_time)
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)
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
PGDLLIMPORT bool pgstat_track_counts
void pgstat_drop_relation(Relation rel)
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
PgStat_Backend * pgstat_fetch_stat_backend(ProcNumber procNumber)
struct PgStat_WalCounters PgStat_WalCounters
void pgstat_discard_stats(void)
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
PgStat_WalStats * pgstat_fetch_stat_wal(void)
void pgstat_report_bgwriter(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)
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
PGDLLIMPORT SessionEndType pgStatSessionEndCause
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)
void pgstat_init_relation(Relation rel)
struct PgStat_BackendPending PgStat_BackendPending
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_PendingIO pending_io
PgStat_Counter apply_error_count
PgStat_Counter sync_error_count
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
TimestampTz stat_reset_timestamp
PgStat_WalCounters wal_counters
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]
uint64 bytes[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 counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
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
PgStat_Counter total_autovacuum_time
PgStat_Counter total_analyze_time
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 total_autoanalyze_time
PgStat_Counter tuples_inserted
PgStat_Counter total_vacuum_time
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_records
TimestampTz stat_reset_timestamp
PgStat_WalCounters wal_counters