PostgreSQL Source Code  git master
pgstat.h File Reference
#include "datatype/timestamp.h"
#include "fmgr.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
 
union  PgStat_Msg
 
struct  PgStat_StatDBEntry
 
struct  PgStat_StatTabEntry
 
struct  PgStat_StatFuncEntry
 
struct  PgStat_ArchiverStats
 
struct  PgStat_GlobalStats
 
struct  PgBackendSSLStatus
 
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   10
 
#define pgstat_increment_changecount_before(beentry)
 
#define pgstat_increment_changecount_after(beentry)
 
#define pgstat_save_changecount_before(beentry, save_changecount)
 
#define pgstat_save_changecount_after(beentry, save_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 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 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
}
 
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
}
 
enum  WaitEventIPC {
  WAIT_EVENT_BGWORKER_SHUTDOWN = PG_WAIT_IPC, WAIT_EVENT_BGWORKER_STARTUP, WAIT_EVENT_BTREE_PAGE, WAIT_EVENT_CLOG_GROUP_UPDATE,
  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 }
 

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_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 (FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
 
void pgstat_end_function_usage (PgStat_FunctionCallUsage *fcu, bool finalize)
 
void AtEOXact_PgStat (bool isCommit)
 
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 34 of file pgstat.h.

◆ PG_WAIT_ACTIVITY

#define PG_WAIT_ACTIVITY   0x05000000U

Definition at line 740 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 741 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 745 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 743 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 744 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

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

Referenced by ReadBufferExtended().

◆ pgstat_count_buffer_read_time

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

Definition at line 1323 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 1325 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 1298 of file pgstat.h.

Referenced by BitmapHeapNext(), heap_fetch(), 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 1293 of file pgstat.h.

Referenced by heap_getnext(), and tablesample_getnext().

◆ 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 1288 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 1303 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 1308 of file pgstat.h.

Referenced by index_getbitmap(), and index_getnext_tid().

◆ PGSTAT_FILE_FORMAT_ID

#define PGSTAT_FILE_FORMAT_ID   0x01A5BC9D

◆ pgstat_increment_changecount_after

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

Definition at line 1075 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_increment_changecount_before

#define pgstat_increment_changecount_before (   beentry)

◆ 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   10

◆ 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_save_changecount_after

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

Definition at line 1088 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

◆ pgstat_save_changecount_before

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

Definition at line 1082 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

◆ PGSTAT_STAT_PERMANENT_DIRECTORY

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"

Definition at line 29 of file pgstat.h.

Referenced by get_dbstat_filename(), and pgstat_reset_all().

◆ PGSTAT_STAT_PERMANENT_FILENAME

#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/global.stat"

◆ PGSTAT_STAT_PERMANENT_TMPFILE

#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/global.tmp"

Definition at line 31 of file pgstat.h.

Referenced by pgstat_write_statsfiles().

Typedef Documentation

◆ BackendState

◆ BackendType

◆ LocalPgBackendStatus

◆ PgBackendSSLStatus

◆ PgBackendStatus

◆ PgStat_ArchiverStats

◆ PgStat_BackendFunctionEntry

◆ PgStat_Counter

Definition at line 74 of file pgstat.h.

◆ PgStat_FunctionCallUsage

◆ PgStat_FunctionCounts

◆ PgStat_FunctionEntry

◆ PgStat_GlobalStats

◆ PgStat_Msg

◆ PgStat_MsgAnalyze

◆ PgStat_MsgArchiver

◆ PgStat_MsgAutovacStart

◆ PgStat_MsgBgWriter

◆ PgStat_MsgDeadlock

◆ PgStat_MsgDropdb

◆ PgStat_MsgDummy

◆ PgStat_MsgFuncpurge

◆ PgStat_MsgFuncstat

◆ 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

◆ TrackFunctionsLevel

Enumeration Type Documentation

◆ BackendState

Enumerator
STATE_UNDEFINED 
STATE_IDLE 
STATE_RUNNING 
STATE_IDLEINTRANSACTION 
STATE_FASTPATH 
STATE_IDLEINTRANSACTION_ABORTED 
STATE_DISABLED 

Definition at line 721 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 702 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 

Definition at line 934 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 

Definition at line 48 of file pgstat.h.

◆ TrackFunctionsLevel

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 37 of file pgstat.h.

◆ WaitEventActivity

Enumerator
WAIT_EVENT_ARCHIVER_MAIN 
WAIT_EVENT_AUTOVACUUM_MAIN 
WAIT_EVENT_BGWRITER_HIBERNATE 
WAIT_EVENT_BGWRITER_MAIN 
WAIT_EVENT_CHECKPOINTER_MAIN 
WAIT_EVENT_LOGICAL_APPLY_MAIN 
WAIT_EVENT_LOGICAL_LAUNCHER_MAIN 
WAIT_EVENT_PGSTAT_MAIN 
WAIT_EVENT_RECOVERY_WAL_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 755 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 

Definition at line 781 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 858 of file pgstat.h.

859 {
928 } WaitEventIO;
#define PG_WAIT_IO
Definition: pgstat.h:745
WaitEventIO
Definition: pgstat.h:858

◆ WaitEventIPC

Enumerator
WAIT_EVENT_BGWORKER_SHUTDOWN 
WAIT_EVENT_BGWORKER_STARTUP 
WAIT_EVENT_BTREE_PAGE 
WAIT_EVENT_CLOG_GROUP_UPDATE 
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 800 of file pgstat.h.

801 {
837 } WaitEventIPC;
WaitEventIPC
Definition: pgstat.h:800
#define PG_WAIT_IPC
Definition: pgstat.h:743

◆ WaitEventTimeout

Enumerator
WAIT_EVENT_BASE_BACKUP_THROTTLE 
WAIT_EVENT_PG_SLEEP 
WAIT_EVENT_RECOVERY_APPLY_DELAY 

Definition at line 845 of file pgstat.h.

Function Documentation

◆ allow_immediate_pgstat_restart()

void allow_immediate_pgstat_restart ( void  )

Definition at line 789 of file pgstat.c.

References last_pgstat_start_time.

Referenced by HandleChildCrash().

790 {
792 }
static time_t last_pgstat_start_time
Definition: pgstat.c:152

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

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

2140 {
2141  PgStat_SubXactStatus *xact_state;
2142 
2143  /*
2144  * Transfer transactional insert/update counts into the next higher
2145  * subtransaction state.
2146  */
2147  xact_state = pgStatXactStack;
2148  if (xact_state != NULL &&
2149  xact_state->nest_level >= nestDepth)
2150  {
2152  PgStat_TableXactStatus *next_trans;
2153 
2154  /* delink xact_state from stack immediately to simplify reuse case */
2155  pgStatXactStack = xact_state->prev;
2156 
2157  for (trans = xact_state->first; trans != NULL; trans = next_trans)
2158  {
2159  PgStat_TableStatus *tabstat;
2160 
2161  next_trans = trans->next;
2162  Assert(trans->nest_level == nestDepth);
2163  tabstat = trans->parent;
2164  Assert(tabstat->trans == trans);
2165  if (isCommit)
2166  {
2167  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
2168  {
2169  if (trans->truncated)
2170  {
2171  /* propagate the truncate status one level up */
2173  /* replace upper xact stats with ours */
2174  trans->upper->tuples_inserted = trans->tuples_inserted;
2175  trans->upper->tuples_updated = trans->tuples_updated;
2176  trans->upper->tuples_deleted = trans->tuples_deleted;
2177  }
2178  else
2179  {
2180  trans->upper->tuples_inserted += trans->tuples_inserted;
2181  trans->upper->tuples_updated += trans->tuples_updated;
2182  trans->upper->tuples_deleted += trans->tuples_deleted;
2183  }
2184  tabstat->trans = trans->upper;
2185  pfree(trans);
2186  }
2187  else
2188  {
2189  /*
2190  * When there isn't an immediate parent state, we can just
2191  * reuse the record instead of going through a
2192  * palloc/pfree pushup (this works since it's all in
2193  * TopTransactionContext anyway). We have to re-link it
2194  * into the parent level, though, and that might mean
2195  * pushing a new entry into the pgStatXactStack.
2196  */
2197  PgStat_SubXactStatus *upper_xact_state;
2198 
2199  upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
2200  trans->next = upper_xact_state->first;
2201  upper_xact_state->first = trans;
2202  trans->nest_level = nestDepth - 1;
2203  }
2204  }
2205  else
2206  {
2207  /*
2208  * On abort, update top-level tabstat counts, then forget the
2209  * subtransaction
2210  */
2211 
2212  /* first restore values obliterated by truncate */
2214  /* count attempted actions regardless of commit/abort */
2215  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2216  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2217  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2218  /* inserted tuples are dead, deleted tuples are unaffected */
2219  tabstat->t_counts.t_delta_dead_tuples +=
2220  trans->tuples_inserted + trans->tuples_updated;
2221  tabstat->trans = trans->upper;
2222  pfree(trans);
2223  }
2224  }
2225  pfree(xact_state);
2226  }
2227 }
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:1861
void pfree(void *pointer)
Definition: mcxt.c:1031
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:1997
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:214
#define Assert(condition)
Definition: c.h:732
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:218
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:398
PgStat_TableXactStatus * first
Definition: pgstat.c:215
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:1982
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
PgStat_TableStatus * parent
Definition: pgstat.h:177

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit)

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

