PostgreSQL Source Code  git master
pgstat.h File Reference
#include "datatype/timestamp.h"
#include "libpq/pqcomm.h"
#include "miscadmin.h"
#include "port/atomics.h"
#include "portability/instr_time.h"
#include "postmaster/pgarch.h"
#include "storage/proc.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
Include dependency graph for pgstat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PgStat_TableCounts
 
struct  PgStat_TableStatus
 
struct  PgStat_TableXactStatus
 
struct  PgStat_MsgHdr
 
struct  PgStat_MsgDummy
 
struct  PgStat_MsgInquiry
 
struct  PgStat_TableEntry
 
struct  PgStat_MsgTabstat
 
struct  PgStat_MsgTabpurge
 
struct  PgStat_MsgDropdb
 
struct  PgStat_MsgResetcounter
 
struct  PgStat_MsgResetsharedcounter
 
struct  PgStat_MsgResetsinglecounter
 
struct  PgStat_MsgResetslrucounter
 
struct  PgStat_MsgResetreplslotcounter
 
struct  PgStat_MsgAutovacStart
 
struct  PgStat_MsgVacuum
 
struct  PgStat_MsgAnalyze
 
struct  PgStat_MsgArchiver
 
struct  PgStat_MsgBgWriter
 
struct  PgStat_MsgWal
 
struct  PgStat_MsgSLRU
 
struct  PgStat_MsgReplSlot
 
struct  PgStat_MsgRecoveryConflict
 
struct  PgStat_MsgTempFile
 
struct  PgStat_FunctionCounts
 
struct  PgStat_BackendFunctionEntry
 
struct  PgStat_FunctionEntry
 
struct  PgStat_MsgFuncstat
 
struct  PgStat_MsgFuncpurge
 
struct  PgStat_MsgDeadlock
 
struct  PgStat_MsgChecksumFailure
 
union  PgStat_Msg
 
struct  PgStat_StatDBEntry
 
struct  PgStat_StatTabEntry
 
struct  PgStat_StatFuncEntry
 
struct  PgStat_ArchiverStats
 
struct  PgStat_GlobalStats
 
struct  PgStat_WalStats
 
struct  PgStat_SLRUStats
 
struct  PgStat_ReplSlotStats
 
struct  PgBackendSSLStatus
 
struct  PgBackendGSSStatus
 
struct  PgBackendStatus
 
struct  LocalPgBackendStatus
 
struct  PgStat_FunctionCallUsage
 

Macros

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"
 
#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/global.stat"
 
#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/global.tmp"
 
#define PG_STAT_TMP_DIR   "pg_stat_tmp"
 
#define PGSTAT_MAX_MSG_SIZE   1000
 
#define PGSTAT_MSG_PAYLOAD   (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))
 
#define PGSTAT_NUM_TABENTRIES
 
#define PGSTAT_NUM_TABPURGE
 
#define PGSTAT_NUM_FUNCENTRIES
 
#define PGSTAT_NUM_FUNCPURGE
 
#define PGSTAT_FILE_FORMAT_ID   0x01A5BC9F
 
#define PG_WAIT_LWLOCK   0x01000000U
 
#define PG_WAIT_LOCK   0x03000000U
 
#define PG_WAIT_BUFFER_PIN   0x04000000U
 
#define PG_WAIT_ACTIVITY   0x05000000U
 
#define PG_WAIT_CLIENT   0x06000000U
 
#define PG_WAIT_EXTENSION   0x07000000U
 
#define PG_WAIT_IPC   0x08000000U
 
#define PG_WAIT_TIMEOUT   0x09000000U
 
#define PG_WAIT_IO   0x0A000000U
 
#define PGSTAT_NUM_PROGRESS_PARAM   20
 
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
 
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
 
#define pgstat_begin_read_activity(beentry, before_changecount)
 
#define pgstat_end_read_activity(beentry, after_changecount)
 
#define pgstat_read_activity_complete(before_changecount, after_changecount)
 
#define pgstat_count_heap_scan(rel)
 
#define pgstat_count_heap_getnext(rel)
 
#define pgstat_count_heap_fetch(rel)
 
#define pgstat_count_index_scan(rel)
 
#define pgstat_count_index_tuples(rel, n)
 
#define pgstat_count_buffer_read(rel)
 
#define pgstat_count_buffer_hit(rel)
 
#define pgstat_count_buffer_read_time(n)   (pgStatBlockReadTime += (n))
 
#define pgstat_count_buffer_write_time(n)   (pgStatBlockWriteTime += (n))
 

Typedefs

typedef enum TrackFunctionsLevel TrackFunctionsLevel
 
typedef enum StatMsgType StatMsgType
 
typedef int64 PgStat_Counter
 
typedef struct PgStat_TableCounts PgStat_TableCounts
 
typedef enum PgStat_Shared_Reset_Target PgStat_Shared_Reset_Target
 
typedef enum PgStat_Single_Reset_Type PgStat_Single_Reset_Type
 
typedef struct PgStat_TableStatus PgStat_TableStatus
 
typedef struct PgStat_TableXactStatus PgStat_TableXactStatus
 
typedef struct PgStat_MsgHdr PgStat_MsgHdr
 
typedef struct PgStat_MsgDummy PgStat_MsgDummy
 
typedef struct PgStat_MsgInquiry PgStat_MsgInquiry
 
typedef struct PgStat_TableEntry PgStat_TableEntry
 
typedef struct PgStat_MsgTabstat PgStat_MsgTabstat
 
typedef struct PgStat_MsgTabpurge PgStat_MsgTabpurge
 
typedef struct PgStat_MsgDropdb PgStat_MsgDropdb
 
typedef struct PgStat_MsgResetcounter PgStat_MsgResetcounter
 
typedef struct PgStat_MsgResetsharedcounter PgStat_MsgResetsharedcounter
 
typedef struct PgStat_MsgResetsinglecounter PgStat_MsgResetsinglecounter
 
typedef struct PgStat_MsgResetslrucounter PgStat_MsgResetslrucounter
 
typedef struct PgStat_MsgResetreplslotcounter PgStat_MsgResetreplslotcounter
 
typedef struct PgStat_MsgAutovacStart PgStat_MsgAutovacStart
 
typedef struct PgStat_MsgVacuum PgStat_MsgVacuum
 
typedef struct PgStat_MsgAnalyze PgStat_MsgAnalyze
 
typedef struct PgStat_MsgArchiver PgStat_MsgArchiver
 
typedef struct PgStat_MsgBgWriter PgStat_MsgBgWriter
 
typedef struct PgStat_MsgWal PgStat_MsgWal
 
typedef struct PgStat_MsgSLRU PgStat_MsgSLRU
 
typedef struct PgStat_MsgReplSlot PgStat_MsgReplSlot
 
typedef struct PgStat_MsgRecoveryConflict PgStat_MsgRecoveryConflict
 
typedef struct PgStat_MsgTempFile PgStat_MsgTempFile
 
typedef struct PgStat_FunctionCounts PgStat_FunctionCounts
 
typedef struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
 
typedef struct PgStat_FunctionEntry PgStat_FunctionEntry
 
typedef struct PgStat_MsgFuncstat PgStat_MsgFuncstat
 
typedef struct PgStat_MsgFuncpurge PgStat_MsgFuncpurge
 
typedef struct PgStat_MsgDeadlock PgStat_MsgDeadlock
 
typedef struct PgStat_MsgChecksumFailure PgStat_MsgChecksumFailure
 
typedef union PgStat_Msg PgStat_Msg
 
typedef struct PgStat_StatDBEntry PgStat_StatDBEntry
 
typedef struct PgStat_StatTabEntry PgStat_StatTabEntry
 
typedef struct PgStat_StatFuncEntry PgStat_StatFuncEntry
 
typedef struct PgStat_ArchiverStats PgStat_ArchiverStats
 
typedef struct PgStat_GlobalStats PgStat_GlobalStats
 
typedef struct PgStat_WalStats PgStat_WalStats
 
typedef struct PgStat_SLRUStats PgStat_SLRUStats
 
typedef struct PgStat_ReplSlotStats PgStat_ReplSlotStats
 
typedef enum BackendState BackendState
 
typedef enum ProgressCommandType ProgressCommandType
 
typedef struct PgBackendSSLStatus PgBackendSSLStatus
 
typedef struct PgBackendGSSStatus PgBackendGSSStatus
 
typedef struct PgBackendStatus PgBackendStatus
 
typedef struct LocalPgBackendStatus LocalPgBackendStatus
 
typedef struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
 

Enumerations

enum  TrackFunctionsLevel { TRACK_FUNC_OFF, TRACK_FUNC_PL, TRACK_FUNC_ALL }
 
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_AUTOVAC_START, PGSTAT_MTYPE_VACUUM,
  PGSTAT_MTYPE_ANALYZE, PGSTAT_MTYPE_ARCHIVER, PGSTAT_MTYPE_BGWRITER, 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
}
 
enum  PgStat_Shared_Reset_Target { RESET_ARCHIVER, RESET_BGWRITER, RESET_WAL }
 
enum  PgStat_Single_Reset_Type { RESET_TABLE, RESET_FUNCTION }
 
enum  BackendState {
  STATE_UNDEFINED, STATE_IDLE, STATE_RUNNING, STATE_IDLEINTRANSACTION,
  STATE_FASTPATH, STATE_IDLEINTRANSACTION_ABORTED, STATE_DISABLED
}
 
enum  WaitEventActivity {
  WAIT_EVENT_ARCHIVER_MAIN = PG_WAIT_ACTIVITY, WAIT_EVENT_AUTOVACUUM_MAIN, WAIT_EVENT_BGWRITER_HIBERNATE, WAIT_EVENT_BGWRITER_MAIN,
  WAIT_EVENT_CHECKPOINTER_MAIN, WAIT_EVENT_LOGICAL_APPLY_MAIN, WAIT_EVENT_LOGICAL_LAUNCHER_MAIN, WAIT_EVENT_PGSTAT_MAIN,
  WAIT_EVENT_RECOVERY_WAL_STREAM, WAIT_EVENT_SYSLOGGER_MAIN, WAIT_EVENT_WAL_RECEIVER_MAIN, WAIT_EVENT_WAL_SENDER_MAIN,
  WAIT_EVENT_WAL_WRITER_MAIN
}
 
enum  WaitEventClient {
  WAIT_EVENT_CLIENT_READ = PG_WAIT_CLIENT, WAIT_EVENT_CLIENT_WRITE, WAIT_EVENT_GSS_OPEN_SERVER, WAIT_EVENT_LIBPQWALRECEIVER_CONNECT,
  WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE, WAIT_EVENT_SSL_OPEN_SERVER, WAIT_EVENT_WAL_RECEIVER_WAIT_START, WAIT_EVENT_WAL_SENDER_WAIT_WAL,
  WAIT_EVENT_WAL_SENDER_WRITE_DATA
}
 
enum  WaitEventIPC {
  WAIT_EVENT_BACKUP_WAIT_WAL_ARCHIVE = PG_WAIT_IPC, WAIT_EVENT_BGWORKER_SHUTDOWN, WAIT_EVENT_BGWORKER_STARTUP, WAIT_EVENT_BTREE_PAGE,
  WAIT_EVENT_CHECKPOINT_DONE, WAIT_EVENT_CHECKPOINT_START, WAIT_EVENT_EXECUTE_GATHER, WAIT_EVENT_HASH_BATCH_ALLOCATE,
  WAIT_EVENT_HASH_BATCH_ELECT, WAIT_EVENT_HASH_BATCH_LOAD, WAIT_EVENT_HASH_BUILD_ALLOCATE, WAIT_EVENT_HASH_BUILD_ELECT,
  WAIT_EVENT_HASH_BUILD_HASH_INNER, WAIT_EVENT_HASH_BUILD_HASH_OUTER, WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATE, WAIT_EVENT_HASH_GROW_BATCHES_DECIDE,
  WAIT_EVENT_HASH_GROW_BATCHES_ELECT, WAIT_EVENT_HASH_GROW_BATCHES_FINISH, WAIT_EVENT_HASH_GROW_BATCHES_REPARTITION, WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATE,
  WAIT_EVENT_HASH_GROW_BUCKETS_ELECT, WAIT_EVENT_HASH_GROW_BUCKETS_REINSERT, WAIT_EVENT_LOGICAL_SYNC_DATA, WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE,
  WAIT_EVENT_MQ_INTERNAL, WAIT_EVENT_MQ_PUT_MESSAGE, WAIT_EVENT_MQ_RECEIVE, WAIT_EVENT_MQ_SEND,
  WAIT_EVENT_PARALLEL_BITMAP_SCAN, WAIT_EVENT_PARALLEL_CREATE_INDEX_SCAN, WAIT_EVENT_PARALLEL_FINISH, WAIT_EVENT_PROCARRAY_GROUP_UPDATE,
  WAIT_EVENT_PROC_SIGNAL_BARRIER, WAIT_EVENT_PROMOTE, WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT, WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE,
  WAIT_EVENT_RECOVERY_PAUSE, WAIT_EVENT_REPLICATION_ORIGIN_DROP, WAIT_EVENT_REPLICATION_SLOT_DROP, WAIT_EVENT_SAFE_SNAPSHOT,
  WAIT_EVENT_SYNC_REP, WAIT_EVENT_XACT_GROUP_UPDATE
}
 
enum  WaitEventTimeout {
  WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT, WAIT_EVENT_PG_SLEEP, WAIT_EVENT_RECOVERY_APPLY_DELAY, WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL,
  WAIT_EVENT_VACUUM_DELAY
}
 
enum  WaitEventIO {
  WAIT_EVENT_BASEBACKUP_READ = PG_WAIT_IO, WAIT_EVENT_BUFFILE_READ, WAIT_EVENT_BUFFILE_WRITE, WAIT_EVENT_BUFFILE_TRUNCATE,
  WAIT_EVENT_CONTROL_FILE_READ, WAIT_EVENT_CONTROL_FILE_SYNC, WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE, WAIT_EVENT_CONTROL_FILE_WRITE,
  WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE, WAIT_EVENT_COPY_FILE_READ, WAIT_EVENT_COPY_FILE_WRITE, WAIT_EVENT_DATA_FILE_EXTEND,
  WAIT_EVENT_DATA_FILE_FLUSH, WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC, WAIT_EVENT_DATA_FILE_PREFETCH, WAIT_EVENT_DATA_FILE_READ,
  WAIT_EVENT_DATA_FILE_SYNC, WAIT_EVENT_DATA_FILE_TRUNCATE, WAIT_EVENT_DATA_FILE_WRITE, WAIT_EVENT_DSM_FILL_ZERO_WRITE,
  WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ, WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC, WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE, WAIT_EVENT_LOCK_FILE_CREATE_READ,
  WAIT_EVENT_LOCK_FILE_CREATE_SYNC, WAIT_EVENT_LOCK_FILE_CREATE_WRITE, WAIT_EVENT_LOCK_FILE_RECHECKDATADIR_READ, WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC,
  WAIT_EVENT_LOGICAL_REWRITE_MAPPING_SYNC, WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE, WAIT_EVENT_LOGICAL_REWRITE_SYNC, WAIT_EVENT_LOGICAL_REWRITE_TRUNCATE,
  WAIT_EVENT_LOGICAL_REWRITE_WRITE, WAIT_EVENT_RELATION_MAP_READ, WAIT_EVENT_RELATION_MAP_SYNC, WAIT_EVENT_RELATION_MAP_WRITE,
  WAIT_EVENT_REORDER_BUFFER_READ, WAIT_EVENT_REORDER_BUFFER_WRITE, WAIT_EVENT_REORDER_LOGICAL_MAPPING_READ, WAIT_EVENT_REPLICATION_SLOT_READ,
  WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC, WAIT_EVENT_REPLICATION_SLOT_SYNC, WAIT_EVENT_REPLICATION_SLOT_WRITE, WAIT_EVENT_SLRU_FLUSH_SYNC,
  WAIT_EVENT_SLRU_READ, WAIT_EVENT_SLRU_SYNC, WAIT_EVENT_SLRU_WRITE, WAIT_EVENT_SNAPBUILD_READ,
  WAIT_EVENT_SNAPBUILD_SYNC, WAIT_EVENT_SNAPBUILD_WRITE, WAIT_EVENT_TIMELINE_HISTORY_FILE_SYNC, WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE,
  WAIT_EVENT_TIMELINE_HISTORY_READ, WAIT_EVENT_TIMELINE_HISTORY_SYNC, WAIT_EVENT_TIMELINE_HISTORY_WRITE, WAIT_EVENT_TWOPHASE_FILE_READ,
  WAIT_EVENT_TWOPHASE_FILE_SYNC, WAIT_EVENT_TWOPHASE_FILE_WRITE, WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ, WAIT_EVENT_WAL_BOOTSTRAP_SYNC,
  WAIT_EVENT_WAL_BOOTSTRAP_WRITE, WAIT_EVENT_WAL_COPY_READ, WAIT_EVENT_WAL_COPY_SYNC, WAIT_EVENT_WAL_COPY_WRITE,
  WAIT_EVENT_WAL_INIT_SYNC, WAIT_EVENT_WAL_INIT_WRITE, WAIT_EVENT_WAL_READ, WAIT_EVENT_WAL_SYNC,
  WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN, WAIT_EVENT_WAL_WRITE, WAIT_EVENT_LOGICAL_CHANGES_READ, WAIT_EVENT_LOGICAL_CHANGES_WRITE,
  WAIT_EVENT_LOGICAL_SUBXACT_READ, WAIT_EVENT_LOGICAL_SUBXACT_WRITE
}
 
enum  ProgressCommandType {
  PROGRESS_COMMAND_INVALID, PROGRESS_COMMAND_VACUUM, PROGRESS_COMMAND_ANALYZE, PROGRESS_COMMAND_CLUSTER,
  PROGRESS_COMMAND_CREATE_INDEX, PROGRESS_COMMAND_BASEBACKUP
}
 

Functions

Size BackendStatusShmemSize (void)
 
void CreateSharedBackendStatus (void)
 
void pgstat_init (void)
 
int pgstat_start (void)
 
void pgstat_reset_all (void)
 
void allow_immediate_pgstat_restart (void)
 
void pgstat_ping (void)
 
void pgstat_report_stat (bool force)
 
void pgstat_vacuum_stat (void)
 
void pgstat_drop_database (Oid databaseid)
 
void pgstat_clear_snapshot (void)
 
void pgstat_reset_counters (void)
 
void pgstat_reset_shared_counters (const char *)
 
