PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 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  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_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,
  WAIT_EVENT_LOGICAL_LAUNCHER_MAIN, WAIT_EVENT_LOGICAL_APPLY_MAIN
}
 
enum  WaitEventClient {
  WAIT_EVENT_CLIENT_READ = PG_WAIT_CLIENT, WAIT_EVENT_CLIENT_WRITE, WAIT_EVENT_SSL_OPEN_SERVER, WAIT_EVENT_WAL_RECEIVER_WAIT_START,
  WAIT_EVENT_LIBPQWALRECEIVER, 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_EXECUTE_GATHER,
  WAIT_EVENT_MQ_INTERNAL, WAIT_EVENT_MQ_PUT_MESSAGE, WAIT_EVENT_MQ_RECEIVE, WAIT_EVENT_MQ_SEND,
  WAIT_EVENT_PARALLEL_FINISH, WAIT_EVENT_PARALLEL_BITMAP_SCAN, WAIT_EVENT_SAFE_SNAPSHOT, WAIT_EVENT_SYNC_REP,
  WAIT_EVENT_LOGICAL_SYNC_DATA, WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE
}
 
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_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)
 
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)
 
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 (FunctionCallInfoData *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

#define PG_STAT_TMP_DIR   "pg_stat_tmp"

Definition at line 34 of file pgstat.h.

#define PG_WAIT_ACTIVITY   0x05000000U

Definition at line 721 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

#define PG_WAIT_BUFFER_PIN   0x04000000U
#define PG_WAIT_CLIENT   0x06000000U

Definition at line 722 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

#define PG_WAIT_EXTENSION   0x07000000U
#define PG_WAIT_IO   0x0A000000U

Definition at line 726 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

#define PG_WAIT_IPC   0x08000000U

Definition at line 724 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

#define PG_WAIT_LOCK   0x03000000U
#define PG_WAIT_LWLOCK   0x01000000U
#define PG_WAIT_TIMEOUT   0x09000000U

Definition at line 725 of file pgstat.h.

Referenced by pgstat_get_wait_event(), and pgstat_get_wait_event_type().

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

Definition at line 1251 of file pgstat.h.

Referenced by ReadBufferExtended().

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

Definition at line 1246 of file pgstat.h.

Referenced by ReadBufferExtended().

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

Definition at line 1256 of file pgstat.h.

Referenced by ReadBuffer_common().

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

Definition at line 1258 of file pgstat.h.

Referenced by FlushBuffer().

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

Definition at line 1231 of file pgstat.h.

Referenced by BitmapHeapNext(), heap_fetch(), and index_fetch_heap().

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

Definition at line 1226 of file pgstat.h.

Referenced by heap_getnext(), and tablesample_getnext().

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

Definition at line 1221 of file pgstat.h.

Referenced by initscan().

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

Definition at line 1236 of file pgstat.h.

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

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

Definition at line 1241 of file pgstat.h.

Referenced by index_getbitmap(), and index_getnext_tid().

#define PGSTAT_FILE_FORMAT_ID   0x01A5BC9D
#define pgstat_increment_changecount_after (   beentry)
Value:
do { \
beentry->st_changecount++; \
Assert((beentry->st_changecount & 1) == 0); \
} while (0)
#define Assert(condition)
Definition: c.h:675
#define pg_write_barrier()
Definition: atomics.h:161

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

#define pgstat_increment_changecount_before (   beentry)
#define PGSTAT_MAX_MSG_SIZE   1000

Definition at line 206 of file pgstat.h.

Referenced by pgstat_init().

#define PGSTAT_MSG_PAYLOAD   (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))

Definition at line 207 of file pgstat.h.

#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().

#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().

#define PGSTAT_NUM_PROGRESS_PARAM   10
#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().

#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().

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

Definition at line 1024 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

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

Definition at line 1018 of file pgstat.h.

Referenced by pgstat_get_backend_current_activity(), and pgstat_read_current_status().

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"

Definition at line 29 of file pgstat.h.

Referenced by get_dbstat_filename(), and pgstat_reset_all().

#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/global.stat"
#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/global.tmp"

Definition at line 31 of file pgstat.h.

Referenced by pgstat_write_statsfiles().

Typedef Documentation

Definition at line 74 of file pgstat.h.

Enumeration Type Documentation

Enumerator
STATE_UNDEFINED 
STATE_IDLE 
STATE_RUNNING 
STATE_IDLEINTRANSACTION 
STATE_FASTPATH 
STATE_IDLEINTRANSACTION_ABORTED 
STATE_DISABLED 

Definition at line 702 of file pgstat.h.

Enumerator
RESET_ARCHIVER 
RESET_BGWRITER 

Definition at line 119 of file pgstat.h.

120 {
PgStat_Shared_Reset_Target
Definition: pgstat.h:119
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
Enumerator
PROGRESS_COMMAND_INVALID 
PROGRESS_COMMAND_VACUUM 

Definition at line 892 of file pgstat.h.

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.

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 37 of file pgstat.h.

Enumerator
WAIT_EVENT_ARCHIVER_MAIN 
WAIT_EVENT_AUTOVACUUM_MAIN 
WAIT_EVENT_BGWRITER_HIBERNATE 
WAIT_EVENT_BGWRITER_MAIN 
WAIT_EVENT_CHECKPOINTER_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 
WAIT_EVENT_LOGICAL_LAUNCHER_MAIN 
WAIT_EVENT_LOGICAL_APPLY_MAIN 

Definition at line 736 of file pgstat.h.

Enumerator
WAIT_EVENT_CLIENT_READ 
WAIT_EVENT_CLIENT_WRITE 
WAIT_EVENT_SSL_OPEN_SERVER 
WAIT_EVENT_WAL_RECEIVER_WAIT_START 
WAIT_EVENT_LIBPQWALRECEIVER 
WAIT_EVENT_WAL_SENDER_WAIT_WAL 
WAIT_EVENT_WAL_SENDER_WRITE_DATA 

Definition at line 762 of file pgstat.h.

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_METHOD_ASSIGN 
WAIT_EVENT_WAL_WRITE 

Definition at line 817 of file pgstat.h.

818 {
886 } WaitEventIO;
#define PG_WAIT_IO
Definition: pgstat.h:726
WaitEventIO
Definition: pgstat.h:817
Enumerator
WAIT_EVENT_BGWORKER_SHUTDOWN 
WAIT_EVENT_BGWORKER_STARTUP 
WAIT_EVENT_BTREE_PAGE 
WAIT_EVENT_EXECUTE_GATHER 
WAIT_EVENT_MQ_INTERNAL 
WAIT_EVENT_MQ_PUT_MESSAGE 
WAIT_EVENT_MQ_RECEIVE 
WAIT_EVENT_MQ_SEND 
WAIT_EVENT_PARALLEL_FINISH 
WAIT_EVENT_PARALLEL_BITMAP_SCAN 
WAIT_EVENT_SAFE_SNAPSHOT 
WAIT_EVENT_SYNC_REP 
WAIT_EVENT_LOGICAL_SYNC_DATA 
WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE 

Definition at line 780 of file pgstat.h.

Enumerator
WAIT_EVENT_BASE_BACKUP_THROTTLE 
WAIT_EVENT_PG_SLEEP 
WAIT_EVENT_RECOVERY_APPLY_DELAY 

Definition at line 804 of file pgstat.h.

Function Documentation

void allow_immediate_pgstat_restart ( void  )

Definition at line 727 of file pgstat.c.

References last_pgstat_start_time.

Referenced by HandleChildCrash().

728 {
730 }
static time_t last_pgstat_start_time
Definition: pgstat.c:137
void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

Definition at line 2035 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, get_tabstat_stack_level(), PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, NULL, 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().

2036 {
2037  PgStat_SubXactStatus *xact_state;
2038 
2039  /*
2040  * Transfer transactional insert/update counts into the next higher
2041  * subtransaction state.
2042  */
2043  xact_state = pgStatXactStack;
2044  if (xact_state != NULL &&
2045  xact_state->nest_level >= nestDepth)
2046  {
2048  PgStat_TableXactStatus *next_trans;
2049 
2050  /* delink xact_state from stack immediately to simplify reuse case */
2051  pgStatXactStack = xact_state->prev;
2052 
2053  for (trans = xact_state->first; trans != NULL; trans = next_trans)
2054  {
2055  PgStat_TableStatus *tabstat;
2056 
2057  next_trans = trans->next;
2058  Assert(trans->nest_level == nestDepth);
2059  tabstat = trans->parent;
2060  Assert(tabstat->trans == trans);
2061  if (isCommit)
2062  {
2063  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
2064  {
2065  if (trans->truncated)
2066  {
2067  /* propagate the truncate status one level up */
2069  /* replace upper xact stats with ours */
2070  trans->upper->tuples_inserted = trans->tuples_inserted;
2071  trans->upper->tuples_updated = trans->tuples_updated;
2072  trans->upper->tuples_deleted = trans->tuples_deleted;
2073  }
2074  else
2075  {
2076  trans->upper->tuples_inserted += trans->tuples_inserted;
2077  trans->upper->tuples_updated += trans->tuples_updated;
2078  trans->upper->tuples_deleted += trans->tuples_deleted;
2079  }
2080  tabstat->trans = trans->upper;
2081  pfree(trans);
2082  }
2083  else
2084  {
2085  /*
2086  * When there isn't an immediate parent state, we can just
2087  * reuse the record instead of going through a
2088  * palloc/pfree pushup (this works since it's all in
2089  * TopTransactionContext anyway). We have to re-link it
2090  * into the parent level, though, and that might mean
2091  * pushing a new entry into the pgStatXactStack.
2092  */
2093  PgStat_SubXactStatus *upper_xact_state;
2094 
2095  upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
2096  trans->next = upper_xact_state->first;
2097  upper_xact_state->first = trans;
2098  trans->nest_level = nestDepth - 1;
2099  }
2100  }
2101  else
2102  {
2103  /*
2104  * On abort, update top-level tabstat counts, then forget the
2105  * subtransaction
2106  */
2107 
2108  /* first restore values obliterated by truncate */
2110  /* count attempted actions regardless of commit/abort */
2111  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2112  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2113  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2114  /* inserted tuples are dead, deleted tuples are unaffected */
2115  tabstat->t_counts.t_delta_dead_tuples +=
2116  trans->tuples_inserted + trans->tuples_updated;
2117  tabstat->trans = trans->upper;
2118  pfree(trans);
2119  }
2120  }
2121  pfree(xact_state);
2122  }
2123 }
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:1757
void pfree(void *pointer)
Definition: mcxt.c:950
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:1893
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:185
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:189
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:382
PgStat_TableXactStatus * first
Definition: pgstat.c:186
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:1878
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
PgStat_TableStatus * parent
Definition: pgstat.h:177
void AtEOXact_PgStat ( bool  isCommit)

Definition at line 1952 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, NULL, 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().

1953 {
1954  PgStat_SubXactStatus *xact_state;
1955 
1956  /*
1957  * Count transaction commit or abort. (We use counters, not just bools,
1958  * in case the reporting message isn't sent right away.)
1959  */
1960  if (isCommit)
1961  pgStatXactCommit++;
1962  else
1964 
1965  /*
1966  * Transfer transactional insert/update counts into the base tabstat
1967  * entries. We don't bother to free any of the transactional state, since
1968  * it's all in TopTransactionContext and will go away anyway.
1969  */
1970  xact_state = pgStatXactStack;
1971  if (xact_state != NULL)
1972  {
1974 
1975  Assert(xact_state->nest_level == 1);
1976  Assert(xact_state->prev == NULL);
1977  for (trans = xact_state->first; trans != NULL; trans = trans->next)
1978  {
1979  PgStat_TableStatus *tabstat;
1980 
1981  Assert(trans->nest_level == 1);
1982  Assert(trans->upper == NULL);
1983  tabstat = trans->parent;
1984  Assert(tabstat->trans == trans);
1985  /* restore pre-truncate stats (if any) in case of aborted xact */
1986  if (!isCommit)
1988  /* count attempted actions regardless of commit/abort */
1989  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
1990  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
1991  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
1992  if (isCommit)
1993  {
1994  tabstat->t_counts.t_truncated = trans->truncated;
1995  if (trans->truncated)
1996  {
1997  /* forget live/dead stats seen by backend thus far */
1998  tabstat->t_counts.t_delta_live_tuples = 0;
1999  tabstat->t_counts.t_delta_dead_tuples = 0;
2000  }
2001  /* insert adds a live tuple, delete removes one */
2002  tabstat->t_counts.t_delta_live_tuples +=
2003  trans->tuples_inserted - trans->tuples_deleted;
2004  /* update and delete each create a dead tuple */
2005  tabstat->t_counts.t_delta_dead_tuples +=
2006  trans->tuples_updated + trans->tuples_deleted;
2007  /* insert, update, delete each count as one change event */
2008  tabstat->t_counts.t_changed_tuples +=
2009  trans->tuples_inserted + trans->tuples_updated +
2010  trans->tuples_deleted;
2011  }
2012  else
2013  {
2014  /* inserted tuples are dead, deleted tuples are unaffected */
2015  tabstat->t_counts.t_delta_dead_tuples +=
2016  trans->tuples_inserted + trans->tuples_updated;
2017  /* an aborted xact generates no changed_tuple events */
2018  }
2019  tabstat->trans = NULL;
2020  }
2021  }
2023 
2024  /* Make sure any stats snapshot is thrown away */
2026 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:110
PgStat_Counter tuples_updated
Definition: pgstat.h:168
static int pgStatXactCommit
Definition: pgstat.c:191
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:1893
static int pgStatXactRollback
Definition: pgstat.c:192
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:185
PgStat_Counter t_changed_tuples
Definition: pgstat.h:112
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5287
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:189
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:382
PgStat_TableXactStatus * first
Definition: pgstat.c:186
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
PgStat_TableStatus * parent
Definition: pgstat.h:177
void AtPrepare_PgStat ( void  )

Definition at line 2134 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, NULL, 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().

2135 {
2136  PgStat_SubXactStatus *xact_state;
2137 
2138  xact_state = pgStatXactStack;
2139  if (xact_state != NULL)
2140  {
2142 
2143  Assert(xact_state->nest_level == 1);
2144  Assert(xact_state->prev == NULL);
2145  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2146  {
2147  PgStat_TableStatus *tabstat;
2148  TwoPhasePgStatRecord record;
2149 
2150  Assert(trans->nest_level == 1);
2151  Assert(trans->upper == NULL);
2152  tabstat = trans->parent;
2153  Assert(tabstat->trans == trans);
2154 
2155  record.tuples_inserted = trans->tuples_inserted;
2156  record.tuples_updated = trans->tuples_updated;
2157  record.tuples_deleted = trans->tuples_deleted;
2158  record.inserted_pre_trunc = trans->inserted_pre_trunc;
2159  record.updated_pre_trunc = trans->updated_pre_trunc;
2160  record.deleted_pre_trunc = trans->deleted_pre_trunc;
2161  record.t_id = tabstat->t_id;
2162  record.t_shared = tabstat->t_shared;
2163  record.t_truncated = trans->truncated;
2164 
2166  &record, sizeof(TwoPhasePgStatRecord));
2167  }
2168  }
2169 }
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:204
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1120
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter updated_pre_trunc
Definition: pgstat.c:203
PgStat_Counter inserted_pre_trunc
Definition: pgstat.c:202
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter tuples_updated
Definition: pgstat.c:200
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:185
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:171
PgStat_Counter tuples_inserted
Definition: pgstat.c:199
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:189
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
PgStat_Counter tuples_deleted
Definition: pgstat.c:201
#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:382
PgStat_TableXactStatus * first
Definition: pgstat.c:186
PgStat_TableStatus * parent
Definition: pgstat.h:177
Size BackendStatusShmemSize ( void  )

Definition at line 2503 of file pgstat.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

2504 {
2505  Size size;
2506 
2507  /* BackendStatusArray: */
2508  size = mul_size(sizeof(PgBackendStatus), MaxBackends);
2509  /* BackendAppnameBuffer: */
2510  size = add_size(size,
2512  /* BackendClientHostnameBuffer: */
2513  size = add_size(size,
2515  /* BackendActivityBuffer: */
2516  size = add_size(size,
2518 #ifdef USE_SSL
2519  /* BackendSslStatusBuffer: */
2520  size = add_size(size,
2522 #endif
2523  return size;
2524 }
#define NAMEDATALEN
int MaxBackends
Definition: globals.c:126
int pgstat_track_activity_query_size
Definition: pgstat.c:112
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:356
void CreateSharedBackendStatus ( void  )

Definition at line 2531 of file pgstat.c.

References BackendActivityBuffer, BackendAppnameBuffer, BackendClientHostnameBuffer, buffer, i, MaxBackends, MemSet, mul_size(), NAMEDATALEN, pgstat_track_activity_query_size, ShmemInitStruct(), PgBackendStatus::st_activity, PgBackendStatus::st_appname, PgBackendStatus::st_clienthostname, and PgBackendStatus::st_sslstatus.

Referenced by CreateSharedMemoryAndSemaphores().

2532 {
2533  Size size;
2534  bool found;
2535  int i;
2536  char *buffer;
2537 
2538  /* Create or attach to the shared array */
2539  size = mul_size(sizeof(PgBackendStatus), MaxBackends);
2541  ShmemInitStruct("Backend Status Array", size, &found);
2542 
2543  if (!found)
2544  {
2545  /*
2546  * We're the first - initialize.
2547  */
2548  MemSet(BackendStatusArray, 0, size);
2549  }
2550 
2551  /* Create or attach to the shared appname buffer */
2552  size = mul_size(NAMEDATALEN, MaxBackends);
2553  BackendAppnameBuffer = (char *)
2554  ShmemInitStruct("Backend Application Name Buffer", size, &found);
2555 
2556  if (!found)
2557  {
2558  MemSet(BackendAppnameBuffer, 0, size);
2559 
2560  /* Initialize st_appname pointers. */
2561  buffer = BackendAppnameBuffer;
2562  for (i = 0; i < MaxBackends; i++)
2563  {
2565  buffer += NAMEDATALEN;
2566  }
2567  }
2568 
2569  /* Create or attach to the shared client hostname buffer */
2570  size = mul_size(NAMEDATALEN, MaxBackends);
2571  BackendClientHostnameBuffer = (char *)
2572  ShmemInitStruct("Backend Client Host Name Buffer", size, &found);
2573 
2574  if (!found)
2575  {
2577 
2578  /* Initialize st_clienthostname pointers. */
2579  buffer = BackendClientHostnameBuffer;
2580  for (i = 0; i < MaxBackends; i++)
2581  {
2583  buffer += NAMEDATALEN;
2584  }
2585  }
2586 
2587  /* Create or attach to the shared activity buffer */
2589  MaxBackends);
2590  BackendActivityBuffer = (char *)
2591  ShmemInitStruct("Backend Activity Buffer",
2593  &found);
2594 
2595  if (!found)
2596  {
2597  MemSet(BackendActivityBuffer, 0, size);
2598 
2599  /* Initialize st_activity pointers. */
2600  buffer = BackendActivityBuffer;
2601  for (i = 0; i < MaxBackends; i++)
2602  {
2605  }
2606  }
2607 
2608 #ifdef USE_SSL
2609  /* Create or attach to the shared SSL status buffer */
2610  size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
2611  BackendSslStatusBuffer = (PgBackendSSLStatus *)
2612  ShmemInitStruct("Backend SSL Status Buffer", size, &found);
2613 
2614  if (!found)
2615  {
2616  PgBackendSSLStatus *ptr;
2617 
2618  MemSet(BackendSslStatusBuffer, 0, size);
2619 
2620  /* Initialize st_sslstatus pointers. */
2621  ptr = BackendSslStatusBuffer;
2622  for (i = 0; i < MaxBackends; i++)
2623  {
2625  ptr++;
2626  }
2627  }
2628 #endif
2629 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2488
static char * BackendActivityBuffer
Definition: pgstat.c:2492
static Size BackendActivityBufferSize
Definition: pgstat.c:2493
#define MemSet(start, val, len)
Definition: c.h:857
char * st_clienthostname
Definition: pgstat.h:964
#define NAMEDATALEN
static char * BackendAppnameBuffer
Definition: pgstat.c:2490
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
int MaxBackends
Definition: globals.c:126
int pgstat_track_activity_query_size
Definition: pgstat.c:112
char * st_appname
Definition: pgstat.h:974
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
char * st_activity
Definition: pgstat.h:977
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
size_t Size
Definition: c.h:356
int i
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:968
static char * BackendClientHostnameBuffer
Definition: pgstat.c:2491
PgStat_BackendFunctionEntry* find_funcstat_entry ( Oid  func_id)

Definition at line 1558 of file pgstat.c.

References HASH_FIND, hash_search(), and NULL.

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

1559 {
1560  if (pgStatFunctions == NULL)
1561  return NULL;
1562 
1564  (void *) &func_id,
1565  HASH_FIND, NULL);
1566 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
static HTAB * pgStatFunctions
Definition: pgstat.c:167
#define NULL
Definition: c.h:229
PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

Definition at line 1733 of file pgstat.c.

References i, NULL, PgStat_TableStatus::t_id, TabStatusArray::tsa_entries, TabStatusArray::tsa_next, and TabStatusArray::tsa_used.

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

1734 {
1735  PgStat_TableStatus *entry;
1736  TabStatusArray *tsa;
1737  int i;
1738 
1739  for (tsa = pgStatTabList; tsa != NULL; tsa = tsa->tsa_next)
1740  {
1741  for (i = 0; i < tsa->tsa_used; i++)
1742  {
1743  entry = &tsa->tsa_entries[i];
1744  if (entry->t_id == rel_id)
1745  return entry;
1746  }
1747  }
1748 
1749  /* Not present */
1750  return NULL;
1751 }
int tsa_used
Definition: pgstat.c:157
struct TabStatusArray * tsa_next
Definition: pgstat.c:156
PgStat_TableStatus tsa_entries[TABSTAT_QUANTUM]
Definition: pgstat.c:158
static TabStatusArray * pgStatTabList
Definition: pgstat.c:161
#define NULL
Definition: c.h:229
int i
void pgstat_bestart ( void  )

Definition at line 2663 of file pgstat.c.

References application_name, be_tls_get_cipher(), be_tls_get_cipher_bits(), be_tls_get_compression(), be_tls_get_peerdn_name(), be_tls_get_version(), GetCurrentTimestamp(), GetSessionUserId(), InvalidOid, MemSet, MyBEEntry, MyDatabaseId, MyProcPid, MyProcPort, NAMEDATALEN, NULL, pgstat_increment_changecount_after, pgstat_increment_changecount_before, pgstat_report_appname(), pgstat_track_activity_query_size, PROGRESS_COMMAND_INVALID, Port::raddr, Port::remote_hostname, Port::SessionStartTime, PgBackendSSLStatus::ssl_bits, PgBackendSSLStatus::ssl_cipher, PgBackendSSLStatus::ssl_clientdn, PgBackendSSLStatus::ssl_compression, PgBackendSSLStatus::ssl_version, PgBackendStatus::st_activity, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_appname, 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, STATE_UNDEFINED, and strlcpy().

Referenced by InitPostgres().

2664 {
2665  TimestampTz proc_start_timestamp;
2666  Oid userid;
2667  SockAddr clientaddr;
2668  volatile PgBackendStatus *beentry;
2669 
2670  /*
2671  * To minimize the time spent modifying the PgBackendStatus entry, fetch
2672  * all the needed data first.
2673  *
2674  * If we have a MyProcPort, use its session start time (for consistency,
2675  * and to save a kernel call).
2676  */
2677  if (MyProcPort)
2678  proc_start_timestamp = MyProcPort->SessionStartTime;
2679  else
2680  proc_start_timestamp = GetCurrentTimestamp();
2681  userid = GetSessionUserId();
2682 
2683  /*
2684  * We may not have a MyProcPort (eg, if this is the autovacuum process).
2685  * If so, use all-zeroes client address, which is dealt with specially in
2686  * pg_stat_get_backend_client_addr and pg_stat_get_backend_client_port.
2687  */
2688  if (MyProcPort)
2689  memcpy(&clientaddr, &MyProcPort->raddr, sizeof(clientaddr));
2690  else
2691  MemSet(&clientaddr, 0, sizeof(clientaddr));
2692 
2693  /*
2694  * Initialize my status entry, following the protocol of bumping
2695  * st_changecount before and after; and make sure it's even afterwards. We
2696  * use a volatile pointer here to ensure the compiler doesn't try to get
2697  * cute.
2698  */
2699  beentry = MyBEEntry;
2700  do
2701  {
2703  } while ((beentry->st_changecount & 1) == 0);
2704 
2705  beentry->st_procpid = MyProcPid;
2706  beentry->st_proc_start_timestamp = proc_start_timestamp;
2707  beentry->st_activity_start_timestamp = 0;
2708  beentry->st_state_start_timestamp = 0;
2709  beentry->st_xact_start_timestamp = 0;
2710  beentry->st_databaseid = MyDatabaseId;
2711  beentry->st_userid = userid;
2712  beentry->st_clientaddr = clientaddr;
2715  NAMEDATALEN);
2716  else
2717  beentry->st_clienthostname[0] = '\0';
2718 #ifdef USE_SSL
2719  if (MyProcPort && MyProcPort->ssl != NULL)
2720  {
2721  beentry->st_ssl = true;
2727  }
2728  else
2729  {
2730  beentry->st_ssl = false;
2731  }
2732 #else
2733  beentry->st_ssl = false;
2734 #endif
2735  beentry->st_state = STATE_UNDEFINED;
2736  beentry->st_appname[0] = '\0';
2737  beentry->st_activity[0] = '\0';
2738  /* Also make sure the last byte in each string area is always 0 */
2739  beentry->st_clienthostname[NAMEDATALEN - 1] = '\0';
2740  beentry->st_appname[NAMEDATALEN - 1] = '\0';
2741  beentry->st_activity[pgstat_track_activity_query_size - 1] = '\0';
2744 
2745  /*
2746  * we don't zero st_progress_param here to save cycles; nobody should
2747  * examine it until st_progress_command has been set to something other
2748  * than PROGRESS_COMMAND_INVALID
2749  */
2750 
2752 
2753  /* Update app name to current GUC setting */
2754  if (application_name)
2756 }
bool ssl_compression
Definition: pgstat.h:916
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:918
Oid st_progress_command_target
Definition: pgstat.h:989
int MyProcPid
Definition: globals.c:38
struct Port * MyProcPort
Definition: globals.c:40
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:957
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
int64 TimestampTz
Definition: timestamp.h:39
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:917
SockAddr st_clientaddr
Definition: pgstat.h:963
#define MemSet(start, val, len)
Definition: c.h:857
ProgressCommandType st_progress_command
Definition: pgstat.h:988
unsigned int Oid
Definition: postgres_ext.h:31
BackendState st_state
Definition: pgstat.h:971
char * st_clienthostname
Definition: pgstat.h:964
Oid GetSessionUserId(void)
Definition: miscinit.c:317
Oid st_databaseid
Definition: pgstat.h:961
#define NAMEDATALEN
char * remote_hostname
Definition: libpq-be.h:124
SockAddr raddr
Definition: libpq-be.h:122
bool be_tls_get_compression(Port *port)
TimestampTz SessionStartTime
Definition: libpq-be.h:151
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
int pgstat_track_activity_query_size
Definition: pgstat.c:112
TimestampTz st_state_start_timestamp
Definition: pgstat.h:958
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
char * st_appname
Definition: pgstat.h:974
int be_tls_get_cipher_bits(Port *port)
Oid MyDatabaseId
Definition: globals.c:76
void be_tls_get_version(Port *port, char *ptr, size_t len)
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:2975
#define InvalidOid
Definition: postgres_ext.h:36
void be_tls_get_peerdn_name(Port *port, char *ptr, size_t len)
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:229
char * st_activity
Definition: pgstat.h:977
int st_procpid
Definition: pgstat.h:952
char * application_name
Definition: guc.c:472
void be_tls_get_cipher(Port *port, char *ptr, size_t len)
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:956
int st_changecount
Definition: pgstat.h:949
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:955
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:968
char ssl_clientdn[NAMEDATALEN]
Definition: pgstat.h:919
void pgstat_clear_snapshot ( void  )

Definition at line 5287 of file pgstat.c.

References localNumBackends, MemoryContextDelete(), and NULL.

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

5288 {
5289  /* Release memory, if any was allocated */
5290  if (pgStatLocalContext)
5292 
5293  /* Reset variables */
5295  pgStatDBHash = NULL;
5297  localNumBackends = 0;
5298 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
#define NULL
Definition: c.h:229
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:215
static HTAB * pgStatDBHash
Definition: pgstat.c:214
static int localNumBackends
Definition: pgstat.c:216
static MemoryContext pgStatLocalContext
Definition: pgstat.c:213
void pgstat_count_heap_delete ( Relation  rel)

Definition at line 1852 of file pgstat.c.

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

Referenced by heap_abort_speculative(), and heap_delete().

1853 {
1854  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1855 
1856  if (pgstat_info != NULL)
1857  {
1858  /* We have to log the effect at the proper transactional level */
1859  int nest_level = GetCurrentTransactionNestLevel();
1860 
1861  if (pgstat_info->trans == NULL ||
1862  pgstat_info->trans->nest_level != nest_level)
1863  add_tabstat_xact_level(pgstat_info, nest_level);
1864 
1865  pgstat_info->trans->tuples_deleted++;
1866  }
1867 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:761
#define NULL
Definition: c.h:229
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1779
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 1806 of file pgstat.c.

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

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

1807 {
1808  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1809 
1810  if (pgstat_info != NULL)
1811  {
1812  /* We have to log the effect at the proper transactional level */
1813  int nest_level = GetCurrentTransactionNestLevel();
1814 
1815  if (pgstat_info->trans == NULL ||
1816  pgstat_info->trans->nest_level != nest_level)
1817  add_tabstat_xact_level(pgstat_info, nest_level);
1818 
1819  pgstat_info->trans->tuples_inserted += n;
1820  }
1821 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:761
#define NULL
Definition: c.h:229
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1779
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

Definition at line 1827 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, NULL, 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().

1828 {
1829  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1830 
1831  if (pgstat_info != NULL)
1832  {
1833  /* We have to log the effect at the proper transactional level */
1834  int nest_level = GetCurrentTransactionNestLevel();
1835 
1836  if (pgstat_info->trans == NULL ||
1837  pgstat_info->trans->nest_level != nest_level)
1838  add_tabstat_xact_level(pgstat_info, nest_level);
1839 
1840  pgstat_info->trans->tuples_updated++;
1841 
1842  /* t_tuples_hot_updated is nontransactional, so just advance it */
1843  if (hot)
1844  pgstat_info->t_counts.t_tuples_hot_updated++;
1845  }
1846 }
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:761
#define NULL
Definition: c.h:229
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1779
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
void pgstat_count_truncate ( Relation  rel)

Definition at line 1907 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, NULL, 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 ExecuteTruncate().

1908 {
1909  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1910 
1911  if (pgstat_info != NULL)
1912  {
1913  /* We have to log the effect at the proper transactional level */
1914  int nest_level = GetCurrentTransactionNestLevel();
1915 
1916  if (pgstat_info->trans == NULL ||
1917  pgstat_info->trans->nest_level != nest_level)
1918  add_tabstat_xact_level(pgstat_info, nest_level);
1919 
1920  pgstat_truncate_save_counters(pgstat_info->trans);
1921  pgstat_info->trans->tuples_inserted = 0;
1922  pgstat_info->trans->tuples_updated = 0;
1923  pgstat_info->trans->tuples_deleted = 0;
1924  }
1925 }
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:761
#define NULL
Definition: c.h:229
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:1779
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:1878
void pgstat_drop_database ( Oid  databaseid)

Definition at line 1175 of file pgstat.c.

References PgStat_MsgDropdb::m_databaseid, PgStat_MsgDropdb::m_hdr, PGINVALID_SOCKET, PGSTAT_MTYPE_DROPDB, pgstat_send(), pgstat_setheader(), and pgStatSock.

Referenced by dropdb(), and pgstat_vacuum_stat().

1176 {
1177  PgStat_MsgDropdb msg;
1178 
1180  return;
1181 
1183  msg.m_databaseid = databaseid;
1184  pgstat_send(&msg, sizeof(msg));
1185 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
Oid m_databaseid
Definition: pgstat.h:306
PgStat_MsgHdr m_hdr
Definition: pgstat.h:305
#define PGINVALID_SOCKET
Definition: port.h:24
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 1578 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, NULL, PgStat_FunctionCallUsage::save_f_total_time, PgStat_FunctionCallUsage::save_total, and total_func_time.

Referenced by call_pltcl_start_proc(), EventTriggerInvoke(), ExecCallTriggerFunc(), ExecInterpExpr(), ExecMakeFunctionResultSet(), ExecMakeTableFunctionResult(), and fmgr_security_definer().

1579 {
1580  PgStat_FunctionCounts *fs = fcu->fs;
1581  instr_time f_total;
1582  instr_time f_others;
1583  instr_time f_self;
1584 
1585  /* stats not wanted? */
1586  if (fs == NULL)
1587  return;
1588 
1589  /* total elapsed time in this function call */
1590  INSTR_TIME_SET_CURRENT(f_total);
1591  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
1592 
1593  /* self usage: elapsed minus anything already charged to other calls */
1594  f_others = total_func_time;
1595  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
1596  f_self = f_total;
1597  INSTR_TIME_SUBTRACT(f_self, f_others);
1598 
1599  /* update backend-wide total time */
1601 
1602  /*
1603  * Compute the new f_total_time as the total elapsed time added to the
1604  * pre-call value of f_total_time. This is necessary to avoid
1605  * double-counting any time taken by recursive calls of myself. (We do
1606  * not need any similar kluge for self time, since that already excludes
1607  * any recursive calls.)
1608  */
1609  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
1610 
1611  /* update counters in function stats table */
1612  if (finalize)
1613  fs->f_numcalls++;
1614  fs->f_total_time = f_total;
1615  INSTR_TIME_ADD(fs->f_self_time, f_self);
1616 
1617  /* indicate that we have something to send */
1618  have_function_stats = true;
1619 }
instr_time f_self_time
Definition: pgstat.h:463
instr_time save_total
Definition: pgstat.h:1069
struct timeval instr_time
Definition: instr_time.h:147
instr_time f_total_time
Definition: pgstat.h:462
PgStat_FunctionCounts * fs
Definition: pgstat.h:1065
PgStat_Counter f_numcalls
Definition: pgstat.h:461
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:167
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:155
static instr_time total_func_time
Definition: pgstat.c:242
static bool have_function_stats
Definition: pgstat.c:173
#define NULL
Definition: c.h:229
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:153
instr_time save_f_total_time
Definition: pgstat.h:1067
PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 2458 of file pgstat.c.

References archiverStats, and backend_read_statsfile().

Referenced by pg_stat_get_archiver().

2459 {
2461 
2462  return &archiverStats;
2463 }
static void backend_read_statsfile(void)
Definition: pgstat.c:5133
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:223
PgBackendStatus* pgstat_fetch_stat_beentry ( int  beid)
PgStat_StatDBEntry* pgstat_fetch_stat_dbentry ( Oid  dbid)

Definition at line 2286 of file pgstat.c.

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

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

2287 {
2288  /*
2289  * If not done for this transaction, read the statistics collector stats
2290  * file into some hash tables.
2291  */
2293 
2294  /*
2295  * Lookup the requested database; return NULL if not found
2296  */
2298  (void *) &dbid,
2299  HASH_FIND, NULL);
2300 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
static void backend_read_statsfile(void)
Definition: pgstat.c:5133
#define NULL
Definition: c.h:229
static HTAB * pgStatDBHash
Definition: pgstat.c:214
PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  funcid)

Definition at line 2369 of file pgstat.c.

References backend_read_statsfile(), PgStat_StatDBEntry::functions, HASH_FIND, hash_search(), MyDatabaseId, NULL, 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().

2370 {
2371  PgStat_StatDBEntry *dbentry;
2372  PgStat_StatFuncEntry *funcentry = NULL;
2373 
2374  /* load the stats file if needed */
2376 
2377  /* Lookup our database, then find the requested function. */
2379  if (dbentry != NULL && dbentry->functions != NULL)
2380  {
2381  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
2382  (void *) &func_id,
2383  HASH_FIND, NULL);
2384  }
2385 
2386  return funcentry;
2387 }
HTAB * functions
Definition: pgstat.h:607
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2286
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
static void backend_read_statsfile(void)
Definition: pgstat.c:5133
Oid MyDatabaseId
Definition: globals.c:76
#define NULL
Definition: c.h:229
LocalPgBackendStatus* pgstat_fetch_stat_local_beentry ( int  beid)

Definition at line 2423 of file pgstat.c.

References localNumBackends, NULL, and pgstat_read_current_status().

Referenced by pg_stat_get_activity(), and pg_stat_get_progress_info().

2424 {
2426 
2427  if (beid < 1 || beid > localNumBackends)
2428  return NULL;
2429 
2430  return &localBackendStatusTable[beid - 1];
2431 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3029
#define NULL
Definition: c.h:229
static LocalPgBackendStatus * localBackendStatusTable
Definition: pgstat.c:215
static int localNumBackends
Definition: pgstat.c:216
int pgstat_fetch_stat_numbackends ( void  )

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

2443 {
2445 
2446  return localNumBackends;
2447 }
static void pgstat_read_current_status(void)
Definition: pgstat.c:3029
static int localNumBackends
Definition: pgstat.c:216
PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 2313 of file pgstat.c.

References backend_read_statsfile(), HASH_FIND, hash_search(), InvalidOid, MyDatabaseId, NULL, 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().

2314 {
2315  Oid dbid;
2316  PgStat_StatDBEntry *dbentry;
2317  PgStat_StatTabEntry *tabentry;
2318 
2319  /*
2320  * If not done for this transaction, read the statistics collector stats
2321  * file into some hash tables.
2322  */
2324 
2325  /*
2326  * Lookup our database, then look in its table hash table.
2327  */
2328  dbid = MyDatabaseId;
2330  (void *) &dbid,
2331  HASH_FIND, NULL);
2332  if (dbentry != NULL && dbentry->tables != NULL)
2333  {
2334  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2335  (void *) &relid,
2336  HASH_FIND, NULL);
2337  if (tabentry)
2338  return tabentry;
2339  }
2340 
2341  /*
2342  * If we didn't find it, maybe it's a shared table.
2343  */
2344  dbid = InvalidOid;
2346  (void *) &dbid,
2347  HASH_FIND, NULL);
2348  if (dbentry != NULL && dbentry->tables != NULL)
2349  {
2350  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2351  (void *) &relid,
2352  HASH_FIND, NULL);
2353  if (tabentry)
2354  return tabentry;
2355  }
2356 
2357  return NULL;
2358 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
static void backend_read_statsfile(void)
Definition: pgstat.c:5133
Oid MyDatabaseId
Definition: globals.c:76
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
static HTAB * pgStatDBHash
Definition: pgstat.c:214
const char* pgstat_get_backend_current_activity ( int  pid,
bool  checkUser 
)

Definition at line 3700 of file pgstat.c.

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

Referenced by DeadLockReport().

3701 {
3702  PgBackendStatus *beentry;
3703  int i;
3704 
3705  beentry = BackendStatusArray;
3706  for (i = 1; i <= MaxBackends; i++)
3707  {
3708  /*
3709  * Although we expect the target backend's entry to be stable, that
3710  * doesn't imply that anyone else's is. To avoid identifying the
3711  * wrong backend, while we check for a match to the desired PID we
3712  * must follow the protocol of retrying if st_changecount changes
3713  * while we examine the entry, or if it's odd. (This might be
3714  * unnecessary, since fetching or storing an int is almost certainly
3715  * atomic, but let's play it safe.) We use a volatile pointer here to
3716  * ensure the compiler doesn't try to get cute.
3717  */
3718  volatile PgBackendStatus *vbeentry = beentry;
3719  bool found;
3720 
3721  for (;;)
3722  {
3723  int before_changecount;
3724  int after_changecount;
3725 
3726  pgstat_save_changecount_before(vbeentry, before_changecount);
3727 
3728  found = (vbeentry->st_procpid == pid);
3729 
3730  pgstat_save_changecount_after(vbeentry, after_changecount);
3731 
3732  if (before_changecount == after_changecount &&
3733  (before_changecount & 1) == 0)
3734  break;
3735 
3736  /* Make sure we can break out of loop if stuck... */
3738  }
3739 
3740  if (found)
3741  {
3742  /* Now it is safe to use the non-volatile pointer */
3743  if (checkUser && !superuser() && beentry->st_userid != GetUserId())
3744  return "<insufficient privilege>";
3745  else if (*(beentry->st_activity) == '\0')
3746  return "<command string not enabled>";
3747  else
3748  return beentry->st_activity;
3749  }
3750 
3751  beentry++;
3752  }
3753 
3754  /* If we get here, caller is in error ... */
3755  return "<backend information not available>";
3756 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2488
Oid GetUserId(void)
Definition: miscinit.c:283
bool superuser(void)
Definition: superuser.c:47
int MaxBackends
Definition: globals.c:126
#define pgstat_save_changecount_before(beentry, save_changecount)
Definition: pgstat.h:1018
char * st_activity
Definition: pgstat.h:977
#define pgstat_save_changecount_after(beentry, save_changecount)
Definition: pgstat.h:1024
int st_procpid
Definition: pgstat.h:952
int i
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
const char* pgstat_get_crashed_backend_activity ( int  pid,
char *  buffer,
int  buflen 
)

Definition at line 3775 of file pgstat.c.

References ascii_safe_strlcpy(), BackendStatusArray, buffer, i, MaxBackends, Min, NULL, pgstat_track_activity_query_size, PgBackendStatus::st_activity, and PgBackendStatus::st_procpid.

Referenced by LogChildExit().

3776 {
3777  volatile PgBackendStatus *beentry;
3778  int i;
3779 
3780  beentry = BackendStatusArray;
3781 
3782  /*
3783  * We probably shouldn't get here before shared memory has been set up,
3784  * but be safe.
3785  */
3786  if (beentry == NULL || BackendActivityBuffer == NULL)
3787  return NULL;
3788 
3789  for (i = 1; i <= MaxBackends; i++)
3790  {
3791  if (beentry->st_procpid == pid)
3792  {
3793  /* Read pointer just once, so it can't change after validation */
3794  const char *activity = beentry->st_activity;
3795  const char *activity_last;
3796 
3797  /*
3798  * We mustn't access activity string before we verify that it
3799  * falls within the BackendActivityBuffer. To make sure that the
3800  * entire string including its ending is contained within the
3801  * buffer, subtract one activity length from the buffer size.
3802  */
3805 
3806  if (activity < BackendActivityBuffer ||
3807  activity > activity_last)
3808  return NULL;
3809 
3810  /* If no string available, no point in a report */
3811  if (activity[0] == '\0')
3812  return NULL;
3813 
3814  /*
3815  * Copy only ASCII-safe characters so we don't run into encoding
3816  * problems when reporting the message; and be sure not to run off
3817  * the end of memory.
3818  */
3819  ascii_safe_strlcpy(buffer, activity,
3820  Min(buflen, pgstat_track_activity_query_size));
3821 
3822  return buffer;
3823  }
3824 
3825  beentry++;
3826  }
3827 
3828  /* PID not found */
3829  return NULL;
3830 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2488
static char * BackendActivityBuffer
Definition: pgstat.c:2492
#define Min(x, y)
Definition: c.h:806
static Size BackendActivityBufferSize
Definition: pgstat.c:2493
void ascii_safe_strlcpy(char *dest, const char *src, size_t destsiz)
Definition: ascii.c:173
int MaxBackends
Definition: globals.c:126
int pgstat_track_activity_query_size
Definition: pgstat.c:112
#define NULL
Definition: c.h:229
char * st_activity
Definition: pgstat.h:977
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
int st_procpid
Definition: pgstat.h:952
int i
const char* pgstat_get_wait_event ( uint32  wait_event_info)

Definition at line 3198 of file pgstat.c.

References GetLockNameFromTagType(), GetLWLockIdentifier(), NULL, 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().

3199 {
3200  uint32 classId;
3201  uint16 eventId;
3202  const char *event_name;
3203 
3204  /* report process as not waiting. */
3205  if (wait_event_info == 0)
3206  return NULL;
3207 
3208  classId = wait_event_info & 0xFF000000;
3209  eventId = wait_event_info & 0x0000FFFF;
3210 
3211  switch (classId)
3212  {
3213  case PG_WAIT_LWLOCK:
3214  event_name = GetLWLockIdentifier(classId, eventId);
3215  break;
3216  case PG_WAIT_LOCK:
3217  event_name = GetLockNameFromTagType(eventId);
3218  break;
3219  case PG_WAIT_BUFFER_PIN:
3220  event_name = "BufferPin";
3221  break;
3222  case PG_WAIT_ACTIVITY:
3223  {
3224  WaitEventActivity w = (WaitEventActivity) wait_event_info;
3225 
3226  event_name = pgstat_get_wait_activity(w);
3227  break;
3228  }
3229  case PG_WAIT_CLIENT:
3230  {
3231  WaitEventClient w = (WaitEventClient) wait_event_info;
3232 
3233  event_name = pgstat_get_wait_client(w);
3234  break;
3235  }
3236  case PG_WAIT_EXTENSION:
3237  event_name = "Extension";
3238  break;
3239  case PG_WAIT_IPC:
3240  {
3241  WaitEventIPC w = (WaitEventIPC) wait_event_info;
3242 
3243  event_name = pgstat_get_wait_ipc(w);
3244  break;
3245  }
3246  case PG_WAIT_TIMEOUT:
3247  {
3248  WaitEventTimeout w = (WaitEventTimeout) wait_event_info;
3249 
3250  event_name = pgstat_get_wait_timeout(w);
3251  break;
3252  }
3253  case PG_WAIT_IO:
3254  {
3255  WaitEventIO w = (WaitEventIO) wait_event_info;
3256 
3257  event_name = pgstat_get_wait_io(w);
3258  break;
3259  }
3260  default:
3261  event_name = "unknown wait event";
3262  break;
3263  }
3264 
3265  return event_name;
3266 }
#define PG_WAIT_LOCK
Definition: pgstat.h:719
WaitEventIPC
Definition: pgstat.h:780
static const char * pgstat_get_wait_timeout(WaitEventTimeout w)
Definition: pgstat.c:3437
static const char * pgstat_get_wait_ipc(WaitEventIPC w)
Definition: pgstat.c:3376
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:721
#define PG_WAIT_IO
Definition: pgstat.h:726
static const char * pgstat_get_wait_activity(WaitEventActivity w)
Definition: pgstat.c:3275
unsigned short uint16
Definition: c.h:267
#define PG_WAIT_CLIENT
Definition: pgstat.h:722
WaitEventClient
Definition: pgstat.h:762
static const char * pgstat_get_wait_client(WaitEventClient w)
Definition: pgstat.c:3336
unsigned int uint32
Definition: c.h:268
WaitEventTimeout
Definition: pgstat.h:804
#define PG_WAIT_EXTENSION
Definition: pgstat.h:723
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:720
#define NULL
Definition: c.h:229
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1039
WaitEventIO
Definition: pgstat.h:817
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:725
#define PG_WAIT_IPC
Definition: pgstat.h:724
const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)
Definition: lwlock.c:703
static const char * pgstat_get_wait_io(WaitEventIO w)
Definition: pgstat.c:3465
#define PG_WAIT_LWLOCK
Definition: pgstat.h:718
WaitEventActivity
Definition: pgstat.h:736
const char* pgstat_get_wait_event_type ( uint32  wait_event_info)

Definition at line 3143 of file pgstat.c.

References NULL, 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().

3144 {
3145  uint32 classId;
3146  const char *event_type;
3147 
3148  /* report process as not waiting. */
3149  if (wait_event_info == 0)
3150  return NULL;
3151 
3152  classId = wait_event_info & 0xFF000000;
3153 
3154  switch (classId)
3155  {
3156  case PG_WAIT_LWLOCK:
3157  event_type = "LWLock";
3158  break;
3159  case PG_WAIT_LOCK:
3160  event_type = "Lock";
3161  break;
3162  case PG_WAIT_BUFFER_PIN:
3163  event_type = "BufferPin";
3164  break;
3165  case PG_WAIT_ACTIVITY:
3166  event_type = "Activity";
3167  break;
3168  case PG_WAIT_CLIENT:
3169  event_type = "Client";
3170  break;
3171  case PG_WAIT_EXTENSION:
3172  event_type = "Extension";
3173  break;
3174  case PG_WAIT_IPC:
3175  event_type = "IPC";
3176  break;
3177  case PG_WAIT_TIMEOUT:
3178  event_type = "Timeout";
3179  break;
3180  case PG_WAIT_IO:
3181  event_type = "IO";
3182  break;
3183  default:
3184  event_type = "???";
3185  break;
3186  }
3187 
3188  return event_type;
3189 }
#define PG_WAIT_LOCK
Definition: pgstat.h:719
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:721
#define PG_WAIT_IO
Definition: pgstat.h:726
#define PG_WAIT_CLIENT
Definition: pgstat.h:722
unsigned int uint32
Definition: c.h:268
#define PG_WAIT_EXTENSION
Definition: pgstat.h:723
#define PG_WAIT_BUFFER_PIN
Definition: pgstat.h:720
#define NULL
Definition: c.h:229
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:725
#define PG_WAIT_IPC
Definition: pgstat.h:724
#define PG_WAIT_LWLOCK
Definition: pgstat.h:718
void pgstat_init ( void  )

Definition at line 321 of file pgstat.c.

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

Referenced by PostmasterMain().

322 {
323  ACCEPT_TYPE_ARG3 alen;
324  struct addrinfo *addrs = NULL,
325  *addr,
326  hints;
327  int ret;
328  fd_set rset;
329  struct timeval tv;
330  char test_byte;
331  int sel_res;
332  int tries = 0;
333 
334 #define TESTBYTEVAL ((char) 199)
335 
336  /*
337  * This static assertion verifies that we didn't mess up the calculations
338  * involved in selecting maximum payload sizes for our UDP messages.
339  * Because the only consequence of overrunning PGSTAT_MAX_MSG_SIZE would
340  * be silent performance loss from fragmentation, it seems worth having a
341  * compile-time cross-check that we didn't.
342  */
344  "maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE");
345 
346  /*
347  * Create the UDP socket for sending and receiving statistic messages
348  */
349  hints.ai_flags = AI_PASSIVE;
350  hints.ai_family = AF_UNSPEC;
351  hints.ai_socktype = SOCK_DGRAM;
352  hints.ai_protocol = 0;
353  hints.ai_addrlen = 0;
354  hints.ai_addr = NULL;
355  hints.ai_canonname = NULL;
356  hints.ai_next = NULL;
357  ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
358  if (ret || !addrs)
359  {
360  ereport(LOG,
361  (errmsg("could not resolve \"localhost\": %s",
362  gai_strerror(ret))));
363  goto startup_failed;
364  }
365 
366  /*
367  * On some platforms, pg_getaddrinfo_all() may return multiple addresses
368  * only one of which will actually work (eg, both IPv6 and IPv4 addresses
369  * when kernel will reject IPv6). Worse, the failure may occur at the
370  * bind() or perhaps even connect() stage. So we must loop through the
371  * results till we find a working combination. We will generate LOG
372  * messages, but no error, for bogus combinations.
373  */
374  for (addr = addrs; addr; addr = addr->ai_next)
375  {
376 #ifdef HAVE_UNIX_SOCKETS
377  /* Ignore AF_UNIX sockets, if any are returned. */
378  if (addr->ai_family == AF_UNIX)
379  continue;
380 #endif
381 
382  if (++tries > 1)
383  ereport(LOG,
384  (errmsg("trying another address for the statistics collector")));
385 
386  /*
387  * Create the socket.
388  */
389  if ((pgStatSock = socket(addr->ai_family, SOCK_DGRAM, 0)) == PGINVALID_SOCKET)
390  {
391  ereport(LOG,
393  errmsg("could not create socket for statistics collector: %m")));
394  continue;
395  }
396 
397  /*
398  * Bind it to a kernel assigned port on localhost and get the assigned
399  * port via getsockname().
400  */
401  if (bind(pgStatSock, addr->ai_addr, addr->ai_addrlen) < 0)
402  {
403  ereport(LOG,
405  errmsg("could not bind socket for statistics collector: %m")));
408  continue;
409  }
410 
411  alen = sizeof(pgStatAddr);
412  if (getsockname(pgStatSock, (struct sockaddr *) & pgStatAddr, &alen) < 0)
413  {
414  ereport(LOG,
416  errmsg("could not get address of socket for statistics collector: %m")));
419  continue;
420  }
421 
422  /*
423  * Connect the socket to its own address. This saves a few cycles by
424  * not having to respecify the target address on every send. This also
425  * provides a kernel-level check that only packets from this same
426  * address will be received.
427  */
428  if (connect(pgStatSock, (struct sockaddr *) & pgStatAddr, alen) < 0)
429  {
430  ereport(LOG,
432  errmsg("could not connect socket for statistics collector: %m")));
435  continue;
436  }
437 
438  /*
439  * Try to send and receive a one-byte test message on the socket. This
440  * is to catch situations where the socket can be created but will not
441  * actually pass data (for instance, because kernel packet filtering
442  * rules prevent it).
443  */
444  test_byte = TESTBYTEVAL;
445 
446 retry1:
447  if (send(pgStatSock, &test_byte, 1, 0) != 1)
448  {
449  if (errno == EINTR)
450  goto retry1; /* if interrupted, just retry */
451  ereport(LOG,
453  errmsg("could not send test message on socket for statistics collector: %m")));
456  continue;
457  }
458 
459  /*
460  * There could possibly be a little delay before the message can be
461  * received. We arbitrarily allow up to half a second before deciding
462  * it's broken.
463  */
464  for (;;) /* need a loop to handle EINTR */
465  {
466  FD_ZERO(&rset);
467  FD_SET(pgStatSock, &rset);
468 
469  tv.tv_sec = 0;
470  tv.tv_usec = 500000;
471  sel_res = select(pgStatSock + 1, &rset, NULL, NULL, &tv);
472  if (sel_res >= 0 || errno != EINTR)
473  break;
474  }
475  if (sel_res < 0)
476  {
477  ereport(LOG,
479  errmsg("select() failed in statistics collector: %m")));
482  continue;
483  }
484  if (sel_res == 0 || !FD_ISSET(pgStatSock, &rset))
485  {
486  /*
487  * This is the case we actually think is likely, so take pains to
488  * give a specific message for it.
489  *
490  * errno will not be set meaningfully here, so don't use it.
491  */
492  ereport(LOG,
493  (errcode(ERRCODE_CONNECTION_FAILURE),
494  errmsg("test message did not get through on socket for statistics collector")));
497  continue;
498  }
499 
500  test_byte++; /* just make sure variable is changed */
501 
502 retry2:
503  if (recv(pgStatSock, &test_byte, 1, 0) != 1)
504  {
505  if (errno == EINTR)
506  goto retry2; /* if interrupted, just retry */
507  ereport(LOG,
509  errmsg("could not receive test message on socket for statistics collector: %m")));
512  continue;
513  }
514 
515  if (test_byte != TESTBYTEVAL) /* strictly paranoia ... */
516  {
517  ereport(LOG,
518  (errcode(ERRCODE_INTERNAL_ERROR),
519  errmsg("incorrect test message transmission on socket for statistics collector")));
522  continue;
523  }
524 
525  /* If we get here, we have a working socket */
526  break;
527  }
528 
529  /* Did we find a working address? */
530  if (!addr || pgStatSock == PGINVALID_SOCKET)
531  goto startup_failed;
532 
533  /*
534  * Set the socket to non-blocking IO. This ensures that if the collector
535  * falls behind, statistics messages will be discarded; backends won't
536  * block waiting to send messages to the collector.
537  */
539  {
540  ereport(LOG,
542  errmsg("could not set statistics collector socket to nonblocking mode: %m")));
543  goto startup_failed;
544  }
545 
546  pg_freeaddrinfo_all(hints.ai_family, addrs);
547 
548  return;
549 
550 startup_failed:
551  ereport(LOG,
552  (errmsg("disabling statistics collector for lack of working socket")));
553 
554  if (addrs)
555  pg_freeaddrinfo_all(hints.ai_family, addrs);
556 
560 
561  /*
562  * Adjust GUC variables to suppress useless activity, and for debugging
563  * purposes (seeing track_counts off is a clue that we failed here). We
564  * use PGC_S_OVERRIDE because there is no point in trying to turn it back
565  * on from postgresql.conf without a restart.
566  */
567  SetConfigOption("track_counts", "off", PGC_INTERNAL, PGC_S_OVERRIDE);
568 }
#define send(s, buf, len, flags)
Definition: win32.h:386
#define connect(s, name, namelen)
Definition: win32.h:383
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
Definition: ip.c:88
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
#define closesocket
Definition: port.h:328
#define socket(af, type, protocol)
Definition: win32.h:379
int errcode(int sqlerrcode)
Definition: elog.c:575
#define select(n, r, w, e, timeout)
Definition: win32.h:384
#define recv(s, buf, len, flags)
Definition: win32.h:385
#define LOG
Definition: elog.h:26
#define gai_strerror
Definition: getaddrinfo.h:148
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:757
#define bind(s, addr, addrlen)
Definition: win32.h:380
#define TESTBYTEVAL
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6651
#define AI_PASSIVE
Definition: getaddrinfo.h:64
#define ereport(elevel, rest)
Definition: elog.h:122
int errcode_for_socket_access(void)
Definition: elog.c:669
#define PGSTAT_MAX_MSG_SIZE
Definition: pgstat.h:206
#define PGINVALID_SOCKET
Definition: port.h:24
#define EINTR
Definition: win32.h:295
static struct sockaddr_storage pgStatAddr
Definition: pgstat.c:135
#define NULL
Definition: c.h:229
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:21
struct addrinfo * ai_next
Definition: getaddrinfo.h:109
int errmsg(const char *fmt,...)
Definition: elog.c:797
void pgstat_init_function_usage ( FunctionCallInfoData fcinfo,
PgStat_FunctionCallUsage fcu 
)

