PostgreSQL Source Code  git master
pgstat.h File Reference
#include "datatype/timestamp.h"
#include "libpq/pqcomm.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_MsgAutovacStart
 
struct  PgStat_MsgVacuum
 
struct  PgStat_MsgAnalyze
 
struct  PgStat_MsgArchiver
 
struct  PgStat_MsgBgWriter
 
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  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   0x01A5BC9D
 
#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_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_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 enum BackendType BackendType
 
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_AUTOVAC_START, PGSTAT_MTYPE_VACUUM, PGSTAT_MTYPE_ANALYZE, PGSTAT_MTYPE_ARCHIVER,
  PGSTAT_MTYPE_BGWRITER, PGSTAT_MTYPE_FUNCSTAT, PGSTAT_MTYPE_FUNCPURGE, PGSTAT_MTYPE_RECOVERYCONFLICT,
  PGSTAT_MTYPE_TEMPFILE, PGSTAT_MTYPE_DEADLOCK, PGSTAT_MTYPE_CHECKSUMFAILURE
}
 
enum  PgStat_Shared_Reset_Target { RESET_ARCHIVER, RESET_BGWRITER }
 
enum  PgStat_Single_Reset_Type { RESET_TABLE, RESET_FUNCTION }
 
enum  BackendType {
  B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER,
  B_BG_WRITER, B_CHECKPOINTER, B_STARTUP, B_WAL_RECEIVER,
  B_WAL_SENDER, B_WAL_WRITER
}
 
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_ALL, 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_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,
  WAIT_EVENT_GSS_OPEN_SERVER
}
 
enum  WaitEventIPC {
  WAIT_EVENT_BGWORKER_SHUTDOWN = PG_WAIT_IPC, WAIT_EVENT_BGWORKER_STARTUP, WAIT_EVENT_BTREE_PAGE, WAIT_EVENT_CLOG_GROUP_UPDATE,
  WAIT_EVENT_CHECKPOINT_DONE, WAIT_EVENT_CHECKPOINT_START, WAIT_EVENT_EXECUTE_GATHER, WAIT_EVENT_HASH_BATCH_ALLOCATING,
  WAIT_EVENT_HASH_BATCH_ELECTING, WAIT_EVENT_HASH_BATCH_LOADING, WAIT_EVENT_HASH_BUILD_ALLOCATING, WAIT_EVENT_HASH_BUILD_ELECTING,
  WAIT_EVENT_HASH_BUILD_HASHING_INNER, WAIT_EVENT_HASH_BUILD_HASHING_OUTER, WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATING, WAIT_EVENT_HASH_GROW_BATCHES_DECIDING,
  WAIT_EVENT_HASH_GROW_BATCHES_ELECTING, WAIT_EVENT_HASH_GROW_BATCHES_FINISHING, WAIT_EVENT_HASH_GROW_BATCHES_REPARTITIONING, WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATING,
  WAIT_EVENT_HASH_GROW_BUCKETS_ELECTING, WAIT_EVENT_HASH_GROW_BUCKETS_REINSERTING, 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_PROMOTE, WAIT_EVENT_REPLICATION_ORIGIN_DROP, WAIT_EVENT_REPLICATION_SLOT_DROP, WAIT_EVENT_SAFE_SNAPSHOT,
  WAIT_EVENT_SYNC_REP
}
 
enum  WaitEventTimeout { WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT, WAIT_EVENT_PG_SLEEP, WAIT_EVENT_RECOVERY_APPLY_DELAY }
 
enum  WaitEventIO {
  WAIT_EVENT_BUFFILE_READ = PG_WAIT_IO, WAIT_EVENT_BUFFILE_WRITE, 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
}
 
enum  ProgressCommandType { PROGRESS_COMMAND_INVALID, PROGRESS_COMMAND_VACUUM, PROGRESS_COMMAND_CLUSTER, PROGRESS_COMMAND_CREATE_INDEX }
 

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_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_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)
 
const char * pgstat_get_backend_desc (BackendType backendType)
 
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)
 
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)
 

Variables

bool pgstat_track_activities
 
bool pgstat_track_counts
 
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_Counter pgStatBlockReadTime
 
PgStat_Counter pgStatBlockWriteTime
 

Macro Definition Documentation

◆ PG_STAT_TMP_DIR

#define PG_STAT_TMP_DIR   "pg_stat_tmp"

Definition at line 33 of file pgstat.h.

◆ PG_WAIT_ACTIVITY

#define PG_WAIT_ACTIVITY   0x05000000U

Definition at line 757 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 758 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 762 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 760 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 761 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 1145 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 1388 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 1383 of file pgstat.h.

Referenced by ReadBufferExtended().

◆ pgstat_count_buffer_read_time

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

Definition at line 1393 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 1395 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 1368 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 1363 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 1358 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 1373 of file pgstat.h.

Referenced by _bt_first(), _hash_first(), bringetbitmap(), ginNewScanKey(), 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 1378 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 1151 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 1137 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   0x01A5BC9D

◆ PGSTAT_MAX_MSG_SIZE

#define PGSTAT_MAX_MSG_SIZE   1000

Definition at line 206 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 207 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:207

Definition at line 493 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:207

Definition at line 510 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:74
unsigned int Oid
Definition: postgres_ext.h:31
struct PgStat_TableEntry PgStat_TableEntry
#define PGSTAT_MSG_PAYLOAD
Definition: pgstat.h:207

Definition at line 263 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:207

Definition at line 285 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 1157 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 28 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 30 of file pgstat.h.

Referenced by pgstat_write_statsfiles().

Typedef Documentation

◆ BackendState

typedef enum BackendState BackendState

◆ BackendType

typedef enum BackendType BackendType

◆ LocalPgBackendStatus

◆ PgBackendGSSStatus

◆ PgBackendSSLStatus

◆ PgBackendStatus

◆ PgStat_ArchiverStats

◆ PgStat_BackendFunctionEntry

◆ PgStat_Counter

typedef int64 PgStat_Counter

Definition at line 74 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_MsgResetcounter

◆ PgStat_MsgResetsharedcounter

◆ PgStat_MsgResetsinglecounter

◆ PgStat_MsgTabpurge

◆ PgStat_MsgTabstat

◆ PgStat_MsgTempFile

◆ PgStat_MsgVacuum

◆ PgStat_Shared_Reset_Target

◆ PgStat_Single_Reset_Type

◆ PgStat_StatDBEntry

◆ PgStat_StatFuncEntry

◆ PgStat_StatTabEntry

◆ PgStat_TableCounts

◆ PgStat_TableEntry

◆ PgStat_TableStatus

◆ PgStat_TableXactStatus

◆ 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 738 of file pgstat.h.

◆ BackendType

Enumerator
B_AUTOVAC_LAUNCHER 
B_AUTOVAC_WORKER 
B_BACKEND 
B_BG_WORKER 
B_BG_WRITER 
B_CHECKPOINTER 
B_STARTUP 
B_WAL_RECEIVER 
B_WAL_SENDER 
B_WAL_WRITER 

Definition at line 719 of file pgstat.h.

◆ PgStat_Shared_Reset_Target

Enumerator
RESET_ARCHIVER 
RESET_BGWRITER 

Definition at line 119 of file pgstat.h.

