27 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
28 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/pgstat.stat"
29 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/pgstat.tmp"
32 #define PG_STAT_TMP_DIR "pg_stat_tmp"
56 #define PGSTAT_KIND_FIRST_VALID PGSTAT_KIND_DATABASE
57 #define PGSTAT_KIND_LAST PGSTAT_KIND_WAL
58 #define PGSTAT_NUM_KINDS (PGSTAT_KIND_LAST + 1)
238 #define PGSTAT_FILE_FORMAT_ID 0x01A5BCAC
282 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
292 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
306 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
550 #define pgstat_count_buffer_read_time(n) \
551 (pgStatBlockReadTime += (n))
552 #define pgstat_count_buffer_write_time(n) \
553 (pgStatBlockWriteTime += (n))
554 #define pgstat_count_conn_active_time(n) \
555 (pgStatActiveTime += (n))
556 #define pgstat_count_conn_txn_idle_time(n) \
557 (pgStatTransactionIdleTime += (n))
602 #define pgstat_should_count_relation(rel) \
603 (likely((rel)->pgstat_info != NULL) ? true : \
604 ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
608 #define pgstat_count_heap_scan(rel) \
610 if (pgstat_should_count_relation(rel)) \
611 (rel)->pgstat_info->counts.numscans++; \
613 #define pgstat_count_heap_getnext(rel) \
615 if (pgstat_should_count_relation(rel)) \
616 (rel)->pgstat_info->counts.tuples_returned++; \
618 #define pgstat_count_heap_fetch(rel) \
620 if (pgstat_should_count_relation(rel)) \
621 (rel)->pgstat_info->counts.tuples_fetched++; \
623 #define pgstat_count_index_scan(rel) \
625 if (pgstat_should_count_relation(rel)) \
626 (rel)->pgstat_info->counts.numscans++; \
628 #define pgstat_count_index_tuples(rel, n) \
630 if (pgstat_should_count_relation(rel)) \
631 (rel)->pgstat_info->counts.tuples_returned += (n); \
633 #define pgstat_count_buffer_read(rel) \
635 if (pgstat_should_count_relation(rel)) \
636 (rel)->pgstat_info->counts.blocks_fetched++; \
638 #define pgstat_count_buffer_hit(rel) \
640 if (pgstat_should_count_relation(rel)) \
641 (rel)->pgstat_info->counts.blocks_hit++; \
#define BACKEND_NUM_TYPES
void pgstat_drop_function(Oid proid)
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
void pgstat_drop_subscription(Oid subid)
struct PgStat_TableStatus PgStat_TableStatus
void pgstat_reset_replslot(const char *name)
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 *)
@ PGSTAT_KIND_SUBSCRIPTION
@ PGSTAT_KIND_CHECKPOINTER
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)
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)
struct PgStat_TableCounts PgStat_TableCounts
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
void pgstat_report_connect(Oid dboid)
void pgstat_initialize(void)
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
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)
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
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
struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
instr_time pgstat_prepare_io_time(void)
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)
void pgstat_restore_stats(void)
struct PgStat_StatDBEntry PgStat_StatDBEntry
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
PgStat_IO * pgstat_fetch_stat_io(void)
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)
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 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 buf_written_backend
PgStat_Counter checkpoint_sync_time
PgStat_Counter checkpoint_write_time
PgStat_Counter requested_checkpoints
PgStat_Counter timed_checkpoints
PgStat_Counter buf_fsync_backend
PgStat_Counter buf_written_checkpoints
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 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 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
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