Definition at line 1506 of file pgstat.c.

References HASHCTL::entrysize, PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCallUsage::f_start, PgStat_FunctionCounts::f_total_time, FunctionCallInfoData::flinfo, FmgrInfo::fn_oid, PgStat_FunctionCallUsage::fs, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), INSTR_TIME_SET_CURRENT, HASHCTL::keysize, MemSet, NULL, 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(), ExecInterpExpr(), ExecMakeFunctionResultSet(), ExecMakeTableFunctionResult(), and fmgr_security_definer().

1508 {
1509  PgStat_BackendFunctionEntry *htabent;
1510  bool found;
1511 
1512  if (pgstat_track_functions <= fcinfo->flinfo->fn_stats)
1513  {
1514  /* stats not wanted */
1515  fcu->fs = NULL;
1516  return;
1517  }
1518 
1519  if (!pgStatFunctions)
1520  {
1521  /* First time through - initialize function stat table */
1522  HASHCTL hash_ctl;
1523 
1524  memset(&hash_ctl, 0, sizeof(hash_ctl));
1525  hash_ctl.keysize = sizeof(Oid);
1526  hash_ctl.entrysize = sizeof(PgStat_BackendFunctionEntry);
1527  pgStatFunctions = hash_create("Function stat entries",
1529  &hash_ctl,
1530  HASH_ELEM | HASH_BLOBS);
1531  }
1532 
1533  /* Get the stats entry for this function, create if necessary */
1534  htabent = hash_search(pgStatFunctions, &fcinfo->flinfo->fn_oid,
1535  HASH_ENTER, &found);
1536  if (!found)
1537  MemSet(&htabent->f_counts, 0, sizeof(PgStat_FunctionCounts));
1538 
1539  fcu->fs = &htabent->f_counts;
1540 
1541  /* save stats for this function, later used to compensate for recursion */
1542  fcu->save_f_total_time = htabent->f_counts.f_total_time;
1543 
1544  /* save current backend-wide total time */
1545  fcu->save_total = total_func_time;
1546 
1547  /* get clock time as of function start */
1549 }
#define HASH_ELEM
Definition: hsearch.h:87
instr_time save_total
Definition: pgstat.h:1069
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:857
instr_time f_total_time
Definition: pgstat.h:462
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts * fs
Definition: pgstat.h:1065
FmgrInfo * flinfo
Definition: fmgr.h:79
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PGSTAT_FUNCTION_HASH_SIZE
Definition: pgstat.c:102
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
Size keysize
Definition: hsearch.h:72
Oid fn_oid
Definition: fmgr.h:59
static instr_time total_func_time
Definition: pgstat.c:242
static HTAB * pgStatFunctions
Definition: pgstat.c:167
#define NULL
Definition: c.h:229
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:153
instr_time save_f_total_time
Definition: pgstat.h:1067
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
void pgstat_initialize ( void  )