120 {
PgStat_Shared_Reset_Target
Definition: pgstat.h:119

◆ PgStat_Single_Reset_Type

Enumerator
RESET_TABLE 
RESET_FUNCTION 

Definition at line 126 of file pgstat.h.

127 {
128  RESET_TABLE,
PgStat_Single_Reset_Type
Definition: pgstat.h:126

◆ ProgressCommandType

Enumerator
PROGRESS_COMMAND_INVALID 
PROGRESS_COMMAND_VACUUM 
PROGRESS_COMMAND_CLUSTER 
PROGRESS_COMMAND_CREATE_INDEX 

Definition at line 954 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_AUTOVAC_START 
PGSTAT_MTYPE_VACUUM 
PGSTAT_MTYPE_ANALYZE 
PGSTAT_MTYPE_ARCHIVER 
PGSTAT_MTYPE_BGWRITER 
PGSTAT_MTYPE_FUNCSTAT 
PGSTAT_MTYPE_FUNCPURGE 
PGSTAT_MTYPE_RECOVERYCONFLICT 
PGSTAT_MTYPE_TEMPFILE 
PGSTAT_MTYPE_DEADLOCK 
PGSTAT_MTYPE_CHECKSUMFAILURE 

Definition at line 47 of file pgstat.h.

48 {
68 } StatMsgType;
StatMsgType
Definition: pgstat.h:47

◆ TrackFunctionsLevel

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 36 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_ALL 
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 772 of file pgstat.h.

◆ WaitEventClient

Enumerator
WAIT_EVENT_CLIENT_READ 
WAIT_EVENT_CLIENT_WRITE 
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 
WAIT_EVENT_GSS_OPEN_SERVER 

Definition at line 798 of file pgstat.h.

◆ WaitEventIO

Enumerator
WAIT_EVENT_BUFFILE_READ 
WAIT_EVENT_BUFFILE_WRITE 
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 

Definition at line 878 of file pgstat.h.

879 {
948 } WaitEventIO;
#define PG_WAIT_IO
Definition: pgstat.h:762
WaitEventIO
Definition: pgstat.h:878

◆ WaitEventIPC

Enumerator
WAIT_EVENT_BGWORKER_SHUTDOWN 
WAIT_EVENT_BGWORKER_STARTUP 
WAIT_EVENT_BTREE_PAGE 
WAIT_EVENT_CLOG_GROUP_UPDATE 
WAIT_EVENT_CHECKPOINT_DONE 
WAIT_EVENT_CHECKPOINT_START 
WAIT_EVENT_EXECUTE_GATHER 
WAIT_EVENT_HASH_BATCH_ALLOCATING 
WAIT_EVENT_HASH_BATCH_ELECTING 
WAIT_EVENT_HASH_BATCH_LOADING 
WAIT_EVENT_HASH_BUILD_ALLOCATING 
WAIT_EVENT_HASH_BUILD_ELECTING 
WAIT_EVENT_HASH_BUILD_HASHING_INNER 
WAIT_EVENT_HASH_BUILD_HASHING_OUTER 
WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATING 
WAIT_EVENT_HASH_GROW_BATCHES_DECIDING 
WAIT_EVENT_HASH_GROW_BATCHES_ELECTING 
WAIT_EVENT_HASH_GROW_BATCHES_FINISHING 
WAIT_EVENT_HASH_GROW_BATCHES_REPARTITIONING 
WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATING 
WAIT_EVENT_HASH_GROW_BUCKETS_ELECTING 
WAIT_EVENT_HASH_GROW_BUCKETS_REINSERTING 
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_PROMOTE 
WAIT_EVENT_REPLICATION_ORIGIN_DROP 
WAIT_EVENT_REPLICATION_SLOT_DROP 
WAIT_EVENT_SAFE_SNAPSHOT 
WAIT_EVENT_SYNC_REP 

Definition at line 818 of file pgstat.h.

819 {
857 } WaitEventIPC;
WaitEventIPC
Definition: pgstat.h:818
#define PG_WAIT_IPC
Definition: pgstat.h:760

◆ WaitEventTimeout

Enumerator
WAIT_EVENT_BASE_BACKUP_THROTTLE 
WAIT_EVENT_PG_SLEEP 
WAIT_EVENT_RECOVERY_APPLY_DELAY 

Definition at line 865 of file pgstat.h.

Function Documentation

◆ allow_immediate_pgstat_restart()

void allow_immediate_pgstat_restart ( void  )

Definition at line 791 of file pgstat.c.

References last_pgstat_start_time.

Referenced by HandleChildCrash().

792 {
794 }
static time_t last_pgstat_start_time
Definition: pgstat.c:153

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

Definition at line 2181 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().

2182 {
2183  PgStat_SubXactStatus *xact_state;
2184 
2185  /*
2186  * Transfer transactional insert/update counts into the next higher
2187  * subtransaction state.
2188  */
2189  xact_state = pgStatXactStack;
2190  if (xact_state != NULL &&
2191  xact_state->nest_level >= nestDepth)
2192  {
2194  PgStat_TableXactStatus *next_trans;
2195 
2196  /* delink xact_state from stack immediately to simplify reuse case */
2197  pgStatXactStack = xact_state->prev;
2198 
2199  for (trans = xact_state->first; trans != NULL; trans = next_trans)
2200  {
2201  PgStat_TableStatus *tabstat;
2202 
2203  next_trans = trans->next;
2204  Assert(trans->nest_level == nestDepth);
2205  tabstat = trans->parent;
2206  Assert(tabstat->trans == trans);
2207  if (isCommit)
2208  {
2209  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
2210  {
2211  if (trans->truncated)
2212  {
2213  /* propagate the truncate status one level up */
2215  /* replace upper xact stats with ours */
2216  trans->upper->tuples_inserted = trans->tuples_inserted;
2217  trans->upper->tuples_updated = trans->tuples_updated;
2218  trans->upper->tuples_deleted = trans->tuples_deleted;
2219  }
2220  else
2221  {
2222  trans->upper->tuples_inserted += trans->tuples_inserted;
2223  trans->upper->tuples_updated += trans->tuples_updated;
2224  trans->upper->tuples_deleted += trans->tuples_deleted;
2225  }
2226  tabstat->trans = trans->upper;
2227  pfree(trans);
2228  }
2229  else
2230  {
2231  /*
2232  * When there isn't an immediate parent state, we can just
2233  * reuse the record instead of going through a
2234  * palloc/pfree pushup (this works since it's all in
2235  * TopTransactionContext anyway). We have to re-link it
2236  * into the parent level, though, and that might mean
2237  * pushing a new entry into the pgStatXactStack.
2238  */
2239  PgStat_SubXactStatus *upper_xact_state;
2240 
2241  upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
2242  trans->next = upper_xact_state->first;
2243  upper_xact_state->first = trans;
2244  trans->nest_level = nestDepth - 1;
2245  }
2246  }
2247  else
2248  {
2249  /*
2250  * On abort, update top-level tabstat counts, then forget the
2251  * subtransaction
2252  */
2253 
2254  /* first restore values obliterated by truncate */
2256  /* count attempted actions regardless of commit/abort */
2257  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2258  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2259  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2260  /* inserted tuples are dead, deleted tuples are unaffected */
2261  tabstat->t_counts.t_delta_dead_tuples +=
2262  trans->tuples_inserted + trans->tuples_updated;
2263  tabstat->trans = trans->upper;
2264  pfree(trans);
2265  }
2266  }
2267  pfree(xact_state);
2268  }
2269 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
struct PgStat_TableXactStatus * next
Definition: pgstat.h:179
PgStat_TableCounts t_counts
Definition: pgstat.h:158
static PgStat_SubXactStatus * get_tabstat_stack_level(int nest_level)
Definition: pgstat.c:1899
void pfree(void *pointer)
Definition: mcxt.c:1056
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2035
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:215
#define Assert(condition)
Definition: c.h:732
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:219
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396
PgStat_TableXactStatus * first
Definition: pgstat.c:216
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2020
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
PgStat_TableStatus * parent
Definition: pgstat.h:177

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)

Definition at line 2094 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().

2095 {
2096  PgStat_SubXactStatus *xact_state;
2097 
2098  /* Don't count parallel worker transaction stats */
2099  if (!parallel)
2100  {
2101  /*
2102  * Count transaction commit or abort. (We use counters, not just
2103  * bools, in case the reporting message isn't sent right away.)
2104  */
2105  if (isCommit)
2106  pgStatXactCommit++;
2107  else
2109  }
2110 
2111  /*
2112  * Transfer transactional insert/update counts into the base tabstat
2113  * entries. We don't bother to free any of the transactional state, since
2114  * it's all in TopTransactionContext and will go away anyway.
2115  */
2116  xact_state = pgStatXactStack;
2117  if (xact_state != NULL)
2118  {
2120 
2121  Assert(xact_state->nest_level == 1);
2122  Assert(xact_state->prev == NULL);
2123  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2124  {
2125  PgStat_TableStatus *tabstat;
2126 
2127  Assert(trans->nest_level == 1);
2128  Assert(trans->upper == NULL);
2129  tabstat = trans->parent;
2130  Assert(tabstat->trans == trans);
2131  /* restore pre-truncate stats (if any) in case of aborted xact */
2132  if (!isCommit)
2134  /* count attempted actions regardless of commit/abort */
2135  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2136  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2137  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2138  if (isCommit)
2139  {
2140  tabstat->t_counts.t_truncated = trans->truncated;
2141  if (trans->truncated)
2142  {
2143  /* forget live/dead stats seen by backend thus far */
2144  tabstat->t_counts.t_delta_live_tuples = 0;
2145  tabstat->t_counts.t_delta_dead_tuples = 0;
2146  }
2147  /* insert adds a live tuple, delete removes one */
2148  tabstat->t_counts.t_delta_live_tuples +=
2149  trans->tuples_inserted - trans->tuples_deleted;
2150  /* update and delete each create a dead tuple */
2151  tabstat->t_counts.t_delta_dead_tuples +=
2152  trans->tuples_updated + trans->tuples_deleted;
2153  /* insert, update, delete each count as one change event */
2154  tabstat->t_counts.t_changed_tuples +=
2155  trans->tuples_inserted + trans->tuples_updated +
2156  trans->tuples_deleted;
2157  }
2158  else
2159  {
2160  /* inserted tuples are dead, deleted tuples are unaffected */
2161  tabstat->t_counts.t_delta_dead_tuples +=
2162  trans->tuples_inserted + trans->tuples_updated;
2163  /* an aborted xact generates no changed_tuple events */
2164  }
2165  tabstat->trans = NULL;
2166  }
2167  }
2168  pgStatXactStack = NULL;
2169 
2170  /* Make sure any stats snapshot is thrown away */
2172 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:110
PgStat_Counter tuples_updated
Definition: pgstat.h:168
static int pgStatXactCommit
Definition: pgstat.c:221
struct PgStat_TableXactStatus * next
Definition: pgstat.h:179
PgStat_TableCounts t_counts
Definition: pgstat.h:158
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2035
static int pgStatXactRollback
Definition: pgstat.c:222
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:215
PgStat_Counter t_changed_tuples
Definition: pgstat.h:112
#define Assert(condition)
Definition: c.h:732
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5796
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:219
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396
PgStat_TableXactStatus * first
Definition: pgstat.c:216
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
PgStat_TableStatus * parent
Definition: pgstat.h:177

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )

Definition at line 2280 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().

2281 {
2282  PgStat_SubXactStatus *xact_state;
2283 
2284  xact_state = pgStatXactStack;
2285  if (xact_state != NULL)
2286  {
2288 
2289  Assert(xact_state->nest_level == 1);
2290  Assert(xact_state->prev == NULL);
2291  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2292  {
2293  PgStat_TableStatus *tabstat;
2294  TwoPhasePgStatRecord record;
2295 
2296  Assert(trans->nest_level == 1);
2297  Assert(trans->upper == NULL);
2298  tabstat = trans->parent;
2299  Assert(tabstat->trans == trans);
2300 
2301  record.tuples_inserted = trans->tuples_inserted;
2302  record.tuples_updated = trans->tuples_updated;
2303  record.tuples_deleted = trans->tuples_deleted;
2304  record.inserted_pre_trunc = trans->inserted_pre_trunc;
2305  record.updated_pre_trunc = trans->updated_pre_trunc;
2306  record.deleted_pre_trunc = trans->deleted_pre_trunc;
2307  record.t_id = tabstat->t_id;
2308  record.t_shared = tabstat->t_shared;
2309  record.t_truncated = trans->truncated;
2310 
2312  &record, sizeof(TwoPhasePgStatRecord));
2313  }
2314  }
2315 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
struct PgStat_TableXactStatus * next
Definition: pgstat.h:179
PgStat_Counter deleted_pre_trunc
Definition: pgstat.h:173
PgStat_Counter deleted_pre_trunc
Definition: pgstat.c:234
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1204
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter updated_pre_trunc
Definition: pgstat.c:233
PgStat_Counter inserted_pre_trunc
Definition: pgstat.c:232
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter tuples_updated
Definition: pgstat.c:230
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:215
#define Assert(condition)
Definition: c.h:732
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:171
PgStat_Counter tuples_inserted
Definition: pgstat.c:229
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:219
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
PgStat_Counter tuples_deleted
Definition: pgstat.c:231
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:172
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396
PgStat_TableXactStatus * first
Definition: pgstat.c:216
PgStat_TableStatus * parent
Definition: pgstat.h:177

◆ BackendStatusShmemSize()

Size BackendStatusShmemSize ( void  )

Definition at line 2652 of file pgstat.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

2653 {
2654  Size size;
2655 
2656  /* BackendStatusArray: */
2657  size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
2658  /* BackendAppnameBuffer: */
2659  size = add_size(size,
2661  /* BackendClientHostnameBuffer: */
2662  size = add_size(size,
2664  /* BackendActivityBuffer: */
2665  size = add_size(size,
2667 #ifdef USE_SSL
2668  /* BackendSslStatusBuffer: */
2669  size = add_size(size,
2671 #endif
2672  return size;
2673 }
#define NumBackendStatSlots
Definition: pgstat.c:118
#define NAMEDATALEN
int pgstat_track_activity_query_size
Definition: pgstat.c:128
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:466

◆ CreateSharedBackendStatus()

void CreateSharedBackendStatus ( void  )

Definition at line 2680 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().

2681 {
2682  Size size;
2683  bool found;
2684  int i;
2685  char *buffer;
2686 
2687  /* Create or attach to the shared array */
2688  size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
2690  ShmemInitStruct("Backend Status Array", size, &found);
2691 
2692  if (!found)
2693  {
2694  /*
2695  * We're the first - initialize.
2696  */
2697  MemSet(BackendStatusArray, 0, size);
2698  }
2699 
2700  /* Create or attach to the shared appname buffer */
2702  BackendAppnameBuffer = (char *)
2703  ShmemInitStruct("Backend Application Name Buffer", size, &found);
2704 
2705  if (!found)
2706  {
2707  MemSet(BackendAppnameBuffer, 0, size);
2708 
2709  /* Initialize st_appname pointers. */
2710  buffer = BackendAppnameBuffer;
2711  for (i = 0; i < NumBackendStatSlots; i++)
2712  {
2713  BackendStatusArray[i].st_appname = buffer;
2714  buffer += NAMEDATALEN;
2715  }
2716  }
2717 
2718  /* Create or attach to the shared client hostname buffer */
2720  BackendClientHostnameBuffer = (char *)
2721  ShmemInitStruct("Backend Client Host Name Buffer", size, &found);
2722 
2723  if (!found)
2724  {
2726 
2727  /* Initialize st_clienthostname pointers. */
2728  buffer = BackendClientHostnameBuffer;
2729  for (i = 0; i < NumBackendStatSlots; i++)
2730  {
2732  buffer += NAMEDATALEN;
2733  }
2734  }
2735 
2736  /* Create or attach to the shared activity buffer */
2739  BackendActivityBuffer = (char *)
2740  ShmemInitStruct("Backend Activity Buffer",
2742  &found);
2743 
2744  if (!found)
2745  {
2747 
2748  /* Initialize st_activity pointers. */
2749  buffer = BackendActivityBuffer;
2750  for (i = 0; i < NumBackendStatSlots; i++)
2751  {
2754  }
2755  }
2756 
2757 #ifdef USE_SSL
2758  /* Create or attach to the shared SSL status buffer */
2760  BackendSslStatusBuffer = (PgBackendSSLStatus *)
2761  ShmemInitStruct("Backend SSL Status Buffer", size, &found);
2762 
2763  if (!found)
2764  {
2765  PgBackendSSLStatus *ptr;
2766 
2767  MemSet(BackendSslStatusBuffer, 0, size);
2768 
2769  /* Initialize st_sslstatus pointers. */
2770  ptr = BackendSslStatusBuffer;
2771  for (i = 0; i < NumBackendStatSlots; i++)
2772  {
2774  ptr++;
2775  }
2776  }
2777 #endif
2778 
2779 #ifdef ENABLE_GSS
2780  /* Create or attach to the shared GSSAPI status buffer */
2782  BackendGssStatusBuffer = (PgBackendGSSStatus *)
2783  ShmemInitStruct("Backend GSS Status Buffer", size, &found);
2784 
2785  if (!found)
2786  {
2787  PgBackendGSSStatus *ptr;
2788 
2789  MemSet(BackendGssStatusBuffer, 0, size);
2790 
2791  /* Initialize st_gssstatus pointers. */
2792  ptr = BackendGssStatusBuffer;
2793  for (i = 0; i < NumBackendStatSlots; i++)
2794  {
2796  ptr++;
2797  }
2798  }
2799 #endif
2800 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2634
static char * BackendActivityBuffer
Definition: pgstat.c:2638
static Size BackendActivityBufferSize
Definition: pgstat.c:2639
#define MemSet(start, val, len)
Definition: c.h:955
#define NumBackendStatSlots
Definition: pgstat.c:118
char * st_clienthostname
Definition: pgstat.h:1062
#define NAMEDATALEN
static char * BackendAppnameBuffer
Definition: pgstat.c:2636
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
char * st_activity_raw
Definition: pgstat.h:1085
int pgstat_track_activity_query_size
Definition: pgstat.c:128
char * st_appname
Definition: pgstat.h:1076
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
size_t Size
Definition: c.h:466
int i
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1066
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1070
static char * BackendClientHostnameBuffer
Definition: pgstat.c:2637

◆ find_funcstat_entry()

PgStat_BackendFunctionEntry* find_funcstat_entry ( Oid  func_id)

Definition at line 1674 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().

1675 {
1676  if (pgStatFunctions == NULL)
1677  return NULL;
1678 
1680  (void *) &func_id,
1681  HASH_FIND, NULL);
1682 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
static HTAB * pgStatFunctions
Definition: pgstat.c:197

◆ find_tabstat_entry()

PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

Definition at line 1879 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().

1880 {
1881  TabStatHashEntry *hash_entry;
1882 
1883  /* If hashtable doesn't exist, there are no entries at all */
1884  if (!pgStatTabHash)
1885  return NULL;
1886 
1887  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_FIND, NULL);
1888  if (!hash_entry)
1889  return NULL;
1890 
1891  /* Note that this step could also return NULL, but that's correct */
1892  return hash_entry->tsa_entry;
1893 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
static HTAB * pgStatTabHash
Definition: pgstat.c:191
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:185

◆ pgstat_bestart()

void pgstat_bestart ( void  )

Definition at line 2857 of file pgstat.c.

References am_walsender, application_name, Assert, B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_STARTUP, B_WAL_RECEIVER, B_WAL_SENDER, B_WAL_WRITER, 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(), BgWriterProcess, CheckpointerProcess, elog, FATAL, GetSessionUserId(), Port::gss, PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, InvalidBackendId, InvalidOid, IsAutoVacuumLauncherProcess(), IsAutoVacuumWorkerProcess(), IsBackgroundWorker, MemSet, MyAuxProcType, MyBackendId, MyBEEntry, MyDatabaseId, MyProcPid, MyProcPort, MyStartTimestamp, NAMEDATALEN, NotAnAuxProcess, 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, 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, StartupProcess, STATE_UNDEFINED, strlcpy(), unvolatize, WalReceiverProcess, and WalWriterProcess.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

2858 {
2859  volatile PgBackendStatus *vbeentry = MyBEEntry;
2860  PgBackendStatus lbeentry;
2861 #ifdef USE_SSL
2862  PgBackendSSLStatus lsslstatus;
2863 #endif
2864 #ifdef ENABLE_GSS
2865  PgBackendGSSStatus lgssstatus;
2866 #endif
2867 
2868  /* pgstats state must be initialized from pgstat_initialize() */
2869  Assert(vbeentry != NULL);
2870 
2871  /*
2872  * To minimize the time spent modifying the PgBackendStatus entry, and
2873  * avoid risk of errors inside the critical section, we first copy the
2874  * shared-memory struct to a local variable, then modify the data in the
2875  * local variable, then copy the local variable back to shared memory.
2876  * Only the last step has to be inside the critical section.
2877  *
2878  * Most of the data we copy from shared memory is just going to be
2879  * overwritten, but the struct's not so large that it's worth the
2880  * maintenance hassle to copy only the needful fields.
2881  */
2882  memcpy(&lbeentry,
2883  unvolatize(PgBackendStatus *, vbeentry),
2884  sizeof(PgBackendStatus));
2885 
2886  /* These structs can just start from zeroes each time, though */
2887 #ifdef USE_SSL
2888  memset(&lsslstatus, 0, sizeof(lsslstatus));
2889 #endif
2890 #ifdef ENABLE_GSS
2891  memset(&lgssstatus, 0, sizeof(lgssstatus));
2892 #endif
2893 
2894  /*
2895  * Now fill in all the fields of lbeentry, except for strings that are
2896  * out-of-line data. Those have to be handled separately, below.
2897  */
2898  lbeentry.st_procpid = MyProcPid;
2899 
2901  {
2903  {
2904  /* Autovacuum Launcher */
2906  }
2907  else if (IsAutoVacuumWorkerProcess())
2908  {
2909  /* Autovacuum Worker */
2910  lbeentry.st_backendType = B_AUTOVAC_WORKER;
2911  }
2912  else if (am_walsender)
2913  {
2914  /* Wal sender */
2915  lbeentry.st_backendType = B_WAL_SENDER;
2916  }
2917  else if (IsBackgroundWorker)
2918  {
2919  /* bgworker */
2920  lbeentry.st_backendType = B_BG_WORKER;
2921  }
2922  else
2923  {
2924  /* client-backend */
2925  lbeentry.st_backendType = B_BACKEND;
2926  }
2927  }
2928  else
2929  {
2930  /* Must be an auxiliary process */
2932  switch (MyAuxProcType)
2933  {
2934  case StartupProcess:
2935  lbeentry.st_backendType = B_STARTUP;
2936  break;
2937  case BgWriterProcess:
2938  lbeentry.st_backendType = B_BG_WRITER;
2939  break;
2940  case CheckpointerProcess:
2941  lbeentry.st_backendType = B_CHECKPOINTER;
2942  break;
2943  case WalWriterProcess:
2944  lbeentry.st_backendType = B_WAL_WRITER;
2945  break;
2946  case WalReceiverProcess:
2947  lbeentry.st_backendType = B_WAL_RECEIVER;
2948  break;
2949  default:
2950  elog(FATAL, "unrecognized process type: %d",
2951  (int) MyAuxProcType);
2952  }
2953  }
2954 
2956  lbeentry.st_activity_start_timestamp = 0;
2957  lbeentry.st_state_start_timestamp = 0;
2958  lbeentry.st_xact_start_timestamp = 0;
2959  lbeentry.st_databaseid = MyDatabaseId;
2960 
2961  /* We have userid for client-backends, wal-sender and bgworker processes */
2962  if (lbeentry.st_backendType == B_BACKEND
2963  || lbeentry.st_backendType == B_WAL_SENDER
2964  || lbeentry.st_backendType == B_BG_WORKER)
2965  lbeentry.st_userid = GetSessionUserId();
2966  else
2967  lbeentry.st_userid = InvalidOid;
2968 
2969  /*
2970  * We may not have a MyProcPort (eg, if this is the autovacuum process).
2971  * If so, use all-zeroes client address, which is dealt with specially in
2972  * pg_stat_get_backend_client_addr and pg_stat_get_backend_client_port.
2973  */
2974  if (MyProcPort)
2975  memcpy(&lbeentry.st_clientaddr, &MyProcPort->raddr,
2976  sizeof(lbeentry.st_clientaddr));
2977  else
2978  MemSet(&lbeentry.st_clientaddr, 0, sizeof(lbeentry.st_clientaddr));
2979 
2980 #ifdef USE_SSL
2981  if (MyProcPort && MyProcPort->ssl != NULL)
2982  {
2983  lbeentry.st_ssl = true;
2991  }
2992  else
2993  {
2994  lbeentry.st_ssl = false;
2995  }
2996 #else
2997  lbeentry.st_ssl = false;
2998 #endif
2999 
3000 #ifdef ENABLE_GSS
3001  if (MyProcPort && MyProcPort->gss != NULL)
3002  {
3003  lbeentry.st_gss = true;
3004  lgssstatus.gss_auth = be_gssapi_get_auth(MyProcPort);
3005  lgssstatus.gss_enc = be_gssapi_get_enc(MyProcPort);
3006 
3007  if (lgssstatus.gss_auth)
3009  }
3010  else
3011  {
3012  lbeentry.st_gss = false;
3013  }
3014 #else
3015  lbeentry.st_gss = false;
3016 #endif
3017 
3018  lbeentry.st_state = STATE_UNDEFINED;
3021 
3022  /*
3023  * we don't zero st_progress_param here to save cycles; nobody should
3024  * examine it until st_progress_command has been set to something other
3025  * than PROGRESS_COMMAND_INVALID
3026  */
3027 
3028  /*
3029  * We're ready to enter the critical section that fills the shared-memory
3030  * status entry. We follow the protocol of bumping st_changecount before
3031  * and after; and make sure it's even afterwards. We use a volatile
3032  * pointer here to ensure the compiler doesn't try to get cute.
3033  */
3034  PGSTAT_BEGIN_WRITE_ACTIVITY(vbeentry);
3035 
3036  /* make sure we'll memcpy the same st_changecount back */
3037  lbeentry.st_changecount = vbeentry->st_changecount;
3038 
3039  memcpy(unvolatize(PgBackendStatus *, vbeentry),
3040  &lbeentry,
3041  sizeof(PgBackendStatus));
3042 
3043  /*
3044  * We can write the out-of-line strings and structs using the pointers
3045  * that are in lbeentry; this saves some de-volatilizing messiness.
3046  */
3047  lbeentry.st_appname[0] = '\0';
3050  NAMEDATALEN);
3051  else
3052  lbeentry.st_clienthostname[0] = '\0';
3053  lbeentry.st_activity_raw[0] = '\0';
3054  /* Also make sure the last byte in each string area is always 0 */
3055  lbeentry.st_appname[NAMEDATALEN - 1] = '\0';
3056  lbeentry.st_clienthostname[NAMEDATALEN - 1] = '\0';
3058 
3059 #ifdef USE_SSL
3060  memcpy(lbeentry.st_sslstatus, &lsslstatus, sizeof(PgBackendSSLStatus));
3061 #endif
3062 #ifdef ENABLE_GSS
3063  memcpy(lbeentry.st_gssstatus, &lgssstatus, sizeof(PgBackendGSSStatus));
3064 #endif
3065 
3066  PGSTAT_END_WRITE_ACTIVITY(vbeentry);
3067 
3068  /* Update app name to current GUC setting */
3069  if (application_name)
3071 }
char ssl_issuer_dn[NAMEDATALEN]
Definition: pgstat.h:993
char gss_princ[NAMEDATALEN]
Definition: pgstat.h:1007
bool ssl_compression
Definition: pgstat.h:982
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:984
Oid st_progress_command_target
Definition: pgstat.h:1097
int MyProcPid
Definition: globals.c:40
BackendId MyBackendId
Definition: globals.c:81
struct Port * MyProcPort
Definition: globals.c:43
const char * be_gssapi_get_princ(Port *port)
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1055
char ssl_client_dn[NAMEDATALEN]
Definition: pgstat.h:985
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:983
SockAddr st_clientaddr
Definition: pgstat.h:1061
#define MemSet(start, val, len)
Definition: c.h:955
ProgressCommandType st_progress_command
Definition: pgstat.h:1096
char ssl_client_serial[NAMEDATALEN]
Definition: pgstat.h:991
BackendState st_state
Definition: pgstat.h:1073
char * st_clienthostname
Definition: pgstat.h:1062
Oid GetSessionUserId(void)
Definition: miscinit.c:414
bool IsBackgroundWorker
Definition: globals.c:111
Oid st_databaseid
Definition: pgstat.h:1059
#define NAMEDATALEN
char * remote_hostname
Definition: libpq-be.h:128
SockAddr raddr
Definition: libpq-be.h:126
bool am_walsender
Definition: walsender.c:114
bool be_tls_get_compression(Port *port)
#define FATAL
Definition: elog.h:52
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
char * st_activity_raw
Definition: pgstat.h:1085
int pgstat_track_activity_query_size
Definition: pgstat.c:128
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1056
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3278
char * st_appname
Definition: pgstat.h:1076
bool be_gssapi_get_enc(Port *port)
#define InvalidBackendId
Definition: backendid.h:23
TimestampTz MyStartTimestamp
Definition: globals.c:42
int be_tls_get_cipher_bits(Port *port)
AuxProcType MyAuxProcType
Definition: bootstrap.c:72
Oid MyDatabaseId
Definition: globals.c:85
BackendType st_backendType
Definition: pgstat.h:1050
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3294
#define InvalidOid
Definition: postgres_ext.h:36
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
bool IsAutoVacuumLauncherProcess(void)
Definition: autovacuum.c:3272
#define Assert(condition)
Definition: c.h:732
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:529
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:1165
void be_tls_get_peer_serial(Port *port, char *ptr, size_t len)
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1054
#define elog(elevel,...)
Definition: elog.h:226
int st_changecount
Definition: pgstat.h:1044
const char * be_tls_get_cipher(Port *port)
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1053
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1066
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1070
bool be_gssapi_get_auth(Port *port)

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 5796 of file pgstat.c.

References localNumBackends, and MemoryContextDelete().

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

5797 {
5798  /* Release memory, if any was allocated */
5799  if (pgStatLocalContext)
5801 
5802  /* Reset variables */
5803  pgStatLocalContext = NULL;
5804  pgStatDBHash = NULL;
5805  localBackendStatusTable = NULL;
5806  localNumBackends = 0;
5807 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:247
static HTAB * pgStatDBHash
Definition: pgstat.c:244
static int localNumBackends
Definition: pgstat.c:250
static MemoryContext pgStatLocalContext
Definition: pgstat.c:243

◆ pgstat_clip_activity()

char* pgstat_clip_activity ( const char *  raw_activity)

Definition at line 6544 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().

6545 {
6546  char *activity;
6547  int rawlen;
6548  int cliplen;
6549 
6550  /*
6551  * Some callers, like pgstat_get_backend_current_activity(), do not
6552  * guarantee that the buffer isn't concurrently modified. We try to take
6553  * care that the buffer is always terminated by a NUL byte regardless, but
6554  * let's still be paranoid about the string's length. In those cases the
6555  * underlying buffer is guaranteed to be pgstat_track_activity_query_size
6556  * large.
6557  */
6558  activity = pnstrdup(raw_activity, pgstat_track_activity_query_size - 1);
6559 
6560  /* now double-guaranteed to be NUL terminated */
6561  rawlen = strlen(activity);
6562 
6563  /*
6564  * All supported server-encodings make it possible to determine the length
6565  * of a multi-byte character from its first byte (this is not the case for
6566  * client encodings, see GB18030). As st_activity is always stored using
6567  * server encoding, this allows us to perform multi-byte aware truncation,
6568  * even if the string earlier was truncated in the middle of a multi-byte
6569  * character.
6570  */
6571  cliplen = pg_mbcliplen(activity, rawlen,
6573 
6574  activity[cliplen] = '\0';
6575 
6576  return activity;
6577 }
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1197
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:862
int pgstat_track_activity_query_size
Definition: pgstat.c:128
static int cliplen(const char *str, int len, int limit)
Definition: mbutils.c:929

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

Definition at line 1994 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().

1995 {
1996  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1997 
1998  if (pgstat_info != NULL)
1999  {
2000  /* We have to log the effect at the proper transactional level */
2001  int nest_level = GetCurrentTransactionNestLevel();
2002 
2003  if (pgstat_info->trans == NULL ||
2004  pgstat_info->trans->nest_level != nest_level)
2005  add_tabstat_xact_level(pgstat_info, nest_level);
2006 
2007  pgstat_info->trans->tuples_deleted++;
2008  }
2009 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:842
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:204
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1921
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 1948 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().

1949 {
1950  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1951 
1952  if (pgstat_info != NULL)
1953  {
1954  /* We have to log the effect at the proper transactional level */
1955  int nest_level = GetCurrentTransactionNestLevel();
1956 
1957  if (pgstat_info->trans == NULL ||
1958  pgstat_info->trans->nest_level != nest_level)
1959  add_tabstat_xact_level(pgstat_info, nest_level);
1960 
1961  pgstat_info->trans->tuples_inserted += n;
1962  }
1963 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:842
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:204
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1921
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

Definition at line 1969 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().

1970 {
1971  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1972 
1973  if (pgstat_info != NULL)
1974  {
1975  /* We have to log the effect at the proper transactional level */
1976  int nest_level = GetCurrentTransactionNestLevel();
1977 
1978  if (pgstat_info->trans == NULL ||
1979  pgstat_info->trans->nest_level != nest_level)
1980  add_tabstat_xact_level(pgstat_info, nest_level);
1981 
1982  pgstat_info->trans->tuples_updated++;
1983 
1984  /* t_tuples_hot_updated is nontransactional, so just advance it */
1985  if (hot)
1986  pgstat_info->t_counts.t_tuples_hot_updated++;
1987  }
1988 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:107
PgStat_TableCounts t_counts
Definition: pgstat.h:158
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:842
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:204
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1921
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

Definition at line 2049 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().

2050 {
2051  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2052 
2053  if (pgstat_info != NULL)
2054  {
2055  /* We have to log the effect at the proper transactional level */
2056  int nest_level = GetCurrentTransactionNestLevel();
2057 
2058  if (pgstat_info->trans == NULL ||
2059  pgstat_info->trans->nest_level != nest_level)
2060  add_tabstat_xact_level(pgstat_info, nest_level);
2061 
2062  pgstat_truncate_save_counters(pgstat_info->trans);
2063  pgstat_info->trans->tuples_inserted = 0;
2064  pgstat_info->trans->tuples_updated = 0;
2065  pgstat_info->trans->tuples_deleted = 0;
2066  }
2067 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:842
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:204
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1921
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2020

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)

Definition at line 1255 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().

1256 {
1257  PgStat_MsgDropdb msg;
1258 
1260  return;
1261 
1263  msg.m_databaseid = databaseid;
1264  pgstat_send(&msg, sizeof(msg));
1265 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
Oid m_databaseid
Definition: pgstat.h:306
PgStat_MsgHdr m_hdr
Definition: pgstat.h:305
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4328

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 1694 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().

1695 {
1696  PgStat_FunctionCounts *fs = fcu->fs;
1697  instr_time f_total;
1698  instr_time f_others;
1699  instr_time f_self;
1700 
1701  /* stats not wanted? */
1702  if (fs == NULL)
1703  return;
1704 
1705  /* total elapsed time in this function call */
1706  INSTR_TIME_SET_CURRENT(f_total);
1707  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
1708 
1709  /* self usage: elapsed minus anything already charged to other calls */
1710  f_others = total_func_time;
1711  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
1712  f_self = f_total;
1713  INSTR_TIME_SUBTRACT(f_self, f_others);
1714 
1715  /* update backend-wide total time */
1717 
1718  /*
1719  * Compute the new f_total_time as the total elapsed time added to the
1720  * pre-call value of f_total_time. This is necessary to avoid
1721  * double-counting any time taken by recursive calls of myself. (We do
1722  * not need any similar kluge for self time, since that already excludes
1723  * any recursive calls.)
1724  */
1725  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
1726 
1727  /* update counters in function stats table */
1728  if (finalize)
1729  fs->f_numcalls++;
1730  fs->f_total_time = f_total;
1731  INSTR_TIME_ADD(fs->f_self_time, f_self);
1732 
1733  /* indicate that we have something to send */
1734  have_function_stats = true;
1735 }
instr_time f_self_time
Definition: pgstat.h:463
instr_time save_total
Definition: pgstat.h:1201
struct timeval instr_time
Definition: instr_time.h:150
instr_time f_total_time
Definition: pgstat.h:462
PgStat_FunctionCounts * fs
Definition: pgstat.h:1197
PgStat_Counter f_numcalls
Definition: pgstat.h:461
#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:276
static bool have_function_stats
Definition: pgstat.c:203
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:1199

◆ pgstat_fetch_global()

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 2604 of file pgstat.c.

References archiverStats, and backend_read_statsfile().

Referenced by pg_stat_get_archiver().

2605 {
2607 
2608  return &archiverStats;
2609 }
static void backend_read_statsfile(void)
Definition: pgstat.c:5642
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:257

◆ pgstat_fetch_stat_beentry()

◆ pgstat_fetch_stat_dbentry()

PgStat_StatDBEntry* pgstat_fetch_stat_dbentry ( Oid  dbid)

Definition at line 2432 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().

2433 {
2434  /*
2435  * If not done for this transaction, read the statistics collector stats
2436  * file into some hash tables.
2437  */
2439 
2440  /*
2441  * Lookup the requested database; return NULL if not found
2442  */
2444  (void *) &dbid,
2445  HASH_FIND, NULL);
2446 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
static void backend_read_statsfile(void)
Definition: pgstat.c:5642
static HTAB * pgStatDBHash
Definition: pgstat.c:244

◆ pgstat_fetch_stat_funcentry()

PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  funcid)

Definition at line 2515 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().

2516 {
2517  PgStat_StatDBEntry *dbentry;
2518  PgStat_StatFuncEntry *funcentry = NULL;
2519 
2520  /* load the stats file if needed */
2522 
2523  /* Lookup our database, then find the requested function. */
2525  if (dbentry != NULL && dbentry->functions != NULL)
2526  {
2527  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
2528  (void *) &func_id,
2529  HASH_FIND, NULL);
2530  }
2531 
2532  return funcentry;
2533 }
HTAB * functions
Definition: pgstat.h:624
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
static void backend_read_statsfile(void)
Definition: pgstat.c:5642
Oid MyDatabaseId
Definition: globals.c:85

◆ pgstat_fetch_stat_local_beentry()

LocalPgBackendStatus* pgstat_fetch_stat_local_beentry ( int  beid)

Definition at line 2569 of file pgstat.c.

References localNumBackends, and pgstat_read_current_status().

Referenced by pg_stat_get_activity(), and pg_stat_get_progress_info().

2570 {
2572 
2573  if (beid < 1 || beid > localNumBackends)
2574  return NULL;
2575 
2576  return &localBackendStatusTable[beid - 1];
2577 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3350
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:247
static int localNumBackends
Definition: pgstat.c:250

◆ pgstat_fetch_stat_numbackends()

int pgstat_fetch_stat_numbackends ( void  )

Definition at line 2588 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().

2589 {
2591 
2592  return localNumBackends;
2593 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3350
static int localNumBackends
Definition: pgstat.c:250

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 2459 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_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().

2460 {
2461  Oid dbid;
2462  PgStat_StatDBEntry *dbentry;
2463  PgStat_StatTabEntry *tabentry;
2464 
2465  /*
2466  * If not done for this transaction, read the statistics collector stats
2467  * file into some hash tables.
2468  */
2470 
2471  /*
2472  * Lookup our database, then look in its table hash table.
2473  */
2474  dbid = MyDatabaseId;
2476  (void *) &dbid,
2477  HASH_FIND, NULL);
2478  if (dbentry != NULL && dbentry->tables != NULL)
2479  {
2480  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2481  (void *) &relid,
2482  HASH_FIND, NULL);
2483  if (tabentry)
2484  return tabentry;
2485  }
2486 
2487  /*
2488  * If we didn't find it, maybe it's a shared table.
2489  */
2490  dbid = InvalidOid;
2492  (void *) &dbid,
2493  HASH_FIND, NULL);
2494  if (dbentry != NULL && dbentry->tables != NULL)
2495  {
2496  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2497  (void *) &relid,
2498  HASH_FIND, NULL);
2499  if (tabentry)
2500  return tabentry;
2501  }
2502 
2503  return NULL;
2504 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
unsigned int Oid
Definition: postgres_ext.h:31
static void backend_read_statsfile(void)
Definition: pgstat.c:5642
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static HTAB * pgStatDBHash
Definition: pgstat.c:244

◆ pgstat_get_backend_current_activity()

const char* pgstat_get_backend_current_activity ( int  pid,
bool  checkUser 
)

Definition at line 4137 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().

4138 {
4139  PgBackendStatus *beentry;
4140  int i;
4141 
4142  beentry = BackendStatusArray;
4143  for (i = 1; i <= MaxBackends; i++)
4144  {
4145  /*
4146  * Although we expect the target backend's entry to be stable, that
4147  * doesn't imply that anyone else's is. To avoid identifying the
4148  * wrong backend, while we check for a match to the desired PID we
4149  * must follow the protocol of retrying if st_changecount changes
4150  * while we examine the entry, or if it's odd. (This might be
4151  * unnecessary, since fetching or storing an int is almost certainly
4152  * atomic, but let's play it safe.) We use a volatile pointer here to
4153  * ensure the compiler doesn't try to get cute.
4154  */
4155  volatile PgBackendStatus *vbeentry = beentry;
4156  bool found;
4157 
4158  for (;;)
4159  {
4160  int before_changecount;
4161  int after_changecount;
4162 
4163  pgstat_begin_read_activity(vbeentry, before_changecount);
4164 
4165  found = (vbeentry->st_procpid == pid);
4166 
4167  pgstat_end_read_activity(vbeentry, after_changecount);
4168 
4169  if (pgstat_read_activity_complete(before_changecount,
4170  after_changecount))
4171  break;
4172 
4173  /* Make sure we can break out of loop if stuck... */
4175  }
4176 
4177  if (found)
4178  {
4179  /* Now it is safe to use the non-volatile pointer */
4180  if (checkUser && !superuser() && beentry->st_userid != GetUserId())
4181  return "<insufficient privilege>";
4182  else if (*(beentry->st_activity_raw) == '\0')
4183  return "<command string not enabled>";
4184  else
4185  {
4186  /* this'll leak a bit of memory, but that seems acceptable */
4187  return pgstat_clip_activity(beentry->st_activity_raw);
4188  }
4189  }
4190 
4191  beentry++;
4192  }
4193 
4194  /* If we get here, caller is in error ... */
4195  return "<backend information not available>";
4196 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2634
Oid GetUserId(void)
Definition: miscinit.c:380
bool superuser(void)
Definition: superuser.c:47
int MaxBackends
Definition: globals.c:135
char * st_activity_raw
Definition: pgstat.h:1085
#define pgstat_end_read_activity(beentry, after_changecount)
Definition: pgstat.h:1151
#define pgstat_begin_read_activity(beentry, before_changecount)
Definition: pgstat.h:1145
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6544
int i
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define pgstat_read_activity_complete(before_changecount, after_changecount)
Definition: pgstat.h:1157

◆ pgstat_get_backend_desc()

const char* pgstat_get_backend_desc ( BackendType  backendType)

Definition at line 4274 of file pgstat.c.

References B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_STARTUP, B_WAL_RECEIVER, B_WAL_SENDER, and B_WAL_WRITER.

Referenced by AutoVacLauncherMain(), AutoVacWorkerMain(), AuxiliaryProcessMain(), BackendInitialize(), and pg_stat_get_activity().

4275 {
4276  const char *backendDesc = "unknown process type";
4277 
4278  switch (backendType)
4279  {
4280  case B_AUTOVAC_LAUNCHER:
4281  backendDesc = "autovacuum launcher";
4282  break;
4283  case B_AUTOVAC_WORKER:
4284  backendDesc = "autovacuum worker";
4285  break;
4286  case B_BACKEND:
4287  backendDesc = "client backend";
4288  break;
4289  case B_BG_WORKER:
4290  backendDesc = "background worker";
4291  break;
4292  case B_BG_WRITER:
4293  backendDesc = "background writer";
4294  break;
4295  case B_CHECKPOINTER:
4296  backendDesc = "checkpointer";
4297  break;
4298  case B_STARTUP:
4299  backendDesc = "startup";
4300  break;
4301  case B_WAL_RECEIVER:
4302  backendDesc = "walreceiver";
4303  break;
4304  case B_WAL_SENDER:
4305  backendDesc = "walsender";
4306  break;
4307  case B_WAL_WRITER:
4308  backendDesc = "walwriter";
4309  break;
4310  }
4311 
4312  return backendDesc;
4313 }

◆ pgstat_get_crashed_backend_activity()

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

Definition at line 4215 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().

4216 {
4217  volatile PgBackendStatus *beentry;
4218  int i;
4219 
4220  beentry = BackendStatusArray;
4221 
4222  /*
4223  * We probably shouldn't get here before shared memory has been set up,
4224  * but be safe.
4225  */
4226  if (beentry == NULL || BackendActivityBuffer == NULL)
4227  return NULL;
4228 
4229  for (i = 1; i <= MaxBackends; i++)
4230  {
4231  if (beentry->st_procpid == pid)
4232  {
4233  /* Read pointer just once, so it can't change after validation */
4234  const char *activity = beentry->st_activity_raw;
4235  const char *activity_last;
4236 
4237  /*
4238  * We mustn't access activity string before we verify that it
4239  * falls within the BackendActivityBuffer. To make sure that the
4240  * entire string including its ending is contained within the
4241  * buffer, subtract one activity length from the buffer size.
4242  */
4245 
4246  if (activity < BackendActivityBuffer ||
4247  activity > activity_last)
4248  return NULL;
4249 
4250  /* If no string available, no point in a report */
4251  if (activity[0] == '\0')
4252  return NULL;
4253 
4254  /*
4255  * Copy only ASCII-safe characters so we don't run into encoding
4256  * problems when reporting the message; and be sure not to run off
4257  * the end of memory. As only ASCII characters are reported, it
4258  * doesn't seem necessary to perform multibyte aware clipping.
4259  */
4260  ascii_safe_strlcpy(buffer, activity,
4261  Min(buflen, pgstat_track_activity_query_size));
4262 
4263  return buffer;
4264  }
4265 
4266  beentry++;
4267  }
4268 
4269  /* PID not found */
4270  return NULL;
4271 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2634
static char * BackendActivityBuffer
Definition: pgstat.c:2638
#define Min(x, y)
Definition: c.h:904
static Size BackendActivityBufferSize
Definition: pgstat.c:2639
void ascii_safe_strlcpy(char *dest, const char *src, size_t destsiz)
Definition: ascii.c:173
int MaxBackends
Definition: globals.c:135
char * st_activity_raw
Definition: pgstat.h:1085
int pgstat_track_activity_query_size
Definition: pgstat.c:128
int i

◆ pgstat_get_wait_event()

const char* pgstat_get_wait_event ( uint32  wait_event_info)

Definition at line 3557 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().

3558 {
3559  uint32 classId;
3560  uint16 eventId;
3561  const char *event_name;
3562 
3563  /* report process as not waiting. */
3564  if (wait_event_info == 0)
3565  return NULL;
3566 
3567  classId = wait_event_info & 0xFF000000;
3568  eventId = wait_event_info & 0x0000FFFF;
3569 
3570  switch (classId)
3571  {
3572  case PG_WAIT_LWLOCK:
3573  event_name = GetLWLockIdentifier(classId, eventId);
3574  break;
3575  case PG_WAIT_LOCK:
3576  event_name = GetLockNameFromTagType(eventId);
3577  break;
3578  case PG_WAIT_BUFFER_PIN:
3579  event_name = "BufferPin";
3580  break;
3581  case PG_WAIT_ACTIVITY:
3582  {
3583  WaitEventActivity w = (WaitEventActivity) wait_event_info;
3584 
3585  event_name = pgstat_get_wait_activity(w);
3586  break;
3587  }
3588  case PG_WAIT_CLIENT:
3589  {
3590  WaitEventClient w = (WaitEventClient) wait_event_info;
3591 
3592  event_name = pgstat_get_wait_client(w);
3593  break;
3594  }
3595  case PG_WAIT_EXTENSION:
3596  event_name = "Extension";
3597  break;
3598  case PG_WAIT_IPC:
3599  {
3600  WaitEventIPC w = (WaitEventIPC) wait_event_info;
3601 
3602  event_name = pgstat_get_wait_ipc(w);
3603  break;
3604  }
3605  case PG_WAIT_TIMEOUT:
3606  {
3607  WaitEventTimeout w = (WaitEventTimeout) wait_event_info;
3608 
3609  event_name = pgstat_get_wait_timeout(w);
3610  break;
3611  }
3612  case PG_WAIT_IO:
3613  {
3614  WaitEventIO w = (WaitEventIO) wait_event_info;
3615 
3616  event_name = pgstat_get_wait_io(w);
3617  break;
3618  }
3619  default:
3620  event_name = "unknown wait event";
3621  break;
3622  }
3623 
3624  return event_name;
3625 }
#define PG_WAIT_LOCK
Definition: pgstat.h:755
WaitEventIPC
Definition: pgstat.h:818
static const char * pgstat_get_wait_timeout(WaitEventTimeout w)
Definition: pgstat.c:3871
static const char * pgstat_get_wait_ipc(WaitEventIPC w)
Definition: pgstat.c:3741
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:757
#define PG_WAIT_IO
Definition: pgstat.h:762
static const char * pgstat_get_wait_activity(WaitEventActivity w)
Definition: pgstat.c:3634
unsigned short uint16
Definition: c.h:357
#define PG_WAIT_CLIENT
Definition: pgstat.h:758
WaitEventClient
Definition: pgstat.h:798
static const char * pgstat_get_wait_client(WaitEventClient w)
Definition: pgstat.c:3695
unsigned int uint32
Definition: c.h:358
WaitEventTimeout
Definition: pgstat.h:865
#define PG_WAIT_EXTENSION
Definition: pgstat.h:759
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:756
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1170
WaitEventIO
Definition: pgstat.h:878
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:761
#define PG_WAIT_IPC
Definition: pgstat.h:760
const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)
Definition: lwlock.c:714
static const char * pgstat_get_wait_io(WaitEventIO w)
Definition: pgstat.c:3899
#define PG_WAIT_LWLOCK
Definition: pgstat.h:754
WaitEventActivity
Definition: pgstat.h:772

◆ pgstat_get_wait_event_type()

const char* pgstat_get_wait_event_type ( uint32  wait_event_info)

Definition at line 3502 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().

3503 {
3504  uint32 classId;
3505  const char *event_type;
3506 
3507  /* report process as not waiting. */
3508  if (wait_event_info == 0)
3509  return NULL;
3510 
3511  classId = wait_event_info & 0xFF000000;
3512 
3513  switch (classId)
3514  {
3515  case PG_WAIT_LWLOCK:
3516  event_type = "LWLock";
3517  break;
3518  case PG_WAIT_LOCK:
3519  event_type = "Lock";
3520  break;
3521  case PG_WAIT_BUFFER_PIN:
3522  event_type = "BufferPin";
3523  break;
3524  case PG_WAIT_ACTIVITY:
3525  event_type = "Activity";
3526  break;
3527  case PG_WAIT_CLIENT:
3528  event_type = "Client";
3529  break;
3530  case PG_WAIT_EXTENSION:
3531  event_type = "Extension";
3532  break;
3533  case PG_WAIT_IPC:
3534  event_type = "IPC";
3535  break;
3536  case PG_WAIT_TIMEOUT:
3537  event_type = "Timeout";
3538  break;
3539  case PG_WAIT_IO:
3540  event_type = "IO";
3541  break;
3542  default:
3543  event_type = "???";
3544  break;
3545  }
3546 
3547  return event_type;
3548 }
#define PG_WAIT_LOCK
Definition: pgstat.h:755
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:757
#define PG_WAIT_IO
Definition: pgstat.h:762
#define PG_WAIT_CLIENT
Definition: pgstat.h:758
unsigned int uint32
Definition: c.h:358
#define PG_WAIT_EXTENSION
Definition: pgstat.h:759
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:756
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:761
#define PG_WAIT_IPC
Definition: pgstat.h:760
#define PG_WAIT_LWLOCK
Definition: pgstat.h:754

◆ pgstat_init()

void pgstat_init ( void  )

Definition at line 356 of file pgstat.c.

References addrinfo::ai_next, AI_PASSIVE, bind, closesocket, connect, EINTR, elog, 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, select, send, SetConfigOption(), socket, StaticAssertStmt, and TESTBYTEVAL.

Referenced by PostmasterMain().

357 {
358  ACCEPT_TYPE_ARG3 alen;
359  struct addrinfo *addrs = NULL,
360  *addr,
361  hints;
362  int ret;
363  fd_set rset;
364  struct timeval tv;
365  char test_byte;
366  int sel_res;
367  int tries = 0;
368 
369 #define TESTBYTEVAL ((char) 199)
370 
371  /*
372  * This static assertion verifies that we didn't mess up the calculations
373  * involved in selecting maximum payload sizes for our UDP messages.
374  * Because the only consequence of overrunning PGSTAT_MAX_MSG_SIZE would
375  * be silent performance loss from fragmentation, it seems worth having a
376  * compile-time cross-check that we didn't.
377  */
379  "maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE");
380 
381  /*
382  * Create the UDP socket for sending and receiving statistic messages
383  */
384  hints.ai_flags = AI_PASSIVE;
385  hints.ai_family = AF_UNSPEC;
386  hints.ai_socktype = SOCK_DGRAM;
387  hints.ai_protocol = 0;
388  hints.ai_addrlen = 0;
389  hints.ai_addr = NULL;
390  hints.ai_canonname = NULL;
391  hints.ai_next = NULL;
392  ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
393  if (ret || !addrs)
394  {
395  ereport(LOG,
396  (errmsg("could not resolve \"localhost\": %s",
397  gai_strerror(ret))));
398  goto startup_failed;
399  }
400 
401  /*
402  * On some platforms, pg_getaddrinfo_all() may return multiple addresses
403  * only one of which will actually work (eg, both IPv6 and IPv4 addresses
404  * when kernel will reject IPv6). Worse, the failure may occur at the
405  * bind() or perhaps even connect() stage. So we must loop through the
406  * results till we find a working combination. We will generate LOG
407  * messages, but no error, for bogus combinations.
408  */
409  for (addr = addrs; addr; addr = addr->ai_next)
410  {
411 #ifdef HAVE_UNIX_SOCKETS
412  /* Ignore AF_UNIX sockets, if any are returned. */
413  if (addr->ai_family == AF_UNIX)
414  continue;
415 #endif
416 
417  if (++tries > 1)
418  ereport(LOG,
419  (errmsg("trying another address for the statistics collector")));
420 
421  /*
422  * Create the socket.
423  */
424  if ((pgStatSock = socket(addr->ai_family, SOCK_DGRAM, 0)) == PGINVALID_SOCKET)
425  {
426  ereport(LOG,
428  errmsg("could not create socket for statistics collector: %m")));
429  continue;
430  }
431 
432  /*
433  * Bind it to a kernel assigned port on localhost and get the assigned
434  * port via getsockname().
435  */
436  if (bind(pgStatSock, addr->ai_addr, addr->ai_addrlen) < 0)
437  {
438  ereport(LOG,
440  errmsg("could not bind socket for statistics collector: %m")));
443  continue;
444  }
445 
446  alen = sizeof(pgStatAddr);
447  if (getsockname(pgStatSock, (struct sockaddr *) &pgStatAddr, &alen) < 0)
448  {
449  ereport(LOG,
451  errmsg("could not get address of socket for statistics collector: %m")));
454  continue;
455  }
456 
457  /*
458  * Connect the socket to its own address. This saves a few cycles by
459  * not having to respecify the target address on every send. This also
460  * provides a kernel-level check that only packets from this same
461  * address will be received.
462  */
463  if (connect(pgStatSock, (struct sockaddr *) &pgStatAddr, alen) < 0)
464  {
465  ereport(LOG,
467  errmsg("could not connect socket for statistics collector: %m")));
470  continue;
471  }
472 
473  /*
474  * Try to send and receive a one-byte test message on the socket. This
475  * is to catch situations where the socket can be created but will not
476  * actually pass data (for instance, because kernel packet filtering
477  * rules prevent it).
478  */
479  test_byte = TESTBYTEVAL;
480 
481 retry1:
482  if (send(pgStatSock, &test_byte, 1, 0) != 1)
483  {
484  if (errno == EINTR)
485  goto retry1; /* if interrupted, just retry */
486  ereport(LOG,
488  errmsg("could not send test message on socket for statistics collector: %m")));
491  continue;
492  }
493 
494  /*
495  * There could possibly be a little delay before the message can be
496  * received. We arbitrarily allow up to half a second before deciding
497  * it's broken.
498  */
499  for (;;) /* need a loop to handle EINTR */
500  {
501  FD_ZERO(&rset);
502  FD_SET(pgStatSock, &rset);
503 
504  tv.tv_sec = 0;
505  tv.tv_usec = 500000;
506  sel_res = select(pgStatSock + 1, &rset, NULL, NULL, &tv);
507  if (sel_res >= 0 || errno != EINTR)
508  break;
509  }
510  if (sel_res < 0)
511  {
512  ereport(LOG,
514  errmsg("select() failed in statistics collector: %m")));
517  continue;
518  }
519  if (sel_res == 0 || !FD_ISSET(pgStatSock, &rset))
520  {
521  /*
522  * This is the case we actually think is likely, so take pains to
523  * give a specific message for it.
524  *
525  * errno will not be set meaningfully here, so don't use it.
526  */
527  ereport(LOG,
528  (errcode(ERRCODE_CONNECTION_FAILURE),
529  errmsg("test message did not get through on socket for statistics collector")));
532  continue;
533  }
534 
535  test_byte++; /* just make sure variable is changed */
536 
537 retry2:
538  if (recv(pgStatSock, &test_byte, 1, 0) != 1)
539  {
540  if (errno == EINTR)
541  goto retry2; /* if interrupted, just retry */
542  ereport(LOG,
544  errmsg("could not receive test message on socket for statistics collector: %m")));
547  continue;
548  }
549 
550  if (test_byte != TESTBYTEVAL) /* strictly paranoia ... */
551  {
552  ereport(LOG,
553  (errcode(ERRCODE_INTERNAL_ERROR),
554  errmsg("incorrect test message transmission on socket for statistics collector")));
557  continue;
558  }
559 
560  /* If we get here, we have a working socket */
561  break;
562  }
563 
564  /* Did we find a working address? */
565  if (!addr || pgStatSock == PGINVALID_SOCKET)
566  goto startup_failed;
567 
568  /*
569  * Set the socket to non-blocking IO. This ensures that if the collector
570  * falls behind, statistics messages will be discarded; backends won't
571  * block waiting to send messages to the collector.
572  */
574  {
575  ereport(LOG,
577  errmsg("could not set statistics collector socket to nonblocking mode: %m")));
578  goto startup_failed;
579  }
580 
581  /*
582  * Try to ensure that the socket's receive buffer is at least
583  * PGSTAT_MIN_RCVBUF bytes, so that it won't easily overflow and lose
584  * data. Use of UDP protocol means that we are willing to lose data under
585  * heavy load, but we don't want it to happen just because of ridiculously
586  * small default buffer sizes (such as 8KB on older Windows versions).
587  */
588  {
589  int old_rcvbuf;
590  int new_rcvbuf;
591  ACCEPT_TYPE_ARG3 rcvbufsize = sizeof(old_rcvbuf);
592 
593  if (getsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
594  (char *) &old_rcvbuf, &rcvbufsize) < 0)
595  {
596  elog(LOG, "getsockopt(SO_RCVBUF) failed: %m");
597  /* if we can't get existing size, always try to set it */
598  old_rcvbuf = 0;
599  }
600 
601  new_rcvbuf = PGSTAT_MIN_RCVBUF;
602  if (old_rcvbuf < new_rcvbuf)
603  {
604  if (setsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
605  (char *) &new_rcvbuf, sizeof(new_rcvbuf)) < 0)
606  elog(LOG, "setsockopt(SO_RCVBUF) failed: %m");
607  }
608  }
609 
610  pg_freeaddrinfo_all(hints.ai_family, addrs);
611 
612  return;
613 
614 startup_failed:
615  ereport(LOG,
616  (errmsg("disabling statistics collector for lack of working socket")));
617 
618  if (addrs)
619  pg_freeaddrinfo_all(hints.ai_family, addrs);
620 
624 
625  /*
626  * Adjust GUC variables to suppress useless activity, and for debugging
627  * purposes (seeing track_counts off is a clue that we failed here). We
628  * use PGC_S_OVERRIDE because there is no point in trying to turn it back
629  * on from postgresql.conf without a restart.
630  */
631  SetConfigOption("track_counts", "off", PGC_INTERNAL, PGC_S_OVERRIDE);
632 }
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
Definition: ip.c:88
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
#define closesocket
Definition: port.h:312
int errcode(int sqlerrcode)
Definition: elog.c:570
#define connect(s, name, namelen)
Definition: win32_port.h:435
#define LOG
Definition: elog.h:26
#define bind(s, addr, addrlen)
Definition: win32_port.h:432
#define recv(s, buf, len, flags)
Definition: win32_port.h:437
#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:842
#define PGSTAT_MIN_RCVBUF
Definition: pgstat.c:97
#define TESTBYTEVAL
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7487
#define AI_PASSIVE
Definition: getaddrinfo.h:62
#define select(n, r, w, e, timeout)
Definition: win32_port.h:436
#define ereport(elevel, rest)
Definition: elog.h:141
int errcode_for_socket_access(void)
Definition: elog.c:664
#define socket(af, type, protocol)
Definition: win32_port.h:431
#define PGSTAT_MAX_MSG_SIZE
Definition: pgstat.h:206
#define PGINVALID_SOCKET
Definition: port.h:33
static struct sockaddr_storage pgStatAddr
Definition: pgstat.c:151
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:784
#define elog(elevel,...)
Definition: elog.h:226
#define EINTR
Definition: win32_port.h:323
#define send(s, buf, len, flags)
Definition: win32_port.h:438

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( struct FunctionCallInfoBaseData fcinfo,
PgStat_FunctionCallUsage fcu 
)