2057 {
2058  PgStat_SubXactStatus *xact_state;
2059 
2060  /*
2061  * Count transaction commit or abort. (We use counters, not just bools,
2062  * in case the reporting message isn't sent right away.)
2063  */
2064  if (isCommit)
2065  pgStatXactCommit++;
2066  else
2068 
2069  /*
2070  * Transfer transactional insert/update counts into the base tabstat
2071  * entries. We don't bother to free any of the transactional state, since
2072  * it's all in TopTransactionContext and will go away anyway.
2073  */
2074  xact_state = pgStatXactStack;
2075  if (xact_state != NULL)
2076  {
2078 
2079  Assert(xact_state->nest_level == 1);
2080  Assert(xact_state->prev == NULL);
2081  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2082  {
2083  PgStat_TableStatus *tabstat;
2084 
2085  Assert(trans->nest_level == 1);
2086  Assert(trans->upper == NULL);
2087  tabstat = trans->parent;
2088  Assert(tabstat->trans == trans);
2089  /* restore pre-truncate stats (if any) in case of aborted xact */
2090  if (!isCommit)
2092  /* count attempted actions regardless of commit/abort */
2093  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2094  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2095  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2096  if (isCommit)
2097  {
2098  tabstat->t_counts.t_truncated = trans->truncated;
2099  if (trans->truncated)
2100  {
2101  /* forget live/dead stats seen by backend thus far */
2102  tabstat->t_counts.t_delta_live_tuples = 0;
2103  tabstat->t_counts.t_delta_dead_tuples = 0;
2104  }
2105  /* insert adds a live tuple, delete removes one */
2106  tabstat->t_counts.t_delta_live_tuples +=
2107  trans->tuples_inserted - trans->tuples_deleted;
2108  /* update and delete each create a dead tuple */
2109  tabstat->t_counts.t_delta_dead_tuples +=
2110  trans->tuples_updated + trans->tuples_deleted;
2111  /* insert, update, delete each count as one change event */
2112  tabstat->t_counts.t_changed_tuples +=
2113  trans->tuples_inserted + trans->tuples_updated +
2114  trans->tuples_deleted;
2115  }
2116  else
2117  {
2118  /* inserted tuples are dead, deleted tuples are unaffected */
2119  tabstat->t_counts.t_delta_dead_tuples +=
2120  trans->tuples_inserted + trans->tuples_updated;
2121  /* an aborted xact generates no changed_tuple events */
2122  }
2123  tabstat->trans = NULL;
2124  }
2125  }
2126  pgStatXactStack = NULL;
2127 
2128  /* Make sure any stats snapshot is thrown away */
2130 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:110
PgStat_Counter tuples_updated
Definition: pgstat.h:168
static int pgStatXactCommit
Definition: pgstat.c:220
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:1997
static int pgStatXactRollback
Definition: pgstat.c:221
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:214
PgStat_Counter t_changed_tuples
Definition: pgstat.h:112
#define Assert(condition)
Definition: c.h:732
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5615
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:218
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:398
PgStat_TableXactStatus * first
Definition: pgstat.c:215
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 2238 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().

2239 {
2240  PgStat_SubXactStatus *xact_state;
2241 
2242  xact_state = pgStatXactStack;
2243  if (xact_state != NULL)
2244  {
2246 
2247  Assert(xact_state->nest_level == 1);
2248  Assert(xact_state->prev == NULL);
2249  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2250  {
2251  PgStat_TableStatus *tabstat;
2252  TwoPhasePgStatRecord record;
2253 
2254  Assert(trans->nest_level == 1);
2255  Assert(trans->upper == NULL);
2256  tabstat = trans->parent;
2257  Assert(tabstat->trans == trans);
2258 
2259  record.tuples_inserted = trans->tuples_inserted;
2260  record.tuples_updated = trans->tuples_updated;
2261  record.tuples_deleted = trans->tuples_deleted;
2262  record.inserted_pre_trunc = trans->inserted_pre_trunc;
2263  record.updated_pre_trunc = trans->updated_pre_trunc;
2264  record.deleted_pre_trunc = trans->deleted_pre_trunc;
2265  record.t_id = tabstat->t_id;
2266  record.t_shared = tabstat->t_shared;
2267  record.t_truncated = trans->truncated;
2268 
2270  &record, sizeof(TwoPhasePgStatRecord));
2271  }
2272  }
2273 }
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:233
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1192
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter updated_pre_trunc
Definition: pgstat.c:232
PgStat_Counter inserted_pre_trunc
Definition: pgstat.c:231
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter tuples_updated
Definition: pgstat.c:229
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:214
#define Assert(condition)
Definition: c.h:732
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:171
PgStat_Counter tuples_inserted
Definition: pgstat.c:228
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:218
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
PgStat_Counter tuples_deleted
Definition: pgstat.c:230
#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:398
PgStat_TableXactStatus * first
Definition: pgstat.c:215
PgStat_TableStatus * parent
Definition: pgstat.h:177

◆ BackendStatusShmemSize()

Size BackendStatusShmemSize ( void  )

Definition at line 2607 of file pgstat.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

