pgstat: reorder pgstat.[ch] contents.
Now that 13619598f10 has split pgstat up into multiple files it isn't quite as hard to come up with a sensible order for pgstat.[ch]. Inconsistent naming makes it still not quite right looking, but that's work for another commit. Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
This commit is contained in:
parent
2591ee8ec4
commit
315ae75e9b
File diff suppressed because it is too large
Load Diff
@ -33,6 +33,7 @@
|
||||
/* Default directory to store temporary statistics data in */
|
||||
#define PG_STAT_TMP_DIR "pg_stat_tmp"
|
||||
|
||||
|
||||
/* Values for track_functions GUC variable --- order is significant! */
|
||||
typedef enum TrackFunctionsLevel
|
||||
{
|
||||
@ -51,50 +52,76 @@ typedef enum SessionEndType
|
||||
DISCONNECT_KILLED
|
||||
} SessionEndType;
|
||||
|
||||
/* ----------
|
||||
* The types of backend -> collector messages
|
||||
* ----------
|
||||
*/
|
||||
typedef enum StatMsgType
|
||||
{
|
||||
PGSTAT_MTYPE_DUMMY,
|
||||
PGSTAT_MTYPE_INQUIRY,
|
||||
PGSTAT_MTYPE_TABSTAT,
|
||||
PGSTAT_MTYPE_TABPURGE,
|
||||
PGSTAT_MTYPE_DROPDB,
|
||||
PGSTAT_MTYPE_RESETCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSHAREDCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSINGLECOUNTER,
|
||||
PGSTAT_MTYPE_RESETSLRUCOUNTER,
|
||||
PGSTAT_MTYPE_RESETREPLSLOTCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSUBCOUNTER,
|
||||
PGSTAT_MTYPE_AUTOVAC_START,
|
||||
PGSTAT_MTYPE_VACUUM,
|
||||
PGSTAT_MTYPE_ANALYZE,
|
||||
PGSTAT_MTYPE_ARCHIVER,
|
||||
PGSTAT_MTYPE_BGWRITER,
|
||||
PGSTAT_MTYPE_CHECKPOINTER,
|
||||
PGSTAT_MTYPE_WAL,
|
||||
PGSTAT_MTYPE_SLRU,
|
||||
PGSTAT_MTYPE_FUNCSTAT,
|
||||
PGSTAT_MTYPE_FUNCPURGE,
|
||||
PGSTAT_MTYPE_RECOVERYCONFLICT,
|
||||
PGSTAT_MTYPE_TEMPFILE,
|
||||
PGSTAT_MTYPE_DEADLOCK,
|
||||
PGSTAT_MTYPE_CHECKSUMFAILURE,
|
||||
PGSTAT_MTYPE_REPLSLOT,
|
||||
PGSTAT_MTYPE_CONNECT,
|
||||
PGSTAT_MTYPE_DISCONNECT,
|
||||
PGSTAT_MTYPE_SUBSCRIPTIONDROP,
|
||||
PGSTAT_MTYPE_SUBSCRIPTIONERROR,
|
||||
} StatMsgType;
|
||||
|
||||
/* ----------
|
||||
* The data type used for counters.
|
||||
* ----------
|
||||
*/
|
||||
typedef int64 PgStat_Counter;
|
||||
|
||||
/* Possible targets for resetting cluster-wide shared values */
|
||||
typedef enum PgStat_Shared_Reset_Target
|
||||
{
|
||||
RESET_ARCHIVER,
|
||||
RESET_BGWRITER,
|
||||
RESET_WAL
|
||||
} PgStat_Shared_Reset_Target;
|
||||
|
||||
/* Possible object types for resetting single counters */
|
||||
typedef enum PgStat_Single_Reset_Type
|
||||
{
|
||||
RESET_TABLE,
|
||||
RESET_FUNCTION
|
||||
} PgStat_Single_Reset_Type;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Structures kept in backend local memory while accumulating counts
|
||||
* ------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* ----------
|
||||
* PgStat_FunctionCounts The actual per-function counts kept by a backend
|
||||
*
|
||||
* This struct should contain only actual event counters, because we memcmp
|
||||
* it against zeroes to detect whether there are any counts to transmit.
|
||||
*
|
||||
* Note that the time counters are in instr_time format here. We convert to
|
||||
* microseconds in PgStat_Counter format when transmitting to the collector.
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_FunctionCounts
|
||||
{
|
||||
PgStat_Counter f_numcalls;
|
||||
instr_time f_total_time;
|
||||
instr_time f_self_time;
|
||||
} PgStat_FunctionCounts;
|
||||
|
||||
/* ----------
|
||||
* PgStat_BackendFunctionEntry Entry in backend's per-function hash table
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_BackendFunctionEntry
|
||||
{
|
||||
Oid f_id;
|
||||
PgStat_FunctionCounts f_counts;
|
||||
} PgStat_BackendFunctionEntry;
|
||||
|
||||
/*
|
||||
* Working state needed to accumulate per-function-call timing statistics.
|
||||
*/
|
||||
typedef struct PgStat_FunctionCallUsage
|
||||
{
|
||||
/* Link to function's hashtable entry (must still be there at exit!) */
|
||||
/* NULL means we are not tracking the current function call */
|
||||
PgStat_FunctionCounts *fs;
|
||||
/* Total time previously charged to function, as of function start */
|
||||
instr_time save_f_total_time;
|
||||
/* Backend-wide total time as of function start */
|
||||
instr_time save_total;
|
||||
/* system clock as of function start */
|
||||
instr_time f_start;
|
||||
} PgStat_FunctionCallUsage;
|
||||
|
||||
/* ----------
|
||||
* PgStat_TableCounts The actual per-table counts kept by a backend
|
||||
*
|
||||
@ -137,27 +164,6 @@ typedef struct PgStat_TableCounts
|
||||
PgStat_Counter t_blocks_hit;
|
||||
} PgStat_TableCounts;
|
||||
|
||||
/* Possible targets for resetting cluster-wide shared values */
|
||||
typedef enum PgStat_Shared_Reset_Target
|
||||
{
|
||||
RESET_ARCHIVER,
|
||||
RESET_BGWRITER,
|
||||
RESET_WAL
|
||||
} PgStat_Shared_Reset_Target;
|
||||
|
||||
/* Possible object types for resetting single counters */
|
||||
typedef enum PgStat_Single_Reset_Type
|
||||
{
|
||||
RESET_TABLE,
|
||||
RESET_FUNCTION
|
||||
} PgStat_Single_Reset_Type;
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Structures kept in backend local memory while accumulating counts
|
||||
* ------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_TableStatus Per-table status within a backend
|
||||
*
|
||||
@ -210,6 +216,43 @@ typedef struct PgStat_TableXactStatus
|
||||
* ------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* ----------
|
||||
* The types of backend -> collector messages
|
||||
* ----------
|
||||
*/
|
||||
typedef enum StatMsgType
|
||||
{
|
||||
PGSTAT_MTYPE_DUMMY,
|
||||
PGSTAT_MTYPE_INQUIRY,
|
||||
PGSTAT_MTYPE_TABSTAT,
|
||||
PGSTAT_MTYPE_TABPURGE,
|
||||
PGSTAT_MTYPE_DROPDB,
|
||||
PGSTAT_MTYPE_RESETCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSHAREDCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSINGLECOUNTER,
|
||||
PGSTAT_MTYPE_RESETSLRUCOUNTER,
|
||||
PGSTAT_MTYPE_RESETREPLSLOTCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSUBCOUNTER,
|
||||
PGSTAT_MTYPE_AUTOVAC_START,
|
||||
PGSTAT_MTYPE_VACUUM,
|
||||
PGSTAT_MTYPE_ANALYZE,
|
||||
PGSTAT_MTYPE_ARCHIVER,
|
||||
PGSTAT_MTYPE_BGWRITER,
|
||||
PGSTAT_MTYPE_CHECKPOINTER,
|
||||
PGSTAT_MTYPE_WAL,
|
||||
PGSTAT_MTYPE_SLRU,
|
||||
PGSTAT_MTYPE_FUNCSTAT,
|
||||
PGSTAT_MTYPE_FUNCPURGE,
|
||||
PGSTAT_MTYPE_RECOVERYCONFLICT,
|
||||
PGSTAT_MTYPE_TEMPFILE,
|
||||
PGSTAT_MTYPE_DEADLOCK,
|
||||
PGSTAT_MTYPE_CHECKSUMFAILURE,
|
||||
PGSTAT_MTYPE_REPLSLOT,
|
||||
PGSTAT_MTYPE_CONNECT,
|
||||
PGSTAT_MTYPE_DISCONNECT,
|
||||
PGSTAT_MTYPE_SUBSCRIPTIONDROP,
|
||||
PGSTAT_MTYPE_SUBSCRIPTIONERROR,
|
||||
} StatMsgType;
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgHdr The common message header
|
||||
@ -241,7 +284,6 @@ typedef struct PgStat_MsgDummy
|
||||
PgStat_MsgHdr m_hdr;
|
||||
} PgStat_MsgDummy;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgInquiry Sent by a backend to ask the collector
|
||||
* to write the stats file(s).
|
||||
@ -260,7 +302,6 @@ typedef struct PgStat_MsgDummy
|
||||
* effect unless that occurs. We assume clock_time >= cutoff_time, though.
|
||||
* ----------
|
||||
*/
|
||||
|
||||
typedef struct PgStat_MsgInquiry
|
||||
{
|
||||
PgStat_MsgHdr m_hdr;
|
||||
@ -269,7 +310,6 @@ typedef struct PgStat_MsgInquiry
|
||||
Oid databaseid; /* requested DB (InvalidOid => shared only) */
|
||||
} PgStat_MsgInquiry;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_TableEntry Per-table info in a MsgTabstat
|
||||
* ----------
|
||||
@ -304,7 +344,6 @@ typedef struct PgStat_MsgTabstat
|
||||
PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES];
|
||||
} PgStat_MsgTabstat;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgTabpurge Sent by the backend to tell the collector
|
||||
* about dead tables.
|
||||
@ -322,7 +361,6 @@ typedef struct PgStat_MsgTabpurge
|
||||
Oid m_tableid[PGSTAT_NUM_TABPURGE];
|
||||
} PgStat_MsgTabpurge;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgDropdb Sent by the backend to tell the collector
|
||||
* about a dropped database
|
||||
@ -334,7 +372,6 @@ typedef struct PgStat_MsgDropdb
|
||||
Oid m_databaseid;
|
||||
} PgStat_MsgDropdb;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgResetcounter Sent by the backend to tell the collector
|
||||
* to reset counters
|
||||
@ -405,7 +442,6 @@ typedef struct PgStat_MsgResetsubcounter
|
||||
* stats */
|
||||
} PgStat_MsgResetsubcounter;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
|
||||
* that a database is going to be processed
|
||||
@ -418,7 +454,6 @@ typedef struct PgStat_MsgAutovacStart
|
||||
TimestampTz m_start_time;
|
||||
} PgStat_MsgAutovacStart;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgVacuum Sent by the backend or autovacuum daemon
|
||||
* after VACUUM
|
||||
@ -435,7 +470,6 @@ typedef struct PgStat_MsgVacuum
|
||||
PgStat_Counter m_dead_tuples;
|
||||
} PgStat_MsgVacuum;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgAnalyze Sent by the backend or autovacuum daemon
|
||||
* after ANALYZE
|
||||
@ -453,7 +487,6 @@ typedef struct PgStat_MsgAnalyze
|
||||
PgStat_Counter m_dead_tuples;
|
||||
} PgStat_MsgAnalyze;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgArchiver Sent by the archiver to update statistics.
|
||||
* ----------
|
||||
@ -601,33 +634,6 @@ typedef struct PgStat_MsgTempFile
|
||||
size_t m_filesize;
|
||||
} PgStat_MsgTempFile;
|
||||
|
||||
/* ----------
|
||||
* PgStat_FunctionCounts The actual per-function counts kept by a backend
|
||||
*
|
||||
* This struct should contain only actual event counters, because we memcmp
|
||||
* it against zeroes to detect whether there are any counts to transmit.
|
||||
*
|
||||
* Note that the time counters are in instr_time format here. We convert to
|
||||
* microseconds in PgStat_Counter format when transmitting to the collector.
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_FunctionCounts
|
||||
{
|
||||
PgStat_Counter f_numcalls;
|
||||
instr_time f_total_time;
|
||||
instr_time f_self_time;
|
||||
} PgStat_FunctionCounts;
|
||||
|
||||
/* ----------
|
||||
* PgStat_BackendFunctionEntry Entry in backend's per-function hash table
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_BackendFunctionEntry
|
||||
{
|
||||
Oid f_id;
|
||||
PgStat_FunctionCounts f_counts;
|
||||
} PgStat_BackendFunctionEntry;
|
||||
|
||||
/* ----------
|
||||
* PgStat_FunctionEntry Per-function info in a MsgFuncstat
|
||||
* ----------
|
||||
@ -770,6 +776,48 @@ typedef union PgStat_Msg
|
||||
|
||||
#define PGSTAT_FILE_FORMAT_ID 0x01A5BCA6
|
||||
|
||||
/*
|
||||
* Archiver statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_ArchiverStats
|
||||
{
|
||||
PgStat_Counter archived_count; /* archival successes */
|
||||
char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
|
||||
* archived */
|
||||
TimestampTz last_archived_timestamp; /* last archival success time */
|
||||
PgStat_Counter failed_count; /* failed archival attempts */
|
||||
char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
|
||||
* last failure */
|
||||
TimestampTz last_failed_timestamp; /* last archival failure time */
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_ArchiverStats;
|
||||
|
||||
/*
|
||||
* Background writer statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_BgWriterStats
|
||||
{
|
||||
PgStat_Counter buf_written_clean;
|
||||
PgStat_Counter maxwritten_clean;
|
||||
PgStat_Counter buf_alloc;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_BgWriterStats;
|
||||
|
||||
/*
|
||||
* Checkpointer statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_CheckpointerStats
|
||||
{
|
||||
TimestampTz stats_timestamp; /* time of stats file update */
|
||||
PgStat_Counter timed_checkpoints;
|
||||
PgStat_Counter requested_checkpoints;
|
||||
PgStat_Counter checkpoint_write_time; /* times in milliseconds */
|
||||
PgStat_Counter checkpoint_sync_time;
|
||||
PgStat_Counter buf_written_checkpoints;
|
||||
PgStat_Counter buf_written_backend;
|
||||
PgStat_Counter buf_fsync_backend;
|
||||
} PgStat_CheckpointerStats;
|
||||
|
||||
/* ----------
|
||||
* PgStat_StatDBEntry The collector's data per database
|
||||
* ----------
|
||||
@ -818,6 +866,74 @@ typedef struct PgStat_StatDBEntry
|
||||
HTAB *functions;
|
||||
} PgStat_StatDBEntry;
|
||||
|
||||
/* ----------
|
||||
* PgStat_StatFuncEntry The collector's data per function
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_StatFuncEntry
|
||||
{
|
||||
Oid functionid;
|
||||
|
||||
PgStat_Counter f_numcalls;
|
||||
|
||||
PgStat_Counter f_total_time; /* times in microseconds */
|
||||
PgStat_Counter f_self_time;
|
||||
} PgStat_StatFuncEntry;
|
||||
|
||||
/*
|
||||
* Global statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_GlobalStats
|
||||
{
|
||||
TimestampTz stats_timestamp; /* time of stats file update */
|
||||
|
||||
PgStat_CheckpointerStats checkpointer;
|
||||
PgStat_BgWriterStats bgwriter;
|
||||
} PgStat_GlobalStats;
|
||||
|
||||
/*
|
||||
* Replication slot statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_StatReplSlotEntry
|
||||
{
|
||||
NameData slotname;
|
||||
PgStat_Counter spill_txns;
|
||||
PgStat_Counter spill_count;
|
||||
PgStat_Counter spill_bytes;
|
||||
PgStat_Counter stream_txns;
|
||||
PgStat_Counter stream_count;
|
||||
PgStat_Counter stream_bytes;
|
||||
PgStat_Counter total_txns;
|
||||
PgStat_Counter total_bytes;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_StatReplSlotEntry;
|
||||
|
||||
/*
|
||||
* SLRU statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_SLRUStats
|
||||
{
|
||||
PgStat_Counter blocks_zeroed;
|
||||
PgStat_Counter blocks_hit;
|
||||
PgStat_Counter blocks_read;
|
||||
PgStat_Counter blocks_written;
|
||||
PgStat_Counter blocks_exists;
|
||||
PgStat_Counter flush;
|
||||
PgStat_Counter truncate;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_SLRUStats;
|
||||
|
||||
/*
|
||||
* Subscription statistics kept in the stats collector.
|
||||
*/
|
||||
typedef struct PgStat_StatSubEntry
|
||||
{
|
||||
Oid subid; /* hash key (must be first) */
|
||||
|
||||
PgStat_Counter apply_error_count;
|
||||
PgStat_Counter sync_error_count;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_StatSubEntry;
|
||||
|
||||
/* ----------
|
||||
* PgStat_StatTabEntry The collector's data per table (or index)
|
||||
@ -855,75 +971,6 @@ typedef struct PgStat_StatTabEntry
|
||||
PgStat_Counter autovac_analyze_count;
|
||||
} PgStat_StatTabEntry;
|
||||
|
||||
|
||||
/* ----------
|
||||
* PgStat_StatFuncEntry The collector's data per function
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_StatFuncEntry
|
||||
{
|
||||
Oid functionid;
|
||||
|
||||
PgStat_Counter f_numcalls;
|
||||
|
||||
PgStat_Counter f_total_time; /* times in microseconds */
|
||||
PgStat_Counter f_self_time;
|
||||
} PgStat_StatFuncEntry;
|
||||
|
||||
|
||||
/*
|
||||
* Archiver statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_ArchiverStats
|
||||
{
|
||||
PgStat_Counter archived_count; /* archival successes */
|
||||
char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
|
||||
* archived */
|
||||
TimestampTz last_archived_timestamp; /* last archival success time */
|
||||
PgStat_Counter failed_count; /* failed archival attempts */
|
||||
char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
|
||||
* last failure */
|
||||
TimestampTz last_failed_timestamp; /* last archival failure time */
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_ArchiverStats;
|
||||
|
||||
/*
|
||||
* Background writer statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_BgWriterStats
|
||||
{
|
||||
PgStat_Counter buf_written_clean;
|
||||
PgStat_Counter maxwritten_clean;
|
||||
PgStat_Counter buf_alloc;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_BgWriterStats;
|
||||
|
||||
/*
|
||||
* Checkpointer statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_CheckpointerStats
|
||||
{
|
||||
TimestampTz stats_timestamp; /* time of stats file update */
|
||||
PgStat_Counter timed_checkpoints;
|
||||
PgStat_Counter requested_checkpoints;
|
||||
PgStat_Counter checkpoint_write_time; /* times in milliseconds */
|
||||
PgStat_Counter checkpoint_sync_time;
|
||||
PgStat_Counter buf_written_checkpoints;
|
||||
PgStat_Counter buf_written_backend;
|
||||
PgStat_Counter buf_fsync_backend;
|
||||
} PgStat_CheckpointerStats;
|
||||
|
||||
/*
|
||||
* Global statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_GlobalStats
|
||||
{
|
||||
TimestampTz stats_timestamp; /* time of stats file update */
|
||||
|
||||
PgStat_CheckpointerStats checkpointer;
|
||||
PgStat_BgWriterStats bgwriter;
|
||||
} PgStat_GlobalStats;
|
||||
|
||||
/*
|
||||
* WAL statistics kept in the stats collector
|
||||
*/
|
||||
@ -940,145 +987,115 @@ typedef struct PgStat_WalStats
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_WalStats;
|
||||
|
||||
/*
|
||||
* SLRU statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_SLRUStats
|
||||
{
|
||||
PgStat_Counter blocks_zeroed;
|
||||
PgStat_Counter blocks_hit;
|
||||
PgStat_Counter blocks_read;
|
||||
PgStat_Counter blocks_written;
|
||||
PgStat_Counter blocks_exists;
|
||||
PgStat_Counter flush;
|
||||
PgStat_Counter truncate;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_SLRUStats;
|
||||
|
||||
/*
|
||||
* Replication slot statistics kept in the stats collector
|
||||
* Functions in pgstat.c
|
||||
*/
|
||||
typedef struct PgStat_StatReplSlotEntry
|
||||
{
|
||||
NameData slotname;
|
||||
PgStat_Counter spill_txns;
|
||||
PgStat_Counter spill_count;
|
||||
PgStat_Counter spill_bytes;
|
||||
PgStat_Counter stream_txns;
|
||||
PgStat_Counter stream_count;
|
||||
PgStat_Counter stream_bytes;
|
||||
PgStat_Counter total_txns;
|
||||
PgStat_Counter total_bytes;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_StatReplSlotEntry;
|
||||
|
||||
/*
|
||||
* Subscription statistics kept in the stats collector.
|
||||
*/
|
||||
typedef struct PgStat_StatSubEntry
|
||||
{
|
||||
Oid subid; /* hash key (must be first) */
|
||||
|
||||
PgStat_Counter apply_error_count;
|
||||
PgStat_Counter sync_error_count;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_StatSubEntry;
|
||||
|
||||
/*
|
||||
* Working state needed to accumulate per-function-call timing statistics.
|
||||
*/
|
||||
typedef struct PgStat_FunctionCallUsage
|
||||
{
|
||||
/* Link to function's hashtable entry (must still be there at exit!) */
|
||||
/* NULL means we are not tracking the current function call */
|
||||
PgStat_FunctionCounts *fs;
|
||||
/* Total time previously charged to function, as of function start */
|
||||
instr_time save_f_total_time;
|
||||
/* Backend-wide total time as of function start */
|
||||
instr_time save_total;
|
||||
/* system clock as of function start */
|
||||
instr_time f_start;
|
||||
} PgStat_FunctionCallUsage;
|
||||
|
||||
|
||||
/* ----------
|
||||
* GUC parameters
|
||||
* ----------
|
||||
*/
|
||||
extern PGDLLIMPORT bool pgstat_track_counts;
|
||||
extern PGDLLIMPORT int pgstat_track_functions;
|
||||
extern char *pgstat_stat_directory;
|
||||
extern char *pgstat_stat_tmpname;
|
||||
extern char *pgstat_stat_filename;
|
||||
|
||||
/*
|
||||
* BgWriter statistics counters are updated directly by bgwriter and bufmgr
|
||||
*/
|
||||
extern PgStat_MsgBgWriter PendingBgWriterStats;
|
||||
|
||||
/*
|
||||
* Checkpointer statistics counters are updated directly by checkpointer and
|
||||
* bufmgr.
|
||||
*/
|
||||
extern PgStat_MsgCheckpointer PendingCheckpointerStats;
|
||||
|
||||
/*
|
||||
* WAL statistics counter is updated by backends and background processes
|
||||
*/
|
||||
extern PgStat_MsgWal WalStats;
|
||||
|
||||
/*
|
||||
* Updated by pgstat_count_buffer_*_time macros
|
||||
*/
|
||||
extern PgStat_Counter pgStatBlockReadTime;
|
||||
extern PgStat_Counter pgStatBlockWriteTime;
|
||||
|
||||
/*
|
||||
* Updated by pgstat_count_conn_*_time macros, called by
|
||||
* pgstat_report_activity().
|
||||
*/
|
||||
extern PgStat_Counter pgStatActiveTime;
|
||||
extern PgStat_Counter pgStatTransactionIdleTime;
|
||||
|
||||
|
||||
/*
|
||||
* Updated by the traffic cop and in errfinish()
|
||||
*/
|
||||
extern SessionEndType pgStatSessionEndCause;
|
||||
|
||||
/* ----------
|
||||
* Functions called from postmaster
|
||||
* ----------
|
||||
*/
|
||||
/* functions called from postmaster */
|
||||
extern void pgstat_init(void);
|
||||
extern int pgstat_start(void);
|
||||
extern void pgstat_reset_all(void);
|
||||
extern int pgstat_start(void);
|
||||
extern void allow_immediate_pgstat_restart(void);
|
||||
|
||||
#ifdef EXEC_BACKEND
|
||||
extern void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
|
||||
#endif
|
||||
|
||||
/* Functions for backend initialization */
|
||||
extern void pgstat_initialize(void);
|
||||
|
||||
/* ----------
|
||||
* Functions called from backends
|
||||
* ----------
|
||||
*/
|
||||
extern void pgstat_ping(void);
|
||||
/* transactional integration */
|
||||
extern void AtEOXact_PgStat(bool isCommit, bool parallel);
|
||||
extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
|
||||
extern void AtPrepare_PgStat(void);
|
||||
extern void PostPrepare_PgStat(void);
|
||||
extern void pgstat_clear_snapshot(void);
|
||||
|
||||
/* Functions called from backends */
|
||||
extern void pgstat_report_stat(bool force);
|
||||
extern void pgstat_vacuum_stat(void);
|
||||
extern void pgstat_drop_database(Oid databaseid);
|
||||
extern void pgstat_ping(void);
|
||||
|
||||
extern void pgstat_clear_snapshot(void);
|
||||
extern void pgstat_reset_counters(void);
|
||||
extern void pgstat_reset_shared_counters(const char *);
|
||||
extern void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type);
|
||||
extern void pgstat_reset_slru_counter(const char *);
|
||||
extern void pgstat_reset_replslot_counter(const char *name);
|
||||
extern void pgstat_reset_subscription_counter(Oid subid);
|
||||
extern void pgstat_reset_shared_counters(const char *);
|
||||
|
||||
/* stats accessors */
|
||||
extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void);
|
||||
extern PgStat_BgWriterStats *pgstat_fetch_stat_bgwriter(void);
|
||||
extern PgStat_CheckpointerStats *pgstat_fetch_stat_checkpointer(void);
|
||||
extern PgStat_StatDBEntry *pgstat_fetch_stat_dbentry(Oid dbid);
|
||||
extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid);
|
||||
extern PgStat_GlobalStats *pgstat_fetch_global(void);
|
||||
extern PgStat_StatReplSlotEntry *pgstat_fetch_replslot(NameData slotname);
|
||||
extern PgStat_StatSubEntry *pgstat_fetch_stat_subscription(Oid subid);
|
||||
extern PgStat_SLRUStats *pgstat_fetch_slru(void);
|
||||
extern PgStat_StatTabEntry *pgstat_fetch_stat_tabentry(Oid relid);
|
||||
extern PgStat_WalStats *pgstat_fetch_stat_wal(void);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_archiver.c
|
||||
*/
|
||||
|
||||
extern void pgstat_send_archiver(const char *xlog, bool failed);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_bgwriter.c
|
||||
*/
|
||||
|
||||
extern void pgstat_send_bgwriter(void);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_checkpointer.c
|
||||
*/
|
||||
|
||||
extern void pgstat_send_checkpointer(void);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_database.c
|
||||
*/
|
||||
|
||||
extern void pgstat_drop_database(Oid databaseid);
|
||||
extern void pgstat_report_recovery_conflict(int reason);
|
||||
extern void pgstat_report_deadlock(void);
|
||||
extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
|
||||
extern void pgstat_report_checksum_failure(void);
|
||||
extern void pgstat_report_connect(Oid dboid);
|
||||
|
||||
#define pgstat_count_buffer_read_time(n) \
|
||||
(pgStatBlockReadTime += (n))
|
||||
#define pgstat_count_buffer_write_time(n) \
|
||||
(pgStatBlockWriteTime += (n))
|
||||
#define pgstat_count_conn_active_time(n) \
|
||||
(pgStatActiveTime += (n))
|
||||
#define pgstat_count_conn_txn_idle_time(n) \
|
||||
(pgStatTransactionIdleTime += (n))
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_function.c
|
||||
*/
|
||||
|
||||
struct FunctionCallInfoBaseData;
|
||||
extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
|
||||
PgStat_FunctionCallUsage *fcu);
|
||||
extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
|
||||
bool finalize);
|
||||
|
||||
extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_relation.c
|
||||
*/
|
||||
|
||||
extern void pgstat_relation_init(Relation rel);
|
||||
|
||||
extern void pgstat_report_autovac(Oid dboid);
|
||||
extern void pgstat_report_vacuum(Oid tableoid, bool shared,
|
||||
PgStat_Counter livetuples, PgStat_Counter deadtuples);
|
||||
@ -1086,24 +1103,6 @@ extern void pgstat_report_analyze(Relation rel,
|
||||
PgStat_Counter livetuples, PgStat_Counter deadtuples,
|
||||
bool resetcounter);
|
||||
|
||||
extern void pgstat_report_recovery_conflict(int reason);
|
||||
extern void pgstat_report_deadlock(void);
|
||||
extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
|
||||
extern void pgstat_report_checksum_failure(void);
|
||||
extern void pgstat_report_replslot(const PgStat_StatReplSlotEntry *repSlotStat);
|
||||
extern void pgstat_report_replslot_create(const char *slotname);
|
||||
extern void pgstat_report_replslot_drop(const char *slotname);
|
||||
extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
|
||||
extern void pgstat_report_subscription_drop(Oid subid);
|
||||
|
||||
extern void pgstat_initialize(void);
|
||||
|
||||
|
||||
extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
|
||||
extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
|
||||
|
||||
extern void pgstat_relation_init(Relation rel);
|
||||
|
||||
#define pgstat_relation_should_count(rel) \
|
||||
(likely((rel)->pgstat_info != NULL))
|
||||
|
||||
@ -1144,14 +1143,6 @@ extern void pgstat_relation_init(Relation rel);
|
||||
if (pgstat_relation_should_count(rel)) \
|
||||
(rel)->pgstat_info->t_counts.t_blocks_hit++; \
|
||||
} while (0)
|
||||
#define pgstat_count_buffer_read_time(n) \
|
||||
(pgStatBlockReadTime += (n))
|
||||
#define pgstat_count_buffer_write_time(n) \
|
||||
(pgStatBlockWriteTime += (n))
|
||||
#define pgstat_count_conn_active_time(n) \
|
||||
(pgStatActiveTime += (n))
|
||||
#define pgstat_count_conn_txn_idle_time(n) \
|
||||
(pgStatTransactionIdleTime += (n))
|
||||
|
||||
extern void pgstat_count_heap_insert(Relation rel, PgStat_Counter n);
|
||||
extern void pgstat_count_heap_update(Relation rel, bool hot);
|
||||
@ -1159,45 +1150,29 @@ extern void pgstat_count_heap_delete(Relation rel);
|
||||
extern void pgstat_count_truncate(Relation rel);
|
||||
extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
|
||||
|
||||
struct FunctionCallInfoBaseData;
|
||||
extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
|
||||
PgStat_FunctionCallUsage *fcu);
|
||||
extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
|
||||
bool finalize);
|
||||
|
||||
extern void AtEOXact_PgStat(bool isCommit, bool parallel);
|
||||
extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
|
||||
|
||||
extern void AtPrepare_PgStat(void);
|
||||
extern void PostPrepare_PgStat(void);
|
||||
|
||||
extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
|
||||
void *recdata, uint32 len);
|
||||
extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
|
||||
void *recdata, uint32 len);
|
||||
|
||||
extern void pgstat_send_archiver(const char *xlog, bool failed);
|
||||
extern void pgstat_send_bgwriter(void);
|
||||
extern void pgstat_send_checkpointer(void);
|
||||
extern void pgstat_send_wal(bool force);
|
||||
extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
|
||||
|
||||
/* ----------
|
||||
* Support functions for the SQL-callable functions to
|
||||
* generate the pgstat* views.
|
||||
* ----------
|
||||
|
||||
/*
|
||||
* Functions in pgstat_replslot.c
|
||||
*/
|
||||
extern PgStat_StatDBEntry *pgstat_fetch_stat_dbentry(Oid dbid);
|
||||
extern PgStat_StatTabEntry *pgstat_fetch_stat_tabentry(Oid relid);
|
||||
extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid);
|
||||
extern PgStat_StatSubEntry *pgstat_fetch_stat_subscription(Oid subid);
|
||||
extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void);
|
||||
extern PgStat_BgWriterStats *pgstat_fetch_stat_bgwriter(void);
|
||||
extern PgStat_CheckpointerStats *pgstat_fetch_stat_checkpointer(void);
|
||||
extern PgStat_GlobalStats *pgstat_fetch_global(void);
|
||||
extern PgStat_WalStats *pgstat_fetch_stat_wal(void);
|
||||
extern PgStat_SLRUStats *pgstat_fetch_slru(void);
|
||||
extern PgStat_StatReplSlotEntry *pgstat_fetch_replslot(NameData slotname);
|
||||
|
||||
extern void pgstat_reset_replslot_counter(const char *name);
|
||||
extern void pgstat_report_replslot(const PgStat_StatReplSlotEntry *repSlotStat);
|
||||
extern void pgstat_report_replslot_create(const char *slotname);
|
||||
extern void pgstat_report_replslot_drop(const char *slotname);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_slru.c
|
||||
*/
|
||||
|
||||
extern void pgstat_reset_slru_counter(const char *);
|
||||
extern void pgstat_count_slru_page_zeroed(int slru_idx);
|
||||
extern void pgstat_count_slru_page_hit(int slru_idx);
|
||||
extern void pgstat_count_slru_page_read(int slru_idx);
|
||||
@ -1208,4 +1183,79 @@ extern void pgstat_count_slru_truncate(int slru_idx);
|
||||
extern const char *pgstat_slru_name(int slru_idx);
|
||||
extern int pgstat_slru_index(const char *name);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_subscription.c
|
||||
*/
|
||||
|
||||
extern void pgstat_reset_subscription_counter(Oid subid);
|
||||
extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
|
||||
extern void pgstat_report_subscription_drop(Oid subid);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in pgstat_wal.c
|
||||
*/
|
||||
|
||||
extern void pgstat_send_wal(bool force);
|
||||
|
||||
|
||||
/*
|
||||
* Variables in pgstat.c
|
||||
*/
|
||||
|
||||
/* GUC parameters */
|
||||
extern PGDLLIMPORT bool pgstat_track_counts;
|
||||
extern PGDLLIMPORT int pgstat_track_functions;
|
||||
extern char *pgstat_stat_directory;
|
||||
extern char *pgstat_stat_tmpname;
|
||||
extern char *pgstat_stat_filename;
|
||||
|
||||
|
||||
/*
|
||||
* Variables in pgstat_bgwriter.c
|
||||
*/
|
||||
|
||||
/* updated directly by bgwriter and bufmgr */
|
||||
extern PgStat_MsgBgWriter PendingBgWriterStats;
|
||||
|
||||
|
||||
/*
|
||||
* Variables in pgstat_checkpointer.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Checkpointer statistics counters are updated directly by checkpointer and
|
||||
* bufmgr.
|
||||
*/
|
||||
extern PgStat_MsgCheckpointer PendingCheckpointerStats;
|
||||
|
||||
|
||||
/*
|
||||
* Variables in pgstat_database.c
|
||||
*/
|
||||
|
||||
/* Updated by pgstat_count_buffer_*_time macros */
|
||||
extern PgStat_Counter pgStatBlockReadTime;
|
||||
extern PgStat_Counter pgStatBlockWriteTime;
|
||||
|
||||
/*
|
||||
* Updated by pgstat_count_conn_*_time macros, called by
|
||||
* pgstat_report_activity().
|
||||
*/
|
||||
extern PgStat_Counter pgStatActiveTime;
|
||||
extern PgStat_Counter pgStatTransactionIdleTime;
|
||||
|
||||
/* updated by the traffic cop and in errfinish() */
|
||||
extern SessionEndType pgStatSessionEndCause;
|
||||
|
||||
|
||||
/*
|
||||
* Variables in pgstat_wal.c
|
||||
*/
|
||||
|
||||
/* updated directly by backends and background processes */
|
||||
extern PgStat_MsgWal WalStats;
|
||||
|
||||
|
||||
#endif /* PGSTAT_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user