void pgstat_reset_single_counter (Oid objectid, PgStat_Single_Reset_Type type)
 
void pgstat_reset_slru_counter (const char *)
 
void pgstat_reset_replslot_counter (const char *name)
 
void pgstat_report_autovac (Oid dboid)
 
void pgstat_report_vacuum (Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
 
void pgstat_report_analyze (Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
 
void pgstat_report_recovery_conflict (int reason)
 
void pgstat_report_deadlock (void)
 
void pgstat_report_checksum_failures_in_db (Oid dboid, int failurecount)
 
void pgstat_report_checksum_failure (void)
 
void pgstat_report_replslot (const char *slotname, int spilltxns, int spillcount, int spillbytes, int streamtxns, int streamcount, int streambytes)
 
void pgstat_report_replslot_drop (const char *slotname)
 
void pgstat_initialize (void)
 
void pgstat_bestart (void)
 
void pgstat_report_activity (BackendState state, const char *cmd_str)
 
void pgstat_report_tempfile (size_t filesize)
 
void pgstat_report_appname (const char *appname)
 
void pgstat_report_xact_timestamp (TimestampTz tstamp)
 
const char * pgstat_get_wait_event (uint32 wait_event_info)
 
const char * pgstat_get_wait_event_type (uint32 wait_event_info)
 
const char * pgstat_get_backend_current_activity (int pid, bool checkUser)
 
const char * pgstat_get_crashed_backend_activity (int pid, char *buffer, int buflen)
 
void pgstat_progress_start_command (ProgressCommandType cmdtype, Oid relid)
 
void pgstat_progress_update_param (int index, int64 val)
 
void pgstat_progress_update_multi_param (int nparam, const int *index, const int64 *val)
 
void pgstat_progress_end_command (void)
 
PgStat_TableStatusfind_tabstat_entry (Oid rel_id)
 
PgStat_BackendFunctionEntryfind_funcstat_entry (Oid func_id)
 
void pgstat_initstats (Relation rel)
 
char * pgstat_clip_activity (const char *raw_activity)
 
static void pgstat_report_wait_start (uint32 wait_event_info)
 
static void pgstat_report_wait_end (void)
 
void pgstat_count_heap_insert (Relation rel, PgStat_Counter n)
 
void pgstat_count_heap_update (Relation rel, bool hot)
 
void pgstat_count_heap_delete (Relation rel)
 
void pgstat_count_truncate (Relation rel)
 
void pgstat_update_heap_dead_tuples (Relation rel, int delta)
 
void pgstat_init_function_usage (struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
 
void pgstat_end_function_usage (PgStat_FunctionCallUsage *fcu, bool finalize)
 
void AtEOXact_PgStat (bool isCommit, bool parallel)
 
void AtEOSubXact_PgStat (bool isCommit, int nestDepth)
 
void AtPrepare_PgStat (void)
 
void PostPrepare_PgStat (void)
 
void pgstat_twophase_postcommit (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
void pgstat_twophase_postabort (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
void pgstat_send_archiver (const char *xlog, bool failed)
 
void pgstat_send_bgwriter (void)
 
void pgstat_send_wal (void)
 
PgStat_StatDBEntrypgstat_fetch_stat_dbentry (Oid dbid)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry (Oid relid)
 
PgBackendStatuspgstat_fetch_stat_beentry (int beid)
 
LocalPgBackendStatuspgstat_fetch_stat_local_beentry (int beid)
 
PgStat_StatFuncEntrypgstat_fetch_stat_funcentry (Oid funcid)
 
int pgstat_fetch_stat_numbackends (void)
 
PgStat_ArchiverStatspgstat_fetch_stat_archiver (void)
 
PgStat_GlobalStatspgstat_fetch_global (void)
 
PgStat_WalStatspgstat_fetch_stat_wal (void)
 
PgStat_SLRUStatspgstat_fetch_slru (void)
 
PgStat_ReplSlotStatspgstat_fetch_replslot (int *nslots_p)
 
void pgstat_count_slru_page_zeroed (int slru_idx)
 
void pgstat_count_slru_page_hit (int slru_idx)
 
void pgstat_count_slru_page_read (int slru_idx)
 
void pgstat_count_slru_page_written (int slru_idx)
 
void pgstat_count_slru_page_exists (int slru_idx)
 
void pgstat_count_slru_flush (int slru_idx)
 
void pgstat_count_slru_truncate (int slru_idx)
 
const char * pgstat_slru_name (int slru_idx)
 
int pgstat_slru_index (const char *name)
 

Variables

PGDLLIMPORT bool pgstat_track_activities
 
PGDLLIMPORT bool pgstat_track_counts
 
PGDLLIMPORT int pgstat_track_functions
 
PGDLLIMPORT int pgstat_track_activity_query_size
 
char * pgstat_stat_directory
 
char * pgstat_stat_tmpname
 
char * pgstat_stat_filename
 
PgStat_MsgBgWriter BgWriterStats
 
PgStat_MsgWal WalStats
 
PgStat_Counter pgStatBlockReadTime
 
PgStat_Counter pgStatBlockWriteTime
 

Macro Definition Documentation

◆ PG_STAT_TMP_DIR

#define PG_STAT_TMP_DIR   "pg_stat_tmp"

Definition at line 34 of file pgstat.h.

◆ PG_WAIT_ACTIVITY

#define PG_WAIT_ACTIVITY   0x05000000U

Definition at line 864 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

◆ PG_WAIT_BUFFER_PIN

#define PG_WAIT_BUFFER_PIN   0x04000000U

◆ PG_WAIT_CLIENT

#define PG_WAIT_CLIENT   0x06000000U

Definition at line 865 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

◆ PG_WAIT_EXTENSION

◆ PG_WAIT_IO

#define PG_WAIT_IO   0x0A000000U

Definition at line 869 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

◆ PG_WAIT_IPC

#define PG_WAIT_IPC   0x08000000U

Definition at line 867 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

◆ PG_WAIT_LOCK

#define PG_WAIT_LOCK   0x03000000U

◆ PG_WAIT_LWLOCK

#define PG_WAIT_LWLOCK   0x01000000U

◆ PG_WAIT_TIMEOUT

#define PG_WAIT_TIMEOUT   0x09000000U

Definition at line 868 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

◆ pgstat_begin_read_activity

#define pgstat_begin_read_activity (   beentry,
  before_changecount 
)
Value:
do { \
(before_changecount) = (beentry)->st_changecount; \
pg_read_barrier(); \
} while (0)

Definition at line 1266 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

◆ PGSTAT_BEGIN_WRITE_ACTIVITY

#define PGSTAT_BEGIN_WRITE_ACTIVITY (   beentry)

◆ pgstat_count_buffer_hit

#define pgstat_count_buffer_hit (   rel)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_blocks_hit++; \
} while (0)

Definition at line 1518 of file pgstat.h.

Referenced by ReadBufferExtended().

◆ pgstat_count_buffer_read

#define pgstat_count_buffer_read (   rel)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_blocks_fetched++; \
} while (0)

Definition at line 1513 of file pgstat.h.

Referenced by ReadBufferExtended().

◆ pgstat_count_buffer_read_time

#define pgstat_count_buffer_read_time (   n)    (pgStatBlockReadTime += (n))

Definition at line 1523 of file pgstat.h.

Referenced by ReadBuffer_common().

◆ pgstat_count_buffer_write_time

#define pgstat_count_buffer_write_time (   n)    (pgStatBlockWriteTime += (n))

Definition at line 1525 of file pgstat.h.

Referenced by FlushBuffer().

◆ pgstat_count_heap_fetch

#define pgstat_count_heap_fetch (   rel)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_tuples_fetched++; \
} while (0)

Definition at line 1498 of file pgstat.h.

Referenced by heapam_scan_bitmap_next_tuple(), and index_fetch_heap().

◆ pgstat_count_heap_getnext

#define pgstat_count_heap_getnext (   rel)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_tuples_returned++; \
} while (0)

Definition at line 1493 of file pgstat.h.

Referenced by heap_getnext(), heap_getnextslot(), and heapam_scan_sample_next_tuple().

◆ pgstat_count_heap_scan

#define pgstat_count_heap_scan (   rel)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_numscans++; \
} while (0)

Definition at line 1488 of file pgstat.h.

Referenced by initscan().

◆ pgstat_count_index_scan

#define pgstat_count_index_scan (   rel)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_numscans++; \
} while (0)

Definition at line 1503 of file pgstat.h.

Referenced by _bt_first(), _hash_first(), bringetbitmap(), gistgetbitmap(), and gistgettuple().

◆ pgstat_count_index_tuples

#define pgstat_count_index_tuples (   rel,
 
)
Value:
do { \
if ((rel)->pgstat_info != NULL) \
(rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
} while (0)

Definition at line 1508 of file pgstat.h.

Referenced by index_getbitmap(), and index_getnext_tid().

◆ pgstat_end_read_activity

#define pgstat_end_read_activity (   beentry,
  after_changecount 
)
Value:
do { \
pg_read_barrier(); \
(after_changecount) = (beentry)->st_changecount; \
} while (0)

Definition at line 1272 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

◆ PGSTAT_END_WRITE_ACTIVITY

#define PGSTAT_END_WRITE_ACTIVITY (   beentry)
Value:
do { \
pg_write_barrier(); \
(beentry)->st_changecount++; \
Assert(((beentry)->st_changecount & 1) == 0); \
END_CRIT_SECTION(); \
} while (0)

Definition at line 1258 of file pgstat.h.

Referenced by pgstat_beshutdown_hook(), pgstat_bestart(), pgstat_progress_end_command(), pgstat_progress_start_command(), pgstat_progress_update_multi_param(), pgstat_progress_update_param(), pgstat_report_activity(), pgstat_report_appname(), and pgstat_report_xact_timestamp().

◆ PGSTAT_FILE_FORMAT_ID

#define PGSTAT_FILE_FORMAT_ID   0x01A5BC9F

◆ PGSTAT_MAX_MSG_SIZE

#define PGSTAT_MAX_MSG_SIZE   1000

Definition at line 213 of file pgstat.h.

Referenced by pgstat_init().

◆ PGSTAT_MSG_PAYLOAD

#define PGSTAT_MSG_PAYLOAD   (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))

Definition at line 214 of file pgstat.h.

◆ PGSTAT_NUM_FUNCENTRIES