Definition at line 2643 of file pgstat.c.

References Assert, MaxBackends, MyBackendId, on_shmem_exit(), and pgstat_beshutdown_hook().

Referenced by InitPostgres().

2644 {
2645  /* Initialize MyBEEntry */
2648 
2649  /* Set up a process-exit hook to clean up */
2651 }
static PgBackendStatus * BackendStatusArray
Definition: pgstat.c:2488
BackendId MyBackendId
Definition: globals.c:72
int MaxBackends
Definition: globals.c:126
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:348
static void pgstat_beshutdown_hook(int code, Datum arg)
Definition: pgstat.c:2768
#define Assert(condition)
Definition: c.h:675
void pgstat_initstats ( Relation  rel)

Definition at line 1635 of file pgstat.c.

References get_tabstat_entry(), NULL, PGINVALID_SOCKET, RelationData::pgstat_info, pgstat_track_counts, pgStatSock, RelationData::rd_id, RelationData::rd_rel, RELKIND_INDEX, RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_TOASTVALUE, and PgStat_TableStatus::t_id.

Referenced by relation_open(), and try_relation_open().

1636 {
1637  Oid rel_id = rel->rd_id;
1638  char relkind = rel->rd_rel->relkind;
1639 
1640  /* We only count stats for things that have storage */
1641  if (!(relkind == RELKIND_RELATION ||
1642  relkind == RELKIND_MATVIEW ||
1643  relkind == RELKIND_INDEX ||
1644  relkind == RELKIND_TOASTVALUE ||
1645  relkind == RELKIND_SEQUENCE))
1646  {
1647  rel->pgstat_info = NULL;
1648  return;
1649  }
1650 
1652  {
1653  /* We're not counting at all */
1654  rel->pgstat_info = NULL;
1655  return;
1656  }
1657 
1658  /*
1659  * If we already set up this relation in the current transaction, nothing
1660  * to do.
1661  */
1662  if (rel->pgstat_info != NULL &&
1663  rel->pgstat_info->t_id == rel_id)
1664  return;
1665 
1666  /* Else find or make the PgStat_TableStatus entry, and update link */
1667  rel->pgstat_info = get_tabstat_entry(rel_id, rel->rd_rel->relisshared);
1668 }
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
#define RELKIND_MATVIEW
Definition: pg_class.h:165
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
bool pgstat_track_counts
Definition: pgstat.c:110
Oid rd_id
Definition: rel.h:116
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:1674
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
#define PGINVALID_SOCKET
Definition: port.h:24
#define NULL
Definition: c.h:229
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
#define RELKIND_INDEX
Definition: pg_class.h:161
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
void pgstat_ping ( void  )