2608 {
2609  Size size;
2610 
2611  /* BackendStatusArray: */
2612  size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
2613  /* BackendAppnameBuffer: */
2614  size = add_size(size,
2616  /* BackendClientHostnameBuffer: */
2617  size = add_size(size,
2619  /* BackendActivityBuffer: */
2620  size = add_size(size,
2622 #ifdef USE_SSL
2623  /* BackendSslStatusBuffer: */
2624  size = add_size(size,
2626 #endif
2627  return size;
2628 }
#define NumBackendStatSlots
Definition: pgstat.c:117
#define NAMEDATALEN
int pgstat_track_activity_query_size
Definition: pgstat.c:127
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 2635 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, and PgBackendStatus::st_sslstatus.

Referenced by CreateSharedMemoryAndSemaphores().

2636 {
2637  Size size;
2638  bool found;
2639  int i;
2640  char *buffer;
2641 
2642  /* Create or attach to the shared array */
2643  size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
2645  ShmemInitStruct("Backend Status Array", size, &found);
2646 
2647  if (!found)
2648  {
2649  /*
2650  * We're the first - initialize.
2651  */
2652  MemSet(BackendStatusArray, 0, size);
2653  }
2654 
2655  /* Create or attach to the shared appname buffer */
2657  BackendAppnameBuffer = (char *)
2658  ShmemInitStruct("Backend Application Name Buffer", size, &found);
2659 
2660  if (!found)
2661  {
2662  MemSet(BackendAppnameBuffer, 0, size);
2663 
2664  /* Initialize st_appname pointers. */
2665  buffer = BackendAppnameBuffer;
2666  for (i = 0; i < NumBackendStatSlots; i++)
2667  {
2668  BackendStatusArray[i].st_appname = buffer;
2669  buffer += NAMEDATALEN;
2670  }
2671  }
2672 
2673  /* Create or attach to the shared client hostname buffer */
2675  BackendClientHostnameBuffer = (char *)
2676  ShmemInitStruct("Backend Client Host Name Buffer", size, &found);
2677 
2678  if (!found)
2679  {
2681 
2682  /* Initialize st_clienthostname pointers. */
2683  buffer = BackendClientHostnameBuffer;
2684  for (i = 0; i < NumBackendStatSlots; i++)
2685  {
2687  buffer += NAMEDATALEN;
2688  }
2689  }
2690 
2691  /* Create or attach to the shared activity buffer */
2694  BackendActivityBuffer = (char *)
2695  ShmemInitStruct("Backend Activity Buffer",
2697  &found);
2698 
2699  if (!found)
2700  {
2702 
2703  /* Initialize st_activity pointers. */
2704  buffer = BackendActivityBuffer;
2705  for (i = 0; i < NumBackendStatSlots; i++)
2706  {
2709  }
2710  }
2711 
2712 #ifdef USE_SSL
2713  /* Create or attach to the shared SSL status buffer */
2715  BackendSslStatusBuffer = (PgBackendSSLStatus *)
2716  ShmemInitStruct("Backend SSL Status Buffer", size, &found);
2717 
2718  if (!found)
2719  {
2720  PgBackendSSLStatus *ptr;
2721 
2722  MemSet(BackendSslStatusBuffer, 0, size);
2723 
2724  /* Initialize st_sslstatus pointers. */
2725  ptr = BackendSslStatusBuffer;
2726  for (i = 0; i < NumBackendStatSlots; i++)
2727  {
2729  ptr++;
2730  }
2731  }
2732 #endif
2733 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2592
static char * BackendActivityBuffer
Definition: pgstat.c:2596
static Size BackendActivityBufferSize
Definition: pgstat.c:2597
#define MemSet(start, val, len)
Definition: c.h:941
#define NumBackendStatSlots
Definition: pgstat.c:117
char * st_clienthostname
Definition: pgstat.h:1022
#define NAMEDATALEN
static char * BackendAppnameBuffer
Definition: pgstat.c:2594
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
char * st_activity_raw
Definition: pgstat.h:1041
int pgstat_track_activity_query_size
Definition: pgstat.c:127
char * st_appname
Definition: pgstat.h:1032
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:1026
static char * BackendClientHostnameBuffer
Definition: pgstat.c:2595

◆ find_funcstat_entry()

PgStat_BackendFunctionEntry* find_funcstat_entry ( Oid  func_id)

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

1637 {
1638  if (pgStatFunctions == NULL)
1639  return NULL;
1640 
1642  (void *) &func_id,
1643  HASH_FIND, NULL);
1644 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
static HTAB * pgStatFunctions
Definition: pgstat.c:196

◆ find_tabstat_entry()

PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

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

1842 {
1843  TabStatHashEntry *hash_entry;
1844 
1845  /* If hashtable doesn't exist, there are no entries at all */
1846  if (!pgStatTabHash)
1847  return NULL;
1848 
1849  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_FIND, NULL);
1850  if (!hash_entry)
1851  return NULL;
1852 
1853  /* Note that this step could also return NULL, but that's correct */
1854  return hash_entry->tsa_entry;
1855 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
static HTAB * pgStatTabHash
Definition: pgstat.c:190
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:184

◆ pgstat_bestart()

void pgstat_bestart ( void  )

Definition at line 2788 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_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(), InvalidBackendId, InvalidOid, IsAutoVacuumLauncherProcess(), IsAutoVacuumWorkerProcess(), IsBackgroundWorker, MemSet, MyAuxProcType, MyBackendId, MyBEEntry, MyDatabaseId, MyProcPid, MyProcPort, MyStartTimestamp, NAMEDATALEN, NotAnAuxProcess, pgstat_increment_changecount_after, pgstat_increment_changecount_before, pgstat_report_appname(), pgstat_track_activity_query_size, proc_exit(), 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_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(), WalReceiverProcess, and WalWriterProcess.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

2789 {
2790  SockAddr clientaddr;
2791  volatile PgBackendStatus *beentry;
2792 
2793  /*
2794  * To minimize the time spent modifying the PgBackendStatus entry, fetch
2795  * all the needed data first.
2796  */
2797 
2798  /*
2799  * We may not have a MyProcPort (eg, if this is the autovacuum process).
2800  * If so, use all-zeroes client address, which is dealt with specially in
2801  * pg_stat_get_backend_client_addr and pg_stat_get_backend_client_port.
2802  */
2803  if (MyProcPort)
2804  memcpy(&clientaddr, &MyProcPort->raddr, sizeof(clientaddr));
2805  else
2806  MemSet(&clientaddr, 0, sizeof(clientaddr));
2807 
2808  /*
2809  * Initialize my status entry, following the protocol of bumping
2810  * st_changecount before and after; and make sure it's even afterwards. We
2811  * use a volatile pointer here to ensure the compiler doesn't try to get
2812  * cute.
2813  */
2814  beentry = MyBEEntry;
2815 
2816  /* pgstats state must be initialized from pgstat_initialize() */
2817  Assert(beentry != NULL);
2818 
2820  {
2822  {
2823  /* Autovacuum Launcher */
2825  }
2826  else if (IsAutoVacuumWorkerProcess())
2827  {
2828  /* Autovacuum Worker */
2829  beentry->st_backendType = B_AUTOVAC_WORKER;
2830  }
2831  else if (am_walsender)
2832  {
2833  /* Wal sender */
2834  beentry->st_backendType = B_WAL_SENDER;
2835  }
2836  else if (IsBackgroundWorker)
2837  {
2838  /* bgworker */
2839  beentry->st_backendType = B_BG_WORKER;
2840  }
2841  else
2842  {
2843  /* client-backend */
2844  beentry->st_backendType = B_BACKEND;
2845  }
2846  }
2847  else
2848  {
2849  /* Must be an auxiliary process */
2851  switch (MyAuxProcType)
2852  {
2853  case StartupProcess:
2854  beentry->st_backendType = B_STARTUP;
2855  break;
2856  case BgWriterProcess:
2857  beentry->st_backendType = B_BG_WRITER;
2858  break;
2859  case CheckpointerProcess:
2860  beentry->st_backendType = B_CHECKPOINTER;
2861  break;
2862  case WalWriterProcess:
2863  beentry->st_backendType = B_WAL_WRITER;
2864  break;
2865  case WalReceiverProcess:
2866  beentry->st_backendType = B_WAL_RECEIVER;
2867  break;
2868  default:
2869  elog(FATAL, "unrecognized process type: %d",
2870  (int) MyAuxProcType);
2871  proc_exit(1);
2872  }
2873  }
2874 
2875  do
2876  {
2878  } while ((beentry->st_changecount & 1) == 0);
2879 
2880  beentry->st_procpid = MyProcPid;
2882  beentry->st_activity_start_timestamp = 0;
2883  beentry->st_state_start_timestamp = 0;
2884  beentry->st_xact_start_timestamp = 0;
2885  beentry->st_databaseid = MyDatabaseId;
2886 
2887  /* We have userid for client-backends, wal-sender and bgworker processes */
2888  if (beentry->st_backendType == B_BACKEND
2889  || beentry->st_backendType == B_WAL_SENDER
2890  || beentry->st_backendType == B_BG_WORKER)
2891  beentry->st_userid = GetSessionUserId();
2892  else
2893  beentry->st_userid = InvalidOid;
2894 
2895  beentry->st_clientaddr = clientaddr;
2898  NAMEDATALEN);
2899  else
2900  beentry->st_clienthostname[0] = '\0';
2901 #ifdef USE_SSL
2902  if (MyProcPort && MyProcPort->ssl != NULL)
2903  {
2904  beentry->st_ssl = true;
2912  }
2913  else
2914  {
2915  beentry->st_ssl = false;
2916  }
2917 #else
2918  beentry->st_ssl = false;
2919 #endif
2920  beentry->st_state = STATE_UNDEFINED;
2921  beentry->st_appname[0] = '\0';
2922  beentry->st_activity_raw[0] = '\0';
2923  /* Also make sure the last byte in each string area is always 0 */
2924  beentry->st_clienthostname[NAMEDATALEN - 1] = '\0';
2925  beentry->st_appname[NAMEDATALEN - 1] = '\0';
2929 
2930  /*
2931  * we don't zero st_progress_param here to save cycles; nobody should
2932  * examine it until st_progress_command has been set to something other
2933  * than PROGRESS_COMMAND_INVALID
2934  */
2935 
2937 
2938  /* Update app name to current GUC setting */
2939  if (application_name)
2941 }
char ssl_issuer_dn[NAMEDATALEN]
Definition: pgstat.h:971
bool ssl_compression
Definition: pgstat.h:960
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:962
Oid st_progress_command_target
Definition: pgstat.h:1053
int MyProcPid
Definition: globals.c:40
BackendId MyBackendId
Definition: globals.c:81
struct Port * MyProcPort
Definition: globals.c:43
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1015
char ssl_client_dn[NAMEDATALEN]
Definition: pgstat.h:963
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:961
SockAddr st_clientaddr
Definition: pgstat.h:1021
void proc_exit(int code)
Definition: ipc.c:104
#define MemSet(start, val, len)
Definition: c.h:941
ProgressCommandType st_progress_command
Definition: pgstat.h:1052
char ssl_client_serial[NAMEDATALEN]
Definition: pgstat.h:969
BackendState st_state
Definition: pgstat.h:1029
char * st_clienthostname
Definition: pgstat.h:1022
Oid GetSessionUserId(void)
Definition: miscinit.c:414
bool IsBackgroundWorker
Definition: globals.c:111
Oid st_databaseid
Definition: pgstat.h:1019
#define NAMEDATALEN
char * remote_hostname
Definition: libpq-be.h:124
SockAddr raddr
Definition: libpq-be.h:122
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:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
char * st_activity_raw
Definition: pgstat.h:1041
int pgstat_track_activity_query_size
Definition: pgstat.c:127
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1016
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3276
char * st_appname
Definition: pgstat.h:1032
#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:71
Oid MyDatabaseId
Definition: globals.c:85
BackendType st_backendType
Definition: pgstat.h:1010
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3164
#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:3270
#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:526
void be_tls_get_peer_subject_name(Port *port, char *ptr, size_t len)
void be_tls_get_peer_serial(Port *port, char *ptr, size_t len)
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1014
#define elog(elevel,...)
Definition: elog.h:226
int st_changecount
Definition: pgstat.h:1004
const char * be_tls_get_cipher(Port *port)
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1013
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1026

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 5615 of file pgstat.c.

References localNumBackends, and MemoryContextDelete().

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

5616 {
5617  /* Release memory, if any was allocated */
5618  if (pgStatLocalContext)
5620 
5621  /* Reset variables */
5622  pgStatLocalContext = NULL;
5623  pgStatDBHash = NULL;
5624  localBackendStatusTable = NULL;
5625  localNumBackends = 0;
5626 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:246
static HTAB * pgStatDBHash
Definition: pgstat.c:243
static int localNumBackends
Definition: pgstat.c:249
static MemoryContext pgStatLocalContext
Definition: pgstat.c:242

◆ pgstat_clip_activity()

char* pgstat_clip_activity ( const char *  raw_activity)

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

6347 {
6348  char *activity;
6349  int rawlen;
6350  int cliplen;
6351 
6352  /*
6353  * Some callers, like pgstat_get_backend_current_activity(), do not
6354  * guarantee that the buffer isn't concurrently modified. We try to take
6355  * care that the buffer is always terminated by a NUL byte regardless, but
6356  * let's still be paranoid about the string's length. In those cases the
6357  * underlying buffer is guaranteed to be pgstat_track_activity_query_size
6358  * large.
6359  */
6360  activity = pnstrdup(raw_activity, pgstat_track_activity_query_size - 1);
6361 
6362  /* now double-guaranteed to be NUL terminated */
6363  rawlen = strlen(activity);
6364 
6365  /*
6366  * All supported server-encodings make it possible to determine the length
6367  * of a multi-byte character from its first byte (this is not the case for
6368  * client encodings, see GB18030). As st_activity is always stored using
6369  * server encoding, this allows us to perform multi-byte aware truncation,
6370  * even if the string earlier was truncated in the middle of a multi-byte
6371  * character.
6372  */
6373  cliplen = pg_mbcliplen(activity, rawlen,
6375 
6376  activity[cliplen] = '\0';
6377 
6378  return activity;
6379 }
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1172
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:820
int pgstat_track_activity_query_size
Definition: pgstat.c:127
static int cliplen(const char *str, int len, int limit)
Definition: mbutils.c:887

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

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

1957 {
1958  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1959 
1960  if (pgstat_info != NULL)
1961  {
1962  /* We have to log the effect at the proper transactional level */
1963  int nest_level = GetCurrentTransactionNestLevel();
1964 
1965  if (pgstat_info->trans == NULL ||
1966  pgstat_info->trans->nest_level != nest_level)
1967  add_tabstat_xact_level(pgstat_info, nest_level);
1968 
1969  pgstat_info->trans->tuples_deleted++;
1970  }
1971 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:758
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:187
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1883
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 1910 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().

1911 {
1912  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1913 
1914  if (pgstat_info != NULL)
1915  {
1916  /* We have to log the effect at the proper transactional level */
1917  int nest_level = GetCurrentTransactionNestLevel();
1918 
1919  if (pgstat_info->trans == NULL ||
1920  pgstat_info->trans->nest_level != nest_level)
1921  add_tabstat_xact_level(pgstat_info, nest_level);
1922 
1923  pgstat_info->trans->tuples_inserted += n;
1924  }
1925 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:758
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:187
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1883
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

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

1932 {
1933  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1934 
1935  if (pgstat_info != NULL)
1936  {
1937  /* We have to log the effect at the proper transactional level */
1938  int nest_level = GetCurrentTransactionNestLevel();
1939 
1940  if (pgstat_info->trans == NULL ||
1941  pgstat_info->trans->nest_level != nest_level)
1942  add_tabstat_xact_level(pgstat_info, nest_level);
1943 
1944  pgstat_info->trans->tuples_updated++;
1945 
1946  /* t_tuples_hot_updated is nontransactional, so just advance it */
1947  if (hot)
1948  pgstat_info->t_counts.t_tuples_hot_updated++;
1949  }
1950 }
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:758
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:187
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1883
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

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

2012 {
2013  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2014 
2015  if (pgstat_info != NULL)
2016  {
2017  /* We have to log the effect at the proper transactional level */
2018  int nest_level = GetCurrentTransactionNestLevel();
2019 
2020  if (pgstat_info->trans == NULL ||
2021  pgstat_info->trans->nest_level != nest_level)
2022  add_tabstat_xact_level(pgstat_info, nest_level);
2023 
2024  pgstat_truncate_save_counters(pgstat_info->trans);
2025  pgstat_info->trans->tuples_inserted = 0;
2026  pgstat_info->trans->tuples_updated = 0;
2027  pgstat_info->trans->tuples_deleted = 0;
2028  }
2029 }
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:758
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:187
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1883
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:1982

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)

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

1254 {
1255  PgStat_MsgDropdb msg;
1256 
1258  return;
1259 
1261  msg.m_databaseid = databaseid;
1262  pgstat_send(&msg, sizeof(msg));
1263 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
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:4156

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

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

1657 {
1658  PgStat_FunctionCounts *fs = fcu->fs;
1659  instr_time f_total;
1660  instr_time f_others;
1661  instr_time f_self;
1662 
1663  /* stats not wanted? */
1664  if (fs == NULL)
1665  return;
1666 
1667  /* total elapsed time in this function call */
1668  INSTR_TIME_SET_CURRENT(f_total);
1669  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
1670 
1671  /* self usage: elapsed minus anything already charged to other calls */
1672  f_others = total_func_time;
1673  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
1674  f_self = f_total;
1675  INSTR_TIME_SUBTRACT(f_self, f_others);
1676 
1677  /* update backend-wide total time */
1679 
1680  /*
1681  * Compute the new f_total_time as the total elapsed time added to the
1682  * pre-call value of f_total_time. This is necessary to avoid
1683  * double-counting any time taken by recursive calls of myself. (We do
1684  * not need any similar kluge for self time, since that already excludes
1685  * any recursive calls.)
1686  */
1687  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
1688 
1689  /* update counters in function stats table */
1690  if (finalize)
1691  fs->f_numcalls++;
1692  fs->f_total_time = f_total;
1693  INSTR_TIME_ADD(fs->f_self_time, f_self);
1694 
1695  /* indicate that we have something to send */
1696  have_function_stats = true;
1697 }
instr_time f_self_time
Definition: pgstat.h:463
instr_time save_total
Definition: pgstat.h:1133
struct timeval instr_time
Definition: instr_time.h:150
instr_time f_total_time
Definition: pgstat.h:462
PgStat_FunctionCounts * fs
Definition: pgstat.h:1129
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:275
static bool have_function_stats
Definition: pgstat.c:202
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:1131

◆ pgstat_fetch_global()

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 2562 of file pgstat.c.

References archiverStats, and backend_read_statsfile().

Referenced by pg_stat_get_archiver().

2563 {
2565 
2566  return &archiverStats;
2567 }
static void backend_read_statsfile(void)
Definition: pgstat.c:5461
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:256

◆ pgstat_fetch_stat_beentry()

◆ pgstat_fetch_stat_dbentry()

PgStat_StatDBEntry* pgstat_fetch_stat_dbentry ( Oid  dbid)

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

2391 {
2392  /*
2393  * If not done for this transaction, read the statistics collector stats
2394  * file into some hash tables.
2395  */
2397 
2398  /*
2399  * Lookup the requested database; return NULL if not found
2400  */
2402  (void *) &dbid,
2403  HASH_FIND, NULL);
2404 }
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:5461
static HTAB * pgStatDBHash
Definition: pgstat.c:243

◆ pgstat_fetch_stat_funcentry()

PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  funcid)

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

2474 {
2475  PgStat_StatDBEntry *dbentry;
2476  PgStat_StatFuncEntry *funcentry = NULL;
2477 
2478  /* load the stats file if needed */
2480 
2481  /* Lookup our database, then find the requested function. */
2483  if (dbentry != NULL && dbentry->functions != NULL)
2484  {
2485  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
2486  (void *) &func_id,
2487  HASH_FIND, NULL);
2488  }
2489 
2490  return funcentry;
2491 }
HTAB * functions
Definition: pgstat.h:607
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2390
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:5461
Oid MyDatabaseId
Definition: globals.c:85

◆ pgstat_fetch_stat_local_beentry()

LocalPgBackendStatus* pgstat_fetch_stat_local_beentry ( int  beid)

Definition at line 2527 of file pgstat.c.

References localNumBackends, and pgstat_read_current_status().

Referenced by pg_stat_get_activity(), and pg_stat_get_progress_info().

2528 {
2530 
2531  if (beid < 1 || beid > localNumBackends)
2532  return NULL;
2533 
2534  return &localBackendStatusTable[beid - 1];
2535 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3218
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:246
static int localNumBackends
Definition: pgstat.c:249

◆ pgstat_fetch_stat_numbackends()

int pgstat_fetch_stat_numbackends ( void  )

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

2547 {
2549 
2550  return localNumBackends;
2551 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3218
static int localNumBackends
Definition: pgstat.c:249

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 2417 of file pgstat.c.

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

Referenced by 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().

2418 {
2419  Oid dbid;
2420  PgStat_StatDBEntry *dbentry;
2421  PgStat_StatTabEntry *tabentry;
2422 
2423  /*
2424  * If not done for this transaction, read the statistics collector stats
2425  * file into some hash tables.
2426  */
2428 
2429  /*
2430  * Lookup our database, then look in its table hash table.
2431  */
2432  dbid = MyDatabaseId;
2434  (void *) &dbid,
2435  HASH_FIND, NULL);
2436  if (dbentry != NULL && dbentry->tables != NULL)
2437  {
2438  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2439  (void *) &relid,
2440  HASH_FIND, NULL);
2441  if (tabentry)
2442  return tabentry;
2443  }
2444 
2445  /*
2446  * If we didn't find it, maybe it's a shared table.
2447  */
2448  dbid = InvalidOid;
2450  (void *) &dbid,
2451  HASH_FIND, NULL);
2452  if (dbentry != NULL && dbentry->tables != NULL)
2453  {
2454  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2455  (void *) &relid,
2456  HASH_FIND, NULL);
2457  if (tabentry)
2458  return tabentry;
2459  }
2460 
2461  return NULL;
2462 }
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:5461
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static HTAB * pgStatDBHash
Definition: pgstat.c:243

◆ pgstat_get_backend_current_activity()

const char* pgstat_get_backend_current_activity ( int  pid,
bool  checkUser 
)

Definition at line 3965 of file pgstat.c.

References BackendStatusArray, CHECK_FOR_INTERRUPTS, GetUserId(), i, MaxBackends, pgstat_clip_activity(), pgstat_save_changecount_after, pgstat_save_changecount_before, PgBackendStatus::st_activity_raw, PgBackendStatus::st_procpid, PgBackendStatus::st_userid, and superuser().

Referenced by DeadLockReport().

3966 {
3967  PgBackendStatus *beentry;
3968  int i;
3969 
3970  beentry = BackendStatusArray;
3971  for (i = 1; i <= MaxBackends; i++)
3972  {
3973  /*
3974  * Although we expect the target backend's entry to be stable, that
3975  * doesn't imply that anyone else's is. To avoid identifying the
3976  * wrong backend, while we check for a match to the desired PID we
3977  * must follow the protocol of retrying if st_changecount changes
3978  * while we examine the entry, or if it's odd. (This might be
3979  * unnecessary, since fetching or storing an int is almost certainly
3980  * atomic, but let's play it safe.) We use a volatile pointer here to
3981  * ensure the compiler doesn't try to get cute.
3982  */
3983  volatile PgBackendStatus *vbeentry = beentry;
3984  bool found;
3985 
3986  for (;;)
3987  {
3988  int before_changecount;
3989  int after_changecount;
3990 
3991  pgstat_save_changecount_before(vbeentry, before_changecount);
3992 
3993  found = (vbeentry->st_procpid == pid);
3994 
3995  pgstat_save_changecount_after(vbeentry, after_changecount);
3996 
3997  if (before_changecount == after_changecount &&
3998  (before_changecount & 1) == 0)
3999  break;
4000 
4001  /* Make sure we can break out of loop if stuck... */
4003  }
4004 
4005  if (found)
4006  {
4007  /* Now it is safe to use the non-volatile pointer */
4008  if (checkUser && !superuser() && beentry->st_userid != GetUserId())
4009  return "<insufficient privilege>";
4010  else if (*(beentry->st_activity_raw) == '\0')
4011  return "<command string not enabled>";
4012  else
4013  {
4014  /* this'll leak a bit of memory, but that seems acceptable */
4015  return pgstat_clip_activity(beentry->st_activity_raw);
4016  }
4017  }
4018 
4019  beentry++;
4020  }
4021 
4022  /* If we get here, caller is in error ... */
4023  return "<backend information not available>";
4024 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2592
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:1041
#define pgstat_save_changecount_before(beentry, save_changecount)
Definition: pgstat.h:1082
#define pgstat_save_changecount_after(beentry, save_changecount)
Definition: pgstat.h:1088
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6346
int i
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99

◆ pgstat_get_backend_desc()

const char* pgstat_get_backend_desc ( BackendType  backendType)

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

4103 {
4104  const char *backendDesc = "unknown process type";
4105 
4106  switch (backendType)
4107  {
4108  case B_AUTOVAC_LAUNCHER:
4109  backendDesc = "autovacuum launcher";
4110  break;
4111  case B_AUTOVAC_WORKER:
4112  backendDesc = "autovacuum worker";
4113  break;
4114  case B_BACKEND:
4115  backendDesc = "client backend";
4116  break;
4117  case B_BG_WORKER:
4118  backendDesc = "background worker";
4119  break;
4120  case B_BG_WRITER:
4121  backendDesc = "background writer";
4122  break;
4123  case B_CHECKPOINTER:
4124  backendDesc = "checkpointer";
4125  break;
4126  case B_STARTUP:
4127  backendDesc = "startup";
4128  break;
4129  case B_WAL_RECEIVER:
4130  backendDesc = "walreceiver";
4131  break;
4132  case B_WAL_SENDER:
4133  backendDesc = "walsender";
4134  break;
4135  case B_WAL_WRITER:
4136  backendDesc = "walwriter";
4137  break;
4138  }
4139 
4140  return backendDesc;
4141 }

◆ pgstat_get_crashed_backend_activity()

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

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

4044 {
4045  volatile PgBackendStatus *beentry;
4046  int i;
4047 
4048  beentry = BackendStatusArray;
4049 
4050  /*
4051  * We probably shouldn't get here before shared memory has been set up,
4052  * but be safe.
4053  */
4054  if (beentry == NULL || BackendActivityBuffer == NULL)
4055  return NULL;
4056 
4057  for (i = 1; i <= MaxBackends; i++)
4058  {
4059  if (beentry->st_procpid == pid)
4060  {
4061  /* Read pointer just once, so it can't change after validation */
4062  const char *activity = beentry->st_activity_raw;
4063  const char *activity_last;
4064 
4065  /*
4066  * We mustn't access activity string before we verify that it
4067  * falls within the BackendActivityBuffer. To make sure that the
4068  * entire string including its ending is contained within the
4069  * buffer, subtract one activity length from the buffer size.
4070  */
4073 
4074  if (activity < BackendActivityBuffer ||
4075  activity > activity_last)
4076  return NULL;
4077 
4078  /* If no string available, no point in a report */
4079  if (activity[0] == '\0')
4080  return NULL;
4081 
4082  /*
4083  * Copy only ASCII-safe characters so we don't run into encoding
4084  * problems when reporting the message; and be sure not to run off
4085  * the end of memory. As only ASCII characters are reported, it
4086  * doesn't seem necessary to perform multibyte aware clipping.
4087  */
4088  ascii_safe_strlcpy(buffer, activity,
4089  Min(buflen, pgstat_track_activity_query_size));
4090 
4091  return buffer;
4092  }
4093 
4094  beentry++;
4095  }
4096 
4097  /* PID not found */
4098  return NULL;
4099 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2592
static char * BackendActivityBuffer
Definition: pgstat.c:2596
#define Min(x, y)
Definition: c.h:890
static Size BackendActivityBufferSize
Definition: pgstat.c:2597
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:1041
int pgstat_track_activity_query_size
Definition: pgstat.c:127
int i

◆ pgstat_get_wait_event()

const char* pgstat_get_wait_event ( uint32  wait_event_info)

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

3395 {
3396  uint32 classId;
3397  uint16 eventId;
3398  const char *event_name;
3399 
3400  /* report process as not waiting. */
3401  if (wait_event_info == 0)
3402  return NULL;
3403 
3404  classId = wait_event_info & 0xFF000000;
3405  eventId = wait_event_info & 0x0000FFFF;
3406 
3407  switch (classId)
3408  {
3409  case PG_WAIT_LWLOCK:
3410  event_name = GetLWLockIdentifier(classId, eventId);
3411  break;
3412  case PG_WAIT_LOCK:
3413  event_name = GetLockNameFromTagType(eventId);
3414  break;
3415  case PG_WAIT_BUFFER_PIN:
3416  event_name = "BufferPin";
3417  break;
3418  case PG_WAIT_ACTIVITY:
3419  {
3420  WaitEventActivity w = (WaitEventActivity) wait_event_info;
3421 
3422  event_name = pgstat_get_wait_activity(w);
3423  break;
3424  }
3425  case PG_WAIT_CLIENT:
3426  {
3427  WaitEventClient w = (WaitEventClient) wait_event_info;
3428 
3429  event_name = pgstat_get_wait_client(w);
3430  break;
3431  }
3432  case PG_WAIT_EXTENSION:
3433  event_name = "Extension";
3434  break;
3435  case PG_WAIT_IPC:
3436  {
3437  WaitEventIPC w = (WaitEventIPC) wait_event_info;
3438 
3439  event_name = pgstat_get_wait_ipc(w);
3440  break;
3441  }
3442  case PG_WAIT_TIMEOUT:
3443  {
3444  WaitEventTimeout w = (WaitEventTimeout) wait_event_info;
3445 
3446  event_name = pgstat_get_wait_timeout(w);
3447  break;
3448  }
3449  case PG_WAIT_IO:
3450  {
3451  WaitEventIO w = (WaitEventIO) wait_event_info;
3452 
3453  event_name = pgstat_get_wait_io(w);
3454  break;
3455  }
3456  default:
3457  event_name = "unknown wait event";
3458  break;
3459  }
3460 
3461  return event_name;
3462 }
#define PG_WAIT_LOCK
Definition: pgstat.h:738
WaitEventIPC
Definition: pgstat.h:800
static const char * pgstat_get_wait_timeout(WaitEventTimeout w)
Definition: pgstat.c:3699
static const char * pgstat_get_wait_ipc(WaitEventIPC w)
Definition: pgstat.c:3575
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:740
#define PG_WAIT_IO
Definition: pgstat.h:745
static const char * pgstat_get_wait_activity(WaitEventActivity w)
Definition: pgstat.c:3471
unsigned short uint16
Definition: c.h:357
#define PG_WAIT_CLIENT
Definition: pgstat.h:741
WaitEventClient
Definition: pgstat.h:781
static const char * pgstat_get_wait_client(WaitEventClient w)
Definition: pgstat.c:3532
unsigned int uint32
Definition: c.h:358
WaitEventTimeout
Definition: pgstat.h:845
#define PG_WAIT_EXTENSION
Definition: pgstat.h:742
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:739
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1132
WaitEventIO
Definition: pgstat.h:858
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:744
#define PG_WAIT_IPC
Definition: pgstat.h:743
const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)
Definition: lwlock.c:713
static const char * pgstat_get_wait_io(WaitEventIO w)
Definition: pgstat.c:3727
#define PG_WAIT_LWLOCK
Definition: pgstat.h:737
WaitEventActivity
Definition: pgstat.h:755

◆ pgstat_get_wait_event_type()

const char* pgstat_get_wait_event_type ( uint32  wait_event_info)

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

3340 {
3341  uint32 classId;
3342  const char *event_type;
3343 
3344  /* report process as not waiting. */
3345  if (wait_event_info == 0)
3346  return NULL;
3347 
3348  classId = wait_event_info & 0xFF000000;
3349 
3350  switch (classId)
3351  {
3352  case PG_WAIT_LWLOCK:
3353  event_type = "LWLock";
3354  break;
3355  case PG_WAIT_LOCK:
3356  event_type = "Lock";
3357  break;
3358  case PG_WAIT_BUFFER_PIN:
3359  event_type = "BufferPin";
3360  break;
3361  case PG_WAIT_ACTIVITY:
3362  event_type = "Activity";
3363  break;
3364  case PG_WAIT_CLIENT:
3365  event_type = "Client";
3366  break;
3367  case PG_WAIT_EXTENSION:
3368  event_type = "Extension";
3369  break;
3370  case PG_WAIT_IPC:
3371  event_type = "IPC";
3372  break;
3373  case PG_WAIT_TIMEOUT:
3374  event_type = "Timeout";
3375  break;
3376  case PG_WAIT_IO:
3377  event_type = "IO";
3378  break;
3379  default:
3380  event_type = "???";
3381  break;
3382  }
3383 
3384  return event_type;
3385 }
#define PG_WAIT_LOCK
Definition: pgstat.h:738
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:740
#define PG_WAIT_IO
Definition: pgstat.h:745
#define PG_WAIT_CLIENT
Definition: pgstat.h:741
unsigned int uint32
Definition: c.h:358
#define PG_WAIT_EXTENSION
Definition: pgstat.h:742
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:739
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:744
#define PG_WAIT_IPC
Definition: pgstat.h:743
#define PG_WAIT_LWLOCK
Definition: pgstat.h:737

◆ pgstat_init()

void pgstat_init ( void  )

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

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

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( FunctionCallInfo  fcinfo,
PgStat_FunctionCallUsage fcu 
)

Definition at line 1584 of file pgstat.c.

References HASHCTL::entrysize, PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCallUsage::f_start, PgStat_FunctionCounts::f_total_time, FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_oid, PgStat_FunctionCallUsage::fs, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), INSTR_TIME_SET_CURRENT, HASHCTL::keysize, MemSet, PGSTAT_FUNCTION_HASH_SIZE, 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().

1586 {
1587  PgStat_BackendFunctionEntry *htabent;
1588  bool found;
1589 
1590  if (pgstat_track_functions <= fcinfo->flinfo->fn_stats)
1591  {
1592  /* stats not wanted */
1593  fcu->fs = NULL;
1594  return;
1595  }
1596 
1597  if (!pgStatFunctions)
1598  {
1599  /* First time through - initialize function stat table */
1600  HASHCTL hash_ctl;
1601 
1602  memset(&hash_ctl, 0, sizeof(hash_ctl));
1603  hash_ctl.keysize = sizeof(Oid);
1604  hash_ctl.entrysize = sizeof(PgStat_BackendFunctionEntry);
1605  pgStatFunctions = hash_create("Function stat entries",
1607  &hash_ctl,
1608  HASH_ELEM | HASH_BLOBS);
1609  }
1610 
1611  /* Get the stats entry for this function, create if necessary */
1612  htabent = hash_search(pgStatFunctions, &fcinfo->flinfo->fn_oid,
1613  HASH_ENTER, &found);
1614  if (!found)
1615  MemSet(&htabent->f_counts, 0, sizeof(PgStat_FunctionCounts));
1616 
1617  fcu->fs = &htabent->f_counts;
1618 
1619  /* save stats for this function, later used to compensate for recursion */
1620  fcu->save_f_total_time = htabent->f_counts.f_total_time;
1621 
1622  /* save current backend-wide total time */
1623  fcu->save_total = total_func_time;
1624 
1625  /* get clock time as of function start */
1627 }
#define HASH_ELEM
Definition: hsearch.h:87
instr_time save_total
Definition: pgstat.h:1133
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:941
instr_time f_total_time
Definition: pgstat.h:462
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts * fs
Definition: pgstat.h:1129
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PGSTAT_FUNCTION_HASH_SIZE
Definition: pgstat.c:105
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
FmgrInfo * flinfo
Definition: fmgr.h:87
Size keysize
Definition: hsearch.h:72
Oid fn_oid
Definition: fmgr.h:59
static instr_time total_func_time
Definition: pgstat.c:275
static HTAB * pgStatFunctions
Definition: pgstat.c:196
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:1131
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry

◆ pgstat_initialize()

void pgstat_initialize ( void  )

Definition at line 2748 of file pgstat.c.

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

Referenced by AuxiliaryProcessMain(), and InitPostgres().

2749 {
2750  /* Initialize MyBEEntry */
2752  {
2755  }
2756  else
2757  {
2758  /* Must be an auxiliary process */
2760 
2761  /*
2762  * Assign the MyBEEntry for an auxiliary process. Since it doesn't
2763  * have a BackendId, the slot is statically allocated based on the
2764  * auxiliary process type (MyAuxProcType). Backends use slots indexed
2765  * in the range from 1 to MaxBackends (inclusive), so we use
2766  * MaxBackends + AuxBackendType + 1 as the index of the slot for an
2767  * auxiliary process.
2768  */
2770  }
2771 
2772  /* Set up a process-exit hook to clean up */
2774 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2592
BackendId MyBackendId
Definition: globals.c:81
int MaxBackends
Definition: globals.c:135
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
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:2953
#define InvalidBackendId
Definition: backendid.h:23
AuxProcType MyAuxProcType
Definition: bootstrap.c:71
#define Assert(condition)
Definition: c.h:732

◆ pgstat_initstats()

void pgstat_initstats ( Relation  rel)

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

1714 {
1715  Oid rel_id = rel->rd_id;
1716  char relkind = rel->rd_rel->relkind;
1717 
1718  /* We only count stats for things that have storage */
1719  if (!(relkind == RELKIND_RELATION ||
1720  relkind == RELKIND_MATVIEW ||
1721  relkind == RELKIND_INDEX ||
1722  relkind == RELKIND_TOASTVALUE ||
1723  relkind == RELKIND_SEQUENCE))
1724  {
1725  rel->pgstat_info = NULL;
1726  return;
1727  }
1728 
1730  {
1731  /* We're not counting at all */
1732  rel->pgstat_info = NULL;
1733  return;
1734  }
1735 
1736  /*
1737  * If we already set up this relation in the current transaction, nothing
1738  * to do.
1739  */
1740  if (rel->pgstat_info != NULL &&
1741  rel->pgstat_info->t_id == rel_id)
1742  return;
1743 
1744  /* Else find or make the PgStat_TableStatus entry, and update link */
1745  rel->pgstat_info = get_tabstat_entry(rel_id, rel->rd_rel->relisshared);
1746 }
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
Form_pg_class rd_rel
Definition: rel.h:84
unsigned int Oid
Definition: postgres_ext.h:31
char relkind
Definition: pg_class.h:52
bool pgstat_track_counts
Definition: pgstat.c:125
Oid rd_id
Definition: rel.h:86
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:1752
#define PGINVALID_SOCKET
Definition: port.h:33
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:187

◆ pgstat_ping()

void pgstat_ping ( void  )

Definition at line 1549 of file pgstat.c.

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

1550 {
1551  PgStat_MsgDummy msg;
1552 
1554  return;
1555 
1557  pgstat_send(&msg, sizeof(msg));
1558 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
#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:4156

◆ pgstat_progress_end_command()

void pgstat_progress_end_command ( void  )

Definition at line 3141 of file pgstat.c.

References InvalidOid, MyBEEntry, pgstat_increment_changecount_after, pgstat_increment_changecount_before, pgstat_track_activities, PROGRESS_COMMAND_INVALID, PgBackendStatus::st_progress_command, and PgBackendStatus::st_progress_command_target.

Referenced by AbortSubTransaction(), AbortTransaction(), and heap_vacuum_rel().

3142 {
3143  volatile PgBackendStatus *beentry = MyBEEntry;
3144 
3145  if (!beentry)
3146  return;
3149  return;
3150 
3155 }
Oid st_progress_command_target
Definition: pgstat.h:1053
ProgressCommandType st_progress_command
Definition: pgstat.h:1052
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
#define InvalidOid
Definition: postgres_ext.h:36
bool pgstat_track_activities
Definition: pgstat.c:124

◆ pgstat_progress_start_command()

void pgstat_progress_start_command ( ProgressCommandType  cmdtype,
Oid  relid 
)

Definition at line 3069 of file pgstat.c.

References MemSet, MyBEEntry, pgstat_increment_changecount_after, pgstat_increment_changecount_before, pgstat_track_activities, PgBackendStatus::st_progress_command, PgBackendStatus::st_progress_command_target, and PgBackendStatus::st_progress_param.

Referenced by heap_vacuum_rel().

3070 {
3071  volatile PgBackendStatus *beentry = MyBEEntry;
3072 
3073  if (!beentry || !pgstat_track_activities)
3074  return;
3075 
3077  beentry->st_progress_command = cmdtype;
3078  beentry->st_progress_command_target = relid;
3079  MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
3081 }
Oid st_progress_command_target
Definition: pgstat.h:1053
#define MemSet(start, val, len)
Definition: c.h:941
ProgressCommandType st_progress_command
Definition: pgstat.h:1052
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1054
bool pgstat_track_activities
Definition: pgstat.c:124

◆ pgstat_progress_update_multi_param()

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

Definition at line 3112 of file pgstat.c.

References Assert, i, MyBEEntry, pgstat_increment_changecount_after, pgstat_increment_changecount_before, PGSTAT_NUM_PROGRESS_PARAM, pgstat_track_activities, and PgBackendStatus::st_progress_param.

Referenced by lazy_scan_heap().

3114 {
3115  volatile PgBackendStatus *beentry = MyBEEntry;
3116  int i;
3117 
3118  if (!beentry || !pgstat_track_activities || nparam == 0)
3119  return;
3120 
3122 
3123  for (i = 0; i < nparam; ++i)
3124  {
3125  Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
3126 
3127  beentry->st_progress_param[index[i]] = val[i];
3128  }
3129 
3131 }
Definition: type.h:89
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:940
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
#define Assert(condition)
Definition: c.h:732
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1054
bool pgstat_track_activities
Definition: pgstat.c:124
int i
long val
Definition: informix.c:689

◆ pgstat_progress_update_param()

void pgstat_progress_update_param ( int  index,
int64  val 
)

Definition at line 3090 of file pgstat.c.

References Assert, MyBEEntry, pgstat_increment_changecount_after, pgstat_increment_changecount_before, PGSTAT_NUM_PROGRESS_PARAM, pgstat_track_activities, PgBackendStatus::st_progress_param, and val.

Referenced by heap_vacuum_rel(), lazy_record_dead_tuple(), lazy_scan_heap(), lazy_truncate_heap(), and lazy_vacuum_page().

3091 {
3092  volatile PgBackendStatus *beentry = MyBEEntry;
3093 
3095 
3096  if (!beentry || !pgstat_track_activities)
3097  return;
3098 
3100  beentry->st_progress_param[index] = val;
3102 }
Definition: type.h:89
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:940
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
#define Assert(condition)
Definition: c.h:732
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1054
bool pgstat_track_activities
Definition: pgstat.c:124
long val
Definition: informix.c:689

◆ pgstat_report_activity()

void pgstat_report_activity ( BackendState  state,
const char *  cmd_str 
)

Definition at line 2991 of file pgstat.c.

References GetCurrentStatementStartTimestamp(), GetCurrentTimestamp(), Min, MyBEEntry, MyProc, pgstat_increment_changecount_after, pgstat_increment_changecount_before, 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().

2992 {
2993  volatile PgBackendStatus *beentry = MyBEEntry;
2994  TimestampTz start_timestamp;
2995  TimestampTz current_timestamp;
2996  int len = 0;
2997 
2998  TRACE_POSTGRESQL_STATEMENT_STATUS(cmd_str);
2999 
3000  if (!beentry)
3001  return;
3002 
3004  {
3005  if (beentry->st_state != STATE_DISABLED)
3006  {
3007  volatile PGPROC *proc = MyProc;
3008 
3009  /*
3010  * track_activities is disabled, but we last reported a
3011  * non-disabled state. As our final update, change the state and
3012  * clear fields we will not be updating anymore.
3013  */
3015  beentry->st_state = STATE_DISABLED;
3016  beentry->st_state_start_timestamp = 0;
3017  beentry->st_activity_raw[0] = '\0';
3018  beentry->st_activity_start_timestamp = 0;
3019  /* st_xact_start_timestamp and wait_event_info are also disabled */
3020  beentry->st_xact_start_timestamp = 0;
3021  proc->wait_event_info = 0;
3023  }
3024  return;
3025  }
3026 
3027  /*
3028  * To minimize the time spent modifying the entry, fetch all the needed
3029  * data first.
3030  */
3031  start_timestamp = GetCurrentStatementStartTimestamp();
3032  if (cmd_str != NULL)
3033  {
3034  /*
3035  * Compute length of to-be-stored string unaware of multi-byte
3036  * characters. For speed reasons that'll get corrected on read, rather
3037  * than computed every write.
3038  */
3039  len = Min(strlen(cmd_str), pgstat_track_activity_query_size - 1);
3040  }
3041  current_timestamp = GetCurrentTimestamp();
3042 
3043  /*
3044  * Now update the status entry
3045  */
3047 
3048  beentry->st_state = state;
3049  beentry->st_state_start_timestamp = current_timestamp;
3050 
3051  if (cmd_str != NULL)
3052  {
3053  memcpy((char *) beentry->st_activity_raw, cmd_str, len);
3054  beentry->st_activity_raw[len] = '\0';
3055  beentry->st_activity_start_timestamp = start_timestamp;
3056  }
3057 
3059 }
uint32 wait_event_info
Definition: proc.h:176
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1015
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1592
PGPROC * MyProc
Definition: proc.c:68
int64 TimestampTz
Definition: timestamp.h:39
#define Min(x, y)
Definition: c.h:890
BackendState st_state
Definition: pgstat.h:1029
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
char * st_activity_raw
Definition: pgstat.h:1041
int pgstat_track_activity_query_size
Definition: pgstat.c:127
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1016
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
Definition: regguts.h:298
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1014
bool pgstat_track_activities
Definition: pgstat.c:124
Definition: proc.h:95
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:708

◆ pgstat_report_analyze()

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

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

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

◆ pgstat_report_appname()

void pgstat_report_appname ( const char *  appname)

Definition at line 3164 of file pgstat.c.

References MyBEEntry, NAMEDATALEN, pg_mbcliplen(), pgstat_increment_changecount_after, pgstat_increment_changecount_before, and PgBackendStatus::st_appname.

Referenced by assign_application_name(), and pgstat_bestart().

3165 {
3166  volatile PgBackendStatus *beentry = MyBEEntry;
3167  int len;
3168 
3169  if (!beentry)
3170  return;
3171 
3172  /* This should be unnecessary if GUC did its job, but be safe */
3173  len = pg_mbcliplen(appname, strlen(appname), NAMEDATALEN - 1);
3174 
3175  /*
3176  * Update my status entry, following the protocol of bumping
3177  * st_changecount before and after. We use a volatile pointer here to
3178  * ensure the compiler doesn't try to get cute.
3179  */
3181 
3182  memcpy((char *) beentry->st_appname, appname, len);
3183  beentry->st_appname[len] = '\0';
3184 
3186 }
#define NAMEDATALEN
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:820
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
char * st_appname
Definition: pgstat.h:1032

◆ pgstat_report_autovac()

void pgstat_report_autovac ( Oid  dboid)

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

1387 {
1389 
1391  return;
1392 
1394  msg.m_databaseid = dboid;
1396 
1397  pgstat_send(&msg, sizeof(msg));
1398 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1592
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:4156
TimestampTz m_start_time
Definition: pgstat.h:354

◆ pgstat_report_deadlock()

void pgstat_report_deadlock ( void  )

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

1510 {
1511  PgStat_MsgDeadlock msg;
1512 
1514  return;
1515 
1517  msg.m_databaseid = MyDatabaseId;
1518  pgstat_send(&msg, sizeof(msg));
1519 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
bool pgstat_track_counts
Definition: pgstat.c:125
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:4156

◆ pgstat_report_recovery_conflict()

void pgstat_report_recovery_conflict ( int  reason)

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

1490 {
1492 
1494  return;
1495 
1497  msg.m_databaseid = MyDatabaseId;
1498  msg.m_reason = reason;
1499  pgstat_send(&msg, sizeof(msg));
1500 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
bool pgstat_track_counts
Definition: pgstat.c:125
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:4156

◆ pgstat_report_stat()

void pgstat_report_stat ( bool  force)

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

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

◆ pgstat_report_tempfile()

void pgstat_report_tempfile ( size_t  filesize)

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

1529 {
1530  PgStat_MsgTempFile msg;
1531 
1533  return;
1534 
1536  msg.m_databaseid = MyDatabaseId;
1537  msg.m_filesize = filesize;
1538  pgstat_send(&msg, sizeof(msg));
1539 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
PgStat_MsgHdr m_hdr
Definition: pgstat.h:443
size_t m_filesize
Definition: pgstat.h:446
bool pgstat_track_counts
Definition: pgstat.c:125
#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:4156

◆ pgstat_report_vacuum()

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

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

1410 {
1411  PgStat_MsgVacuum msg;
1412 
1414  return;
1415 
1417  msg.m_databaseid = shared ? InvalidOid : MyDatabaseId;
1418  msg.m_tableoid = tableoid;
1421  msg.m_live_tuples = livetuples;
1422  msg.m_dead_tuples = deadtuples;
1423  pgstat_send(&msg, sizeof(msg));
1424 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
PgStat_Counter m_dead_tuples
Definition: pgstat.h:371
TimestampTz m_vacuumtime
Definition: pgstat.h:369
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
PgStat_Counter m_live_tuples
Definition: pgstat.h:370
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1592
Oid m_databaseid
Definition: pgstat.h:366
bool m_autovacuum
Definition: pgstat.h:368
bool pgstat_track_counts
Definition: pgstat.c:125
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3276
#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:4156
PgStat_MsgHdr m_hdr
Definition: pgstat.h:365

◆ pgstat_report_wait_end()

static void pgstat_report_wait_end ( void  )
inlinestatic

Definition at line 1272 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(), UpdateControlFile(), WaitEventSetWait(), WalSndErrorCleanup(), WalWriterMain(), write_relmap_file(), WriteControlFile(), writeTimeLineHistory(), writeTimeLineHistoryFile(), XLogFileCopy(), XLogFileInit(), XLogPageRead(), XLogRead(), and XLogWrite().

1273 {
1274  volatile PGPROC *proc = MyProc;
1275 
1276  if (!pgstat_track_activities || !proc)
1277  return;
1278 
1279  /*
1280  * Since this is a four-byte field which is always read and written as
1281  * four-bytes, updates are atomic.
1282  */
1283  proc->wait_event_info = 0;
1284 }
uint32 wait_event_info
Definition: proc.h:176
PGPROC * MyProc
Definition: proc.c:68
bool pgstat_track_activities
Definition: pgstat.c:124
Definition: proc.h:95

◆ pgstat_report_wait_start()

static void pgstat_report_wait_start ( uint32  wait_event_info)
inlinestatic

Definition at line 1248 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(), UpdateControlFile(), WaitEventSetWait(), write_relmap_file(), WriteControlFile(), writeTimeLineHistory(), writeTimeLineHistoryFile(), XLogFileCopy(), XLogFileInit(), XLogPageRead(), XLogRead(), and XLogWrite().

1249 {
1250  volatile PGPROC *proc = MyProc;
1251 
1252  if (!pgstat_track_activities || !proc)
1253  return;
1254 
1255  /*
1256  * Since this is a four-byte field which is always read and written as
1257  * four-bytes, updates are atomic.
1258  */
1259  proc->wait_event_info = wait_event_info;
1260 }
uint32 wait_event_info
Definition: proc.h:176
PGPROC * MyProc
Definition: proc.c:68
bool pgstat_track_activities
Definition: pgstat.c:124
Definition: proc.h:95

◆ pgstat_report_xact_timestamp()

void pgstat_report_xact_timestamp ( TimestampTz  tstamp)

Definition at line 3193 of file pgstat.c.

References MyBEEntry, pgstat_increment_changecount_after, pgstat_increment_changecount_before, pgstat_track_activities, and PgBackendStatus::st_xact_start_timestamp.

Referenced by AbortTransaction(), CommitTransaction(), PrepareTransaction(), and StartTransaction().

3194 {
3195  volatile PgBackendStatus *beentry = MyBEEntry;
3196 
3197  if (!pgstat_track_activities || !beentry)
3198  return;
3199 
3200  /*
3201  * Update my status entry, following the protocol of bumping
3202  * st_changecount before and after. We use a volatile pointer here to
3203  * ensure the compiler doesn't try to get cute.
3204  */
3206  beentry->st_xact_start_timestamp = tstamp;
3208 }
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2593
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1069
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1075
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1014
bool pgstat_track_activities
Definition: pgstat.c:124

◆ pgstat_reset_all()

void pgstat_reset_all ( void  )

Definition at line 684 of file pgstat.c.

References Assert, av, lengthof, pgstat_reset_remove_files(), pgstat_stat_directory, and PGSTAT_STAT_PERMANENT_DIRECTORY.

Referenced by StartupXLOG().

685 {
688 }
#define PGSTAT_STAT_PERMANENT_DIRECTORY
Definition: pgstat.h:29
char * pgstat_stat_directory
Definition: pgstat.c:133
static void pgstat_reset_remove_files(const char *directory)
Definition: pgstat.c:636

◆ pgstat_reset_counters()

void pgstat_reset_counters ( void  )

Definition at line 1309 of file pgstat.c.

References PgStat_MsgResetcounter::m_databaseid, PgStat_MsgResetcounter::m_hdr, MyDatabaseId, PGINVALID_SOCKET, PGSTAT_MTYPE_RESETCOUNTER, pgstat_send(), pgstat_setheader(), and pgStatSock.

Referenced by pg_stat_reset().

1310 {
1312 
1314  return;
1315 
1317  msg.m_databaseid = MyDatabaseId;
1318  pgstat_send(&msg, sizeof(msg));
1319 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:4169
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:148
PgStat_MsgHdr m_hdr
Definition: pgstat.h:317
#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:4156

◆ pgstat_reset_shared_counters()

void pgstat_reset_shared_counters ( const char *  )

Definition at line 1331 of file pgstat.c.

References ereport, errcode(), errhint(), errmsg(), ERROR, PgStat_MsgResetsharedcounter::m_hdr, PgStat_MsgResetsharedcounter::m_resettarget, PGINVALID_SOCKET, PGSTAT_MTYPE_RESETSHAREDCOUNTER, pgstat_send(), pgstat_setheader(), pgStatSock, RESET_ARCHIVER, and RESET_BGWRITER.

Referenced by pg_stat_reset_shared().

1332 {
1334 
1336  return;
1337 
1338  if (strcmp(target, "archiver") == 0)
1340  else if (strcmp(target, "bgwriter") == 0)
1342  else