#define PGSTAT_NUM_FUNCENTRIES
Value:
((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
unsigned int Oid
Definition: postgres_ext.h:31
#define PGSTAT_MSG_PAYLOAD
Definition: pgstat.h:214

Definition at line 572 of file pgstat.h.

Referenced by pgstat_send_funcstats().

◆ PGSTAT_NUM_FUNCPURGE

#define PGSTAT_NUM_FUNCPURGE
Value:
((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
/ sizeof(Oid))
unsigned int Oid
Definition: postgres_ext.h:31
#define PGSTAT_MSG_PAYLOAD
Definition: pgstat.h:214

Definition at line 589 of file pgstat.h.

Referenced by pgstat_vacuum_stat().

◆ PGSTAT_NUM_PROGRESS_PARAM

#define PGSTAT_NUM_PROGRESS_PARAM   20

◆ PGSTAT_NUM_TABENTRIES

#define PGSTAT_NUM_TABENTRIES
Value:
((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int) - 2 * sizeof(PgStat_Counter)) \
/ sizeof(PgStat_TableEntry))
int64 PgStat_Counter
Definition: pgstat.h:80
unsigned int Oid
Definition: postgres_ext.h:31
struct PgStat_TableEntry PgStat_TableEntry
#define PGSTAT_MSG_PAYLOAD
Definition: pgstat.h:214

Definition at line 270 of file pgstat.h.

Referenced by pgstat_report_stat().

◆ PGSTAT_NUM_TABPURGE

#define PGSTAT_NUM_TABPURGE
Value:
((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
/ sizeof(Oid))
unsigned int Oid
Definition: postgres_ext.h:31
#define PGSTAT_MSG_PAYLOAD
Definition: pgstat.h:214

Definition at line 292 of file pgstat.h.

Referenced by pgstat_vacuum_stat().

◆ pgstat_read_activity_complete

#define pgstat_read_activity_complete (   before_changecount,
  after_changecount 
)
Value:
((before_changecount) == (after_changecount) && \
((before_changecount) & 1) == 0)

Definition at line 1278 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

◆ PGSTAT_STAT_PERMANENT_DIRECTORY

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"

Definition at line 29 of file pgstat.h.

Referenced by get_dbstat_filename(), and pgstat_reset_all().

◆ PGSTAT_STAT_PERMANENT_FILENAME

#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/global.stat"

◆ PGSTAT_STAT_PERMANENT_TMPFILE

#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/global.tmp"

Definition at line 31 of file pgstat.h.

Referenced by pgstat_write_statsfiles().

Typedef Documentation

◆ BackendState

typedef enum BackendState BackendState

◆ LocalPgBackendStatus

◆ PgBackendGSSStatus

◆ PgBackendSSLStatus

◆ PgBackendStatus

◆ PgStat_ArchiverStats

◆ PgStat_BackendFunctionEntry

◆ PgStat_Counter

typedef int64 PgStat_Counter

Definition at line 80 of file pgstat.h.

◆ PgStat_FunctionCallUsage

◆ PgStat_FunctionCounts

◆ PgStat_FunctionEntry

◆ PgStat_GlobalStats

◆ PgStat_Msg

typedef union PgStat_Msg PgStat_Msg

◆ PgStat_MsgAnalyze

◆ PgStat_MsgArchiver

◆ PgStat_MsgAutovacStart

◆ PgStat_MsgBgWriter

◆ PgStat_MsgChecksumFailure

◆ PgStat_MsgDeadlock

◆ PgStat_MsgDropdb

◆ PgStat_MsgDummy

◆ PgStat_MsgFuncpurge

◆ PgStat_MsgFuncstat

◆ PgStat_MsgHdr

typedef struct PgStat_MsgHdr PgStat_MsgHdr

◆ PgStat_MsgInquiry

◆ PgStat_MsgRecoveryConflict

◆ PgStat_MsgReplSlot

◆ PgStat_MsgResetcounter

◆ PgStat_MsgResetreplslotcounter

◆ PgStat_MsgResetsharedcounter

◆ PgStat_MsgResetsinglecounter

◆ PgStat_MsgResetslrucounter

◆ PgStat_MsgSLRU

◆ PgStat_MsgTabpurge

◆ PgStat_MsgTabstat

◆ PgStat_MsgTempFile

◆ PgStat_MsgVacuum

◆ PgStat_MsgWal

typedef struct PgStat_MsgWal PgStat_MsgWal

◆ PgStat_ReplSlotStats

◆ PgStat_Shared_Reset_Target

◆ PgStat_Single_Reset_Type

◆ PgStat_SLRUStats

◆ PgStat_StatDBEntry

◆ PgStat_StatFuncEntry

◆ PgStat_StatTabEntry

◆ PgStat_TableCounts

◆ PgStat_TableEntry

◆ PgStat_TableStatus

◆ PgStat_TableXactStatus

◆ PgStat_WalStats

◆ ProgressCommandType

◆ StatMsgType

typedef enum StatMsgType StatMsgType

◆ TrackFunctionsLevel

Enumeration Type Documentation

◆ BackendState

Enumerator
STATE_UNDEFINED 
STATE_IDLE 
STATE_RUNNING 
STATE_IDLEINTRANSACTION 
STATE_FASTPATH 
STATE_IDLEINTRANSACTION_ABORTED 
STATE_DISABLED 

Definition at line 845 of file pgstat.h.

◆ PgStat_Shared_Reset_Target

Enumerator
RESET_ARCHIVER 
RESET_BGWRITER 
RESET_WAL 

Definition at line 125 of file pgstat.h.

126 {
129  RESET_WAL
PgStat_Shared_Reset_Target
Definition: pgstat.h:125

◆ PgStat_Single_Reset_Type

Enumerator
RESET_TABLE 
RESET_FUNCTION 

Definition at line 133 of file pgstat.h.

134 {
135  RESET_TABLE,
PgStat_Single_Reset_Type
Definition: pgstat.h:133

◆ ProgressCommandType

Enumerator
PROGRESS_COMMAND_INVALID 
PROGRESS_COMMAND_VACUUM 
PROGRESS_COMMAND_ANALYZE 
PROGRESS_COMMAND_CLUSTER 
PROGRESS_COMMAND_CREATE_INDEX 
PROGRESS_COMMAND_BASEBACKUP 

Definition at line 1073 of file pgstat.h.

◆ StatMsgType

Enumerator
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_AUTOVAC_START 
PGSTAT_MTYPE_VACUUM 
PGSTAT_MTYPE_ANALYZE 
PGSTAT_MTYPE_ARCHIVER 
PGSTAT_MTYPE_BGWRITER 
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 

Definition at line 48 of file pgstat.h.

49 {
74 } StatMsgType;
StatMsgType
Definition: pgstat.h:48

◆ TrackFunctionsLevel

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 37 of file pgstat.h.

◆ WaitEventActivity

Enumerator
WAIT_EVENT_ARCHIVER_MAIN 
WAIT_EVENT_AUTOVACUUM_MAIN 
WAIT_EVENT_BGWRITER_HIBERNATE 
WAIT_EVENT_BGWRITER_MAIN 
WAIT_EVENT_CHECKPOINTER_MAIN 
WAIT_EVENT_LOGICAL_APPLY_MAIN 
WAIT_EVENT_LOGICAL_LAUNCHER_MAIN 
WAIT_EVENT_PGSTAT_MAIN 
WAIT_EVENT_RECOVERY_WAL_STREAM 
WAIT_EVENT_SYSLOGGER_MAIN 
WAIT_EVENT_WAL_RECEIVER_MAIN 
WAIT_EVENT_WAL_SENDER_MAIN 
WAIT_EVENT_WAL_WRITER_MAIN 

Definition at line 879 of file pgstat.h.

◆ WaitEventClient

Enumerator
WAIT_EVENT_CLIENT_READ 
WAIT_EVENT_CLIENT_WRITE 
WAIT_EVENT_GSS_OPEN_SERVER 
WAIT_EVENT_LIBPQWALRECEIVER_CONNECT 
WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE 
WAIT_EVENT_SSL_OPEN_SERVER 
WAIT_EVENT_WAL_RECEIVER_WAIT_START 
WAIT_EVENT_WAL_SENDER_WAIT_WAL 
WAIT_EVENT_WAL_SENDER_WRITE_DATA 

Definition at line 904 of file pgstat.h.

◆ WaitEventIO

Enumerator
WAIT_EVENT_BASEBACKUP_READ 
WAIT_EVENT_BUFFILE_READ 
WAIT_EVENT_BUFFILE_WRITE 
WAIT_EVENT_BUFFILE_TRUNCATE 
WAIT_EVENT_CONTROL_FILE_READ 
WAIT_EVENT_CONTROL_FILE_SYNC 
WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE 
WAIT_EVENT_CONTROL_FILE_WRITE 
WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE 
WAIT_EVENT_COPY_FILE_READ 
WAIT_EVENT_COPY_FILE_WRITE 
WAIT_EVENT_DATA_FILE_EXTEND 
WAIT_EVENT_DATA_FILE_FLUSH 
WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC 
WAIT_EVENT_DATA_FILE_PREFETCH 
WAIT_EVENT_DATA_FILE_READ 
WAIT_EVENT_DATA_FILE_SYNC 
WAIT_EVENT_DATA_FILE_TRUNCATE 
WAIT_EVENT_DATA_FILE_WRITE 
WAIT_EVENT_DSM_FILL_ZERO_WRITE 
WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ 
WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC 
WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE 
WAIT_EVENT_LOCK_FILE_CREATE_READ 
WAIT_EVENT_LOCK_FILE_CREATE_SYNC 
WAIT_EVENT_LOCK_FILE_CREATE_WRITE 
WAIT_EVENT_LOCK_FILE_RECHECKDATADIR_READ 
WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC 
WAIT_EVENT_LOGICAL_REWRITE_MAPPING_SYNC 
WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE 
WAIT_EVENT_LOGICAL_REWRITE_SYNC 
WAIT_EVENT_LOGICAL_REWRITE_TRUNCATE 
WAIT_EVENT_LOGICAL_REWRITE_WRITE 
WAIT_EVENT_RELATION_MAP_READ 
WAIT_EVENT_RELATION_MAP_SYNC 
WAIT_EVENT_RELATION_MAP_WRITE 
WAIT_EVENT_REORDER_BUFFER_READ 
WAIT_EVENT_REORDER_BUFFER_WRITE 
WAIT_EVENT_REORDER_LOGICAL_MAPPING_READ 
WAIT_EVENT_REPLICATION_SLOT_READ 
WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC 
WAIT_EVENT_REPLICATION_SLOT_SYNC 
WAIT_EVENT_REPLICATION_SLOT_WRITE 
WAIT_EVENT_SLRU_FLUSH_SYNC 
WAIT_EVENT_SLRU_READ 
WAIT_EVENT_SLRU_SYNC 
WAIT_EVENT_SLRU_WRITE 
WAIT_EVENT_SNAPBUILD_READ 
WAIT_EVENT_SNAPBUILD_SYNC 
WAIT_EVENT_SNAPBUILD_WRITE 
WAIT_EVENT_TIMELINE_HISTORY_FILE_SYNC 
WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE 
WAIT_EVENT_TIMELINE_HISTORY_READ 
WAIT_EVENT_TIMELINE_HISTORY_SYNC 
WAIT_EVENT_TIMELINE_HISTORY_WRITE 
WAIT_EVENT_TWOPHASE_FILE_READ 
WAIT_EVENT_TWOPHASE_FILE_SYNC 
WAIT_EVENT_TWOPHASE_FILE_WRITE 
WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ 
WAIT_EVENT_WAL_BOOTSTRAP_SYNC 
WAIT_EVENT_WAL_BOOTSTRAP_WRITE 
WAIT_EVENT_WAL_COPY_READ 
WAIT_EVENT_WAL_COPY_SYNC 
WAIT_EVENT_WAL_COPY_WRITE 
WAIT_EVENT_WAL_INIT_SYNC 
WAIT_EVENT_WAL_INIT_WRITE 
WAIT_EVENT_WAL_READ 
WAIT_EVENT_WAL_SYNC 
WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN 
WAIT_EVENT_WAL_WRITE 
WAIT_EVENT_LOGICAL_CHANGES_READ 
WAIT_EVENT_LOGICAL_CHANGES_WRITE 
WAIT_EVENT_LOGICAL_SUBXACT_READ 
WAIT_EVENT_LOGICAL_SUBXACT_WRITE 

Definition at line 991 of file pgstat.h.

992 {
1067 } WaitEventIO;
#define PG_WAIT_IO
Definition: pgstat.h:869
WaitEventIO
Definition: pgstat.h:991

◆ WaitEventIPC

Enumerator
WAIT_EVENT_BACKUP_WAIT_WAL_ARCHIVE 
WAIT_EVENT_BGWORKER_SHUTDOWN 
WAIT_EVENT_BGWORKER_STARTUP 
WAIT_EVENT_BTREE_PAGE 
WAIT_EVENT_CHECKPOINT_DONE 
WAIT_EVENT_CHECKPOINT_START 
WAIT_EVENT_EXECUTE_GATHER 
WAIT_EVENT_HASH_BATCH_ALLOCATE 
WAIT_EVENT_HASH_BATCH_ELECT 
WAIT_EVENT_HASH_BATCH_LOAD 
WAIT_EVENT_HASH_BUILD_ALLOCATE 
WAIT_EVENT_HASH_BUILD_ELECT 
WAIT_EVENT_HASH_BUILD_HASH_INNER 
WAIT_EVENT_HASH_BUILD_HASH_OUTER 
WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATE 
WAIT_EVENT_HASH_GROW_BATCHES_DECIDE 
WAIT_EVENT_HASH_GROW_BATCHES_ELECT 
WAIT_EVENT_HASH_GROW_BATCHES_FINISH 
WAIT_EVENT_HASH_GROW_BATCHES_REPARTITION 
WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATE 
WAIT_EVENT_HASH_GROW_BUCKETS_ELECT 
WAIT_EVENT_HASH_GROW_BUCKETS_REINSERT 
WAIT_EVENT_LOGICAL_SYNC_DATA 
WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE 
WAIT_EVENT_MQ_INTERNAL 
WAIT_EVENT_MQ_PUT_MESSAGE 
WAIT_EVENT_MQ_RECEIVE 
WAIT_EVENT_MQ_SEND 
WAIT_EVENT_PARALLEL_BITMAP_SCAN 
WAIT_EVENT_PARALLEL_CREATE_INDEX_SCAN 
WAIT_EVENT_PARALLEL_FINISH 
WAIT_EVENT_PROCARRAY_GROUP_UPDATE 
WAIT_EVENT_PROC_SIGNAL_BARRIER 
WAIT_EVENT_PROMOTE 
WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT 
WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE 
WAIT_EVENT_RECOVERY_PAUSE 
WAIT_EVENT_REPLICATION_ORIGIN_DROP 
WAIT_EVENT_REPLICATION_SLOT_DROP 
WAIT_EVENT_SAFE_SNAPSHOT 
WAIT_EVENT_SYNC_REP 
WAIT_EVENT_XACT_GROUP_UPDATE 

Definition at line 924 of file pgstat.h.

925 {
968 } WaitEventIPC;
WaitEventIPC
Definition: pgstat.h:924
#define PG_WAIT_IPC
Definition: pgstat.h:867

◆ WaitEventTimeout

Enumerator
WAIT_EVENT_BASE_BACKUP_THROTTLE 
WAIT_EVENT_PG_SLEEP 
WAIT_EVENT_RECOVERY_APPLY_DELAY 
WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL 
WAIT_EVENT_VACUUM_DELAY 

Definition at line 976 of file pgstat.h.

Function Documentation

◆ allow_immediate_pgstat_restart()

void allow_immediate_pgstat_restart ( void  )

Definition at line 839 of file pgstat.c.

References last_pgstat_start_time.

Referenced by HandleChildCrash().

840 {
842 }
static time_t last_pgstat_start_time
Definition: pgstat.c:189

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

Definition at line 2355 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, get_tabstat_stack_level(), PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pfree(), pgstat_truncate_restore_counters(), pgstat_truncate_save_counters(), pgStatXactStack, PgStat_SubXactStatus::prev, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncated, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

2356 {
2357  PgStat_SubXactStatus *xact_state;
2358 
2359  /*
2360  * Transfer transactional insert/update counts into the next higher
2361  * subtransaction state.
2362  */
2363  xact_state = pgStatXactStack;
2364  if (xact_state != NULL &&
2365  xact_state->nest_level >= nestDepth)
2366  {
2368  PgStat_TableXactStatus *next_trans;
2369 
2370  /* delink xact_state from stack immediately to simplify reuse case */
2371  pgStatXactStack = xact_state->prev;
2372 
2373  for (trans = xact_state->first; trans != NULL; trans = next_trans)
2374  {
2375  PgStat_TableStatus *tabstat;
2376 
2377  next_trans = trans->next;
2378  Assert(trans->nest_level == nestDepth);
2379  tabstat = trans->parent;
2380  Assert(tabstat->trans == trans);
2381  if (isCommit)
2382  {
2383  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
2384  {
2385  if (trans->truncated)
2386  {
2387  /* propagate the truncate status one level up */
2389  /* replace upper xact stats with ours */
2390  trans->upper->tuples_inserted = trans->tuples_inserted;
2391  trans->upper->tuples_updated = trans->tuples_updated;
2392  trans->upper->tuples_deleted = trans->tuples_deleted;
2393  }
2394  else
2395  {
2396  trans->upper->tuples_inserted += trans->tuples_inserted;
2397  trans->upper->tuples_updated += trans->tuples_updated;
2398  trans->upper->tuples_deleted += trans->tuples_deleted;
2399  }
2400  tabstat->trans = trans->upper;
2401  pfree(trans);
2402  }
2403  else
2404  {
2405  /*
2406  * When there isn't an immediate parent state, we can just
2407  * reuse the record instead of going through a
2408  * palloc/pfree pushup (this works since it's all in
2409  * TopTransactionContext anyway). We have to re-link it
2410  * into the parent level, though, and that might mean
2411  * pushing a new entry into the pgStatXactStack.
2412  */
2413  PgStat_SubXactStatus *upper_xact_state;
2414 
2415  upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
2416  trans->next = upper_xact_state->first;
2417  upper_xact_state->first = trans;
2418  trans->nest_level = nestDepth - 1;
2419  }
2420  }
2421  else
2422  {
2423  /*
2424  * On abort, update top-level tabstat counts, then forget the
2425  * subtransaction
2426  */
2427 
2428  /* first restore values obliterated by truncate */
2430  /* count attempted actions regardless of commit/abort */
2431  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2432  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2433  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2434  /* inserted tuples are dead, deleted tuples are unaffected */
2435  tabstat->t_counts.t_delta_dead_tuples +=
2436  trans->tuples_inserted + trans->tuples_updated;
2437  tabstat->trans = trans->upper;
2438  pfree(trans);
2439  }
2440  }
2441  pfree(xact_state);
2442  }
2443 }
PgStat_Counter tuples_updated
Definition: pgstat.h:175
struct PgStat_TableXactStatus * next
Definition: pgstat.h:186
PgStat_TableCounts t_counts
Definition: pgstat.h:165
static PgStat_SubXactStatus * get_tabstat_stack_level(int nest_level)
Definition: pgstat.c:2073
void pfree(void *pointer)
Definition: mcxt.c:1057
PgStat_Counter t_tuples_updated
Definition: pgstat.h:111
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2209
PgStat_Counter tuples_inserted
Definition: pgstat.h:174
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:117
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:183
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:112
PgStat_Counter tuples_deleted
Definition: pgstat.h:176
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:251
#define Assert(condition)
Definition: c.h:800
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:255
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:252
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2194
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:110
PgStat_TableStatus * parent
Definition: pgstat.h:184

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)

Definition at line 2268 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pgstat_clear_snapshot(), pgstat_truncate_restore_counters(), pgStatXactCommit, pgStatXactRollback, pgStatXactStack, PgStat_SubXactStatus::prev, PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, PgStat_TableCounts::t_truncated, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncated, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

Referenced by AbortTransaction(), CommitTransaction(), and FinishPreparedTransaction().

2269 {
2270  PgStat_SubXactStatus *xact_state;
2271 
2272  /* Don't count parallel worker transaction stats */
2273  if (!parallel)
2274  {
2275  /*
2276  * Count transaction commit or abort. (We use counters, not just
2277  * bools, in case the reporting message isn't sent right away.)
2278  */
2279  if (isCommit)
2280  pgStatXactCommit++;
2281  else
2283  }
2284 
2285  /*
2286  * Transfer transactional insert/update counts into the base tabstat
2287  * entries. We don't bother to free any of the transactional state, since
2288  * it's all in TopTransactionContext and will go away anyway.
2289  */
2290  xact_state = pgStatXactStack;
2291  if (xact_state != NULL)
2292  {
2294 
2295  Assert(xact_state->nest_level == 1);
2296  Assert(xact_state->prev == NULL);
2297  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2298  {
2299  PgStat_TableStatus *tabstat;
2300 
2301  Assert(trans->nest_level == 1);
2302  Assert(trans->upper == NULL);
2303  tabstat = trans->parent;
2304  Assert(tabstat->trans == trans);
2305  /* restore pre-truncate stats (if any) in case of aborted xact */
2306  if (!isCommit)
2308  /* count attempted actions regardless of commit/abort */
2309  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2310  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2311  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2312  if (isCommit)
2313  {
2314  tabstat->t_counts.t_truncated = trans->truncated;
2315  if (trans->truncated)
2316  {
2317  /* forget live/dead stats seen by backend thus far */
2318  tabstat->t_counts.t_delta_live_tuples = 0;
2319  tabstat->t_counts.t_delta_dead_tuples = 0;
2320  }
2321  /* insert adds a live tuple, delete removes one */
2322  tabstat->t_counts.t_delta_live_tuples +=
2323  trans->tuples_inserted - trans->tuples_deleted;
2324  /* update and delete each create a dead tuple */
2325  tabstat->t_counts.t_delta_dead_tuples +=
2326  trans->tuples_updated + trans->tuples_deleted;
2327  /* insert, update, delete each count as one change event */
2328  tabstat->t_counts.t_changed_tuples +=
2329  trans->tuples_inserted + trans->tuples_updated +
2330  trans->tuples_deleted;
2331  }
2332  else
2333  {
2334  /* inserted tuples are dead, deleted tuples are unaffected */
2335  tabstat->t_counts.t_delta_dead_tuples +=
2336  trans->tuples_inserted + trans->tuples_updated;
2337  /* an aborted xact generates no changed_tuple events */
2338  }
2339  tabstat->trans = NULL;
2340  }
2341  }
2342  pgStatXactStack = NULL;
2343 
2344  /* Make sure any stats snapshot is thrown away */
2346 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:116
PgStat_Counter tuples_updated
Definition: pgstat.h:175
static int pgStatXactCommit
Definition: pgstat.c:257
struct PgStat_TableXactStatus * next
Definition: pgstat.h:186
PgStat_TableCounts t_counts
Definition: pgstat.h:165
PgStat_Counter t_tuples_updated
Definition: pgstat.h:111
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2209
static int pgStatXactRollback
Definition: pgstat.c:258
PgStat_Counter tuples_inserted
Definition: pgstat.h:174
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:117
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:183
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:112
PgStat_Counter tuples_deleted
Definition: pgstat.h:176
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:251
PgStat_Counter t_changed_tuples
Definition: pgstat.h:118
#define Assert(condition)
Definition: c.h:800
void pgstat_clear_snapshot(void)
Definition: pgstat.c:6179
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:255
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:252
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:110
PgStat_TableStatus * parent
Definition: pgstat.h:184

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )

Definition at line 2454 of file pgstat.c.

References Assert, PgStat_TableXactStatus::deleted_pre_trunc, TwoPhasePgStatRecord::deleted_pre_trunc, PgStat_SubXactStatus::first, PgStat_TableXactStatus::inserted_pre_trunc, TwoPhasePgStatRecord::inserted_pre_trunc, PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pgStatXactStack, PgStat_SubXactStatus::prev, RegisterTwoPhaseRecord(), PgStat_TableStatus::t_id, TwoPhasePgStatRecord::t_id, PgStat_TableStatus::t_shared, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncated, PgStat_TableXactStatus::tuples_deleted, TwoPhasePgStatRecord::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, TwoPhasePgStatRecord::tuples_inserted, PgStat_TableXactStatus::tuples_updated, TwoPhasePgStatRecord::tuples_updated, TWOPHASE_RM_PGSTAT_ID, PgStat_TableXactStatus::updated_pre_trunc, TwoPhasePgStatRecord::updated_pre_trunc, and PgStat_TableXactStatus::upper.

Referenced by PrepareTransaction().

2455 {
2456  PgStat_SubXactStatus *xact_state;
2457 
2458  xact_state = pgStatXactStack;
2459  if (xact_state != NULL)
2460  {
2462 
2463  Assert(xact_state->nest_level == 1);
2464  Assert(xact_state->prev == NULL);
2465  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2466  {
2467  PgStat_TableStatus *tabstat;
2468  TwoPhasePgStatRecord record;
2469 
2470  Assert(trans->nest_level == 1);
2471  Assert(trans->upper == NULL);
2472  tabstat = trans->parent;
2473  Assert(tabstat->trans == trans);
2474 
2475  record.tuples_inserted = trans->tuples_inserted;
2476  record.tuples_updated = trans->tuples_updated;
2477  record.tuples_deleted = trans->tuples_deleted;
2478  record.inserted_pre_trunc = trans->inserted_pre_trunc;
2479  record.updated_pre_trunc = trans->updated_pre_trunc;
2480  record.deleted_pre_trunc = trans->deleted_pre_trunc;
2481  record.t_id = tabstat->t_id;
2482  record.t_shared = tabstat->t_shared;
2483  record.t_truncated = trans->truncated;
2484 
2486  &record, sizeof(TwoPhasePgStatRecord));
2487  }
2488  }
2489 }
PgStat_Counter tuples_updated
Definition: pgstat.h:175
struct PgStat_TableXactStatus * next
Definition: pgstat.h:186
PgStat_Counter deleted_pre_trunc
Definition: pgstat.h:180
PgStat_Counter deleted_pre_trunc
Definition: pgstat.c:270
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1181
PgStat_Counter tuples_inserted
Definition: pgstat.h:174
PgStat_Counter updated_pre_trunc
Definition: pgstat.c:269
PgStat_Counter inserted_pre_trunc
Definition: pgstat.c:268
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:183
PgStat_Counter tuples_updated
Definition: pgstat.c:266
PgStat_Counter tuples_deleted
Definition: pgstat.h:176
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:251
#define Assert(condition)
Definition: c.h:800
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:178
PgStat_Counter tuples_inserted
Definition: pgstat.c:265
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:255
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164
PgStat_Counter tuples_deleted
Definition: pgstat.c:267
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:179
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:252
PgStat_TableStatus * parent
Definition: pgstat.h:184

◆ BackendStatusShmemSize()

Size BackendStatusShmemSize ( void  )

Definition at line 2875 of file pgstat.c.

References add_size(), mul_size(), NAMEDATALEN, NumBackendStatSlots, and pgstat_track_activity_query_size.

Referenced by CreateSharedMemoryAndSemaphores().

2876 {
2877  Size size;
2878 
2879  /* BackendStatusArray: */
2880  size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
2881  /* BackendAppnameBuffer: */
2882  size = add_size(size,
2884  /* BackendClientHostnameBuffer: */
2885  size = add_size(size,
2887  /* BackendActivityBuffer: */
2888  size = add_size(size,
2890 #ifdef USE_SSL
2891  /* BackendSslStatusBuffer: */
2892  size = add_size(size,
2894 #endif
2895  return size;
2896 }
#define NumBackendStatSlots
Definition: pgstat.c:119
#define NAMEDATALEN
int pgstat_track_activity_query_size
Definition: pgstat.c:129
Size mul_size(Size s1, Size s2)
Definition: shmem.c:515
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:528

◆ CreateSharedBackendStatus()

void CreateSharedBackendStatus ( void  )

Definition at line 2903 of file pgstat.c.

References BackendActivityBuffer, BackendActivityBufferSize, BackendAppnameBuffer, BackendClientHostnameBuffer, i, MemSet, mul_size(), NAMEDATALEN, NumBackendStatSlots, pgstat_track_activity_query_size, ShmemInitStruct(), PgBackendStatus::st_activity_raw, PgBackendStatus::st_appname, PgBackendStatus::st_clienthostname, PgBackendStatus::st_gssstatus, and PgBackendStatus::st_sslstatus.

Referenced by CreateSharedMemoryAndSemaphores().

2904 {
2905  Size size;
2906  bool found;
2907  int i;
2908  char *buffer;
2909 
2910  /* Create or attach to the shared array */
2911  size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
2913  ShmemInitStruct("Backend Status Array", size, &found);
2914 
2915  if (!found)
2916  {
2917  /*
2918  * We're the first - initialize.
2919  */
2920  MemSet(BackendStatusArray, 0, size);
2921  }
2922 
2923  /* Create or attach to the shared appname buffer */
2925  BackendAppnameBuffer = (char *)
2926  ShmemInitStruct("Backend Application Name Buffer", size, &found);
2927 
2928  if (!found)
2929  {
2930  MemSet(BackendAppnameBuffer, 0, size);
2931 
2932  /* Initialize st_appname pointers. */
2933  buffer = BackendAppnameBuffer;
2934  for (i = 0; i < NumBackendStatSlots; i++)
2935  {
2936  BackendStatusArray[i].st_appname = buffer;
2937  buffer += NAMEDATALEN;
2938  }
2939  }
2940 
2941  /* Create or attach to the shared client hostname buffer */
2943  BackendClientHostnameBuffer = (char *)
2944  ShmemInitStruct("Backend Client Host Name Buffer", size, &found);
2945 
2946  if (!found)
2947  {
2949 
2950  /* Initialize st_clienthostname pointers. */
2951  buffer = BackendClientHostnameBuffer;
2952  for (i = 0; i < NumBackendStatSlots; i++)
2953  {
2955  buffer += NAMEDATALEN;
2956  }
2957  }
2958 
2959  /* Create or attach to the shared activity buffer */
2962  BackendActivityBuffer = (char *)
2963  ShmemInitStruct("Backend Activity Buffer",
2965  &found);
2966 
2967  if (!found)
2968  {
2970 
2971  /* Initialize st_activity pointers. */
2972  buffer = BackendActivityBuffer;
2973  for (i = 0; i < NumBackendStatSlots; i++)
2974  {
2977  }
2978  }
2979 
2980 #ifdef USE_SSL
2981  /* Create or attach to the shared SSL status buffer */
2983  BackendSslStatusBuffer = (PgBackendSSLStatus *)
2984  ShmemInitStruct("Backend SSL Status Buffer", size, &found);
2985 
2986  if (!found)
2987  {
2988  PgBackendSSLStatus *ptr;
2989 
2990  MemSet(BackendSslStatusBuffer, 0, size);
2991 
2992  /* Initialize st_sslstatus pointers. */
2993  ptr = BackendSslStatusBuffer;
2994  for (i = 0; i < NumBackendStatSlots; i++)
2995  {
2997  ptr++;
2998  }
2999  }
3000 #endif
3001 
3002 #ifdef ENABLE_GSS
3003  /* Create or attach to the shared GSSAPI status buffer */
3005  BackendGssStatusBuffer = (PgBackendGSSStatus *)
3006  ShmemInitStruct("Backend GSS Status Buffer", size, &found);
3007 
3008  if (!found)
3009  {
3010  PgBackendGSSStatus *ptr;
3011 
3012  MemSet(BackendGssStatusBuffer, 0, size);
3013 
3014  /* Initialize st_gssstatus pointers. */
3015  ptr = BackendGssStatusBuffer;
3016  for (i = 0; i < NumBackendStatSlots; i++)
3017  {
3019  ptr++;
3020  }
3021  }
3022 #endif
3023 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2857
static char * BackendActivityBuffer
Definition: pgstat.c:2861
static Size BackendActivityBufferSize
Definition: pgstat.c:2862
#define MemSet(start, val, len)
Definition: c.h:1004
#define NumBackendStatSlots
Definition: pgstat.c:119
char * st_clienthostname
Definition: pgstat.h:1183
#define NAMEDATALEN
static char * BackendAppnameBuffer
Definition: pgstat.c:2859
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:392
char * st_activity_raw
Definition: pgstat.h:1206
int pgstat_track_activity_query_size
Definition: pgstat.c:129
char * st_appname
Definition: pgstat.h:1197
Size mul_size(Size s1, Size s2)
Definition: shmem.c:515
size_t Size
Definition: c.h:528
int i
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1187
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1191
static char * BackendClientHostnameBuffer
Definition: pgstat.c:2860

◆ find_funcstat_entry()

PgStat_BackendFunctionEntry* find_funcstat_entry ( Oid  func_id)

Definition at line 1852 of file pgstat.c.

References HASH_FIND, and hash_search().

Referenced by pg_stat_get_xact_function_calls(), pg_stat_get_xact_function_self_time(), and pg_stat_get_xact_function_total_time().

1853 {
1854  if (pgStatFunctions == NULL)
1855  return NULL;
1856 
1858  (void *) &func_id,
1859  HASH_FIND, NULL);
1860 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:919
static HTAB * pgStatFunctions
Definition: pgstat.c:233

◆ find_tabstat_entry()

PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

Definition at line 2053 of file pgstat.c.

References HASH_FIND, hash_search(), and TabStatHashEntry::tsa_entry.

Referenced by pg_stat_get_xact_blocks_fetched(), pg_stat_get_xact_blocks_hit(), pg_stat_get_xact_numscans(), pg_stat_get_xact_tuples_deleted(), pg_stat_get_xact_tuples_fetched(), pg_stat_get_xact_tuples_hot_updated(), pg_stat_get_xact_tuples_inserted(), pg_stat_get_xact_tuples_returned(), and pg_stat_get_xact_tuples_updated().

2054 {
2055  TabStatHashEntry *hash_entry;
2056 
2057  /* If hashtable doesn't exist, there are no entries at all */
2058  if (!pgStatTabHash)
2059  return NULL;
2060 
2061  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_FIND, NULL);
2062  if (!hash_entry)
2063  return NULL;
2064 
2065  /* Note that this step could also return NULL, but that's correct */
2066  return hash_entry->tsa_entry;
2067 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:919
static HTAB * pgStatTabHash
Definition: pgstat.c:227
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:221

◆ pgstat_bestart()

void pgstat_bestart ( void  )

Definition at line 3087 of file pgstat.c.

References application_name, Assert, B_BACKEND, B_BG_WORKER, B_WAL_SENDER, be_gssapi_get_auth(), be_gssapi_get_enc(), be_gssapi_get_princ(), be_tls_get_cipher(), be_tls_get_cipher_bits(), be_tls_get_compression(), be_tls_get_peer_issuer_name(), be_tls_get_peer_serial(), be_tls_get_peer_subject_name(), be_tls_get_version(), GetSessionUserId(), Port::gss, PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, InvalidOid, MemSet, MyBackendType, MyBEEntry, MyDatabaseId, MyProcPid, MyProcPort, MyStartTimestamp, NAMEDATALEN, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_report_appname(), pgstat_track_activity_query_size, PROGRESS_COMMAND_INVALID, Port::raddr, Port::remote_hostname, PgBackendSSLStatus::ssl_bits, PgBackendSSLStatus::ssl_cipher, PgBackendSSLStatus::ssl_client_dn, PgBackendSSLStatus::ssl_client_serial, PgBackendSSLStatus::ssl_compression, Port::ssl_in_use, PgBackendSSLStatus::ssl_issuer_dn, PgBackendSSLStatus::ssl_version, PgBackendStatus::st_activity_raw, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_appname, PgBackendStatus::st_backendType, PgBackendStatus::st_changecount, PgBackendStatus::st_clientaddr, PgBackendStatus::st_clienthostname, PgBackendStatus::st_databaseid, PgBackendStatus::st_gss, PgBackendStatus::st_gssstatus, PgBackendStatus::st_proc_start_timestamp, PgBackendStatus::st_procpid, PgBackendStatus::st_progress_command, PgBackendStatus::st_progress_command_target, PgBackendStatus::st_ssl, PgBackendStatus::st_sslstatus, PgBackendStatus::st_state, PgBackendStatus::st_state_start_timestamp, PgBackendStatus::st_userid, PgBackendStatus::st_xact_start_timestamp, STATE_UNDEFINED, strlcpy(), and unvolatize.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

3088 {
3089  volatile PgBackendStatus *vbeentry = MyBEEntry;
3090  PgBackendStatus lbeentry;
3091 #ifdef USE_SSL
3092  PgBackendSSLStatus lsslstatus;
3093 #endif
3094 #ifdef ENABLE_GSS
3095  PgBackendGSSStatus lgssstatus;
3096 #endif
3097 
3098  /* pgstats state must be initialized from pgstat_initialize() */
3099  Assert(vbeentry != NULL);
3100 
3101  /*
3102  * To minimize the time spent modifying the PgBackendStatus entry, and
3103  * avoid risk of errors inside the critical section, we first copy the
3104  * shared-memory struct to a local variable, then modify the data in the
3105  * local variable, then copy the local variable back to shared memory.
3106  * Only the last step has to be inside the critical section.
3107  *
3108  * Most of the data we copy from shared memory is just going to be
3109  * overwritten, but the struct's not so large that it's worth the
3110  * maintenance hassle to copy only the needful fields.
3111  */
3112  memcpy(&lbeentry,
3113  unvolatize(PgBackendStatus *, vbeentry),
3114  sizeof(PgBackendStatus));
3115 
3116  /* These structs can just start from zeroes each time, though */
3117 #ifdef USE_SSL
3118  memset(&lsslstatus, 0, sizeof(lsslstatus));
3119 #endif
3120 #ifdef ENABLE_GSS
3121  memset(&lgssstatus, 0, sizeof(lgssstatus));
3122 #endif
3123 
3124  /*
3125  * Now fill in all the fields of lbeentry, except for strings that are
3126  * out-of-line data. Those have to be handled separately, below.
3127  */
3128  lbeentry.st_procpid = MyProcPid;
3129  lbeentry.st_backendType = MyBackendType;
3131  lbeentry.st_activity_start_timestamp = 0;
3132  lbeentry.st_state_start_timestamp = 0;
3133  lbeentry.st_xact_start_timestamp = 0;
3134  lbeentry.st_databaseid = MyDatabaseId;
3135 
3136  /* We have userid for client-backends, wal-sender and bgworker processes */
3137  if (lbeentry.st_backendType == B_BACKEND
3138  || lbeentry.st_backendType == B_WAL_SENDER
3139  || lbeentry.st_backendType == B_BG_WORKER)
3140  lbeentry.st_userid = GetSessionUserId();
3141  else
3142  lbeentry.st_userid = InvalidOid;
3143 
3144  /*
3145  * We may not have a MyProcPort (eg, if this is the autovacuum process).
3146  * If so, use all-zeroes client address, which is dealt with specially in
3147  * pg_stat_get_backend_client_addr and pg_stat_get_backend_client_port.
3148  */
3149  if (MyProcPort)
3150  memcpy(&lbeentry.st_clientaddr, &MyProcPort->raddr,
3151  sizeof(lbeentry.st_clientaddr));
3152  else
3153  MemSet(&lbeentry.st_clientaddr, 0, sizeof(lbeentry.st_clientaddr));
3154 
3155 #ifdef USE_SSL
3157  {
3158  lbeentry.st_ssl = true;
3166  }
3167  else
3168  {
3169  lbeentry.st_ssl = false;
3170  }
3171 #else
3172  lbeentry.st_ssl = false;
3173 #endif
3174 
3175 #ifdef ENABLE_GSS
3176  if (MyProcPort && MyProcPort->gss != NULL)
3177  {
3178  lbeentry.st_gss = true;
3179  lgssstatus.gss_auth = be_gssapi_get_auth(MyProcPort);
3180  lgssstatus.gss_enc = be_gssapi_get_enc(MyProcPort);
3181 
3182  if (lgssstatus.gss_auth)
3184  }
3185  else
3186  {
3187  lbeentry.st_gss = false;
3188  }
3189 #else
3190  lbeentry.st_gss = false;
3191 #endif
3192 
3193  lbeentry.st_state = STATE_UNDEFINED;
3196 
3197  /*
3198  * we don't zero st_progress_param here to save cycles; nobody should
3199  * examine it until st_progress_command has been set to something other
3200  * than PROGRESS_COMMAND_INVALID
3201  */
3202 
3203  /*
3204  * We're ready to enter the critical section that fills the shared-memory
3205  * status entry. We follow the protocol of bumping st_changecount before
3206  * and after; and make sure it's even afterwards. We use a volatile
3207  * pointer here to ensure the compiler doesn't try to get cute.
3208  */
3209  PGSTAT_BEGIN_WRITE_ACTIVITY(vbeentry);
3210 
3211  /* make sure we'll memcpy the same st_changecount back */
3212  lbeentry.st_changecount = vbeentry->st_changecount;
3213 
3214  memcpy(unvolatize(PgBackendStatus *, vbeentry),
3215  &lbeentry,
3216  sizeof(PgBackendStatus));
3217 
3218  /*
3219  * We can write the out-of-line strings and structs using the pointers
3220  * that are in lbeentry; this saves some de-volatilizing messiness.
3221  */
3222  lbeentry.st_appname[0] = '\0';
3225  NAMEDATALEN);
3226  else
3227  lbeentry.st_clienthostname[0] = '\0';
3228  lbeentry.st_activity_raw[0] = '\0';
3229  /* Also make sure the last byte in each string area is always 0 */
3230  lbeentry.st_appname[NAMEDATALEN - 1] = '\0';
3231  lbeentry.st_clienthostname[NAMEDATALEN - 1] = '\0';
3233 
3234 #ifdef USE_SSL
3235  memcpy(lbeentry.st_sslstatus, &lsslstatus, sizeof(PgBackendSSLStatus));
3236 #endif
3237 #ifdef ENABLE_GSS
3238  memcpy(lbeentry.st_gssstatus, &lgssstatus, sizeof(PgBackendGSSStatus));
3239 #endif
3240 
3241  PGSTAT_END_WRITE_ACTIVITY(vbeentry);
3242 
3243  /* Update app name to current GUC setting */
3244  if (application_name)
3246 }
char ssl_issuer_dn[NAMEDATALEN]
Definition: pgstat.h:1114
char gss_princ[NAMEDATALEN]
Definition: pgstat.h:1128
bool ssl_compression
Definition: pgstat.h:1103
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:1105
Oid st_progress_command_target
Definition: pgstat.h:1218
int MyProcPid
Definition: globals.c:40
struct Port * MyProcPort
Definition: globals.c:43
const char * be_gssapi_get_princ(Port *port)
BackendType MyBackendType
Definition: miscinit.c:62
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1176
char ssl_client_dn[NAMEDATALEN]
Definition: pgstat.h:1106
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:1104
SockAddr st_clientaddr
Definition: pgstat.h:1182
#define MemSet(start, val, len)
Definition: c.h:1004
bool ssl_in_use
Definition: libpq-be.h:190
ProgressCommandType st_progress_command
Definition: pgstat.h:1217
char ssl_client_serial[NAMEDATALEN]
Definition: pgstat.h:1112
BackendState st_state
Definition: pgstat.h:1194
char * st_clienthostname
Definition: pgstat.h:1183
Oid GetSessionUserId(void)
Definition: miscinit.c:510
Oid st_databaseid
Definition: pgstat.h:1180
#define NAMEDATALEN
char * remote_hostname
Definition: libpq-be.h:128
SockAddr raddr
Definition: libpq-be.h:126
bool be_tls_get_compression(Port *port)
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
char * st_activity_raw
Definition: pgstat.h:1206
int pgstat_track_activity_query_size
Definition: pgstat.c:129
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1177
char * st_appname
Definition: pgstat.h:1197
bool be_gssapi_get_enc(Port *port)
TimestampTz MyStartTimestamp
Definition: globals.c:42
int be_tls_get_cipher_bits(Port *port)
Oid MyDatabaseId
Definition: globals.c:85
BackendType st_backendType
Definition: pgstat.h:1171
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3469
#define InvalidOid
Definition: postgres_ext.h:36
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define Assert(condition)
Definition: c.h:800
const char * be_tls_get_version(Port *port)
void be_tls_get_peer_issuer_name(Port *port, char *ptr, size_t len)
char * application_name
Definition: guc.c:563
void be_tls_get_peer_subject_name(Port *port, char *ptr, size_t len)
void * gss
Definition: libpq-be.h:184
#define unvolatize(underlying_type, expr)
Definition: c.h:1241
void be_tls_get_peer_serial(Port *port, char *ptr, size_t len)
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1175
int st_changecount
Definition: pgstat.h:1165
const char * be_tls_get_cipher(Port *port)
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1174
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1187
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1191
bool be_gssapi_get_auth(Port *port)

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 6179 of file pgstat.c.

References localNumBackends, and MemoryContextDelete().

Referenced by AtEOXact_PgStat(), autovac_refresh_stats(), AutoVacLauncherMain(), pg_stat_clear_snapshot(), and PostPrepare_PgStat().

6180 {
6181  /* Release memory, if any was allocated */
6182  if (pgStatLocalContext)
6184 
6185  /* Reset variables */
6186  pgStatLocalContext = NULL;
6187  pgStatDBHash = NULL;
6188  localBackendStatusTable = NULL;
6189  localNumBackends = 0;
6190 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:212
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:283
static HTAB * pgStatDBHash
Definition: pgstat.c:280
static int localNumBackends
Definition: pgstat.c:286
static MemoryContext pgStatLocalContext
Definition: pgstat.c:279

◆ pgstat_clip_activity()

char* pgstat_clip_activity ( const char *  raw_activity)

Definition at line 7094 of file pgstat.c.

References cliplen(), pg_mbcliplen(), pgstat_track_activity_query_size, and pnstrdup().

Referenced by pg_stat_get_activity(), pg_stat_get_backend_activity(), and pgstat_get_backend_current_activity().

7095 {
7096  char *activity;
7097  int rawlen;
7098  int cliplen;
7099 
7100  /*
7101  * Some callers, like pgstat_get_backend_current_activity(), do not
7102  * guarantee that the buffer isn't concurrently modified. We try to take
7103  * care that the buffer is always terminated by a NUL byte regardless, but
7104  * let's still be paranoid about the string's length. In those cases the
7105  * underlying buffer is guaranteed to be pgstat_track_activity_query_size
7106  * large.
7107  */
7108  activity = pnstrdup(raw_activity, pgstat_track_activity_query_size - 1);
7109 
7110  /* now double-guaranteed to be NUL terminated */
7111  rawlen = strlen(activity);
7112 
7113  /*
7114  * All supported server-encodings make it possible to determine the length
7115  * of a multi-byte character from its first byte (this is not the case for
7116  * client encodings, see GB18030). As st_activity is always stored using
7117  * server encoding, this allows us to perform multi-byte aware truncation,
7118  * even if the string earlier was truncated in the middle of a multi-byte
7119  * character.
7120  */
7121  cliplen = pg_mbcliplen(activity, rawlen,
7123 
7124  activity[cliplen] = '\0';
7125 
7126  return activity;
7127 }
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1198
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:967
int pgstat_track_activity_query_size
Definition: pgstat.c:129
static int cliplen(const char *str, int len, int limit)
Definition: mbutils.c:1034

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

Definition at line 2168 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_deleted.

Referenced by heap_abort_speculative(), and heap_delete().

2169 {
2170  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2171 
2172  if (pgstat_info != NULL)
2173  {
2174  /* We have to log the effect at the proper transactional level */
2175  int nest_level = GetCurrentTransactionNestLevel();
2176 
2177  if (pgstat_info->trans == NULL ||
2178  pgstat_info->trans->nest_level != nest_level)
2179  add_tabstat_xact_level(pgstat_info, nest_level);
2180 
2181  pgstat_info->trans->tuples_deleted++;
2182  }
2183 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:176
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:237
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2095
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 2122 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_inserted.

Referenced by ExecRefreshMatView(), heap_insert(), and heap_multi_insert().

2123 {
2124  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2125 
2126  if (pgstat_info != NULL)
2127  {
2128  /* We have to log the effect at the proper transactional level */
2129  int nest_level = GetCurrentTransactionNestLevel();
2130 
2131  if (pgstat_info->trans == NULL ||
2132  pgstat_info->trans->nest_level != nest_level)
2133  add_tabstat_xact_level(pgstat_info, nest_level);
2134 
2135  pgstat_info->trans->tuples_inserted += n;
2136  }
2137 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:174
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:237
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2095
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

Definition at line 2143 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_tuples_hot_updated, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_update().

2144 {
2145  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2146 
2147  if (pgstat_info != NULL)
2148  {
2149  /* We have to log the effect at the proper transactional level */
2150  int nest_level = GetCurrentTransactionNestLevel();
2151 
2152  if (pgstat_info->trans == NULL ||
2153  pgstat_info->trans->nest_level != nest_level)
2154  add_tabstat_xact_level(pgstat_info, nest_level);
2155 
2156  pgstat_info->trans->tuples_updated++;
2157 
2158  /* t_tuples_hot_updated is nontransactional, so just advance it */
2159  if (hot)
2160  pgstat_info->t_counts.t_tuples_hot_updated++;
2161  }
2162 }
PgStat_Counter tuples_updated
Definition: pgstat.h:175
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:113
PgStat_TableCounts t_counts
Definition: pgstat.h:165
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:237
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2095
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164

◆ pgstat_count_slru_flush()

void pgstat_count_slru_flush ( int  slru_idx)

Definition at line 7276 of file pgstat.c.

References PgStat_MsgSLRU::m_flush, and slru_entry().

Referenced by SimpleLruWriteAll().

7277 {
7278  slru_entry(slru_idx)->m_flush += 1;
7279 }
PgStat_Counter m_flush
Definition: pgstat.h:481
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228

◆ pgstat_count_slru_page_exists()

void pgstat_count_slru_page_exists ( int  slru_idx)

Definition at line 7258 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_exists, and slru_entry().

Referenced by SimpleLruDoesPhysicalPageExist().

7259 {
7260  slru_entry(slru_idx)->m_blocks_exists += 1;
7261 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228
PgStat_Counter m_blocks_exists
Definition: pgstat.h:480

◆ pgstat_count_slru_page_hit()

void pgstat_count_slru_page_hit ( int  slru_idx)

Definition at line 7252 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_hit, and slru_entry().

Referenced by SimpleLruReadPage(), and SimpleLruReadPage_ReadOnly().

7253 {
7254  slru_entry(slru_idx)->m_blocks_hit += 1;
7255 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228
PgStat_Counter m_blocks_hit
Definition: pgstat.h:477

◆ pgstat_count_slru_page_read()

void pgstat_count_slru_page_read ( int  slru_idx)

Definition at line 7264 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_read, and slru_entry().

Referenced by SimpleLruReadPage().

7265 {
7266  slru_entry(slru_idx)->m_blocks_read += 1;
7267 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228
PgStat_Counter m_blocks_read
Definition: pgstat.h:478

◆ pgstat_count_slru_page_written()

void pgstat_count_slru_page_written ( int  slru_idx)

Definition at line 7270 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_written, and slru_entry().

Referenced by SlruPhysicalWritePage().

7271 {
7272  slru_entry(slru_idx)->m_blocks_written += 1;
7273 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228
PgStat_Counter m_blocks_written
Definition: pgstat.h:479

◆ pgstat_count_slru_page_zeroed()

void pgstat_count_slru_page_zeroed ( int  slru_idx)

Definition at line 7246 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_zeroed, and slru_entry().

Referenced by SimpleLruZeroPage().

7247 {
7248  slru_entry(slru_idx)->m_blocks_zeroed += 1;
7249 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:476

◆ pgstat_count_slru_truncate()

void pgstat_count_slru_truncate ( int  slru_idx)

Definition at line 7282 of file pgstat.c.

References PgStat_MsgSLRU::m_truncate, and slru_entry().

Referenced by SimpleLruTruncate().

7283 {
7284  slru_entry(slru_idx)->m_truncate += 1;
7285 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:7228
PgStat_Counter m_truncate
Definition: pgstat.h:482

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

Definition at line 2223 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, pgstat_truncate_save_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by ExecRefreshMatView(), and ExecuteTruncateGuts().

2224 {
2225  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2226 
2227  if (pgstat_info != NULL)
2228  {
2229  /* We have to log the effect at the proper transactional level */
2230  int nest_level = GetCurrentTransactionNestLevel();
2231 
2232  if (pgstat_info->trans == NULL ||
2233  pgstat_info->trans->nest_level != nest_level)
2234  add_tabstat_xact_level(pgstat_info, nest_level);
2235 
2236  pgstat_truncate_save_counters(pgstat_info->trans);
2237  pgstat_info->trans->tuples_inserted = 0;
2238  pgstat_info->trans->tuples_updated = 0;
2239  pgstat_info->trans->tuples_deleted = 0;
2240  }
2241 }
PgStat_Counter tuples_updated
Definition: pgstat.h:175
PgStat_Counter tuples_inserted
Definition: pgstat.h:174
PgStat_Counter tuples_deleted
Definition: pgstat.h:176
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:237
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2095
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2194

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)

Definition at line 1309 of file pgstat.c.

References PgStat_MsgTabpurge::m_databaseid, PgStat_MsgDropdb::m_databaseid, PgStat_MsgTabpurge::m_hdr, PgStat_MsgDropdb::m_hdr, PgStat_MsgTabpurge::m_nentries, PgStat_MsgTabpurge::m_tableid, MyDatabaseId, offsetof, PGINVALID_SOCKET, PGSTAT_MTYPE_DROPDB, PGSTAT_MTYPE_TABPURGE, pgstat_send(), pgstat_setheader(), and pgStatSock.

Referenced by dropdb(), and pgstat_vacuum_stat().

1310 {
1311  PgStat_MsgDropdb msg;
1312 
1314  return;
1315 
1317  msg.m_databaseid = databaseid;
1318  pgstat_send(&msg, sizeof(msg));
1319 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
Oid m_databaseid
Definition: pgstat.h:313
PgStat_MsgHdr m_hdr
Definition: pgstat.h:312
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 1872 of file pgstat.c.

References PgStat_FunctionCounts::f_numcalls, PgStat_FunctionCounts::f_self_time, PgStat_FunctionCallUsage::f_start, PgStat_FunctionCounts::f_total_time, PgStat_FunctionCallUsage::fs, have_function_stats, INSTR_TIME_ADD, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, PgStat_FunctionCallUsage::save_f_total_time, PgStat_FunctionCallUsage::save_total, and total_func_time.

Referenced by call_pltcl_start_proc(), EventTriggerInvoke(), ExecCallTriggerFunc(), ExecEvalFuncExprFusage(), ExecEvalFuncExprStrictFusage(), ExecMakeFunctionResultSet(), ExecMakeTableFunctionResult(), ExecuteCallStmt(), and fmgr_security_definer().

1873 {
1874  PgStat_FunctionCounts *fs = fcu->fs;
1875  instr_time f_total;
1876  instr_time f_others;
1877  instr_time f_self;
1878 
1879  /* stats not wanted? */
1880  if (fs == NULL)
1881  return;
1882 
1883  /* total elapsed time in this function call */
1884  INSTR_TIME_SET_CURRENT(f_total);
1885  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
1886 
1887  /* self usage: elapsed minus anything already charged to other calls */
1888  f_others = total_func_time;
1889  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
1890  f_self = f_total;
1891  INSTR_TIME_SUBTRACT(f_self, f_others);
1892 
1893  /* update backend-wide total time */
1895 
1896  /*
1897  * Compute the new f_total_time as the total elapsed time added to the
1898  * pre-call value of f_total_time. This is necessary to avoid
1899  * double-counting any time taken by recursive calls of myself. (We do
1900  * not need any similar kluge for self time, since that already excludes
1901  * any recursive calls.)
1902  */
1903  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
1904 
1905  /* update counters in function stats table */
1906  if (finalize)
1907  fs->f_numcalls++;
1908  fs->f_total_time = f_total;
1909  INSTR_TIME_ADD(fs->f_self_time, f_self);
1910 
1911  /* indicate that we have something to send */
1912  have_function_stats = true;
1913 }
instr_time f_self_time
Definition: pgstat.h:542
instr_time save_total
Definition: pgstat.h:1322
struct timeval instr_time
Definition: instr_time.h:150
instr_time f_total_time
Definition: pgstat.h:541
PgStat_FunctionCounts * fs
Definition: pgstat.h:1318
PgStat_Counter f_numcalls
Definition: pgstat.h:540
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:170
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:158
static instr_time total_func_time
Definition: pgstat.c:312
static bool have_function_stats
Definition: pgstat.c:239
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:1320

◆ pgstat_fetch_global()

◆ pgstat_fetch_replslot()

PgStat_ReplSlotStats* pgstat_fetch_replslot ( int *  nslots_p)

Definition at line 2844 of file pgstat.c.

References backend_read_statsfile(), nReplSlotStats, and replSlotStats.

Referenced by pg_stat_get_replication_slots().

2845 {
2847 
2848  *nslots_p = nReplSlotStats;
2849  return replSlotStats;
2850 }
static void backend_read_statsfile(void)
Definition: pgstat.c:6024
static int nReplSlotStats
Definition: pgstat.c:298
static PgStat_ReplSlotStats * replSlotStats
Definition: pgstat.c:297

◆ pgstat_fetch_slru()

PgStat_SLRUStats* pgstat_fetch_slru ( void  )

Definition at line 2827 of file pgstat.c.

References backend_read_statsfile(), and slruStats.

Referenced by pg_stat_get_slru().

2828 {
2830 
2831  return slruStats;
2832 }
static void backend_read_statsfile(void)
Definition: pgstat.c:6024
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:296

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 2778 of file pgstat.c.

References archiverStats, and backend_read_statsfile().

Referenced by pg_stat_get_archiver().

2779 {
2781 
2782  return &archiverStats;
2783 }
static void backend_read_statsfile(void)
Definition: pgstat.c:6024
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:293

◆ pgstat_fetch_stat_beentry()

◆ pgstat_fetch_stat_dbentry()

PgStat_StatDBEntry* pgstat_fetch_stat_dbentry ( Oid  dbid)

Definition at line 2606 of file pgstat.c.

References backend_read_statsfile(), HASH_FIND, and hash_search().

Referenced by do_autovacuum(), do_start_worker(), pg_stat_get_db_blk_read_time(), pg_stat_get_db_blk_write_time(), pg_stat_get_db_blocks_fetched(), pg_stat_get_db_blocks_hit(), pg_stat_get_db_checksum_failures(), pg_stat_get_db_checksum_last_failure(), pg_stat_get_db_conflict_all(), pg_stat_get_db_conflict_bufferpin(), pg_stat_get_db_conflict_lock(), pg_stat_get_db_conflict_snapshot(), pg_stat_get_db_conflict_startup_deadlock(), pg_stat_get_db_conflict_tablespace(), pg_stat_get_db_deadlocks(), pg_stat_get_db_stat_reset_time(), pg_stat_get_db_temp_bytes(), pg_stat_get_db_temp_files(), pg_stat_get_db_tuples_deleted(), pg_stat_get_db_tuples_fetched(), pg_stat_get_db_tuples_inserted(), pg_stat_get_db_tuples_returned(), pg_stat_get_db_tuples_updated(), pg_stat_get_db_xact_commit(), pg_stat_get_db_xact_rollback(), pgstat_fetch_stat_funcentry(), rebuild_database_list(), and table_recheck_autovac().

2607 {
2608  /*
2609  * If not done for this transaction, read the statistics collector stats
2610  * file into some hash tables.
2611  */
2613 
2614  /*
2615  * Lookup the requested database; return NULL if not found
2616  */
2618  (void *) &dbid,
2619  HASH_FIND, NULL);
2620 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:919
static void backend_read_statsfile(void)
Definition: pgstat.c:6024
static HTAB * pgStatDBHash
Definition: pgstat.c:280

◆ pgstat_fetch_stat_funcentry()

PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  funcid)

Definition at line 2689 of file pgstat.c.

References backend_read_statsfile(), PgStat_StatDBEntry::functions, HASH_FIND, hash_search(), MyDatabaseId, and pgstat_fetch_stat_dbentry().

Referenced by pg_stat_get_function_calls(), pg_stat_get_function_self_time(), and pg_stat_get_function_total_time().

2690 {
2691  PgStat_StatDBEntry *dbentry;
2692  PgStat_StatFuncEntry *funcentry = NULL;
2693 
2694  /* load the stats file if needed */
2696 
2697  /* Lookup our database, then find the requested function. */
2699  if (dbentry != NULL && dbentry->functions != NULL)
2700  {
2701  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
2702  (void *) &func_id,
2703  HASH_FIND, NULL);
2704  }
2705 
2706  return funcentry;
2707 }
HTAB * functions
Definition: pgstat.h:708
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2606
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:919
static void backend_read_statsfile(void)
Definition: pgstat.c:6024
Oid MyDatabaseId
Definition: globals.c:85

◆ pgstat_fetch_stat_local_beentry()

LocalPgBackendStatus* pgstat_fetch_stat_local_beentry ( int  beid)

Definition at line 2743 of file pgstat.c.

References localNumBackends, and pgstat_read_current_status().

Referenced by pg_stat_get_activity(), and pg_stat_get_progress_info().

2744 {
2746 
2747  if (beid < 1 || beid > localNumBackends)
2748  return NULL;
2749 
2750  return &localBackendStatusTable[beid - 1];
2751 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3525
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:283
static int localNumBackends
Definition: pgstat.c:286

◆ pgstat_fetch_stat_numbackends()

int pgstat_fetch_stat_numbackends ( void  )

Definition at line 2762 of file pgstat.c.

References localNumBackends, and pgstat_read_current_status().

Referenced by pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_stat_get_db_numbackends(), and pg_stat_get_progress_info().

2763 {
2765 
2766  return localNumBackends;
2767 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3525
static int localNumBackends
Definition: pgstat.c:286

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 2633 of file pgstat.c.

References backend_read_statsfile(), HASH_FIND, hash_search(), InvalidOid, MyDatabaseId, and PgStat_StatDBEntry::tables.

Referenced by index_concurrently_swap(), pg_stat_get_analyze_count(), pg_stat_get_autoanalyze_count(), pg_stat_get_autovacuum_count(), pg_stat_get_blocks_fetched(), pg_stat_get_blocks_hit(), pg_stat_get_dead_tuples(), pg_stat_get_ins_since_vacuum(), pg_stat_get_last_analyze_time(), pg_stat_get_last_autoanalyze_time(), pg_stat_get_last_autovacuum_time(), pg_stat_get_last_vacuum_time(), pg_stat_get_live_tuples(), pg_stat_get_mod_since_analyze(), pg_stat_get_numscans(), pg_stat_get_tuples_deleted(), pg_stat_get_tuples_fetched(), pg_stat_get_tuples_hot_updated(), pg_stat_get_tuples_inserted(), pg_stat_get_tuples_returned(), pg_stat_get_tuples_updated(), and pg_stat_get_vacuum_count().

2634 {
2635  Oid dbid;
2636  PgStat_StatDBEntry *dbentry;
2637  PgStat_StatTabEntry *tabentry;
2638 
2639  /*
2640  * If not done for this transaction, read the statistics collector stats
2641  * file into some hash tables.
2642  */
2644 
2645  /*
2646  * Lookup our database, then look in its table hash table.
2647  */
2648  dbid = MyDatabaseId;
2650  (void *) &dbid,
2651  HASH_FIND, NULL);
2652  if (dbentry != NULL && dbentry->tables != NULL)
2653  {
2654  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2655  (void *) &relid,
2656  HASH_FIND, NULL);
2657  if (tabentry)
2658  return tabentry;
2659  }
2660 
2661  /*
2662  * If we didn't find it, maybe it's a shared table.
2663  */
2664  dbid = InvalidOid;
2666  (void *) &dbid,
2667  HASH_FIND, NULL);
2668  if (dbentry != NULL && dbentry->tables != NULL)
2669  {
2670  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2671  (void *) &relid,
2672  HASH_FIND, NULL);
2673  if (tabentry)
2674  return tabentry;
2675  }
2676 
2677  return NULL;
2678 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:919
unsigned int Oid
Definition: postgres_ext.h:31
static void backend_read_statsfile(void)
Definition: pgstat.c:6024
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static HTAB * pgStatDBHash
Definition: pgstat.c:280

◆ pgstat_fetch_stat_wal()

PgStat_WalStats* pgstat_fetch_stat_wal ( void  )

Definition at line 2811 of file pgstat.c.

References backend_read_statsfile(), and walStats.

Referenced by pg_stat_get_wal().

2812 {
2814 
2815  return &walStats;
2816 }
static PgStat_WalStats walStats
Definition: pgstat.c:295
static void backend_read_statsfile(void)
Definition: pgstat.c:6024

◆ pgstat_get_backend_current_activity()

const char* pgstat_get_backend_current_activity ( int  pid,
bool  checkUser 
)

Definition at line 4348 of file pgstat.c.

References BackendStatusArray, CHECK_FOR_INTERRUPTS, GetUserId(), i, MaxBackends, pgstat_begin_read_activity, pgstat_clip_activity(), pgstat_end_read_activity, pgstat_read_activity_complete, PgBackendStatus::st_activity_raw, PgBackendStatus::st_procpid, PgBackendStatus::st_userid, and superuser().

Referenced by DeadLockReport().

4349 {
4350  PgBackendStatus *beentry;
4351  int i;
4352 
4353  beentry = BackendStatusArray;
4354  for (i = 1; i <= MaxBackends; i++)
4355  {
4356  /*
4357  * Although we expect the target backend's entry to be stable, that
4358  * doesn't imply that anyone else's is. To avoid identifying the
4359  * wrong backend, while we check for a match to the desired PID we
4360  * must follow the protocol of retrying if st_changecount changes
4361  * while we examine the entry, or if it's odd. (This might be
4362  * unnecessary, since fetching or storing an int is almost certainly
4363  * atomic, but let's play it safe.) We use a volatile pointer here to
4364  * ensure the compiler doesn't try to get cute.
4365  */
4366  volatile PgBackendStatus *vbeentry = beentry;
4367  bool found;
4368 
4369  for (;;)
4370  {
4371  int before_changecount;
4372  int after_changecount;
4373 
4374  pgstat_begin_read_activity(vbeentry, before_changecount);
4375 
4376  found = (vbeentry->st_procpid == pid);
4377 
4378  pgstat_end_read_activity(vbeentry, after_changecount);
4379 
4380  if (pgstat_read_activity_complete(before_changecount,
4381  after_changecount))
4382  break;
4383 
4384  /* Make sure we can break out of loop if stuck... */
4386  }
4387 
4388  if (found)
4389  {
4390  /* Now it is safe to use the non-volatile pointer */
4391  if (checkUser && !superuser() && beentry->st_userid != GetUserId())
4392  return "<insufficient privilege>";
4393  else if (*(beentry->st_activity_raw) == '\0')
4394  return "<command string not enabled>";
4395  else
4396  {
4397  /* this'll leak a bit of memory, but that seems acceptable */
4398  return pgstat_clip_activity(beentry->st_activity_raw);
4399  }
4400  }
4401 
4402  beentry++;
4403  }
4404 
4405  /* If we get here, caller is in error ... */
4406  return "<backend information not available>";
4407 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2857
Oid GetUserId(void)
Definition: miscinit.c:476
bool superuser(void)
Definition: superuser.c:46
int MaxBackends
Definition: globals.c:136
char * st_activity_raw
Definition: pgstat.h:1206
#define pgstat_end_read_activity(beentry, after_changecount)
Definition: pgstat.h:1272
#define pgstat_begin_read_activity(beentry, before_changecount)
Definition: pgstat.h:1266
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:7094
int i
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define pgstat_read_activity_complete(before_changecount, after_changecount)
Definition: pgstat.h:1278

◆ pgstat_get_crashed_backend_activity()

const char* pgstat_get_crashed_backend_activity ( int  pid,
char *  buffer,
int  buflen 
)

Definition at line 4426 of file pgstat.c.

References ascii_safe_strlcpy(), BackendActivityBuffer, BackendActivityBufferSize, BackendStatusArray, i, MaxBackends, Min, pgstat_track_activity_query_size, PgBackendStatus::st_activity_raw, and PgBackendStatus::st_procpid.

Referenced by LogChildExit().

4427 {
4428  volatile PgBackendStatus *beentry;
4429  int i;
4430 
4431  beentry = BackendStatusArray;
4432 
4433  /*
4434  * We probably shouldn't get here before shared memory has been set up,
4435  * but be safe.
4436  */
4437  if (beentry == NULL || BackendActivityBuffer == NULL)
4438  return NULL;
4439 
4440  for (i = 1; i <= MaxBackends; i++)
4441  {
4442  if (beentry->st_procpid == pid)
4443  {
4444  /* Read pointer just once, so it can't change after validation */
4445  const char *activity = beentry->st_activity_raw;
4446  const char *activity_last;
4447 
4448  /*
4449  * We mustn't access activity string before we verify that it
4450  * falls within the BackendActivityBuffer. To make sure that the
4451  * entire string including its ending is contained within the
4452  * buffer, subtract one activity length from the buffer size.
4453  */
4456 
4457  if (activity < BackendActivityBuffer ||
4458  activity > activity_last)
4459  return NULL;
4460 
4461  /* If no string available, no point in a report */
4462  if (activity[0] == '\0')
4463  return NULL;
4464 
4465  /*
4466  * Copy only ASCII-safe characters so we don't run into encoding
4467  * problems when reporting the message; and be sure not to run off
4468  * the end of memory. As only ASCII characters are reported, it
4469  * doesn't seem necessary to perform multibyte aware clipping.
4470  */
4471  ascii_safe_strlcpy(buffer, activity,
4472  Min(buflen, pgstat_track_activity_query_size));
4473 
4474  return buffer;
4475  }
4476 
4477  beentry++;
4478  }
4479 
4480  /* PID not found */
4481  return NULL;
4482 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2857
static char * BackendActivityBuffer
Definition: pgstat.c:2861
#define Min(x, y)
Definition: c.h:982
static Size BackendActivityBufferSize
Definition: pgstat.c:2862
void ascii_safe_strlcpy(char *dest, const char *src, size_t destsiz)
Definition: ascii.c:173
int MaxBackends
Definition: globals.c:136
char * st_activity_raw
Definition: pgstat.h:1206
int pgstat_track_activity_query_size
Definition: pgstat.c:129
int i

◆ pgstat_get_wait_event()

const char* pgstat_get_wait_event ( uint32  wait_event_info)

Definition at line 3732 of file pgstat.c.

References GetLockNameFromTagType(), GetLWLockIdentifier(), PG_WAIT_ACTIVITY, PG_WAIT_BUFFER_PIN, PG_WAIT_CLIENT, PG_WAIT_EXTENSION, PG_WAIT_IO, PG_WAIT_IPC, PG_WAIT_LOCK, PG_WAIT_LWLOCK, PG_WAIT_TIMEOUT, pgstat_get_wait_activity(), pgstat_get_wait_client(), pgstat_get_wait_io(), pgstat_get_wait_ipc(), and pgstat_get_wait_timeout().

Referenced by pg_stat_get_activity(), and pg_stat_get_backend_wait_event().

3733 {
3734  uint32 classId;
3735  uint16 eventId;
3736  const char *event_name;
3737 
3738  /* report process as not waiting. */
3739  if (wait_event_info == 0)
3740  return NULL;
3741 
3742  classId = wait_event_info & 0xFF000000;
3743  eventId = wait_event_info & 0x0000FFFF;
3744 
3745  switch (classId)
3746  {
3747  case PG_WAIT_LWLOCK:
3748  event_name = GetLWLockIdentifier(classId, eventId);
3749  break;
3750  case PG_WAIT_LOCK:
3751  event_name = GetLockNameFromTagType(eventId);
3752  break;
3753  case PG_WAIT_BUFFER_PIN:
3754  event_name = "BufferPin";
3755  break;
3756  case PG_WAIT_ACTIVITY:
3757  {
3758  WaitEventActivity w = (WaitEventActivity) wait_event_info;
3759 
3760  event_name = pgstat_get_wait_activity(w);
3761  break;
3762  }
3763  case PG_WAIT_CLIENT:
3764  {
3765  WaitEventClient w = (WaitEventClient) wait_event_info;
3766 
3767  event_name = pgstat_get_wait_client(w);
3768  break;
3769  }
3770  case PG_WAIT_EXTENSION:
3771  event_name = "Extension";
3772  break;
3773  case PG_WAIT_IPC:
3774  {
3775  WaitEventIPC w = (WaitEventIPC) wait_event_info;
3776 
3777  event_name = pgstat_get_wait_ipc(w);
3778  break;
3779  }
3780  case PG_WAIT_TIMEOUT:
3781  {
3782  WaitEventTimeout w = (WaitEventTimeout) wait_event_info;
3783 
3784  event_name = pgstat_get_wait_timeout(w);
3785  break;
3786  }
3787  case PG_WAIT_IO:
3788  {
3789  WaitEventIO w = (WaitEventIO) wait_event_info;
3790 
3791  event_name = pgstat_get_wait_io(w);
3792  break;
3793  }
3794  default:
3795  event_name = "unknown wait event";
3796  break;
3797  }
3798 
3799  return event_name;
3800 }
#define PG_WAIT_LOCK
Definition: pgstat.h:862
WaitEventIPC
Definition: pgstat.h:924
static const char * pgstat_get_wait_timeout(WaitEventTimeout w)
Definition: pgstat.c:4058
static const char * pgstat_get_wait_ipc(WaitEventIPC w)
Definition: pgstat.c:3913
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:864
#define PG_WAIT_IO
Definition: pgstat.h:869
static const char * pgstat_get_wait_activity(WaitEventActivity w)
Definition: pgstat.c:3809
unsigned short uint16
Definition: c.h:428
#define PG_WAIT_CLIENT
Definition: pgstat.h:865
WaitEventClient
Definition: pgstat.h:904
static const char * pgstat_get_wait_client(WaitEventClient w)
Definition: pgstat.c:3867
unsigned int uint32
Definition: c.h:429
WaitEventTimeout
Definition: pgstat.h:976
#define PG_WAIT_EXTENSION
Definition: pgstat.h:866
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:863
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1190
WaitEventIO
Definition: pgstat.h:991
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:868
#define PG_WAIT_IPC
Definition: pgstat.h:867
const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)
Definition: lwlock.c:808
static const char * pgstat_get_wait_io(WaitEventIO w)
Definition: pgstat.c:4092
#define PG_WAIT_LWLOCK
Definition: pgstat.h:861
WaitEventActivity
Definition: pgstat.h:879

◆ pgstat_get_wait_event_type()

const char* pgstat_get_wait_event_type ( uint32  wait_event_info)

Definition at line 3677 of file pgstat.c.

References PG_WAIT_ACTIVITY, PG_WAIT_BUFFER_PIN, PG_WAIT_CLIENT, PG_WAIT_EXTENSION, PG_WAIT_IO, PG_WAIT_IPC, PG_WAIT_LOCK, PG_WAIT_LWLOCK, and PG_WAIT_TIMEOUT.

Referenced by pg_stat_get_activity(), and pg_stat_get_backend_wait_event_type().

3678 {
3679  uint32 classId;
3680  const char *event_type;
3681 
3682  /* report process as not waiting. */
3683  if (wait_event_info == 0)
3684  return NULL;
3685 
3686  classId = wait_event_info & 0xFF000000;
3687 
3688  switch (classId)
3689  {
3690  case PG_WAIT_LWLOCK:
3691  event_type = "LWLock";
3692  break;
3693  case PG_WAIT_LOCK:
3694  event_type = "Lock";
3695  break;
3696  case PG_WAIT_BUFFER_PIN:
3697  event_type = "BufferPin";
3698  break;
3699  case PG_WAIT_ACTIVITY:
3700  event_type = "Activity";
3701  break;
3702  case PG_WAIT_CLIENT:
3703  event_type = "Client";
3704  break;
3705  case PG_WAIT_EXTENSION:
3706  event_type = "Extension";
3707  break;
3708  case PG_WAIT_IPC:
3709  event_type = "IPC";
3710  break;
3711  case PG_WAIT_TIMEOUT:
3712  event_type = "Timeout";
3713  break;
3714  case PG_WAIT_IO:
3715  event_type = "IO";
3716  break;
3717  default:
3718  event_type = "???";
3719  break;
3720  }
3721 
3722  return event_type;
3723 }
#define PG_WAIT_LOCK
Definition: pgstat.h:862
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:864
#define PG_WAIT_IO
Definition: pgstat.h:869
#define PG_WAIT_CLIENT
Definition: pgstat.h:865
unsigned int uint32
Definition: c.h:429
#define PG_WAIT_EXTENSION
Definition: pgstat.h:866
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:863
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:868
#define PG_WAIT_IPC
Definition: pgstat.h:867
#define PG_WAIT_LWLOCK
Definition: pgstat.h:861

◆ pgstat_init()

void pgstat_init ( void  )

Definition at line 399 of file pgstat.c.

References addrinfo::ai_next, AI_PASSIVE, bind, closesocket, connect, EINTR, ereport, errcode(), errcode_for_socket_access(), errmsg(), gai_strerror, LOG, pg_freeaddrinfo_all(), pg_getaddrinfo_all(), pg_set_noblock(), PGC_INTERNAL, PGC_S_OVERRIDE, PGINVALID_SOCKET, PGSTAT_MAX_MSG_SIZE, PGSTAT_MIN_RCVBUF, pgStatAddr, pgStatSock, recv, ReserveExternalFD(), select, send, SetConfigOption(), socket, StaticAssertStmt, and TESTBYTEVAL.

Referenced by PostmasterMain().

400 {
401  ACCEPT_TYPE_ARG3 alen;
402  struct addrinfo *addrs = NULL,
403  *addr,
404  hints;
405  int ret;
406  fd_set rset;
407  struct timeval tv;
408  char test_byte;
409  int sel_res;
410  int tries = 0;
411 
412 #define TESTBYTEVAL ((char) 199)
413 
414  /*
415  * This static assertion verifies that we didn't mess up the calculations
416  * involved in selecting maximum payload sizes for our UDP messages.
417  * Because the only consequence of overrunning PGSTAT_MAX_MSG_SIZE would
418  * be silent performance loss from fragmentation, it seems worth having a
419  * compile-time cross-check that we didn't.
420  */
422  "maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE");
423 
424  /*
425  * Create the UDP socket for sending and receiving statistic messages
426  */
427  hints.ai_flags = AI_PASSIVE;
428  hints.ai_family = AF_UNSPEC;
429  hints.ai_socktype = SOCK_DGRAM;
430  hints.ai_protocol = 0;
431  hints.ai_addrlen = 0;
432  hints.ai_addr = NULL;
433  hints.ai_canonname = NULL;
434  hints.ai_next = NULL;
435  ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
436  if (ret || !addrs)
437  {
438  ereport(LOG,
439  (errmsg("could not resolve \"localhost\": %s",
440  gai_strerror(ret))));
441  goto startup_failed;
442  }
443 
444  /*
445  * On some platforms, pg_getaddrinfo_all() may return multiple addresses
446  * only one of which will actually work (eg, both IPv6 and IPv4 addresses
447  * when kernel will reject IPv6). Worse, the failure may occur at the
448  * bind() or perhaps even connect() stage. So we must loop through the
449  * results till we find a working combination. We will generate LOG
450  * messages, but no error, for bogus combinations.
451  */
452  for (addr = addrs; addr; addr = addr->ai_next)
453  {
454 #ifdef HAVE_UNIX_SOCKETS
455  /* Ignore AF_UNIX sockets, if any are returned. */
456  if (addr->ai_family == AF_UNIX)
457  continue;
458 #endif
459 
460  if (++tries > 1)
461  ereport(LOG,
462  (errmsg("trying another address for the statistics collector")));
463 
464  /*
465  * Create the socket.
466  */
467  if ((pgStatSock = socket(addr->ai_family, SOCK_DGRAM, 0)) == PGINVALID_SOCKET)
468  {
469  ereport(LOG,
471  errmsg("could not create socket for statistics collector: %m")));
472  continue;
473  }
474 
475  /*
476  * Bind it to a kernel assigned port on localhost and get the assigned
477  * port via getsockname().
478  */
479  if (bind(pgStatSock, addr->ai_addr, addr->ai_addrlen) < 0)
480  {
481  ereport(LOG,
483  errmsg("could not bind socket for statistics collector: %m")));
486  continue;
487  }
488 
489  alen = sizeof(pgStatAddr);
490  if (getsockname(pgStatSock, (struct sockaddr *) &pgStatAddr, &alen) < 0)
491  {
492  ereport(LOG,
494  errmsg("could not get address of socket for statistics collector: %m")));
497  continue;
498  }
499 
500  /*
501  * Connect the socket to its own address. This saves a few cycles by
502  * not having to respecify the target address on every send. This also
503  * provides a kernel-level check that only packets from this same
504  * address will be received.
505  */
506  if (connect(pgStatSock, (struct sockaddr *) &pgStatAddr, alen) < 0)
507  {
508  ereport(LOG,
510  errmsg("could not connect socket for statistics collector: %m")));
513  continue;
514  }
515 
516  /*
517  * Try to send and receive a one-byte test message on the socket. This
518  * is to catch situations where the socket can be created but will not
519  * actually pass data (for instance, because kernel packet filtering
520  * rules prevent it).
521  */
522  test_byte = TESTBYTEVAL;
523 
524 retry1:
525  if (send(pgStatSock, &test_byte, 1, 0) != 1)
526  {
527  if (errno == EINTR)
528  goto retry1; /* if interrupted, just retry */
529  ereport(LOG,
531  errmsg("could not send test message on socket for statistics collector: %m")));
534  continue;
535  }
536 
537  /*
538  * There could possibly be a little delay before the message can be
539  * received. We arbitrarily allow up to half a second before deciding
540  * it's broken.
541  */
542  for (;;) /* need a loop to handle EINTR */
543  {
544  FD_ZERO(&rset);
545  FD_SET(pgStatSock, &rset);
546 
547  tv.tv_sec = 0;
548  tv.tv_usec = 500000;
549  sel_res = select(pgStatSock + 1, &rset, NULL, NULL, &tv);
550  if (sel_res >= 0 || errno != EINTR)
551  break;
552  }
553  if (sel_res < 0)
554  {
555  ereport(LOG,
557  errmsg("select() failed in statistics collector: %m")));
560  continue;
561  }
562  if (sel_res == 0 || !FD_ISSET(pgStatSock, &rset))
563  {
564  /*
565  * This is the case we actually think is likely, so take pains to
566  * give a specific message for it.
567  *
568  * errno will not be set meaningfully here, so don't use it.
569  */
570  ereport(LOG,
571  (errcode(ERRCODE_CONNECTION_FAILURE),
572  errmsg("test message did not get through on socket for statistics collector")));
575  continue;
576  }
577 
578  test_byte++; /* just make sure variable is changed */
579 
580 retry2:
581  if (recv(pgStatSock, &test_byte, 1, 0) != 1)
582  {
583  if (errno == EINTR)
584  goto retry2; /* if interrupted, just retry */
585  ereport(LOG,
587  errmsg("could not receive test message on socket for statistics collector: %m")));
590  continue;
591  }
592 
593  if (test_byte != TESTBYTEVAL) /* strictly paranoia ... */
594  {
595  ereport(LOG,
596  (errcode(ERRCODE_INTERNAL_ERROR),
597  errmsg("incorrect test message transmission on socket for statistics collector")));
600  continue;
601  }
602 
603  /* If we get here, we have a working socket */
604  break;
605  }
606 
607  /* Did we find a working address? */
608  if (!addr || pgStatSock == PGINVALID_SOCKET)
609  goto startup_failed;
610 
611  /*
612  * Set the socket to non-blocking IO. This ensures that if the collector
613  * falls behind, statistics messages will be discarded; backends won't
614  * block waiting to send messages to the collector.
615  */
617  {
618  ereport(LOG,
620  errmsg("could not set statistics collector socket to nonblocking mode: %m")));
621  goto startup_failed;
622  }
623 
624  /*
625  * Try to ensure that the socket's receive buffer is at least
626  * PGSTAT_MIN_RCVBUF bytes, so that it won't easily overflow and lose
627  * data. Use of UDP protocol means that we are willing to lose data under
628  * heavy load, but we don't want it to happen just because of ridiculously
629  * small default buffer sizes (such as 8KB on older Windows versions).
630  */
631  {
632  int old_rcvbuf;
633  int new_rcvbuf;
634  ACCEPT_TYPE_ARG3 rcvbufsize = sizeof(old_rcvbuf);
635 
636  if (getsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
637  (char *) &old_rcvbuf, &rcvbufsize) < 0)
638  {
639  ereport(LOG,
640  (errmsg("getsockopt(%s) failed: %m", "SO_RCVBUF")));
641  /* if we can't get existing size, always try to set it */
642  old_rcvbuf = 0;
643  }
644 
645  new_rcvbuf = PGSTAT_MIN_RCVBUF;
646  if (old_rcvbuf < new_rcvbuf)
647  {
648  if (setsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
649  (char *) &new_rcvbuf, sizeof(new_rcvbuf)) < 0)
650  ereport(LOG,
651  (errmsg("setsockopt(%s) failed: %m", "SO_RCVBUF")));
652  }
653  }
654 
655  pg_freeaddrinfo_all(hints.ai_family, addrs);
656 
657  /* Now that we have a long-lived socket, tell fd.c about it. */
659 
660  return;
661 
662 startup_failed:
663  ereport(LOG,
664  (errmsg("disabling statistics collector for lack of working socket")));
665 
666  if (addrs)
667  pg_freeaddrinfo_all(hints.ai_family, addrs);
668 
672 
673  /*
674  * Adjust GUC variables to suppress useless activity, and for debugging
675  * purposes (seeing track_counts off is a clue that we failed here). We
676  * use PGC_S_OVERRIDE because there is no point in trying to turn it back
677  * on from postgresql.conf without a restart.
678  */
679  SetConfigOption("track_counts", "off", PGC_INTERNAL, PGC_S_OVERRIDE);
680 }
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
Definition: ip.c:88
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
#define closesocket
Definition: port.h:331
int errcode(int sqlerrcode)
Definition: elog.c:691
#define connect(s, name, namelen)
Definition: win32_port.h:463
#define LOG
Definition: elog.h:26
#define bind(s, addr, addrlen)
Definition: win32_port.h:460
#define recv(s, buf, len, flags)
Definition: win32_port.h:465
#define gai_strerror
Definition: getaddrinfo.h:146
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
Definition: ip.c:57
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:914
#define PGSTAT_MIN_RCVBUF
Definition: pgstat.c:98
#define TESTBYTEVAL
void ReserveExternalFD(void)
Definition: fd.c:1110
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7808
#define AI_PASSIVE
Definition: getaddrinfo.h:62
#define select(n, r, w, e, timeout)
Definition: win32_port.h:464
int errcode_for_socket_access(void)
Definition: elog.c:785
#define socket(af, type, protocol)
Definition: win32_port.h:459
#define PGSTAT_MAX_MSG_SIZE
Definition: pgstat.h:213
#define PGINVALID_SOCKET
Definition: port.h:33
#define ereport(elevel,...)
Definition: elog.h:155
static struct sockaddr_storage pgStatAddr
Definition: pgstat.c:187
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:25
struct addrinfo * ai_next
Definition: getaddrinfo.h:107
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define EINTR
Definition: win32_port.h:343
#define send(s, buf, len, flags)
Definition: win32_port.h:466

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( struct FunctionCallInfoBaseData fcinfo,
PgStat_FunctionCallUsage fcu 
)

◆ pgstat_initialize()

void pgstat_initialize ( void  )

Definition at line 3038 of file pgstat.c.

References Assert, InvalidBackendId, MaxBackends, MyAuxProcType, MyBackendId, NotAnAuxProcess, on_shmem_exit(), pgstat_beshutdown_hook(), and pgWalUsage.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

3039 {
3040  /* Initialize MyBEEntry */
3042  {
3045  }
3046  else
3047  {
3048  /* Must be an auxiliary process */
3050 
3051  /*
3052  * Assign the MyBEEntry for an auxiliary process. Since it doesn't
3053  * have a BackendId, the slot is statically allocated based on the
3054  * auxiliary process type (MyAuxProcType). Backends use slots indexed
3055  * in the range from 1 to MaxBackends (inclusive), so we use
3056  * MaxBackends + AuxBackendType + 1 as the index of the slot for an
3057  * auxiliary process.
3058  */
3060  }
3061 
3062  /*
3063  * Initialize prevWalUsage with pgWalUsage so that pgstat_send_wal() can
3064  * calculate how much pgWalUsage counters are increased by substracting
3065  * prevWalUsage from pgWalUsage.
3066  */
3068 
3069  /* Set up a process-exit hook to clean up */
3071 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2857
BackendId MyBackendId
Definition: globals.c:81
WalUsage pgWalUsage
Definition: instrument.c:22
int MaxBackends
Definition: globals.c:136
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
static void pgstat_beshutdown_hook(int code, Datum arg)
Definition: pgstat.c:3258
#define InvalidBackendId
Definition: backendid.h:23
AuxProcType MyAuxProcType
Definition: bootstrap.c:70
#define Assert(condition)
Definition: c.h:800
static WalUsage prevWalUsage
Definition: pgstat.c:153

◆ pgstat_initstats()

void pgstat_initstats ( Relation  rel)

Definition at line 1929 of file pgstat.c.

References get_tabstat_entry(), PGINVALID_SOCKET, RelationData::pgstat_info, pgstat_track_counts, pgStatSock, RelationData::rd_id, RelationData::rd_rel, and PgStat_TableStatus::t_id.

Referenced by relation_open(), and try_relation_open().

1930 {
1931  Oid rel_id = rel->rd_id;
1932  char relkind = rel->rd_rel->relkind;
1933 
1934  /* We only count stats for things that have storage */
1935  if (!RELKIND_HAS_STORAGE(relkind))
1936  {
1937  rel->pgstat_info = NULL;
1938  return;
1939  }
1940 
1942  {
1943  /* We're not counting at all */
1944  rel->pgstat_info = NULL;
1945  return;
1946  }
1947 
1948  /*
1949  * If we already set up this relation in the current transaction, nothing
1950  * to do.
1951  */
1952  if (rel->pgstat_info != NULL &&
1953  rel->pgstat_info->t_id == rel_id)
1954  return;
1955 
1956  /* Else find or make the PgStat_TableStatus entry, and update link */
1957  rel->pgstat_info = get_tabstat_entry(rel_id, rel->rd_rel->relisshared);
1958 }
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
Form_pg_class rd_rel
Definition: rel.h:110
unsigned int Oid
Definition: postgres_ext.h:31
bool pgstat_track_counts
Definition: pgstat.c:127
Oid rd_id
Definition: rel.h:112
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:1964
#define PGINVALID_SOCKET
Definition: port.h:33
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:237

◆ pgstat_ping()

void pgstat_ping ( void  )

Definition at line 1765 of file pgstat.c.

References PgStat_MsgDummy::m_hdr, PGINVALID_SOCKET, PGSTAT_MTYPE_DUMMY, pgstat_send(), pgstat_setheader(), and pgStatSock.

1766 {
1767  PgStat_MsgDummy msg;
1768 
1770  return;
1771 
1773  pgstat_send(&msg, sizeof(msg));
1774 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
#define PGINVALID_SOCKET
Definition: port.h:33
PgStat_MsgHdr m_hdr
Definition: pgstat.h:223
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497

◆ pgstat_progress_end_command()

void pgstat_progress_end_command ( void  )

Definition at line 3446 of file pgstat.c.

References InvalidOid, MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_track_activities, PROGRESS_COMMAND_INVALID, PgBackendStatus::st_progress_command, and PgBackendStatus::st_progress_command_target.

Referenced by AbortSubTransaction(), AbortTransaction(), analyze_rel(), cluster_rel(), DefineIndex(), heap_vacuum_rel(), perform_base_backup(), reindex_index(), and ReindexRelationConcurrently().

3447 {
3448  volatile PgBackendStatus *beentry = MyBEEntry;
3449 
3450  if (!beentry || !pgstat_track_activities)
3451  return;
3452 
3454  return;
3455 
3456  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3459  PGSTAT_END_WRITE_ACTIVITY(beentry);
3460 }
Oid st_progress_command_target
Definition: pgstat.h:1218
ProgressCommandType st_progress_command
Definition: pgstat.h:1217
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
#define InvalidOid
Definition: postgres_ext.h:36
bool pgstat_track_activities
Definition: pgstat.c:126
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251

◆ pgstat_progress_start_command()

void pgstat_progress_start_command ( ProgressCommandType  cmdtype,
Oid  relid 
)

Definition at line 3374 of file pgstat.c.

References MemSet, MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_track_activities, PgBackendStatus::st_progress_command, PgBackendStatus::st_progress_command_target, and PgBackendStatus::st_progress_param.

Referenced by analyze_rel(), cluster_rel(), DefineIndex(), heap_vacuum_rel(), perform_base_backup(), reindex_index(), and ReindexRelationConcurrently().

3375 {
3376  volatile PgBackendStatus *beentry = MyBEEntry;
3377 
3378  if (!beentry || !pgstat_track_activities)
3379  return;
3380 
3381  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3382  beentry->st_progress_command = cmdtype;
3383  beentry->st_progress_command_target = relid;
3384  MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
3385  PGSTAT_END_WRITE_ACTIVITY(beentry);
3386 }
Oid st_progress_command_target
Definition: pgstat.h:1218
#define MemSet(start, val, len)
Definition: c.h:1004
ProgressCommandType st_progress_command
Definition: pgstat.h:1217
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1219
bool pgstat_track_activities
Definition: pgstat.c:126
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251

◆ pgstat_progress_update_multi_param()

void pgstat_progress_update_multi_param ( int  nparam,
const int *  index,
const int64 *  val 
)

Definition at line 3417 of file pgstat.c.

References Assert, i, MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, PGSTAT_NUM_PROGRESS_PARAM, pgstat_track_activities, and PgBackendStatus::st_progress_param.

Referenced by _bt_spools_heapscan(), BuildRelationExtStatistics(), heapam_relation_copy_for_cluster(), index_build(), lazy_scan_heap(), perform_base_backup(), ReindexRelationConcurrently(), update_basebackup_progress(), validate_index(), and WaitForLockersMultiple().

3419 {
3420  volatile PgBackendStatus *beentry = MyBEEntry;
3421  int i;
3422 
3423  if (!beentry || !pgstat_track_activities || nparam == 0)
3424  return;
3425 
3426  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3427 
3428  for (i = 0; i < nparam; ++i)
3429  {
3430  Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
3431 
3432  beentry->st_progress_param[index[i]] = val[i];
3433  }
3434 
3435  PGSTAT_END_WRITE_ACTIVITY(beentry);
3436 }
Definition: type.h:89
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:1083
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
#define Assert(condition)
Definition: c.h:800
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1219
bool pgstat_track_activities
Definition: pgstat.c:126
int i
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251
long val
Definition: informix.c:664

◆ pgstat_progress_update_param()

void pgstat_progress_update_param ( int  index,
int64  val 
)

Definition at line 3395 of file pgstat.c.

References Assert, MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, PGSTAT_NUM_PROGRESS_PARAM, pgstat_track_activities, PgBackendStatus::st_progress_param, and val.

Referenced by _bt_leafbuild(), _bt_load(), _bt_spools_heapscan(), _h_indexbuild(), acquire_inherited_sample_rows(), acquire_sample_rows(), btvacuumscan(), BuildRelationExtStatistics(), cluster_rel(), DefineIndex(), do_analyze_rel(), finish_heap_swap(), hashbuild(), heap_vacuum_rel(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), lazy_cleanup_all_indexes(), lazy_record_dead_tuple(), lazy_scan_heap(), lazy_truncate_heap(), lazy_vacuum_all_indexes(), lazy_vacuum_heap(), lazy_vacuum_page(), perform_base_backup(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), validate_index(), WaitForLockersMultiple(), and WaitForOlderSnapshots().

3396 {
3397  volatile PgBackendStatus *beentry = MyBEEntry;
3398 
3400 
3401  if (!beentry || !pgstat_track_activities)
3402  return;
3403 
3404  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3405  beentry->st_progress_param[index] = val;
3406  PGSTAT_END_WRITE_ACTIVITY(beentry);
3407 }
Definition: type.h:89
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:1083
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
#define Assert(condition)
Definition: c.h:800
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1219
bool pgstat_track_activities
Definition: pgstat.c:126
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251
long val
Definition: informix.c:664

◆ pgstat_report_activity()

void pgstat_report_activity ( BackendState  state,
const char *  cmd_str 
)

Definition at line 3296 of file pgstat.c.

References GetCurrentStatementStartTimestamp(), GetCurrentTimestamp(), Min, MyBEEntry, MyProc, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_track_activities, pgstat_track_activity_query_size, PgBackendStatus::st_activity_raw, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_state, PgBackendStatus::st_state_start_timestamp, PgBackendStatus::st_xact_start_timestamp, STATE_DISABLED, and PGPROC::wait_event_info.

Referenced by _bt_parallel_build_main(), apply_handle_begin(), apply_handle_commit(), apply_handle_stream_commit(), apply_handle_stream_start(), apply_handle_stream_stop(), autovac_report_activity(), autovac_report_workitem(), exec_bind_message(), exec_execute_message(), exec_parse_message(), exec_replication_command(), exec_simple_query(), initialize_worker_spi(), LogicalRepApplyLoop(), parallel_vacuum_main(), ParallelQueryMain(), and PostgresMain().

3297 {
3298  volatile PgBackendStatus *beentry = MyBEEntry;
3299  TimestampTz start_timestamp;
3300  TimestampTz current_timestamp;
3301  int len = 0;
3302 
3303  TRACE_POSTGRESQL_STATEMENT_STATUS(cmd_str);
3304 
3305  if (!beentry)
3306  return;
3307 
3309  {
3310  if (beentry->st_state != STATE_DISABLED)
3311  {
3312  volatile PGPROC *proc = MyProc;
3313 
3314  /*
3315  * track_activities is disabled, but we last reported a
3316  * non-disabled state. As our final update, change the state and
3317  * clear fields we will not be updating anymore.
3318  */
3319  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3320  beentry->st_state = STATE_DISABLED;
3321  beentry->st_state_start_timestamp = 0;
3322  beentry->st_activity_raw[0] = '\0';
3323  beentry->st_activity_start_timestamp = 0;
3324  /* st_xact_start_timestamp and wait_event_info are also disabled */
3325  beentry->st_xact_start_timestamp = 0;
3326  proc->wait_event_info = 0;
3327  PGSTAT_END_WRITE_ACTIVITY(beentry);
3328  }
3329  return;
3330  }
3331 
3332  /*
3333  * To minimize the time spent modifying the entry, and avoid risk of
3334  * errors inside the critical section, fetch all the needed data first.
3335  */
3336  start_timestamp = GetCurrentStatementStartTimestamp();
3337  if (cmd_str != NULL)
3338  {
3339  /*
3340  * Compute length of to-be-stored string unaware of multi-byte
3341  * characters. For speed reasons that'll get corrected on read, rather
3342  * than computed every write.
3343  */
3344  len = Min(strlen(cmd_str), pgstat_track_activity_query_size - 1);
3345  }
3346  current_timestamp = GetCurrentTimestamp();
3347 
3348  /*
3349  * Now update the status entry
3350  */
3351  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3352 
3353  beentry->st_state = state;
3354  beentry->st_state_start_timestamp = current_timestamp;
3355 
3356  if (cmd_str != NULL)
3357  {
3358  memcpy((char *) beentry->st_activity_raw, cmd_str, len);
3359  beentry->st_activity_raw[len] = '\0';
3360  beentry->st_activity_start_timestamp = start_timestamp;
3361  }
3362 
3363  PGSTAT_END_WRITE_ACTIVITY(beentry);
3364 }
uint32 wait_event_info
Definition: proc.h:223
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1176
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1578
PGPROC * MyProc
Definition: proc.c:67
int64 TimestampTz
Definition: timestamp.h:39
#define Min(x, y)
Definition: c.h:982
BackendState st_state
Definition: pgstat.h:1194
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
char * st_activity_raw
Definition: pgstat.h:1206
int pgstat_track_activity_query_size
Definition: pgstat.c:129
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1177
Definition: regguts.h:298
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1175
bool pgstat_track_activities
Definition: pgstat.c:126
Definition: proc.h:120
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:807

◆ pgstat_report_analyze()

void pgstat_report_analyze ( Relation  rel,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples,
bool  resetcounter 
)

Definition at line 1573 of file pgstat.c.

References GetCurrentTimestamp(), InvalidOid, IsAutoVacuumWorkerProcess(), PgStat_MsgAnalyze::m_analyzetime, PgStat_MsgAnalyze::m_autovacuum, PgStat_MsgAnalyze::m_databaseid, PgStat_MsgAnalyze::m_dead_tuples, PgStat_MsgAnalyze::m_hdr, PgStat_MsgAnalyze::m_live_tuples, PgStat_MsgAnalyze::m_resetcounter, PgStat_MsgAnalyze::m_tableoid, Max, MyDatabaseId, PGINVALID_SOCKET, RelationData::pgstat_info, PGSTAT_MTYPE_ANALYZE, pgstat_send(), pgstat_setheader(), pgstat_track_counts, pgStatSock, RelationData::rd_rel, RelationGetRelid, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

Referenced by do_analyze_rel().

1576 {
1577  PgStat_MsgAnalyze msg;
1578 
1580  return;
1581 
1582  /*
1583  * Unlike VACUUM, ANALYZE might be running inside a transaction that has
1584  * already inserted and/or deleted rows in the target table. ANALYZE will
1585  * have counted such rows as live or dead respectively. Because we will
1586  * report our counts of such rows at transaction end, we should subtract
1587  * off these counts from what we send to the collector now, else they'll
1588  * be double-counted after commit. (This approach also ensures that the
1589  * collector ends up with the right numbers if we abort instead of
1590  * committing.)
1591  */
1592  if (rel->pgstat_info != NULL)
1593  {
1595 
1596  for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
1597  {
1598  livetuples -= trans->tuples_inserted - trans->tuples_deleted;
1599  deadtuples -= trans->tuples_updated + trans->tuples_deleted;
1600  }
1601  /* count stuff inserted by already-aborted subxacts, too */
1602  deadtuples -= rel->pgstat_info->t_counts.t_delta_dead_tuples;
1603  /* Since ANALYZE's counts are estimates, we could have underflowed */
1604  livetuples = Max(livetuples, 0);
1605  deadtuples = Max(deadtuples, 0);
1606  }
1607 
1609  msg.m_databaseid = rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId;
1610  msg.m_tableoid = RelationGetRelid(rel);
1612  msg.m_resetcounter = resetcounter;
1614  msg.m_live_tuples = livetuples;
1615  msg.m_dead_tuples = deadtuples;
1616  pgstat_send(&msg, sizeof(msg));
1617 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
PgStat_Counter tuples_updated
Definition: pgstat.h:175
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1578
TimestampTz m_analyzetime
Definition: pgstat.h:417
PgStat_TableCounts t_counts
Definition: pgstat.h:165
Form_pg_class rd_rel
Definition: rel.h:110
bool m_resetcounter
Definition: pgstat.h:416
bool pgstat_track_counts
Definition: pgstat.c:127
PgStat_Counter tuples_inserted
Definition: pgstat.h:174
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:117
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3325
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:183
PgStat_Counter m_live_tuples
Definition: pgstat.h:418
bool m_autovacuum
Definition: pgstat.h:415
PgStat_Counter tuples_deleted
Definition: pgstat.h:176
#define PGINVALID_SOCKET
Definition: port.h:33
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define Max(x, y)
Definition: c.h:976
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:237
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:164
PgStat_MsgHdr m_hdr
Definition: pgstat.h:412
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_Counter m_dead_tuples
Definition: pgstat.h:419
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ pgstat_report_appname()

void pgstat_report_appname ( const char *  appname)

Definition at line 3469 of file pgstat.c.

References MyBEEntry, NAMEDATALEN, pg_mbcliplen(), PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, and PgBackendStatus::st_appname.

Referenced by assign_application_name(), and pgstat_bestart().

3470 {
3471  volatile PgBackendStatus *beentry = MyBEEntry;
3472  int len;
3473 
3474  if (!beentry)
3475  return;
3476 
3477  /* This should be unnecessary if GUC did its job, but be safe */
3478  len = pg_mbcliplen(appname, strlen(appname), NAMEDATALEN - 1);
3479 
3480  /*
3481  * Update my status entry, following the protocol of bumping
3482  * st_changecount before and after. We use a volatile pointer here to
3483  * ensure the compiler doesn't try to get cute.
3484  */
3485  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3486 
3487  memcpy((char *) beentry->st_appname, appname, len);
3488  beentry->st_appname[len] = '\0';
3489 
3490  PGSTAT_END_WRITE_ACTIVITY(beentry);
3491 }
#define NAMEDATALEN
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:967
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2858
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1258
char * st_appname
Definition: pgstat.h:1197
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1251

◆ pgstat_report_autovac()

void pgstat_report_autovac ( Oid  dboid)

Definition at line 1523 of file pgstat.c.

References GetCurrentTimestamp(), PgStat_MsgAutovacStart::m_databaseid, PgStat_MsgAutovacStart::m_hdr, PgStat_MsgAutovacStart::m_start_time, PGINVALID_SOCKET, PGSTAT_MTYPE_AUTOVAC_START, pgstat_send(), pgstat_setheader(), and pgStatSock.

Referenced by AutoVacWorkerMain().

1524 {
1526 
1528  return;
1529 
1531  msg.m_databaseid = dboid;
1533 
1534  pgstat_send(&msg, sizeof(msg));
1535 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1578
PgStat_MsgHdr m_hdr
Definition: pgstat.h:382
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497
TimestampTz m_start_time
Definition: pgstat.h:384

◆ pgstat_report_checksum_failure()

void pgstat_report_checksum_failure ( void  )

Definition at line 1689 of file pgstat.c.

References MyDatabaseId, and pgstat_report_checksum_failures_in_db().

Referenced by PageIsVerifiedExtended().

1690 {
1692 }
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
Definition: pgstat.c:1667
Oid MyDatabaseId
Definition: globals.c:85

◆ pgstat_report_checksum_failures_in_db()

void pgstat_report_checksum_failures_in_db ( Oid  dboid,
int  failurecount 
)

Definition at line 1667 of file pgstat.c.

References GetCurrentTimestamp(), PgStat_MsgChecksumFailure::m_databaseid, PgStat_MsgChecksumFailure::m_failure_time, PgStat_MsgChecksumFailure::m_failurecount, PgStat_MsgChecksumFailure::m_hdr, PGINVALID_SOCKET, PGSTAT_MTYPE_CHECKSUMFAILURE, pgstat_send(), pgstat_setheader(), pgstat_track_counts, and pgStatSock.

Referenced by pgstat_report_checksum_failure(), and sendFile().

1668 {
1670 
1672  return;
1673 
1675  msg.m_databaseid = dboid;
1676  msg.m_failurecount = failurecount;
1678 
1679  pgstat_send(&msg, sizeof(msg));
1680 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1578
PgStat_MsgHdr m_hdr
Definition: pgstat.h:619
bool pgstat_track_counts
Definition: pgstat.c:127
TimestampTz m_failure_time
Definition: pgstat.h:622
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497

◆ pgstat_report_deadlock()

void pgstat_report_deadlock ( void  )

Definition at line 1646 of file pgstat.c.

References PgStat_MsgDeadlock::m_databaseid, PgStat_MsgDeadlock::m_hdr, MyDatabaseId, PGINVALID_SOCKET, PGSTAT_MTYPE_DEADLOCK, pgstat_send(), pgstat_setheader(), pgstat_track_counts, and pgStatSock.

Referenced by DeadLockReport().

1647 {
1648  PgStat_MsgDeadlock msg;
1649 
1651  return;
1652 
1654  msg.m_databaseid = MyDatabaseId;
1655  pgstat_send(&msg, sizeof(msg));
1656 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
bool pgstat_track_counts
Definition: pgstat.c:127
PgStat_MsgHdr m_hdr
Definition: pgstat.h:608
#define PGINVALID_SOCKET
Definition: port.h:33
Oid MyDatabaseId
Definition: globals.c:85
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497

◆ pgstat_report_recovery_conflict()

void pgstat_report_recovery_conflict ( int  reason)

Definition at line 1626 of file pgstat.c.

References PgStat_MsgRecoveryConflict::m_databaseid, PgStat_MsgRecoveryConflict::m_hdr, PgStat_MsgRecoveryConflict::m_reason, MyDatabaseId, PGINVALID_SOCKET, PGSTAT_MTYPE_RECOVERYCONFLICT, pgstat_send(), pgstat_setheader(), pgstat_track_counts, and pgStatSock.

Referenced by ProcessInterrupts().

1627 {
1629 
1631  return;
1632 
1634  msg.m_databaseid = MyDatabaseId;
1635  msg.m_reason = reason;
1636  pgstat_send(&msg, sizeof(msg));
1637 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:185
bool pgstat_track_counts
Definition: pgstat.c:127
PgStat_MsgHdr m_hdr
Definition: pgstat.h:510
#define PGINVALID_SOCKET
Definition: port.h:33
Oid MyDatabaseId
Definition: globals.c:85
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497

◆ pgstat_report_replslot()

void pgstat_report_replslot ( const char *  slotname,
int  spilltxns,
int  spillcount,
int  spillbytes,
int  streamtxns,
int  streamcount,
int  streambytes 
)

Definition at line 1721 of file pgstat.c.

References PgStat_MsgReplSlot::m_drop, PgStat_MsgReplSlot::m_hdr, PgStat_MsgReplSlot::m_slotname, PgStat_MsgReplSlot::m_spill_bytes, PgStat_MsgReplSlot::m_spill_count, PgStat_MsgReplSlot::m_spill_txns, PgStat_MsgReplSlot::m_stream_bytes, PgStat_MsgReplSlot::m_stream_count, PgStat_MsgReplSlot::m_stream_txns, NAMEDATALEN, PGSTAT_MTYPE_REPLSLOT, pgstat_send(), pgstat_setheader(), and strlcpy().

Referenced by ReplicationSlotCreate(), and UpdateDecodingStats().

1723 {
1724  PgStat_MsgReplSlot msg;
1725 
1726  /*
1727  * Prepare and send the message
1728  */
1730  strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
1731  msg.m_drop = false;
1732  msg.m_spill_txns = spilltxns;
1733  msg.m_spill_count = spillcount;
1734  msg.m_spill_bytes = spillbytes;
1735  msg.m_stream_txns = streamtxns;
1736  msg.m_stream_count = streamcount;
1737  msg.m_stream_bytes = streambytes;
1738  pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
1739 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
PgStat_Counter m_spill_bytes
Definition: pgstat.h:497
char m_slotname[NAMEDATALEN]
Definition: pgstat.h:493
PgStat_Counter m_stream_bytes
Definition: pgstat.h:500
#define NAMEDATALEN
PgStat_Counter m_spill_txns
Definition: pgstat.h:495
PgStat_Counter m_stream_txns
Definition: pgstat.h:498
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497
PgStat_Counter m_spill_count
Definition: pgstat.h:496
PgStat_MsgHdr m_hdr
Definition: pgstat.h:492
PgStat_Counter m_stream_count
Definition: pgstat.h:499

◆ pgstat_report_replslot_drop()

void pgstat_report_replslot_drop ( const char *  slotname)

Definition at line 1748 of file pgstat.c.

References PgStat_MsgReplSlot::m_drop, PgStat_MsgReplSlot::m_hdr, PgStat_MsgReplSlot::m_slotname, NAMEDATALEN, PGSTAT_MTYPE_REPLSLOT, pgstat_send(), pgstat_setheader(), and strlcpy().

Referenced by ReplicationSlotDropPtr().

1749 {
1750  PgStat_MsgReplSlot msg;
1751 
1753  strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
1754  msg.m_drop = true;
1755  pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
1756 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4510
char m_slotname[NAMEDATALEN]
Definition: pgstat.h:493
#define NAMEDATALEN
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4497
PgStat_MsgHdr m_hdr
Definition: pgstat.h:492

◆ pgstat_report_stat()

void pgstat_report_stat ( bool  force)

Definition at line 861 of file pgstat.c.

References Assert, GetCurrentTransactionStopTimestamp(), hash_destroy(), have_function_stats, i, InvalidOid, PgStat_MsgTabstat::m_databaseid, PgStat_MsgTabstat::m_entry, PgStat_MsgTabstat::m_nentries, MemSet, MyDatabaseId, now(), PGSTAT_NUM_TABENTRIES, pgstat_send_funcstats(), pgstat_send_slru(), pgstat_send_tabstat(), pgstat_send_wal(), PGSTAT_STAT_INTERVAL, pgStatXactCommit, pgStatXactRollback, PgStat_TableStatus::t_counts, PgStat_TableEntry::t_counts, PgStat_TableStatus::t_id, PgStat_TableEntry::t_id, PgStat_TableStatus::t_shared, TimestampDifferenceExceeds(), PgStat_TableStatus::trans, TabStatusArray::tsa_entries, TabStatusArray::tsa_next, and TabStatusArray::tsa_used.

Referenced by apply_handle_commit_internal(), initialize_worker_spi(), LogicalRepSyncTableStart(), pg_attribute_noreturn(), pgstat_beshutdown_hook(), PostgresMain(), and process_syncing_tables_for_apply().

862 {
863  /* we assume this inits to all zeroes: */
864  static const PgStat_TableCounts all_zeroes;
865  static TimestampTz last_report = 0;
866 
868  PgStat_MsgTabstat regular_msg;
869  PgStat_MsgTabstat shared_msg;
870  TabStatusArray *tsa;
871  int i;
872 
873  /* Don't expend a clock check if nothing to do */
874  if ((pgStatTabList == NULL || pgStatTabList->tsa_used == 0) &&
875  pgStatXactCommit == 0 && pgStatXactRollback == 0 &&
877  return;
878 
879  /*
880  * Don't send a message unless it's been at least PGSTAT_STAT_INTERVAL
881  * msec since we last sent one, or the caller wants to force stats out.
882  */
884  if (!force &&
886  return;
887  last_report = now;
888 
889  /*
890  * Destroy pgStatTabHash before we start invalidating PgStat_TableEntry
891  * entries it points to. (Should we fail partway through the loop below,
892  * it's okay to have removed the hashtable already --- the only
893  * consequence is we'd get multiple entries for the same table in the
894  * pgStatTabList, and that's safe.)
895  */
896  if (pgStatTabHash)
898  pgStatTabHash = NULL;
899 
900  /*
901  * Scan through the TabStatusArray struct(s) to find tables that actually
902  * have counts, and build messages to send. We have to separate shared
903  * relations from regular ones because the databaseid field in the message
904  * header has to depend on that.
905  */
906  regular_msg.m_databaseid = MyDatabaseId;
907  shared_msg.m_databaseid = InvalidOid;
908  regular_msg.m_nentries = 0;
909  shared_msg.m_nentries = 0;
910 
911  for (tsa = pgStatTabList; tsa != NULL; tsa = tsa->tsa_next)
912  {
913  for (i = 0; i < tsa->tsa_used; i++)
914  {
915  PgStat_TableStatus *entry = &tsa->tsa_entries[i];
916  PgStat_MsgTabstat *this_msg;
917  PgStat_TableEntry *this_ent;
918 
919  /* Shouldn't have any pending transaction-dependent counts */
920  Assert(entry->trans == NULL);
921 
922  /*
923  * Ignore entries that didn't accumulate any actual counts, such
924  * as indexes that were opened by the planner but not used.
925  */
926  if (memcmp(&entry->t_counts, &all_zeroes,
927  sizeof(PgStat_TableCounts)) == 0)
928  continue;
929 
930  /*
931  * OK, insert data into the appropriate message, and send if full.
932  */
933  this_msg = entry->t_shared ? &shared_msg : &regular_msg;
934  this_ent = &this_msg->m_entry[this_msg->m_nentries];
935  this_ent->t_id = entry->t_id;
936  memcpy(&this_ent->t_counts, &entry->t_counts,
937  sizeof(PgStat_TableCounts));
938  if (++this_msg->m_nentries >= PGSTAT_NUM_TABENTRIES)
939  {
940  pgstat_send_tabstat(this_msg);
941  this_msg->m_nentries = 0;
942  }
943  }
944  /* zero out PgStat_TableStatus structs after use */
945  MemSet(tsa->tsa_entries, 0,
946  tsa->tsa_used * sizeof(PgStat_TableStatus));
947  tsa->tsa_used = 0;
948  }
949 
950  /*
951  * Send partial messages. Make sure that any pending xact commit/abort
952  * gets counted, even if there are no table stats to send.
953  */
954  if (regular_msg.m_nentries > 0 ||
956  pgstat_send_tabstat(&regular_msg);
957  if (shared_msg.m_nentries > 0)
958  pgstat_send_tabstat(&shared_msg);
959 
960  /* Now, send function statistics */
962 
963  /* Send WAL statistics */
964  pgstat_send_wal();
965 
966  /* Finally send SLRU statistics */
968 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:827
int tsa_used
Definition: pgstat.c:209
static int pgStatXactCommit
Definition: pgstat.c:257
static void pgstat_send_slru(void)
Definition: pgstat.c:4644
int64 TimestampTz
Definition: timestamp.h:39
#define MemSet(start, val, len)
Definition: c.h:1004
struct TabStatusArray * tsa_next
Definition: pgstat.c:208
PgStat_TableCounts t_counts
Definition: pgstat.h:165
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1709
static void pgstat_send_tabstat(PgStat_MsgTabstat *tsmsg)
Definition: pgstat.c:974
static HTAB * pgStatTabHash
Definition: pgstat.c:227
static int pgStatXactRollback