◆ pgstat_initialize()

void pgstat_initialize ( void  )

Definition at line 2815 of file pgstat.c.

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

Referenced by AuxiliaryProcessMain(), and InitPostgres().

2816 {
2817  /* Initialize MyBEEntry */
2819  {
2822  }
2823  else
2824  {
2825  /* Must be an auxiliary process */
2827 
2828  /*
2829  * Assign the MyBEEntry for an auxiliary process. Since it doesn't
2830  * have a BackendId, the slot is statically allocated based on the
2831  * auxiliary process type (MyAuxProcType). Backends use slots indexed
2832  * in the range from 1 to MaxBackends (inclusive), so we use
2833  * MaxBackends + AuxBackendType + 1 as the index of the slot for an
2834  * auxiliary process.
2835  */
2837  }
2838 
2839  /* Set up a process-exit hook to clean up */
2841 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2634
BackendId MyBackendId
Definition: globals.c:81
int MaxBackends
Definition: globals.c:135
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
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:3083
#define InvalidBackendId
Definition: backendid.h:23
AuxProcType MyAuxProcType
Definition: bootstrap.c:72
#define Assert(condition)
Definition: c.h:732

◆ pgstat_initstats()

void pgstat_initstats ( Relation  rel)

Definition at line 1751 of file pgstat.c.

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

Referenced by relation_open(), and try_relation_open().

1752 {
1753  Oid rel_id = rel->rd_id;
1754  char relkind = rel->rd_rel->relkind;
1755 
1756  /* We only count stats for things that have storage */
1757  if (!(relkind == RELKIND_RELATION ||
1758  relkind == RELKIND_MATVIEW ||
1759  relkind == RELKIND_INDEX ||
1760  relkind == RELKIND_TOASTVALUE ||
1761  relkind == RELKIND_SEQUENCE))
1762  {
1763  rel->pgstat_info = NULL;
1764  return;
1765  }
1766 
1768  {
1769  /* We're not counting at all */
1770  rel->pgstat_info = NULL;
1771  return;
1772  }
1773 
1774  /*
1775  * If we already set up this relation in the current transaction, nothing
1776  * to do.
1777  */
1778  if (rel->pgstat_info != NULL &&
1779  rel->pgstat_info->t_id == rel_id)
1780  return;
1781 
1782  /* Else find or make the PgStat_TableStatus entry, and update link */
1783  rel->pgstat_info = get_tabstat_entry(rel_id, rel->rd_rel->relisshared);
1784 }
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
Form_pg_class rd_rel
Definition: rel.h:83
unsigned int Oid
Definition: postgres_ext.h:31
char relkind
Definition: pg_class.h:81
bool pgstat_track_counts
Definition: pgstat.c:126
Oid rd_id
Definition: rel.h:85
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:1790
#define PGINVALID_SOCKET
Definition: port.h:33
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:204

◆ pgstat_ping()

void pgstat_ping ( void  )

Definition at line 1587 of file pgstat.c.

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

1588 {
1589  PgStat_MsgDummy msg;
1590 
1592  return;
1593 
1595  pgstat_send(&msg, sizeof(msg));
1596 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
#define PGINVALID_SOCKET
Definition: port.h:33
PgStat_MsgHdr m_hdr
Definition: pgstat.h:216
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4328

◆ pgstat_progress_end_command()

void pgstat_progress_end_command ( void  )

Definition at line 3271 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(), cluster_rel(), DefineIndex(), heap_vacuum_rel(), reindex_index(), and ReindexRelationConcurrently().

3272 {
3273  volatile PgBackendStatus *beentry = MyBEEntry;
3274 
3275  if (!beentry || !pgstat_track_activities)
3276  return;
3277 
3279  return;
3280 
3281  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3284  PGSTAT_END_WRITE_ACTIVITY(beentry);
3285 }
Oid st_progress_command_target
Definition: pgstat.h:1097
ProgressCommandType st_progress_command
Definition: pgstat.h:1096
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
#define InvalidOid
Definition: postgres_ext.h:36
bool pgstat_track_activities
Definition: pgstat.c:125
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130

◆ pgstat_progress_start_command()

void pgstat_progress_start_command ( ProgressCommandType  cmdtype,
Oid  relid 
)

Definition at line 3199 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 cluster_rel(), DefineIndex(), heap_vacuum_rel(), reindex_index(), and ReindexRelationConcurrently().

3200 {
3201  volatile PgBackendStatus *beentry = MyBEEntry;
3202 
3203  if (!beentry || !pgstat_track_activities)
3204  return;
3205 
3206  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3207  beentry->st_progress_command = cmdtype;
3208  beentry->st_progress_command_target = relid;
3209  MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
3210  PGSTAT_END_WRITE_ACTIVITY(beentry);
3211 }
Oid st_progress_command_target
Definition: pgstat.h:1097
#define MemSet(start, val, len)
Definition: c.h:955
ProgressCommandType st_progress_command
Definition: pgstat.h:1096
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1098
bool pgstat_track_activities
Definition: pgstat.c:125
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130

◆ pgstat_progress_update_multi_param()

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

Definition at line 3242 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(), heapam_relation_copy_for_cluster(), index_build(), lazy_scan_heap(), validate_index(), and WaitForLockersMultiple().

3244 {
3245  volatile PgBackendStatus *beentry = MyBEEntry;
3246  int i;
3247 
3248  if (!beentry || !pgstat_track_activities || nparam == 0)
3249  return;
3250 
3251  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3252 
3253  for (i = 0; i < nparam; ++i)
3254  {
3255  Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
3256 
3257  beentry->st_progress_param[index[i]] = val[i];
3258  }
3259 
3260  PGSTAT_END_WRITE_ACTIVITY(beentry);
3261 }
Definition: type.h:89
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:962
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
#define Assert(condition)
Definition: c.h:732
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1098
bool pgstat_track_activities
Definition: pgstat.c:125
int i
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130
long val
Definition: informix.c:684

◆ pgstat_progress_update_param()

void pgstat_progress_update_param ( int  index,
int64  val 
)

Definition at line 3220 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(), btvacuumscan(), cluster_rel(), DefineIndex(), finish_heap_swap(), hashbuild(), heap_vacuum_rel(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), lazy_record_dead_tuple(), lazy_scan_heap(), lazy_truncate_heap(), lazy_vacuum_page(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), validate_index(), WaitForLockersMultiple(), and WaitForOlderSnapshots().

3221 {
3222  volatile PgBackendStatus *beentry = MyBEEntry;
3223 
3225 
3226  if (!beentry || !pgstat_track_activities)
3227  return;
3228 
3229  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3230  beentry->st_progress_param[index] = val;
3231  PGSTAT_END_WRITE_ACTIVITY(beentry);
3232 }
Definition: type.h:89
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:962
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
#define Assert(condition)
Definition: c.h:732
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1098
bool pgstat_track_activities
Definition: pgstat.c:125
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130
long val
Definition: informix.c:684

◆ pgstat_report_activity()

void pgstat_report_activity ( BackendState  state,
const char *  cmd_str 
)

Definition at line 3121 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(), 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(), ParallelQueryMain(), and PostgresMain().

3122 {
3123  volatile PgBackendStatus *beentry = MyBEEntry;
3124  TimestampTz start_timestamp;
3125  TimestampTz current_timestamp;
3126  int len = 0;
3127 
3128  TRACE_POSTGRESQL_STATEMENT_STATUS(cmd_str);
3129 
3130  if (!beentry)
3131  return;
3132 
3134  {
3135  if (beentry->st_state != STATE_DISABLED)
3136  {
3137  volatile PGPROC *proc = MyProc;
3138 
3139  /*
3140  * track_activities is disabled, but we last reported a
3141  * non-disabled state. As our final update, change the state and
3142  * clear fields we will not be updating anymore.
3143  */
3144  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3145  beentry->st_state = STATE_DISABLED;
3146  beentry->st_state_start_timestamp = 0;
3147  beentry->st_activity_raw[0] = '\0';
3148  beentry->st_activity_start_timestamp = 0;
3149  /* st_xact_start_timestamp and wait_event_info are also disabled */
3150  beentry->st_xact_start_timestamp = 0;
3151  proc->wait_event_info = 0;
3152  PGSTAT_END_WRITE_ACTIVITY(beentry);
3153  }
3154  return;
3155  }
3156 
3157  /*
3158  * To minimize the time spent modifying the entry, and avoid risk of
3159  * errors inside the critical section, fetch all the needed data first.
3160  */
3161  start_timestamp = GetCurrentStatementStartTimestamp();
3162  if (cmd_str != NULL)
3163  {
3164  /*
3165  * Compute length of to-be-stored string unaware of multi-byte
3166  * characters. For speed reasons that'll get corrected on read, rather
3167  * than computed every write.
3168  */
3169  len = Min(strlen(cmd_str), pgstat_track_activity_query_size - 1);
3170  }
3171  current_timestamp = GetCurrentTimestamp();
3172 
3173  /*
3174  * Now update the status entry
3175  */
3176  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3177 
3178  beentry->st_state = state;
3179  beentry->st_state_start_timestamp = current_timestamp;
3180 
3181  if (cmd_str != NULL)
3182  {
3183  memcpy((char *) beentry->st_activity_raw, cmd_str, len);
3184  beentry->st_activity_raw[len] = '\0';
3185  beentry->st_activity_start_timestamp = start_timestamp;
3186  }
3187 
3188  PGSTAT_END_WRITE_ACTIVITY(beentry);
3189 }
uint32 wait_event_info
Definition: proc.h:176
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1055
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
PGPROC * MyProc
Definition: proc.c:68
int64 TimestampTz
Definition: timestamp.h:39
#define Min(x, y)
Definition: c.h:904
BackendState st_state
Definition: pgstat.h:1073
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
char * st_activity_raw
Definition: pgstat.h:1085
int pgstat_track_activity_query_size
Definition: pgstat.c:128
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1056
Definition: regguts.h:298
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1054
bool pgstat_track_activities
Definition: pgstat.c:125
Definition: proc.h:95
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:792

◆ pgstat_report_analyze()

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

Definition at line 1438 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().

1441 {
1442  PgStat_MsgAnalyze msg;
1443 
1445  return;
1446 
1447  /*
1448  * Unlike VACUUM, ANALYZE might be running inside a transaction that has
1449  * already inserted and/or deleted rows in the target table. ANALYZE will
1450  * have counted such rows as live or dead respectively. Because we will
1451  * report our counts of such rows at transaction end, we should subtract
1452  * off these counts from what we send to the collector now, else they'll
1453  * be double-counted after commit. (This approach also ensures that the
1454  * collector ends up with the right numbers if we abort instead of
1455  * committing.)
1456  */
1457  if (rel->pgstat_info != NULL)
1458  {
1460 
1461  for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
1462  {
1463  livetuples -= trans->tuples_inserted - trans->tuples_deleted;
1464  deadtuples -= trans->tuples_updated + trans->tuples_deleted;
1465  }
1466  /* count stuff inserted by already-aborted subxacts, too */
1467  deadtuples -= rel->pgstat_info->t_counts.t_delta_dead_tuples;
1468  /* Since ANALYZE's counts are estimates, we could have underflowed */
1469  livetuples = Max(livetuples, 0);
1470  deadtuples = Max(deadtuples, 0);
1471  }
1472 
1474  msg.m_databaseid = rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId;
1475  msg.m_tableoid = RelationGetRelid(rel);
1477  msg.m_resetcounter = resetcounter;
1479  msg.m_live_tuples = livetuples;
1480  msg.m_dead_tuples = deadtuples;
1481  pgstat_send(&msg, sizeof(msg));
1482 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
PgStat_Counter tuples_updated
Definition: pgstat.h:168
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
TimestampTz m_analyzetime
Definition: pgstat.h:387
PgStat_TableCounts t_counts
Definition: pgstat.h:158
Form_pg_class rd_rel
Definition: rel.h:83
bool m_resetcounter
Definition: pgstat.h:386
bool pgstat_track_counts
Definition: pgstat.c:126
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3278
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter m_live_tuples
Definition: pgstat.h:388
bool m_autovacuum
Definition: pgstat.h:385
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
#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:898
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4328
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:204
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
PgStat_MsgHdr m_hdr
Definition: pgstat.h:382
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396
PgStat_Counter m_dead_tuples
Definition: pgstat.h:389
#define RelationGetRelid(relation)
Definition: rel.h:419

◆ pgstat_report_appname()

void pgstat_report_appname ( const char *  appname)

Definition at line 3294 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().

3295 {
3296  volatile PgBackendStatus *beentry = MyBEEntry;
3297  int len;
3298 
3299  if (!beentry)
3300  return;
3301 
3302  /* This should be unnecessary if GUC did its job, but be safe */
3303  len = pg_mbcliplen(appname, strlen(appname), NAMEDATALEN - 1);
3304 
3305  /*
3306  * Update my status entry, following the protocol of bumping
3307  * st_changecount before and after. We use a volatile pointer here to
3308  * ensure the compiler doesn't try to get cute.
3309  */
3310  PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
3311 
3312  memcpy((char *) beentry->st_appname, appname, len);
3313  beentry->st_appname[len] = '\0';
3314 
3315  PGSTAT_END_WRITE_ACTIVITY(beentry);
3316 }
#define NAMEDATALEN
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:862
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2635
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1137
char * st_appname
Definition: pgstat.h:1076
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
Definition: pgstat.h:1130

◆ pgstat_report_autovac()

void pgstat_report_autovac ( Oid  dboid)

Definition at line 1388 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().

1389 {
1391 
1393  return;
1394 
1396  msg.m_databaseid = dboid;
1398 
1399  pgstat_send(&msg, sizeof(msg));
1400 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
PgStat_MsgHdr m_hdr
Definition: pgstat.h:352
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4328
TimestampTz m_start_time
Definition: pgstat.h:354

◆ pgstat_report_checksum_failure()

void pgstat_report_checksum_failure ( void  )

Definition at line 1554 of file pgstat.c.

References MyDatabaseId, and pgstat_report_checksum_failures_in_db().

Referenced by PageIsVerified().

1555 {
1557 }
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
Definition: pgstat.c:1532
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 1532 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().

1533 {
1535 
1537  return;
1538 
1540  msg.m_databaseid = dboid;
1541  msg.m_failurecount = failurecount;
1543 
1544  pgstat_send(&msg, sizeof(msg));
1545 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
PgStat_MsgHdr m_hdr
Definition: pgstat.h:540
bool pgstat_track_counts
Definition: pgstat.c:126
TimestampTz m_failure_time
Definition: pgstat.h:543
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4328

◆ pgstat_report_deadlock()

void pgstat_report_deadlock ( void  )

Definition at line 1511 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().

1512 {
1513  PgStat_MsgDeadlock msg;
1514 
1516  return;
1517 
1519  msg.m_databaseid = MyDatabaseId;
1520  pgstat_send(&msg, sizeof(msg));
1521 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
bool pgstat_track_counts
Definition: pgstat.c:126
PgStat_MsgHdr m_hdr
Definition: pgstat.h:529
#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:4328

◆ pgstat_report_recovery_conflict()

void pgstat_report_recovery_conflict ( int  reason)

Definition at line 1491 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().

1492 {
1494 
1496  return;
1497 
1499  msg.m_databaseid = MyDatabaseId;
1500  msg.m_reason = reason;
1501  pgstat_send(&msg, sizeof(msg));
1502 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
bool pgstat_track_counts
Definition: pgstat.c:126
PgStat_MsgHdr m_hdr
Definition: pgstat.h:431
#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:4328

◆ pgstat_report_stat()

void pgstat_report_stat ( bool  force)

Definition at line 813 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_tabstat(), 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(), initialize_worker_spi(), LogicalRepSyncTableStart(), pg_attribute_noreturn(), pgstat_beshutdown_hook(), PostgresMain(), and process_syncing_tables_for_apply().

814 {
815  /* we assume this inits to all zeroes: */
816  static const PgStat_TableCounts all_zeroes;
817  static TimestampTz last_report = 0;
818 
820  PgStat_MsgTabstat regular_msg;
821  PgStat_MsgTabstat shared_msg;
822  TabStatusArray *tsa;
823  int i;
824 
825  /* Don't expend a clock check if nothing to do */
826  if ((pgStatTabList == NULL || pgStatTabList->tsa_used == 0) &&
827  pgStatXactCommit == 0 && pgStatXactRollback == 0 &&
829  return;
830 
831  /*
832  * Don't send a message unless it's been at least PGSTAT_STAT_INTERVAL
833  * msec since we last sent one, or the caller wants to force stats out.
834  */
836  if (!force &&
838  return;
839  last_report = now;
840 
841  /*
842  * Destroy pgStatTabHash before we start invalidating PgStat_TableEntry
843  * entries it points to. (Should we fail partway through the loop below,
844  * it's okay to have removed the hashtable already --- the only
845  * consequence is we'd get multiple entries for the same table in the
846  * pgStatTabList, and that's safe.)
847  */
848  if (pgStatTabHash)
850  pgStatTabHash = NULL;
851 
852  /*
853  * Scan through the TabStatusArray struct(s) to find tables that actually
854  * have counts, and build messages to send. We have to separate shared
855  * relations from regular ones because the databaseid field in the message
856  * header has to depend on that.
857  */
858  regular_msg.m_databaseid = MyDatabaseId;
859  shared_msg.m_databaseid = InvalidOid;
860  regular_msg.m_nentries = 0;
861  shared_msg.m_nentries = 0;
862 
863  for (tsa = pgStatTabList; tsa != NULL; tsa = tsa->tsa_next)
864  {
865  for (i = 0; i < tsa->tsa_used; i++)
866  {
867  PgStat_TableStatus *entry = &tsa->tsa_entries[i];
868  PgStat_MsgTabstat *this_msg;
869  PgStat_TableEntry *this_ent;
870 
871  /* Shouldn't have any pending transaction-dependent counts */
872  Assert(entry->trans == NULL);
873 
874  /*
875  * Ignore entries that didn't accumulate any actual counts, such
876  * as indexes that were opened by the planner but not used.
877  */
878  if (memcmp(&entry->t_counts, &all_zeroes,
879  sizeof(PgStat_TableCounts)) == 0)
880  continue;
881 
882  /*
883  * OK, insert data into the appropriate message, and send if full.
884  */
885  this_msg = entry->t_shared ? &shared_msg : &regular_msg;
886  this_ent = &this_msg->m_entry[this_msg->m_nentries];
887  this_ent->t_id = entry->t_id;
888  memcpy(&this_ent->t_counts, &entry->t_counts,
889  sizeof(PgStat_TableCounts));
890  if (++this_msg->m_nentries >= PGSTAT_NUM_TABENTRIES)
891  {
892  pgstat_send_tabstat(this_msg);
893  this_msg->m_nentries = 0;
894  }
895  }
896  /* zero out PgStat_TableStatus structs after use */
897  MemSet(tsa->tsa_entries, 0,
898  tsa->tsa_used * sizeof(PgStat_TableStatus));
899  tsa->tsa_used = 0;
900  }
901 
902  /*
903  * Send partial messages. Make sure that any pending xact commit/abort
904  * gets counted, even if there are no table stats to send.
905  */
906  if (regular_msg.m_nentries > 0 ||
908  pgstat_send_tabstat(&regular_msg);
909  if (shared_msg.m_nentries > 0)
910  pgstat_send_tabstat(&shared_msg);
911 
912  /* Now, send function statistics */
914 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:814
int tsa_used
Definition: pgstat.c:173
static int pgStatXactCommit
Definition: pgstat.c:221
int64 TimestampTz
Definition: timestamp.h:39
#define MemSet(start, val, len)
Definition: c.h:955
struct TabStatusArray * tsa_next
Definition: pgstat.c:172
PgStat_TableCounts t_counts
Definition: pgstat.h:158
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1682
static void pgstat_send_tabstat(PgStat_MsgTabstat *tsmsg)
Definition: pgstat.c:920
static HTAB * pgStatTabHash
Definition: pgstat.c:191
static int pgStatXactRollback
Definition: pgstat.c:222
#define PGSTAT_STAT_INTERVAL
Definition: pgstat.c:77
PgStat_TableStatus tsa_entries[TABSTAT_QUANTUM]
Definition: pgstat.c:174
#define PGSTAT_NUM_TABENTRIES
Definition: pgstat.h:263
Oid MyDatabaseId
Definition: globals.c:85
static TabStatusArray * pgStatTabList
Definition: pgstat.c:177
#define InvalidOid
Definition: postgres_ext.h:36
static bool have_function_stats
Definition: pgstat.c:203
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition: xact.c:804
#define Assert(condition)
Definition: c.h:732
PgStat_TableCounts t_counts
Definition: pgstat.h:255
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES]
Definition: pgstat.h:276
int i
static void pgstat_send_funcstats(void)
Definition: pgstat.c:964
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1547

◆ pgstat_report_tempfile()

void pgstat_report_tempfile ( size_t  filesize)

Definition at line 1566 of file pgstat.c.

References PgStat_MsgTempFile::m_databaseid, PgStat_MsgTempFile::m_filesize, PgStat_MsgTempFile::m_hdr, MyDatabaseId, PGINVALID_SOCKET, PGSTAT_MTYPE_TEMPFILE, pgstat_send(), pgstat_setheader(), pgstat_track_counts, and pgStatSock.

Referenced by ReportTemporaryFileUsage().

1567 {
1568  PgStat_MsgTempFile msg;
1569 
1571  return;
1572 
1574  msg.m_databaseid = MyDatabaseId;
1575  msg.m_filesize = filesize;
1576  pgstat_send(&msg, sizeof(msg));
1577 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
PgStat_MsgHdr m_hdr
Definition: pgstat.h:443
size_t m_filesize
Definition: pgstat.h:446
bool pgstat_track_counts
Definition: pgstat.c:126
#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:4328

◆ pgstat_report_vacuum()

void pgstat_report_vacuum ( Oid  tableoid,
bool  shared,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples 
)

Definition at line 1410 of file pgstat.c.

References GetCurrentTimestamp(), InvalidOid, IsAutoVacuumWorkerProcess(), PgStat_MsgVacuum::m_autovacuum, PgStat_MsgVacuum::m_databaseid, PgStat_MsgVacuum::m_dead_tuples, PgStat_MsgVacuum::m_hdr, PgStat_MsgVacuum::m_live_tuples, PgStat_MsgVacuum::m_tableoid, PgStat_MsgVacuum::m_vacuumtime, MyDatabaseId, PGINVALID_SOCKET, PGSTAT_MTYPE_VACUUM, pgstat_send(), pgstat_setheader(), pgstat_track_counts, and pgStatSock.

Referenced by heap_vacuum_rel().

1412 {
1413  PgStat_MsgVacuum msg;
1414 
1416  return;
1417 
1419  msg.m_databaseid = shared ? InvalidOid : MyDatabaseId;
1420  msg.m_tableoid = tableoid;
1423  msg.m_live_tuples = livetuples;
1424  msg.m_dead_tuples = deadtuples;
1425  pgstat_send(&msg, sizeof(msg));
1426 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4341
PgStat_Counter m_dead_tuples
Definition: pgstat.h:371
TimestampTz m_vacuumtime
Definition: pgstat.h:369
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:149
PgStat_Counter m_live_tuples
Definition: pgstat.h:370
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
Oid m_databaseid
Definition: pgstat.h:366
bool m_autovacuum
Definition: pgstat.h:368
bool pgstat_track_counts
Definition: pgstat.c:126
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3278
#define PGINVALID_SOCKET
Definition: port.h:33
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:4328
PgStat_MsgHdr m_hdr
Definition: pgstat.h:365

◆ pgstat_report_wait_end()

static void pgstat_report_wait_end ( void  )
inlinestatic

Definition at line 1342 of file pgstat.h.

References MyProc, pgstat_track_activities, and PGPROC::wait_event_info.

Referenced by AbortSubTransaction(), AbortTransaction(), AddToDataDirLockFile(), ApplyLogicalMappingFile(), assign_xlog_sync_method(), AutoVacLauncherMain(), BackgroundWriterMain(), BootStrapXLOG(), CheckpointerMain(), CheckPointLogicalRewriteHeap(), copy_file(), CreateLockFile(), dsm_impl_mmap(), FilePrefetch(), FileRead(), FileSync(), FileTruncate(), FileWrite(), FileWriteback(), heap_xlog_logical_rewrite(), issue_xlog_fsync(), load_relmap_file(), LWLockReportWaitEnd(), ProcArrayGroupClearXid(), ReadControlFile(), ReadTwoPhaseFile(), RecheckDataDirLockFile(), RecreateTwoPhaseFile(), ReorderBufferRestoreChanges(), ReorderBufferSerializeChange(), RestoreSlotFromDisk(), SaveSlotToPath(), SendTimeLineHistory(), ShutdownAuxiliaryProcess(), SimpleLruFlush(), SlruPhysicalReadPage(), SlruPhysicalWritePage(), SnapBuildRestore(), SnapBuildSerialize(), TransactionGroupUpdateXidStatus(), update_controlfile(), WaitEventSetWait(), WalSndErrorCleanup(), WalWriterMain(), write_relmap_file(), WriteControlFile(), writeTimeLineHistory(), writeTimeLineHistoryFile(), XLogFileCopy(), XLogFileInit(), XLogPageRead(), XLogRead(), and XLogWrite().

1343 {
1344  volatile PGPROC *proc = MyProc;
1345 
1346  if (!pgstat_track_activities || !proc)
1347  return;
1348 
1349  /*
1350  * Since this is a four-byte field which is always read and written as
1351  * four-bytes, updates are atomic.
1352  */
1353  proc->wait_event_info = 0;
1354 }
uint32 wait_event_info
Definition: proc.h:176
PGPROC * MyProc
Definition: proc.c:68
bool pgstat_track_activities
Definition: pgstat.c:125
Definition: proc.h:95

◆ pgstat_report_wait_start()

static void pgstat_report_wait_start ( uint32  wait_event_info)
inlinestatic

Definition at line 1318 of file pgstat.h.

References MyProc, pgstat_track_activities, and PGPROC::wait_event_info.

Referenced by AddToDataDirLockFile(), ApplyLogicalMappingFile(), assign_xlog_sync_method(), BootStrapXLOG(), CheckPointLogicalRewriteHeap(), copy_file(), CreateLockFile(), dsm_impl_mmap(), FilePrefetch(), FileRead(), FileSync(), FileTruncate(), FileWrite(), FileWriteback(), heap_xlog_logical_rewrite(), issue_xlog_fsync(), load_relmap_file(), LWLockReportWaitStart(), ProcArrayGroupClearXid(), ReadControlFile(), ReadTwoPhaseFile(), RecheckDataDirLockFile(), RecreateTwoPhaseFile(), ReorderBufferRestoreChanges(), ReorderBufferSerializeChange(), RestoreSlotFromDisk(), SaveSlotToPath(), SendTimeLineHistory(), SimpleLruFlush(), SlruPhysicalReadPage(), SlruPhysicalWritePage(), SnapBuildRestore(), SnapBuildSerialize(), TransactionGroupUpdateXidStatus(), update_controlfile(), WaitEventSetWait(), write_relmap_file(), WriteControlFile(), writeTimeLineHistory(), writeTimeLineHistoryFile(), XLogFileCopy(), XLogFileInit(), XLogPageRead(), XLogRead(), and XLogWrite().

1319 {
1320  volatile PGPROC *proc = MyProc;
1321 
1322  if (!pgstat_track_activities || !proc)
1323  return;
1324 
1325  /*
1326  * Since this is a four-byte field which is always read and written as
1327  * four-bytes, updates are atomic.
1328  */
1329  proc->wait_event_info = wait_event_info;
1330 }
uint32 wait_event_info
Definition: proc.h:176
PGPROC * MyProc
Definition: proc.c:68
bool pgstat_track_activities