29 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
30 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/global.stat"
31 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/global.tmp"
34 #define PG_STAT_TMP_DIR "pg_stat_tmp"
206 #define PGSTAT_MAX_MSG_SIZE 1000
207 #define PGSTAT_MSG_PAYLOAD (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))
250 #define PGSTAT_NUM_TABENTRIES \
251 ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int) - 2 * sizeof(PgStat_Counter)) \
252 / sizeof(PgStat_TableEntry))
272 #define PGSTAT_NUM_TABPURGE \
273 ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
479 #define PGSTAT_NUM_FUNCENTRIES \
480 ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
481 / sizeof(PgStat_FunctionEntry))
496 #define PGSTAT_NUM_FUNCPURGE \
497 ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
555 #define PGSTAT_FILE_FORMAT_ID 0x01A5BC9D
724 #define PGSTAT_NUM_PROGRESS_PARAM 10
831 #define pgstat_increment_changecount_before(beentry) \
833 beentry->st_changecount++; \
834 pg_write_barrier(); \
837 #define pgstat_increment_changecount_after(beentry) \
839 pg_write_barrier(); \
840 beentry->st_changecount++; \
841 Assert((beentry->st_changecount & 1) == 0); \
844 #define pgstat_save_changecount_before(beentry, save_changecount) \
846 save_changecount = beentry->st_changecount; \
850 #define pgstat_save_changecount_after(beentry, save_changecount) \
853 save_changecount = beentry->st_changecount; \
1014 wait_event_val = classId;
1015 wait_event_val <<= 24;
1016 wait_event_val |= eventId;
1051 #define pgstat_count_heap_scan(rel) \
1053 if ((rel)->pgstat_info != NULL) \
1054 (rel)->pgstat_info->t_counts.t_numscans++; \
1056 #define pgstat_count_heap_getnext(rel) \
1058 if ((rel)->pgstat_info != NULL) \
1059 (rel)->pgstat_info->t_counts.t_tuples_returned++; \
1061 #define pgstat_count_heap_fetch(rel) \
1063 if ((rel)->pgstat_info != NULL) \
1064 (rel)->pgstat_info->t_counts.t_tuples_fetched++; \
1066 #define pgstat_count_index_scan(rel) \
1068 if ((rel)->pgstat_info != NULL) \
1069 (rel)->pgstat_info->t_counts.t_numscans++; \
1071 #define pgstat_count_index_tuples(rel, n) \
1073 if ((rel)->pgstat_info != NULL) \
1074 (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
1076 #define pgstat_count_buffer_read(rel) \
1078 if ((rel)->pgstat_info != NULL) \
1079 (rel)->pgstat_info->t_counts.t_blocks_fetched++; \
1081 #define pgstat_count_buffer_hit(rel) \
1083 if ((rel)->pgstat_info != NULL) \
1084 (rel)->pgstat_info->t_counts.t_blocks_hit++; \
1086 #define pgstat_count_buffer_read_time(n) \
1087 (pgStatBlockReadTime += (n))
1088 #define pgstat_count_buffer_write_time(n) \
1089 (pgStatBlockWriteTime += (n))
1109 void *recdata,
uint32 len);
1111 void *recdata,
uint32 len);
void pgstat_count_truncate(Relation rel)
PgStat_MsgBgWriter msg_bgwriter
PgStat_Counter m_buf_fsync_backend
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
void pgstat_initialize(void)
PgStat_Counter analyze_count
char ssl_cipher[NAMEDATALEN]
char last_failed_wal[MAX_XFN_CHARS+1]
char m_xlog[MAX_XFN_CHARS+1]
PgStat_Counter archived_count
PgStat_Counter m_buf_written_checkpoints
PgStat_Counter m_buf_alloc
struct PgStat_MsgFuncpurge PgStat_MsgFuncpurge
PgStat_Counter t_delta_live_tuples
Oid st_progress_command_target
PgStat_Counter m_dead_tuples
void pgstat_clear_snapshot(void)
PgStat_Counter m_checkpoint_write_time
PgStat_Counter tuples_updated
void pgstat_report_xact_timestamp(TimestampTz tstamp)
const char * pgstat_get_backend_current_activity(int pid, bool checkUser)
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn()
PgStat_Counter tuples_returned
PgStat_MsgDeadlock msg_deadlock
PgStat_MsgResetsharedcounter msg_resetsharedcounter
union PgStat_Msg PgStat_Msg
TimestampTz stats_timestamp
void pgstat_progress_update_param(int index, int64 val)
PgStat_Counter t_tuples_fetched
PgStat_Counter m_live_tuples
TimestampTz st_activity_start_timestamp
PgStat_Counter n_blocks_hit
#define PGSTAT_NUM_TABPURGE
struct PgStat_MsgTabpurge PgStat_MsgTabpurge
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
struct PgStat_MsgArchiver PgStat_MsgArchiver
PgStat_Counter m_timed_checkpoints
PgStat_Counter n_conflict_bufferpin
void pgstat_report_appname(const char *appname)
PgStat_Counter m_maxwritten_clean
PgStat_Counter n_conflict_startup_deadlock
void CreateSharedBackendStatus(void)
PgStat_Counter t_tuples_hot_updated
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
TimestampTz autovac_analyze_timestamp
bool pgstat_track_activities
struct PgStat_MsgDeadlock PgStat_MsgDeadlock
struct timeval instr_time
PgStat_Counter f_self_time
PgStat_Counter timed_checkpoints
PgStat_Counter n_temp_files
PgStat_Counter m_buf_written_clean
PgStat_MsgDummy msg_dummy
TransactionId backend_xmin
PgStat_GlobalStats * pgstat_fetch_global(void)
char ssl_version[NAMEDATALEN]
PgStat_Counter n_tuples_returned
PgStat_Counter vacuum_count
void pgstat_send_archiver(const char *xlog, bool failed)
PgStat_Counter buf_fsync_backend
struct PgStat_TableCounts PgStat_TableCounts
struct PgStat_MsgDummy PgStat_MsgDummy
TimestampTz stats_timestamp
TimestampTz stat_reset_timestamp
struct PgStat_TableXactStatus * next
TimestampTz m_analyzetime
ProgressCommandType st_progress_command
void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
PgStat_TableCounts t_counts
#define pg_attribute_noreturn()
struct PgBackendSSLStatus PgBackendSSLStatus
struct PgStat_MsgRecoveryConflict PgStat_MsgRecoveryConflict
struct PgStat_ArchiverStats PgStat_ArchiverStats
PgStat_Counter deleted_pre_trunc
PgStat_MsgAnalyze msg_analyze
PgStat_Counter tuples_hot_updated
PgStat_Counter f_total_time
PgStat_Counter t_tuples_returned
PgStat_Shared_Reset_Target
PgStat_Counter tuples_inserted
PgStat_FunctionCounts * fs
PgStat_Counter f_numcalls
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
PgStat_Counter n_xact_commit
void pgstat_report_deadlock(void)
PgStat_MsgBgWriter BgWriterStats
#define PGSTAT_NUM_PROGRESS_PARAM
PgStat_Counter n_blocks_fetched
int pgstat_track_functions
struct PgStat_TableEntry PgStat_TableEntry
PgStat_Counter n_live_tuples
PgStat_Counter m_requested_checkpoints
struct PgStat_MsgAnalyze PgStat_MsgAnalyze
PgStat_FunctionCounts f_counts
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
PgStat_MsgFuncpurge msg_funcpurge
char * pgstat_stat_tmpname
PgStat_Counter buf_written_backend
PgStat_Counter n_conflict_tablespace
TransactionId backend_xid
void AtEOSubXact_PgStat(bool isCommit, int nestDepth)
TimestampTz vacuum_timestamp
PgStat_Counter t_tuples_updated
Oid m_tableid[PGSTAT_NUM_TABPURGE]
PgStat_Counter pgStatBlockReadTime
void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type)
PgStat_Counter checkpoint_write_time
PgStat_Counter n_dead_tuples
struct PgStat_MsgTempFile PgStat_MsgTempFile
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
static void pgstat_report_wait_start(uint8 classId, uint16 eventId)
void allow_immediate_pgstat_restart(void)
PgStat_Counter f_numcalls
TimestampTz last_autovac_time
struct PgStat_GlobalStats PgStat_GlobalStats
PgStat_Counter n_tuples_inserted
PgStat_Counter buf_written_checkpoints
PgStat_Counter tuples_inserted
void AtEOXact_PgStat(bool isCommit)
struct PgStat_MsgDropdb PgStat_MsgDropdb
PgStat_Counter pgStatBlockWriteTime
struct PgStat_MsgInquiry PgStat_MsgInquiry
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
char * pgstat_stat_directory
void pgstat_report_stat(bool force)
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples)
void pgstat_vacuum_stat(void)
PgStat_Counter t_delta_dead_tuples
PgStat_Counter tuples_fetched
PgStat_Counter n_conflict_snapshot
PgStat_Counter m_block_write_time
static void pgstat_report_wait_end(void)
TimestampTz st_state_start_timestamp
PgStat_Counter n_tuples_deleted
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
PgStat_Counter n_conflict_lock
PgStat_Counter t_blocks_hit
struct PgStat_TableXactStatus * upper
PgStat_Counter n_xact_rollback
void pgstat_progress_end_command(void)
PgStat_Counter t_tuples_deleted
PgStat_Counter buf_written_clean
int pgstat_fetch_stat_numbackends(void)
void pgstat_report_recovery_conflict(int reason)
PgStat_MsgRecoveryConflict msg_recoveryconflict
struct PgStat_MsgTabstat PgStat_MsgTabstat
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
PgStat_Counter m_live_tuples
void pgstat_drop_database(Oid databaseid)
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
struct PgStat_MsgResetsharedcounter PgStat_MsgResetsharedcounter
struct PgStat_FunctionCounts PgStat_FunctionCounts
const char * pgstat_get_wait_event(uint32 wait_event_info)
PgBackendStatus backendStatus
#define PGSTAT_NUM_FUNCENTRIES
PgStat_Counter tuples_deleted
struct PgStat_MsgBgWriter PgStat_MsgBgWriter
#define PGSTAT_NUM_TABENTRIES
struct PgStat_MsgResetsinglecounter PgStat_MsgResetsinglecounter
void pgstat_reset_counters(void)
PgStat_Counter f_total_time
PgStat_MsgAutovacStart msg_autovacuum
PgStat_Counter blocks_hit
TimestampTz analyze_timestamp
TimestampTz last_failed_timestamp
PgStat_Counter changes_since_analyze
PgStat_Shared_Reset_Target m_resettarget
void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
PgStat_Counter t_numscans
struct PgStat_MsgVacuum PgStat_MsgVacuum
Size BackendStatusShmemSize(void)
struct PgStat_TableXactStatus PgStat_TableXactStatus
PgStat_Counter n_tuples_updated
char * pgstat_stat_filename
PgStat_Counter t_changed_tuples
PgStat_MsgTabstat msg_tabstat
void pgstat_send_bgwriter(void)
PgStat_Counter m_checkpoint_sync_time
PgStat_MsgVacuum msg_vacuum
PgStat_Counter failed_count
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
PgStat_Counter n_block_write_time
PgStat_Counter m_buf_written_backend
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
void pgstat_count_heap_delete(Relation rel)
PgStat_Counter tuples_deleted
struct PgStat_StatTabEntry PgStat_StatTabEntry
PgStat_TableCounts t_counts
PgStat_Counter inserted_pre_trunc
PgStat_Counter tuples_updated
PgStat_Counter checkpoint_sync_time
void pgstat_report_tempfile(size_t filesize)
PgStat_FunctionEntry m_entry[PGSTAT_NUM_FUNCENTRIES]
void pgstat_init_function_usage(FunctionCallInfoData *fcinfo, PgStat_FunctionCallUsage *fcu)
struct PgStat_FunctionEntry PgStat_FunctionEntry
TimestampTz autovac_vacuum_timestamp
PgStat_Counter maxwritten_clean
PgStat_Counter n_block_read_time
PgStat_Counter m_block_read_time
struct PgStat_MsgFuncstat PgStat_MsgFuncstat
TimestampTz stat_reset_timestamp
void pgstat_bestart(void)
struct PgStat_TableXactStatus * trans
struct PgStat_TableStatus PgStat_TableStatus
struct PgBackendStatus PgBackendStatus
struct PgStat_StatDBEntry PgStat_StatDBEntry
PgStat_Counter autovac_analyze_count
void pgstat_count_heap_insert(Relation rel, int n)
void pgstat_report_autovac(Oid dboid)
PgStat_Counter updated_pre_trunc
void pgstat_report_activity(BackendState state, const char *cmd_str)
void pgstat_count_heap_update(Relation rel, bool hot)
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
TimestampTz stat_reset_timestamp
TimestampTz last_archived_timestamp
PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES]
PgStat_Counter n_deadlocks
struct PgStat_MsgAutovacStart PgStat_MsgAutovacStart
TimestampTz st_xact_start_timestamp
PgStat_MsgArchiver msg_archiver
const char * pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
PgStat_MsgResetsinglecounter msg_resetsinglecounter
PgStat_Counter requested_checkpoints
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid funcid)
instr_time save_f_total_time
PgStat_MsgResetcounter msg_resetcounter
void pgstat_reset_all(void)
PgStat_Counter f_numcalls
struct PgStat_MsgResetcounter PgStat_MsgResetcounter
PgStat_Counter f_self_time
PgStat_Counter m_dead_tuples
PgStat_Counter blocks_fetched
void AtPrepare_PgStat(void)
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
struct PgStat_MsgHdr PgStat_MsgHdr
TimestampTz st_proc_start_timestamp
PgStat_MsgInquiry msg_inquiry
PgStat_MsgDropdb msg_dropdb
PgBackendSSLStatus * st_sslstatus
PgStat_Single_Reset_Type m_resettype
void pgstat_initstats(Relation rel)
PgStat_Counter t_tuples_inserted
void pgstat_reset_shared_counters(const char *)
PgStat_MsgTabpurge msg_tabpurge
#define PGSTAT_NUM_FUNCPURGE
PGDLLIMPORT int pgstat_track_activity_query_size
PgStat_TableStatus * parent
PgStat_Counter t_blocks_fetched
void PostPrepare_PgStat(void)
PgStat_MsgFuncstat msg_funcstat
struct LocalPgBackendStatus LocalPgBackendStatus
PgStat_Counter n_tuples_fetched
char last_archived_wal[MAX_XFN_CHARS+1]
PgStat_Counter autovac_vacuum_count
Oid m_functionid[PGSTAT_NUM_FUNCPURGE]
char ssl_clientdn[NAMEDATALEN]
PgStat_Counter n_temp_bytes