Definition at line 1471 of file pgstat.c.

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

1472 {
1473  PgStat_MsgDummy msg;
1474 
1476  return;
1477 
1479  pgstat_send(&msg, sizeof(msg));
1480 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
#define PGINVALID_SOCKET
Definition: port.h:24
PgStat_MsgHdr m_hdr
Definition: pgstat.h:216
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
void pgstat_progress_end_command ( void  )

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

2953 {
2954  volatile PgBackendStatus *beentry = MyBEEntry;
2955 
2956  if (!beentry)
2957  return;
2960  return;
2961 
2966 }
Oid st_progress_command_target
Definition: pgstat.h:989
ProgressCommandType st_progress_command
Definition: pgstat.h:988
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
#define InvalidOid
Definition: postgres_ext.h:36
bool pgstat_track_activities
Definition: pgstat.c:109
void pgstat_progress_start_command ( ProgressCommandType  cmdtype,
Oid  relid 
)

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

2881 {
2882  volatile PgBackendStatus *beentry = MyBEEntry;
2883 
2884  if (!beentry || !pgstat_track_activities)
2885  return;
2886 
2888  beentry->st_progress_command = cmdtype;
2889  beentry->st_progress_command_target = relid;
2890  MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
2892 }
Oid st_progress_command_target
Definition: pgstat.h:989
#define MemSet(start, val, len)
Definition: c.h:857
ProgressCommandType st_progress_command
Definition: pgstat.h:988
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:990
bool pgstat_track_activities
Definition: pgstat.c:109
void pgstat_progress_update_multi_param ( int  nparam,
const int *  index,
const int64 *  val 
)

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

2925 {
2926  volatile PgBackendStatus *beentry = MyBEEntry;
2927  int i;
2928 
2929  if (!beentry || !pgstat_track_activities || nparam == 0)
2930  return;
2931 
2933 
2934  for (i = 0; i < nparam; ++i)
2935  {
2936  Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
2937 
2938  beentry->st_progress_param[index[i]] = val[i];
2939  }
2940 
2942 }
Definition: type.h:90
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:898
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
#define Assert(condition)
Definition: c.h:675
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:990
bool pgstat_track_activities
Definition: pgstat.c:109
int i
long val
Definition: informix.c:689
void pgstat_progress_update_param ( int  index,
int64  val 
)

Definition at line 2901 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 lazy_record_dead_tuple(), lazy_scan_heap(), lazy_truncate_heap(), lazy_vacuum_page(), and lazy_vacuum_rel().

2902 {
2903  volatile PgBackendStatus *beentry = MyBEEntry;
2904 
2906 
2907  if (!beentry || !pgstat_track_activities)
2908  return;
2909 
2911  beentry->st_progress_param[index] = val;
2913 }
Definition: type.h:90
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:898
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
#define Assert(condition)
Definition: c.h:675
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:990
bool pgstat_track_activities
Definition: pgstat.c:109
long val
Definition: informix.c:689
void pgstat_report_activity ( BackendState  state,
const char *  cmd_str 
)

Definition at line 2806 of file pgstat.c.

References GetCurrentStatementStartTimestamp(), GetCurrentTimestamp(), MyBEEntry, MyProc, NULL, pg_mbcliplen(), pgstat_increment_changecount_after, pgstat_increment_changecount_before, pgstat_track_activities, pgstat_track_activity_query_size, PgBackendStatus::st_activity, 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 apply_handle_begin(), apply_handle_commit(), autovac_report_activity(), exec_bind_message(), exec_execute_message(), exec_parse_message(), exec_simple_query(), initialize_worker_spi(), LogicalRepApplyLoop(), ParallelQueryMain(), PostgresMain(), and WalSndLoop().

2807 {
2808  volatile PgBackendStatus *beentry = MyBEEntry;
2809  TimestampTz start_timestamp;
2810  TimestampTz current_timestamp;
2811  int len = 0;
2812 
2813  TRACE_POSTGRESQL_STATEMENT_STATUS(cmd_str);
2814 
2815  if (!beentry)
2816  return;
2817 
2819  {
2820  if (beentry->st_state != STATE_DISABLED)
2821  {
2822  volatile PGPROC *proc = MyProc;
2823 
2824  /*
2825  * track_activities is disabled, but we last reported a
2826  * non-disabled state. As our final update, change the state and
2827  * clear fields we will not be updating anymore.
2828  */
2830  beentry->st_state = STATE_DISABLED;
2831  beentry->st_state_start_timestamp = 0;
2832  beentry->st_activity[0] = '\0';
2833  beentry->st_activity_start_timestamp = 0;
2834  /* st_xact_start_timestamp and wait_event_info are also disabled */
2835  beentry->st_xact_start_timestamp = 0;
2836  proc->wait_event_info = 0;
2838  }
2839  return;
2840  }
2841 
2842  /*
2843  * To minimize the time spent modifying the entry, fetch all the needed
2844  * data first.
2845  */
2846  start_timestamp = GetCurrentStatementStartTimestamp();
2847  if (cmd_str != NULL)
2848  {
2849  len = pg_mbcliplen(cmd_str, strlen(cmd_str),
2851  }
2852  current_timestamp = GetCurrentTimestamp();
2853 
2854  /*
2855  * Now update the status entry
2856  */
2858 
2859  beentry->st_state = state;
2860  beentry->st_state_start_timestamp = current_timestamp;
2861 
2862  if (cmd_str != NULL)
2863  {
2864  memcpy((char *) beentry->st_activity, cmd_str, len);
2865  beentry->st_activity[len] = '\0';
2866  beentry->st_activity_start_timestamp = start_timestamp;
2867  }
2868 
2870 }
uint32 wait_event_info
Definition: proc.h:172
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:957
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
PGPROC * MyProc
Definition: proc.c:67
int64 TimestampTz
Definition: timestamp.h:39
BackendState st_state
Definition: pgstat.h:971
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:831
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
int pgstat_track_activity_query_size
Definition: pgstat.c:112
TimestampTz st_state_start_timestamp
Definition: pgstat.h:958
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
#define NULL
Definition: c.h:229
char * st_activity
Definition: pgstat.h:977
Definition: regguts.h:298
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:956
bool pgstat_track_activities
Definition: pgstat.c:109
Definition: proc.h:94
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:717
void pgstat_report_analyze ( Relation  rel,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples,
bool  resetcounter 
)

Definition at line 1358 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, NULL, 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().

1361 {
1362  PgStat_MsgAnalyze msg;
1363 
1365  return;
1366 
1367  /*
1368  * Unlike VACUUM, ANALYZE might be running inside a transaction that has
1369  * already inserted and/or deleted rows in the target table. ANALYZE will
1370  * have counted such rows as live or dead respectively. Because we will
1371  * report our counts of such rows at transaction end, we should subtract
1372  * off these counts from what we send to the collector now, else they'll
1373  * be double-counted after commit. (This approach also ensures that the
1374  * collector ends up with the right numbers if we abort instead of
1375  * committing.)
1376  */
1377  if (rel->pgstat_info != NULL)
1378  {
1380 
1381  for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
1382  {
1383  livetuples -= trans->tuples_inserted - trans->tuples_deleted;
1384  deadtuples -= trans->tuples_updated + trans->tuples_deleted;
1385  }
1386  /* count stuff inserted by already-aborted subxacts, too */
1387  deadtuples -= rel->pgstat_info->t_counts.t_delta_dead_tuples;
1388  /* Since ANALYZE's counts are estimates, we could have underflowed */
1389  livetuples = Max(livetuples, 0);
1390  deadtuples = Max(deadtuples, 0);
1391  }
1392 
1394  msg.m_databaseid = rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId;
1395  msg.m_tableoid = RelationGetRelid(rel);
1397  msg.m_resetcounter = resetcounter;
1399  msg.m_live_tuples = livetuples;
1400  msg.m_dead_tuples = deadtuples;
1401  pgstat_send(&msg, sizeof(msg));
1402 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
PgStat_Counter tuples_updated
Definition: pgstat.h:168
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
TimestampTz m_analyzetime
Definition: pgstat.h:387
PgStat_TableCounts t_counts
Definition: pgstat.h:158
Form_pg_class rd_rel
Definition: rel.h:114
bool m_resetcounter
Definition: pgstat.h:386
bool pgstat_track_counts
Definition: pgstat.c:110
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:2988
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:24
Oid MyDatabaseId
Definition: globals.c:76
#define InvalidOid
Definition: postgres_ext.h:36
#define Max(x, y)
Definition: c.h:800
#define NULL
Definition: c.h:229
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
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:382
PgStat_Counter m_dead_tuples
Definition: pgstat.h:389
#define RelationGetRelid(relation)
Definition: rel.h:417
void pgstat_report_appname ( const char *  appname)

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

2976 {
2977  volatile PgBackendStatus *beentry = MyBEEntry;
2978  int len;
2979 
2980  if (!beentry)
2981  return;
2982 
2983  /* This should be unnecessary if GUC did its job, but be safe */
2984  len = pg_mbcliplen(appname, strlen(appname), NAMEDATALEN - 1);
2985 
2986  /*
2987  * Update my status entry, following the protocol of bumping
2988  * st_changecount before and after. We use a volatile pointer here to
2989  * ensure the compiler doesn't try to get cute.
2990  */
2992 
2993  memcpy((char *) beentry->st_appname, appname, len);
2994  beentry->st_appname[len] = '\0';
2995 
2997 }
#define NAMEDATALEN
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:831
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
char * st_appname
Definition: pgstat.h:974
void pgstat_report_autovac ( Oid  dboid)

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

1309 {
1311 
1313  return;
1314 
1316  msg.m_databaseid = dboid;
1318 
1319  pgstat_send(&msg, sizeof(msg));
1320 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
PgStat_MsgHdr m_hdr
Definition: pgstat.h:352
#define PGINVALID_SOCKET
Definition: port.h:24
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
TimestampTz m_start_time
Definition: pgstat.h:354
void pgstat_report_deadlock ( void  )

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

1432 {
1433  PgStat_MsgDeadlock msg;
1434 
1436  return;
1437 
1439  msg.m_databaseid = MyDatabaseId;
1440  pgstat_send(&msg, sizeof(msg));
1441 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
bool pgstat_track_counts
Definition: pgstat.c:110
PgStat_MsgHdr m_hdr
Definition: pgstat.h:529
#define PGINVALID_SOCKET
Definition: port.h:24
Oid MyDatabaseId
Definition: globals.c:76
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
void pgstat_report_recovery_conflict ( int  reason)

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

1412 {
1414 
1416  return;
1417 
1419  msg.m_databaseid = MyDatabaseId;
1420  msg.m_reason = reason;
1421  pgstat_send(&msg, sizeof(msg));
1422 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
bool pgstat_track_counts
Definition: pgstat.c:110
PgStat_MsgHdr m_hdr
Definition: pgstat.h:431
#define PGINVALID_SOCKET
Definition: port.h:24
Oid MyDatabaseId
Definition: globals.c:76
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
void pgstat_report_stat ( bool  force)

Definition at line 748 of file pgstat.c.

References Assert, GetCurrentTransactionStopTimestamp(), have_function_stats, i, InvalidOid, PgStat_MsgTabstat::m_databaseid, PgStat_MsgTabstat::m_entry, PgStat_MsgTabstat::m_nentries, MemSet, MyDatabaseId, now(), NULL, 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 pgstat_beshutdown_hook(), and PostgresMain().

749 {
750  /* we assume this inits to all zeroes: */
751  static const PgStat_TableCounts all_zeroes;
752  static TimestampTz last_report = 0;
753 
755  PgStat_MsgTabstat regular_msg;
756  PgStat_MsgTabstat shared_msg;
757  TabStatusArray *tsa;
758  int i;
759 
760  /* Don't expend a clock check if nothing to do */
761  if ((pgStatTabList == NULL || pgStatTabList->tsa_used == 0) &&
762  pgStatXactCommit == 0 && pgStatXactRollback == 0 &&
764  return;
765 
766  /*
767  * Don't send a message unless it's been at least PGSTAT_STAT_INTERVAL
768  * msec since we last sent one, or the caller wants to force stats out.
769  */
771  if (!force &&
773  return;
774  last_report = now;
775 
776  /*
777  * Scan through the TabStatusArray struct(s) to find tables that actually
778  * have counts, and build messages to send. We have to separate shared
779  * relations from regular ones because the databaseid field in the message
780  * header has to depend on that.
781  */
782  regular_msg.m_databaseid = MyDatabaseId;
783  shared_msg.m_databaseid = InvalidOid;
784  regular_msg.m_nentries = 0;
785  shared_msg.m_nentries = 0;
786 
787  for (tsa = pgStatTabList; tsa != NULL; tsa = tsa->tsa_next)
788  {
789  for (i = 0; i < tsa->tsa_used; i++)
790  {
791  PgStat_TableStatus *entry = &tsa->tsa_entries[i];
792  PgStat_MsgTabstat *this_msg;
793  PgStat_TableEntry *this_ent;
794 
795  /* Shouldn't have any pending transaction-dependent counts */
796  Assert(entry->trans == NULL);
797 
798  /*
799  * Ignore entries that didn't accumulate any actual counts, such
800  * as indexes that were opened by the planner but not used.
801  */
802  if (memcmp(&entry->t_counts, &all_zeroes,
803  sizeof(PgStat_TableCounts)) == 0)
804  continue;
805 
806  /*
807  * OK, insert data into the appropriate message, and send if full.
808  */
809  this_msg = entry->t_shared ? &shared_msg : &regular_msg;
810  this_ent = &this_msg->m_entry[this_msg->m_nentries];
811  this_ent->t_id = entry->t_id;
812  memcpy(&this_ent->t_counts, &entry->t_counts,
813  sizeof(PgStat_TableCounts));
814  if (++this_msg->m_nentries >= PGSTAT_NUM_TABENTRIES)
815  {
816  pgstat_send_tabstat(this_msg);
817  this_msg->m_nentries = 0;
818  }
819  }
820  /* zero out TableStatus structs after use */
821  MemSet(tsa->tsa_entries, 0,
822  tsa->tsa_used * sizeof(PgStat_TableStatus));
823  tsa->tsa_used = 0;
824  }
825 
826  /*
827  * Send partial messages. Make sure that any pending xact commit/abort
828  * gets counted, even if there are no table stats to send.
829  */
830  if (regular_msg.m_nentries > 0 ||
832  pgstat_send_tabstat(&regular_msg);
833  if (shared_msg.m_nentries > 0)
834  pgstat_send_tabstat(&shared_msg);
835 
836  /* Now, send function statistics */
838 }
int tsa_used
Definition: pgstat.c:157
static int pgStatXactCommit
Definition: pgstat.c:191
int64 TimestampTz
Definition: timestamp.h:39
#define MemSet(start, val, len)
Definition: c.h:857
struct TabStatusArray * tsa_next
Definition: pgstat.c:156
PgStat_TableCounts t_counts
Definition: pgstat.h:158
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1648
static void pgstat_send_tabstat(PgStat_MsgTabstat *tsmsg)
Definition: pgstat.c:844
static int pgStatXactRollback
Definition: pgstat.c:192
#define PGSTAT_STAT_INTERVAL
Definition: pgstat.c:76
PgStat_TableStatus tsa_entries[TABSTAT_QUANTUM]
Definition: pgstat.c:158
#define PGSTAT_NUM_TABENTRIES
Definition: pgstat.h:263
Oid MyDatabaseId
Definition: globals.c:76
static TabStatusArray * pgStatTabList
Definition: pgstat.c:161
#define InvalidOid
Definition: postgres_ext.h:36
static bool have_function_stats
Definition: pgstat.c:173
#define NULL
Definition: c.h:229
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition: xact.c:729
#define Assert(condition)
Definition: c.h:675
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:888
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1533
void pgstat_report_tempfile ( size_t  filesize)

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

1451 {
1452  PgStat_MsgTempFile msg;
1453 
1455  return;
1456 
1458  msg.m_databaseid = MyDatabaseId;
1459  msg.m_filesize = filesize;
1460  pgstat_send(&msg, sizeof(msg));
1461 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
PgStat_MsgHdr m_hdr
Definition: pgstat.h:443
size_t m_filesize
Definition: pgstat.h:446
bool pgstat_track_counts
Definition: pgstat.c:110
#define PGINVALID_SOCKET
Definition: port.h:24
Oid MyDatabaseId
Definition: globals.c:76
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
void pgstat_report_vacuum ( Oid  tableoid,
bool  shared,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples 
)

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

1332 {
1333  PgStat_MsgVacuum msg;
1334 
1336  return;
1337 
1339  msg.m_databaseid = shared ? InvalidOid : MyDatabaseId;
1340  msg.m_tableoid = tableoid;
1343  msg.m_live_tuples = livetuples;
1344  msg.m_dead_tuples = deadtuples;
1345  pgstat_send(&msg, sizeof(msg));
1346 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
PgStat_Counter m_dead_tuples
Definition: pgstat.h:371
TimestampTz m_vacuumtime
Definition: pgstat.h:369
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
PgStat_Counter m_live_tuples
Definition: pgstat.h:370
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
Oid m_databaseid
Definition: pgstat.h:366
bool m_autovacuum
Definition: pgstat.h:368
bool pgstat_track_counts
Definition: pgstat.c:110
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:2988
#define PGINVALID_SOCKET
Definition: port.h:24
Oid MyDatabaseId
Definition: globals.c:76
#define InvalidOid
Definition: postgres_ext.h:36
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
PgStat_MsgHdr m_hdr
Definition: pgstat.h:365
static void pgstat_report_wait_end ( void  )
inlinestatic

Definition at line 1205 of file pgstat.h.

References MyProc, pgstat_track_activities, and PGPROC::wait_event_info.

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

1206 {
1207  volatile PGPROC *proc = MyProc;
1208 
1209  if (!pgstat_track_activities || !proc)
1210  return;
1211 
1212  /*
1213  * Since this is a four-byte field which is always read and written as
1214  * four-bytes, updates are atomic.
1215  */
1216  proc->wait_event_info = 0;
1217 }
uint32 wait_event_info
Definition: proc.h:172
PGPROC * MyProc
Definition: proc.c:67
bool pgstat_track_activities
Definition: pgstat.c:109
Definition: proc.h:94
static void pgstat_report_wait_start ( uint32  wait_event_info)
inlinestatic

Definition at line 1181 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(), load_relmap_file(), LWLockReportWaitStart(), ReadControlFile(), ReadTwoPhaseFile(), RecheckDataDirLockFile(), RecreateTwoPhaseFile(), ReorderBufferRestoreChanges(), ReorderBufferSerializeChange(), RestoreSlotFromDisk(), SaveSlotToPath(), SendTimeLineHistory(), SimpleLruFlush(), SlruPhysicalReadPage(), SlruPhysicalWritePage(), SnapBuildRestore(), SnapBuildSerialize(), UpdateControlFile(), WaitEventSetWait(), write_relmap_file(), WriteControlFile(), writeTimeLineHistory(), writeTimeLineHistoryFile(), XLogFileCopy(), XLogFileInit(), XLogPageRead(), XLogRead(), and XLogWrite().

1182 {
1183  volatile PGPROC *proc = MyProc;
1184 
1185  if (!pgstat_track_activities || !proc)
1186  return;
1187 
1188  /*
1189  * Since this is a four-byte field which is always read and written as
1190  * four-bytes, updates are atomic.
1191  */
1192  proc->wait_event_info = wait_event_info;
1193 }
uint32 wait_event_info
Definition: proc.h:172
PGPROC * MyProc
Definition: proc.c:67
bool pgstat_track_activities
Definition: pgstat.c:109
Definition: proc.h:94
void pgstat_report_xact_timestamp ( TimestampTz  tstamp)

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

3005 {
3006  volatile PgBackendStatus *beentry = MyBEEntry;
3007 
3008  if (!pgstat_track_activities || !beentry)
3009  return;
3010 
3011  /*
3012  * Update my status entry, following the protocol of bumping
3013  * st_changecount before and after. We use a volatile pointer here to
3014  * ensure the compiler doesn't try to get cute.
3015  */
3017  beentry->st_xact_start_timestamp = tstamp;
3019 }
static PgBackendStatus * MyBEEntry
Definition: pgstat.c:2489
#define pgstat_increment_changecount_before(beentry)
Definition: pgstat.h:1005
#define pgstat_increment_changecount_after(beentry)
Definition: pgstat.h:1011
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:956
bool pgstat_track_activities
Definition: pgstat.c:109
void pgstat_reset_all ( void  )

Definition at line 622 of file pgstat.c.

References pgstat_reset_remove_files(), pgstat_stat_directory, and PGSTAT_STAT_PERMANENT_DIRECTORY.

Referenced by StartupXLOG().

623 {
626 }
#define PGSTAT_STAT_PERMANENT_DIRECTORY
Definition: pgstat.h:29
char * pgstat_stat_directory
Definition: pgstat.c:118
static void pgstat_reset_remove_files(const char *directory)
Definition: pgstat.c:574
void pgstat_reset_counters ( void  )

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

1232 {
1234 
1236  return;
1237 
1239  msg.m_databaseid = MyDatabaseId;
1240  pgstat_send(&msg, sizeof(msg));
1241 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
PgStat_MsgHdr m_hdr
Definition: pgstat.h:317
#define PGINVALID_SOCKET
Definition: port.h:24
Oid MyDatabaseId
Definition: globals.c:76
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
void pgstat_reset_shared_counters ( const char *  )

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

1254 {
1256 
1258  return;
1259 
1260  if (strcmp(target, "archiver") == 0)
1262  else if (strcmp(target, "bgwriter") == 0)
1264  else
1265  ereport(ERROR,
1266  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1267  errmsg("unrecognized reset target: \"%s\"", target),
1268  errhint("Target must be \"archiver\" or \"bgwriter\".")));
1269 
1271  pgstat_send(&msg, sizeof(msg));
1272 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
int errhint(const char *fmt,...)
Definition: elog.c:987
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define PGINVALID_SOCKET
Definition: port.h:24
PgStat_Shared_Reset_Target m_resettarget
Definition: pgstat.h:329
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
int errmsg(const char *fmt,...)
Definition: elog.c:797
void pgstat_reset_single_counter ( Oid  objectid,
PgStat_Single_Reset_Type  type 
)

Definition at line 1284 of file pgstat.c.

References PgStat_MsgResetsinglecounter::m_databaseid, PgStat_MsgResetsinglecounter::m_hdr, PgStat_MsgResetsinglecounter::m_objectid, PgStat_MsgResetsinglecounter::m_resettype, MyDatabaseId, PGINVALID_SOCKET, PGSTAT_MTYPE_RESETSINGLECOUNTER, pgstat_send(), pgstat_setheader(), and pgStatSock.

Referenced by pg_stat_reset_single_function_counters(), and pg_stat_reset_single_table_counters().

1285 {
1287 
1289  return;
1290 
1292  msg.m_databaseid = MyDatabaseId;
1293  msg.m_resettype = type;
1294  msg.m_objectid = objoid;
1295 
1296  pgstat_send(&msg, sizeof(msg));
1297 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
#define PGINVALID_SOCKET
Definition: port.h:24
Oid MyDatabaseId
Definition: globals.c:76
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
PgStat_Single_Reset_Type m_resettype
Definition: pgstat.h:341
void pgstat_send_archiver ( const char *  xlog,
bool  failed 
)

Definition at line 3889 of file pgstat.c.

References GetCurrentTimestamp(), PgStat_MsgArchiver::m_failed, PgStat_MsgArchiver::m_hdr, PgStat_MsgArchiver::m_timestamp, PgStat_MsgArchiver::m_xlog, PGSTAT_MTYPE_ARCHIVER, pgstat_send(), pgstat_setheader(), and StrNCpy.

Referenced by pgarch_ArchiverCopyLoop().

3890 {
3891  PgStat_MsgArchiver msg;
3892 
3893  /*
3894  * Prepare and send the message
3895  */
3897  msg.m_failed = failed;
3898  StrNCpy(msg.m_xlog, xlog, sizeof(msg.m_xlog));
3900  pgstat_send(&msg, sizeof(msg));
3901 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
char m_xlog[MAX_XFN_CHARS+1]
Definition: pgstat.h:401
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
TimestampTz m_timestamp
Definition: pgstat.h:402
#define StrNCpy(dst, src, len)
Definition: c.h:830
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
PgStat_MsgHdr m_hdr
Definition: pgstat.h:399
void pgstat_send_bgwriter ( void  )

Definition at line 3910 of file pgstat.c.

References PgStat_MsgBgWriter::m_hdr, MemSet, PGSTAT_MTYPE_BGWRITER, pgstat_send(), and pgstat_setheader().

Referenced by BackgroundWriterMain(), CheckpointerMain(), and CheckpointWriteDelay().

3911 {
3912  /* We assume this initializes to zeroes */
3913  static const PgStat_MsgBgWriter all_zeroes;
3914 
3915  /*
3916  * This function can be called even if nothing at all has happened. In
3917  * this case, avoid sending a completely empty message to the stats
3918  * collector.
3919  */
3920  if (memcmp(&BgWriterStats, &all_zeroes, sizeof(PgStat_MsgBgWriter)) == 0)
3921  return;
3922 
3923  /*
3924  * Prepare and send the message
3925  */
3928 
3929  /*
3930  * Clear out the statistics buffer, so it can be re-used.
3931  */
3932  MemSet(&BgWriterStats, 0, sizeof(BgWriterStats));
3933 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3859
PgStat_MsgHdr m_hdr
Definition: pgstat.h:411
PgStat_MsgBgWriter BgWriterStats
Definition: pgstat.c:127
#define MemSet(start, val, len)
Definition: c.h:857
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3846
int pgstat_start ( void  )

Definition at line 664 of file pgstat.c.

References ClosePostmasterPorts(), dsm_detach_all(), ereport, errmsg(), fork_process(), InitPostmasterChild(), last_pgstat_start_time, LOG, NULL, PGINVALID_SOCKET, PGSharedMemoryDetach(), PGSTAT_RESTART_INTERVAL, PgstatCollectorMain(), and pgStatSock.

Referenced by reaper(), ServerLoop(), and sigusr1_handler().

665 {
666  time_t curtime;
667  pid_t pgStatPid;
668 
669  /*
670  * Check that the socket is there, else pgstat_init failed and we can do
671  * nothing useful.
672  */
674  return 0;
675 
676  /*
677  * Do nothing if too soon since last collector start. This is a safety
678  * valve to protect against continuous respawn attempts if the collector
679  * is dying immediately at launch. Note that since we will be re-called
680  * from the postmaster main loop, we will get another chance later.
681  */
682  curtime = time(NULL);
683  if ((unsigned int) (curtime - last_pgstat_start_time) <
684  (unsigned int) PGSTAT_RESTART_INTERVAL)
685  return 0;
686  last_pgstat_start_time = curtime;
687 
688  /*
689  * Okay, fork off the collector.
690  */
691 #ifdef EXEC_BACKEND
692  switch ((pgStatPid = pgstat_forkexec()))
693 #else
694  switch ((pgStatPid = fork_process()))
695 #endif
696  {
697  case -1:
698  ereport(LOG,
699  (errmsg("could not fork statistics collector: %m")));
700  return 0;
701 
702 #ifndef EXEC_BACKEND
703  case 0:
704  /* in postmaster child ... */
706 
707  /* Close the postmaster's sockets */
708  ClosePostmasterPorts(false);
709 
710  /* Drop our connection to postmaster's shared memory, as well */
711  dsm_detach_all();
713 
715  break;
716 #endif
717 
718  default:
719  return (int) pgStatPid;
720  }
721 
722  /* shouldn't get here */
723  return 0;
724 }
#define PGSTAT_RESTART_INTERVAL
Definition: pgstat.c:88
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgstat.c:3946
void InitPostmasterChild(void)
Definition: miscinit.c:175
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:133
pid_t fork_process(void)
Definition: fork_process.c:31
#define LOG
Definition: elog.h:26
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2421
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:768
#define ereport(elevel, rest)
Definition: elog.h:122
#define PGINVALID_SOCKET
Definition: port.h:24
#define NULL
Definition: c.h:229
void dsm_detach_all(void)
Definition: dsm.c:654
static time_t last_pgstat_start_time
Definition: pgstat.c:137
int errmsg(const char *fmt,...)
Definition: elog.c:797
void pgstat_twophase_postabort ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 2252 of file pgstat.c.

References TwoPhasePgStatRecord::deleted_pre_trunc, get_tabstat_entry(), TwoPhasePgStatRecord::inserted_pre_trunc, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, TwoPhasePgStatRecord::t_id, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncated, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, and TwoPhasePgStatRecord::updated_pre_trunc.

2254 {
2255  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
2256  PgStat_TableStatus *pgstat_info;
2257 
2258  /* Find or create a tabstat entry for the rel */
2259  pgstat_info = get_tabstat_entry(rec->t_id, rec->t_shared);
2260 
2261  /* Same math as in AtEOXact_PgStat, abort case */
2262  if (rec->t_truncated)
2263  {
2264  rec->tuples_inserted = rec->inserted_pre_trunc;
2265  rec->tuples_updated = rec->updated_pre_trunc;
2266  rec->tuples_deleted = rec->deleted_pre_trunc;
2267  }
2268  pgstat_info->t_counts.t_tuples_inserted += rec->tuples_inserted;
2269  pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
2270  pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
2271  pgstat_info->t_counts.t_delta_dead_tuples +=
2272  rec->tuples_inserted + rec->tuples_updated;
2273 }
PgStat_TableCounts t_counts
Definition: pgstat.h:158
PgStat_Counter deleted_pre_trunc
Definition: pgstat.c:204
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
PgStat_Counter updated_pre_trunc
Definition: pgstat.c:203
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
PgStat_Counter inserted_pre_trunc
Definition: pgstat.c:202
PgStat_Counter tuples_updated
Definition: pgstat.c:200
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:1674
PgStat_Counter tuples_inserted
Definition: pgstat.c:199
PgStat_Counter tuples_deleted
Definition: pgstat.c:201
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
void pgstat_twophase_postcommit ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 2216 of file pgstat.c.

References get_tabstat_entry(), PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, TwoPhasePgStatRecord::t_id, TwoPhasePgStatRecord::t_shared, PgStat_TableCounts::t_truncated, TwoPhasePgStatRecord::t_truncated, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, and TwoPhasePgStatRecord::tuples_updated.

2218 {
2219  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
2220  PgStat_TableStatus *pgstat_info;
2221 
2222  /* Find or create a tabstat entry for the rel */
2223  pgstat_info = get_tabstat_entry(rec->t_id, rec->t_shared);
2224 
2225  /* Same math as in AtEOXact_PgStat, commit case */
2226  pgstat_info->t_counts.t_tuples_inserted += rec->tuples_inserted;
2227  pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
2228  pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
2229  pgstat_info->t_counts.t_truncated = rec->t_truncated;
2230  if (rec->t_truncated)
2231  {
2232  /* forget live/dead stats seen by backend thus far */
2233  pgstat_info->t_counts.t_delta_live_tuples = 0;
2234  pgstat_info->t_counts.t_delta_dead_tuples = 0;
2235  }
2236  pgstat_info->t_counts.t_delta_live_tuples +=
2237  rec->tuples_inserted - rec->tuples_deleted;
2238  pgstat_info->t_counts.t_delta_dead_tuples +=
2239  rec->tuples_updated + rec->tuples_deleted;
2240  pgstat_info->t_counts.t_changed_tuples +=
2241  rec->tuples_inserted + rec->tuples_updated +
2242  rec->tuples_deleted;
2243 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:110
PgStat_TableCounts t_counts
Definition: pgstat.h:158
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
PgStat_Counter tuples_updated
Definition: pgstat.c:200
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:1674
PgStat_Counter t_changed_tuples
Definition: pgstat.h:112
PgStat_Counter tuples_inserted
Definition: pgstat.c:199
PgStat_Counter tuples_deleted
Definition: pgstat.c:201
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
void pgstat_update_heap_dead_tuples ( Relation  rel,
int  delta 
)

Definition at line 1936 of file pgstat.c.

References NULL, RelationData::pgstat_info, PgStat_TableStatus::t_counts, and PgStat_TableCounts::t_delta_dead_tuples.

Referenced by heap_page_prune().

1937 {
1938  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
1939 
1940  if (pgstat_info != NULL)
1941  pgstat_info->t_counts.t_delta_dead_tuples -= delta;
1942 }
PgStat_TableCounts t_counts
Definition: pgstat.h:158
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:111
#define NULL
Definition: c.h:229
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:218
void pgstat_vacuum_stat ( void  )

Definition at line 947 of file pgstat.c.

References backend_read_statsfile(), CHECK_FOR_INTERRUPTS, PgStat_StatDBEntry::databaseid, DatabaseRelationId, PgStat_StatFuncEntry::functionid, PgStat_StatDBEntry::functions, hash_destroy(), HASH_FIND, hash_get_num_entries(), hash_search(), hash_seq_init(), hash_seq_search(), PgStat_MsgTabpurge::m_databaseid, PgStat_MsgFuncpurge::m_databaseid, PgStat_MsgFuncpurge::m_functionid, PgStat_MsgTabpurge::m_hdr, PgStat_MsgFuncpurge::m_hdr, PgStat_MsgTabpurge::m_nentries, PgStat_MsgFuncpurge::m_nentries, PgStat_MsgTabpurge::m_tableid, MyDatabaseId, NULL, offsetof, OidIsValid, PGINVALID_SOCKET, pgstat_collect_oids(), pgstat_drop_database(), PGSTAT_MTYPE_FUNCPURGE, PGSTAT_MTYPE_TABPURGE, PGSTAT_NUM_FUNCPURGE, PGSTAT_NUM_TABPURGE, pgstat_send(), pgstat_setheader(), pgStatSock, ProcedureRelationId, RelationRelationId, PgStat_StatTabEntry::tableid, and PgStat_StatDBEntry::tables.

Referenced by do_autovacuum(), and vacuum().

948 {
949  HTAB *htab;
950  PgStat_MsgTabpurge msg;
951  PgStat_MsgFuncpurge f_msg;
952  HASH_SEQ_STATUS hstat;
953  PgStat_StatDBEntry *dbentry;
954  PgStat_StatTabEntry *tabentry;
955  PgStat_StatFuncEntry *funcentry;
956  int len;
957 
959  return;
960 
961  /*
962  * If not done for this transaction, read the statistics collector stats
963  * file into some hash tables.
964  */
966 
967  /*
968  * Read pg_database and make a list of OIDs of all existing databases
969  */
971 
972  /*
973  * Search the database hash table for dead databases and tell the
974  * collector to drop them.
975  */
976  hash_seq_init(&hstat, pgStatDBHash);
977  while ((dbentry = (PgStat_StatDBEntry *) hash_seq_search(&hstat)) != NULL)
978  {
979  Oid dbid = dbentry->databaseid;
980