PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgstat.h File Reference
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_FunctionCounts
 
struct  PgStat_FunctionCallUsage
 
struct  PgStat_BackendSubEntry
 
struct  PgStat_TableCounts
 
struct  PgStat_TableStatus
 
struct  PgStat_TableXactStatus
 
struct  PgStat_ArchiverStats
 
struct  PgStat_BgWriterStats
 
struct  PgStat_CheckpointerStats
 
struct  PgStat_BktypeIO
 
struct  PgStat_PendingIO
 
struct  PgStat_IO
 
struct  PgStat_LockEntry
 
struct  PgStat_PendingLock
 
struct  PgStat_Lock
 
struct  PgStat_StatDBEntry
 
struct  PgStat_StatFuncEntry
 
struct  PgStat_StatReplSlotEntry
 
struct  PgStat_SLRUStats
 
struct  PgStat_StatSubEntry
 
struct  PgStat_StatTabEntry
 
struct  PgStat_WalCounters
 
struct  PgStat_WalStats
 
struct  PgStat_Backend
 
struct  PgStat_BackendPending
 

Macros

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"
 
#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/pgstat.stat"
 
#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/pgstat.tmp"
 
#define PG_STAT_TMP_DIR   "pg_stat_tmp"
 
#define PGSTAT_FILE_FORMAT_ID   0x01A5BCBC
 
#define IOOBJECT_NUM_TYPES   (IOOBJECT_WAL + 1)
 
#define IOCONTEXT_NUM_TYPES   (IOCONTEXT_VACUUM + 1)
 
#define IOOP_NUM_TYPES   (IOOP_WRITE + 1)
 
#define pgstat_is_ioop_tracked_in_bytes(io_op)
 
#define pgstat_count_buffer_read_time(n)    (pgStatBlockReadTime += (n))
 
#define pgstat_count_buffer_write_time(n)    (pgStatBlockWriteTime += (n))
 
#define pgstat_count_conn_active_time(n)    (pgStatActiveTime += (n))
 
#define pgstat_count_conn_txn_idle_time(n)    (pgStatTransactionIdleTime += (n))
 
#define pgstat_should_count_relation(rel)
 
#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)
 

Typedefs

typedef struct FullTransactionId FullTransactionId
 
typedef struct RelationDataRelation
 
typedef enum TrackFunctionsLevel TrackFunctionsLevel
 
typedef enum PgStat_FetchConsistency PgStat_FetchConsistency
 
typedef enum SessionEndType SessionEndType
 
typedef int64 PgStat_Counter
 
typedef struct PgStat_FunctionCounts PgStat_FunctionCounts
 
typedef struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
 
typedef struct PgStat_BackendSubEntry PgStat_BackendSubEntry
 
typedef struct PgStat_TableCounts PgStat_TableCounts
 
typedef struct PgStat_TableStatus PgStat_TableStatus
 
typedef struct PgStat_TableXactStatus PgStat_TableXactStatus
 
typedef struct PgStat_ArchiverStats PgStat_ArchiverStats
 
typedef struct PgStat_BgWriterStats PgStat_BgWriterStats
 
typedef struct PgStat_CheckpointerStats PgStat_CheckpointerStats
 
typedef enum IOObject IOObject
 
typedef enum IOContext IOContext
 
typedef enum IOOp IOOp
 
typedef struct PgStat_BktypeIO PgStat_BktypeIO
 
typedef struct PgStat_PendingIO PgStat_PendingIO
 
typedef struct PgStat_IO PgStat_IO
 
typedef struct PgStat_LockEntry PgStat_LockEntry
 
typedef struct PgStat_PendingLock PgStat_PendingLock
 
typedef struct PgStat_Lock PgStat_Lock
 
typedef struct PgStat_StatDBEntry PgStat_StatDBEntry
 
typedef struct PgStat_StatFuncEntry PgStat_StatFuncEntry
 
typedef struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
 
typedef struct PgStat_SLRUStats PgStat_SLRUStats
 
typedef struct PgStat_StatSubEntry PgStat_StatSubEntry
 
typedef struct PgStat_StatTabEntry PgStat_StatTabEntry
 
typedef struct PgStat_WalCounters PgStat_WalCounters
 
typedef struct PgStat_WalStats PgStat_WalStats
 
typedef struct PgStat_Backend PgStat_Backend
 
typedef struct PgStat_BackendPending PgStat_BackendPending
 

Enumerations

enum  TrackFunctionsLevel { TRACK_FUNC_OFF , TRACK_FUNC_PL , TRACK_FUNC_ALL }
 
enum  PgStat_FetchConsistency { PGSTAT_FETCH_CONSISTENCY_NONE , PGSTAT_FETCH_CONSISTENCY_CACHE , PGSTAT_FETCH_CONSISTENCY_SNAPSHOT }
 
enum  SessionEndType {
  DISCONNECT_NOT_YET , DISCONNECT_NORMAL , DISCONNECT_CLIENT_EOF , DISCONNECT_FATAL ,
  DISCONNECT_KILLED
}
 
enum  IOObject { IOOBJECT_RELATION , IOOBJECT_TEMP_RELATION , IOOBJECT_WAL }
 
enum  IOContext {
  IOCONTEXT_BULKREAD , IOCONTEXT_BULKWRITE , IOCONTEXT_INIT , IOCONTEXT_NORMAL ,
  IOCONTEXT_VACUUM
}
 
enum  IOOp {
  IOOP_EVICT , IOOP_FSYNC , IOOP_HIT , IOOP_REUSE ,
  IOOP_WRITEBACK , IOOP_EXTEND , IOOP_READ , IOOP_WRITE
}
 

Functions

void pgstat_restore_stats (void)
 
void pgstat_discard_stats (void)
 
void pgstat_before_server_shutdown (int code, Datum arg)
 
void pgstat_initialize (void)
 
long pgstat_report_stat (bool force)
 
void pgstat_force_next_flush (void)
 
void pgstat_reset_counters (void)
 
void pgstat_reset (PgStat_Kind kind, Oid dboid, uint64 objid)
 
void pgstat_reset_of_kind (PgStat_Kind kind)
 
void pgstat_clear_snapshot (void)
 
TimestampTz pgstat_get_stat_snapshot_timestamp (bool *have_snapshot)
 
PgStat_Kind pgstat_get_kind_from_str (char *kind_str)
 
bool pgstat_have_entry (PgStat_Kind kind, Oid dboid, uint64 objid)
 
void pgstat_report_archiver (const char *xlog, bool failed)
 
PgStat_ArchiverStatspgstat_fetch_stat_archiver (void)
 
void pgstat_count_backend_io_op_time (IOObject io_object, IOContext io_context, IOOp io_op, instr_time io_time)
 
void pgstat_count_backend_io_op (IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
 
PgStat_Backendpgstat_fetch_stat_backend (ProcNumber procNumber)
 
PgStat_Backendpgstat_fetch_stat_backend_by_pid (int pid, BackendType *bktype)
 
bool pgstat_tracks_backend_bktype (BackendType bktype)
 
void pgstat_create_backend (ProcNumber procnum)
 
void pgstat_report_bgwriter (void)
 
PgStat_BgWriterStatspgstat_fetch_stat_bgwriter (void)
 
void pgstat_report_checkpointer (void)
 
PgStat_CheckpointerStatspgstat_fetch_stat_checkpointer (void)
 
bool pgstat_bktype_io_stats_valid (PgStat_BktypeIO *backend_io, BackendType bktype)
 
void pgstat_count_io_op (IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
 
instr_time pgstat_prepare_io_time (bool track_io_guc)
 
void pgstat_count_io_op_time (IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt, uint64 bytes)
 
PgStat_IOpgstat_fetch_stat_io (void)
 
const charpgstat_get_io_context_name (IOContext io_context)
 
const charpgstat_get_io_object_name (IOObject io_object)
 
bool pgstat_tracks_io_bktype (BackendType bktype)
 
bool pgstat_tracks_io_object (BackendType bktype, IOObject io_object, IOContext io_context)
 
bool pgstat_tracks_io_op (BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
 
void pgstat_lock_flush (bool nowait)
 
void pgstat_count_lock_fastpath_exceeded (uint8 locktag_type)
 
void pgstat_count_lock_waits (uint8 locktag_type, long msecs)
 
PgStat_Lockpgstat_fetch_stat_lock (void)
 
void pgstat_drop_database (Oid databaseid)
 
void pgstat_report_autovac (Oid dboid)
 
void pgstat_report_recovery_conflict (int reason)
 
void pgstat_report_deadlock (void)
 
void pgstat_prepare_report_checksum_failure (Oid dboid)
 
void pgstat_report_checksum_failures_in_db (Oid dboid, int failurecount)
 
void pgstat_report_connect (Oid dboid)
 
void pgstat_update_parallel_workers_stats (PgStat_Counter workers_to_launch, PgStat_Counter workers_launched)
 
PgStat_StatDBEntrypgstat_fetch_stat_dbentry (Oid dboid)
 
void pgstat_create_function (Oid proid)
 
void pgstat_drop_function (Oid proid)
 
void pgstat_init_function_usage (struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
 
void pgstat_end_function_usage (PgStat_FunctionCallUsage *fcu, bool finalize)
 
PgStat_StatFuncEntrypgstat_fetch_stat_funcentry (Oid func_id)
 
PgStat_FunctionCountsfind_funcstat_entry (Oid func_id)
 
void pgstat_create_relation (Relation rel)
 
void pgstat_drop_relation (Relation rel)
 
void pgstat_copy_relation_stats (Relation dst, Relation src)
 
void pgstat_init_relation (Relation rel)
 
void pgstat_assoc_relation (Relation rel)
 
void pgstat_unlink_relation (Relation rel)
 
void pgstat_report_vacuum (Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, TimestampTz starttime)
 
void pgstat_report_analyze (Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter, TimestampTz starttime)
 
void pgstat_count_heap_insert (Relation rel, PgStat_Counter n)
 
void pgstat_count_heap_update (Relation rel, bool hot, bool newpage)
 
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_twophase_postcommit (FullTransactionId fxid, uint16 info, void *recdata, uint32 len)
 
void pgstat_twophase_postabort (FullTransactionId fxid, uint16 info, void *recdata, uint32 len)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry (Oid relid)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry_ext (bool shared, Oid reloid, bool *may_free)
 
PgStat_TableStatusfind_tabstat_entry (Oid rel_id)
 
void pgstat_reset_replslot (const char *name)
 
void pgstat_report_replslot (struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
 
void pgstat_report_replslotsync (struct ReplicationSlot *slot)
 
void pgstat_create_replslot (struct ReplicationSlot *slot)
 
void pgstat_acquire_replslot (struct ReplicationSlot *slot)
 
void pgstat_drop_replslot (struct ReplicationSlot *slot)
 
PgStat_StatReplSlotEntrypgstat_fetch_replslot (NameData slotname)
 
void pgstat_reset_slru (const char *)
 
void pgstat_count_slru_blocks_zeroed (int slru_idx)
 
void pgstat_count_slru_blocks_hit (int slru_idx)
 
void pgstat_count_slru_blocks_read (int slru_idx)
 
void pgstat_count_slru_blocks_written (int slru_idx)
 
void pgstat_count_slru_blocks_exists (int slru_idx)
 
void pgstat_count_slru_flush (int slru_idx)
 
void pgstat_count_slru_truncate (int slru_idx)
 
const charpgstat_get_slru_name (int slru_idx)
 
int pgstat_get_slru_index (const char *name)
 
PgStat_SLRUStatspgstat_fetch_slru (void)
 
void pgstat_report_subscription_error (Oid subid)
 
void pgstat_report_subscription_conflict (Oid subid, ConflictType type)
 
void pgstat_create_subscription (Oid subid)
 
void pgstat_drop_subscription (Oid subid)
 
PgStat_StatSubEntrypgstat_fetch_stat_subscription (Oid subid)
 
void AtEOXact_PgStat (bool isCommit, bool parallel)
 
void AtEOSubXact_PgStat (bool isCommit, int nestDepth)
 
void AtPrepare_PgStat (void)
 
void PostPrepare_PgStat (void)
 
int pgstat_get_transactional_drops (bool isCommit, struct xl_xact_stats_item **items)
 
void pgstat_execute_transactional_drops (int ndrops, struct xl_xact_stats_item *items, bool is_redo)
 
void pgstat_report_wal (bool force)
 
PgStat_WalStatspgstat_fetch_stat_wal (void)
 

Variables

PGDLLIMPORT bool pgstat_track_counts
 
PGDLLIMPORT int pgstat_track_functions
 
PGDLLIMPORT int pgstat_fetch_consistency
 
PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
 
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
 
PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
 
PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
 
PGDLLIMPORT PgStat_Counter pgStatActiveTime
 
PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
 
PGDLLIMPORT SessionEndType pgStatSessionEndCause
 

Macro Definition Documentation

◆ IOCONTEXT_NUM_TYPES

#define IOCONTEXT_NUM_TYPES   (IOCONTEXT_VACUUM + 1)

Definition at line 297 of file pgstat.h.

◆ IOOBJECT_NUM_TYPES

#define IOOBJECT_NUM_TYPES   (IOOBJECT_WAL + 1)

Definition at line 286 of file pgstat.h.

◆ IOOP_NUM_TYPES

#define IOOP_NUM_TYPES   (IOOP_WRITE + 1)

Definition at line 323 of file pgstat.h.

◆ PG_STAT_TMP_DIR

#define PG_STAT_TMP_DIR   "pg_stat_tmp"

Definition at line 40 of file pgstat.h.

◆ pgstat_count_buffer_hit

#define pgstat_count_buffer_hit (   rel)
Value:
do { \
(rel)->pgstat_info->counts.blocks_hit++; \
} while (0)
#define pgstat_should_count_relation(rel)
Definition pgstat.h:711
static int fb(int x)

Definition at line 747 of file pgstat.h.

748 { \
750 (rel)->pgstat_info->counts.blocks_hit++; \
751 } while (0)

◆ pgstat_count_buffer_read

#define pgstat_count_buffer_read (   rel)
Value:
do { \
(rel)->pgstat_info->counts.blocks_fetched++; \
} while (0)

Definition at line 742 of file pgstat.h.

743 { \
745 (rel)->pgstat_info->counts.blocks_fetched++; \
746 } while (0)

◆ pgstat_count_buffer_read_time

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

Definition at line 658 of file pgstat.h.

◆ pgstat_count_buffer_write_time

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

Definition at line 660 of file pgstat.h.

◆ pgstat_count_conn_active_time

#define pgstat_count_conn_active_time (   n)     (pgStatActiveTime += (n))

Definition at line 662 of file pgstat.h.

◆ pgstat_count_conn_txn_idle_time

#define pgstat_count_conn_txn_idle_time (   n)     (pgStatTransactionIdleTime += (n))

Definition at line 664 of file pgstat.h.

◆ pgstat_count_heap_fetch

#define pgstat_count_heap_fetch (   rel)
Value:
do { \
(rel)->pgstat_info->counts.tuples_fetched++; \
} while (0)

Definition at line 727 of file pgstat.h.

728 { \
730 (rel)->pgstat_info->counts.tuples_fetched++; \
731 } while (0)

◆ pgstat_count_heap_getnext

#define pgstat_count_heap_getnext (   rel)
Value:
do { \
(rel)->pgstat_info->counts.tuples_returned++; \
} while (0)

Definition at line 722 of file pgstat.h.

723 { \
725 (rel)->pgstat_info->counts.tuples_returned++; \
726 } while (0)

◆ pgstat_count_heap_scan

#define pgstat_count_heap_scan (   rel)
Value:
do { \
(rel)->pgstat_info->counts.numscans++; \
} while (0)

Definition at line 717 of file pgstat.h.

718 { \
720 (rel)->pgstat_info->counts.numscans++; \
721 } while (0)

◆ pgstat_count_index_scan

#define pgstat_count_index_scan (   rel)
Value:
do { \
(rel)->pgstat_info->counts.numscans++; \
} while (0)

Definition at line 732 of file pgstat.h.

733 { \
735 (rel)->pgstat_info->counts.numscans++; \
736 } while (0)

◆ pgstat_count_index_tuples

#define pgstat_count_index_tuples (   rel,
 
)
Value:
do { \
(rel)->pgstat_info->counts.tuples_returned += (n); \
} while (0)

Definition at line 737 of file pgstat.h.

738 { \
740 (rel)->pgstat_info->counts.tuples_returned += (n); \
741 } while (0)

◆ PGSTAT_FILE_FORMAT_ID

#define PGSTAT_FILE_FORMAT_ID   0x01A5BCBC

Definition at line 221 of file pgstat.h.

◆ pgstat_is_ioop_tracked_in_bytes

#define pgstat_is_ioop_tracked_in_bytes (   io_op)
Value:
(((unsigned int) (io_op)) < IOOP_NUM_TYPES && \
((unsigned int) (io_op)) >= IOOP_EXTEND)
#define IOOP_NUM_TYPES
Definition pgstat.h:323
@ IOOP_EXTEND
Definition pgstat.h:318

Definition at line 325 of file pgstat.h.

◆ pgstat_should_count_relation

#define pgstat_should_count_relation (   rel)
Value:
(likely((rel)->pgstat_info != NULL) ? true : \
((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
#define likely(x)
Definition c.h:437
return true
Definition isn.c:130
void pgstat_assoc_relation(Relation rel)

Definition at line 711 of file pgstat.h.

712 : \
713 ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))

◆ PGSTAT_STAT_PERMANENT_DIRECTORY

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"

Definition at line 35 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_FILENAME

#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/pgstat.stat"

Definition at line 36 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_TMPFILE

#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/pgstat.tmp"

Definition at line 37 of file pgstat.h.

Typedef Documentation

◆ FullTransactionId

Definition at line 25 of file pgstat.h.

◆ IOContext

◆ IOObject

◆ IOOp

◆ PgStat_ArchiverStats

◆ PgStat_Backend

◆ PgStat_BackendPending

◆ PgStat_BackendSubEntry

◆ PgStat_BgWriterStats

◆ PgStat_BktypeIO

◆ PgStat_CheckpointerStats

◆ PgStat_Counter

Definition at line 71 of file pgstat.h.

◆ PgStat_FetchConsistency

◆ PgStat_FunctionCallUsage

◆ PgStat_FunctionCounts

◆ PgStat_IO

◆ PgStat_Lock

◆ PgStat_LockEntry

◆ PgStat_PendingIO

◆ PgStat_PendingLock

◆ PgStat_SLRUStats

◆ PgStat_StatDBEntry

◆ PgStat_StatFuncEntry

◆ PgStat_StatReplSlotEntry

◆ PgStat_StatSubEntry

◆ PgStat_StatTabEntry

◆ PgStat_TableCounts

◆ PgStat_TableStatus

◆ PgStat_TableXactStatus

◆ PgStat_WalCounters

◆ PgStat_WalStats

◆ Relation

Definition at line 28 of file pgstat.h.

◆ SessionEndType

◆ TrackFunctionsLevel

Enumeration Type Documentation

◆ IOContext

Enumerator
IOCONTEXT_BULKREAD 
IOCONTEXT_BULKWRITE 
IOCONTEXT_INIT 
IOCONTEXT_NORMAL 
IOCONTEXT_VACUUM 

Definition at line 288 of file pgstat.h.

289{
295} IOContext;
IOContext
Definition pgstat.h:289
@ IOCONTEXT_INIT
Definition pgstat.h:292
@ IOCONTEXT_NORMAL
Definition pgstat.h:293
@ IOCONTEXT_VACUUM
Definition pgstat.h:294
@ IOCONTEXT_BULKREAD
Definition pgstat.h:290
@ IOCONTEXT_BULKWRITE
Definition pgstat.h:291

◆ IOObject

Enumerator
IOOBJECT_RELATION 
IOOBJECT_TEMP_RELATION 
IOOBJECT_WAL 

Definition at line 279 of file pgstat.h.

280{
284} IOObject;
IOObject
Definition pgstat.h:280
@ IOOBJECT_RELATION
Definition pgstat.h:281
@ IOOBJECT_WAL
Definition pgstat.h:283
@ IOOBJECT_TEMP_RELATION
Definition pgstat.h:282

◆ IOOp

Enumerator
IOOP_EVICT 
IOOP_FSYNC 
IOOP_HIT 
IOOP_REUSE 
IOOP_WRITEBACK 
IOOP_EXTEND 
IOOP_READ 
IOOP_WRITE 

Definition at line 308 of file pgstat.h.

309{
310 /* IOs not tracked in bytes */
313 IOOP_HIT,
316
317 /* IOs tracked in bytes */
319 IOOP_READ,
321} IOOp;
IOOp
Definition pgstat.h:309
@ IOOP_FSYNC
Definition pgstat.h:312
@ IOOP_READ
Definition pgstat.h:319
@ IOOP_WRITEBACK
Definition pgstat.h:315
@ IOOP_HIT
Definition pgstat.h:313
@ IOOP_EVICT
Definition pgstat.h:311
@ IOOP_REUSE
Definition pgstat.h:314
@ IOOP_WRITE
Definition pgstat.h:320

◆ PgStat_FetchConsistency

Enumerator
PGSTAT_FETCH_CONSISTENCY_NONE 
PGSTAT_FETCH_CONSISTENCY_CACHE 
PGSTAT_FETCH_CONSISTENCY_SNAPSHOT 

Definition at line 50 of file pgstat.h.

51{
PgStat_FetchConsistency
Definition pgstat.h:51
@ PGSTAT_FETCH_CONSISTENCY_NONE
Definition pgstat.h:52
@ PGSTAT_FETCH_CONSISTENCY_CACHE
Definition pgstat.h:53
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
Definition pgstat.h:54

◆ SessionEndType

Enumerator
DISCONNECT_NOT_YET 
DISCONNECT_NORMAL 
DISCONNECT_CLIENT_EOF 
DISCONNECT_FATAL 
DISCONNECT_KILLED 

Definition at line 58 of file pgstat.h.

59{
60 DISCONNECT_NOT_YET, /* still active */
SessionEndType
Definition pgstat.h:59
@ DISCONNECT_NOT_YET
Definition pgstat.h:60
@ DISCONNECT_FATAL
Definition pgstat.h:63
@ DISCONNECT_KILLED
Definition pgstat.h:64
@ DISCONNECT_CLIENT_EOF
Definition pgstat.h:62
@ DISCONNECT_NORMAL
Definition pgstat.h:61

◆ TrackFunctionsLevel

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 43 of file pgstat.h.

44{
TrackFunctionsLevel
Definition pgstat.h:44
@ TRACK_FUNC_PL
Definition pgstat.h:46
@ TRACK_FUNC_ALL
Definition pgstat.h:47
@ TRACK_FUNC_OFF
Definition pgstat.h:45

Function Documentation

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)
extern

Definition at line 113 of file pgstat_xact.c.

114{
115 PgStat_SubXactStatus *xact_state;
116
117 /* merge the sub-transaction's transactional stats into the parent */
118 xact_state = pgStatXactStack;
119 if (xact_state != NULL &&
120 xact_state->nest_level >= nestDepth)
121 {
122 /* delink xact_state from stack immediately to simplify reuse case */
123 pgStatXactStack = xact_state->prev;
124
127
128 pfree(xact_state);
129 }
130}
void pfree(void *pointer)
Definition mcxt.c:1616
void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
static PgStat_SubXactStatus * pgStatXactStack
Definition pgstat_xact.c:33
static void AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
struct PgStat_SubXactStatus * prev

References AtEOSubXact_PgStat_DroppedStats(), AtEOSubXact_PgStat_Relations(), fb(), PgStat_SubXactStatus::nest_level, pfree(), pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)
extern

Definition at line 40 of file pgstat_xact.c.

41{
42 PgStat_SubXactStatus *xact_state;
43
45
46 /* handle transactional stats information */
47 xact_state = pgStatXactStack;
48 if (xact_state != NULL)
49 {
50 Assert(xact_state->nest_level == 1);
51 Assert(xact_state->prev == NULL);
52
55 }
57
58 /* Make sure any stats snapshot is thrown away */
60}
#define Assert(condition)
Definition c.h:943
void pgstat_clear_snapshot(void)
Definition pgstat.c:930
void AtEOXact_PgStat_Database(bool isCommit, bool parallel)
void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit)
static void AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit)
Definition pgstat_xact.c:67

References Assert, AtEOXact_PgStat_Database(), AtEOXact_PgStat_DroppedStats(), AtEOXact_PgStat_Relations(), fb(), PgStat_SubXactStatus::nest_level, pgstat_clear_snapshot(), pgStatXactStack, and PgStat_SubXactStatus::prev.

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

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )
extern

Definition at line 191 of file pgstat_xact.c.

192{
193 PgStat_SubXactStatus *xact_state;
194
195 xact_state = pgStatXactStack;
196 if (xact_state != NULL)
197 {
198 Assert(xact_state->nest_level == 1);
199 Assert(xact_state->prev == NULL);
200
201 AtPrepare_PgStat_Relations(xact_state);
202 }
203}
void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)

References Assert, AtPrepare_PgStat_Relations(), fb(), PgStat_SubXactStatus::nest_level, pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by PrepareTransaction().

◆ find_funcstat_entry()

PgStat_FunctionCounts * find_funcstat_entry ( Oid  func_id)
extern

Definition at line 229 of file pgstat_function.c.

230{
231 PgStat_EntryRef *entry_ref;
232
234
235 if (entry_ref)
236 return entry_ref->pending;
237 return NULL;
238}
Oid MyDatabaseId
Definition globals.c:96
PgStat_EntryRef * pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:1347
#define PGSTAT_KIND_FUNCTION
Definition pgstat_kind.h:29

References fb(), MyDatabaseId, PgStat_EntryRef::pending, pgstat_fetch_pending_entry(), and PGSTAT_KIND_FUNCTION.

Referenced by pg_stat_get_xact_function_calls().

◆ find_tabstat_entry()

PgStat_TableStatus * find_tabstat_entry ( Oid  rel_id)
extern

Definition at line 502 of file pgstat_relation.c.

503{
504 PgStat_EntryRef *entry_ref;
508
510 if (!entry_ref)
511 {
513 if (!entry_ref)
514 return tablestatus;
515 }
516
517 tabentry = (PgStat_TableStatus *) entry_ref->pending;
520
521 /*
522 * Reset tablestatus->trans in the copy of PgStat_TableStatus as it may
523 * point to a shared memory area. Its data is saved below, so removing it
524 * does not matter.
525 */
526 tablestatus->trans = NULL;
527
528 /*
529 * Live subtransaction counts are not included yet. This is not a hot
530 * code path so reconcile tuples_inserted, tuples_updated and
531 * tuples_deleted even if the caller may not be interested in this data.
532 */
533 for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
534 {
535 tablestatus->counts.tuples_inserted += trans->tuples_inserted;
536 tablestatus->counts.tuples_updated += trans->tuples_updated;
537 tablestatus->counts.tuples_deleted += trans->tuples_deleted;
538 }
539
540 return tablestatus;
541}
#define palloc_object(type)
Definition fe_memutils.h:74
#define PGSTAT_KIND_RELATION
Definition pgstat_kind.h:28
#define InvalidOid
static zic_t trans[TZ_MAX_LEAPS]
Definition zic.c:405

References fb(), InvalidOid, MyDatabaseId, palloc_object, PgStat_EntryRef::pending, pgstat_fetch_pending_entry(), PGSTAT_KIND_RELATION, and trans.

◆ pgstat_acquire_replslot()

void pgstat_acquire_replslot ( struct ReplicationSlot slot)
extern

Definition at line 176 of file pgstat_replslot.c.

177{
179 ReplicationSlotIndex(slot), true, NULL);
180}
#define PGSTAT_KIND_REPLSLOT
Definition pgstat_kind.h:30
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry)
int ReplicationSlotIndex(ReplicationSlot *slot)
Definition slot.c:581

References fb(), InvalidOid, pgstat_get_entry_ref(), PGSTAT_KIND_REPLSLOT, and ReplicationSlotIndex().

Referenced by ReplicationSlotAcquire().

◆ pgstat_assoc_relation()

void pgstat_assoc_relation ( Relation  rel)
extern

Definition at line 132 of file pgstat_relation.c.

133{
135 Assert(rel->pgstat_info == NULL);
136
137 /* Else find or make the PgStat_TableStatus entry, and update link */
139 rel->rd_rel->relisshared);
140
141 /* don't allow link a stats to multiple relcache entries */
143
144 /* mark this relation as the owner */
145 rel->pgstat_info->relation = rel;
146}
static PgStat_TableStatus * pgstat_prep_relation_pending(Oid rel_id, bool isshared)
#define RelationGetRelid(relation)
Definition rel.h:516
Relation relation
Definition pgstat.h:186
bool pgstat_enabled
Definition rel.h:253
Form_pg_class rd_rel
Definition rel.h:111
struct PgStat_TableStatus * pgstat_info
Definition rel.h:255

References Assert, fb(), RelationData::pgstat_enabled, RelationData::pgstat_info, pgstat_prep_relation_pending(), RelationData::rd_rel, PgStat_TableStatus::relation, and RelationGetRelid.

◆ pgstat_before_server_shutdown()

void pgstat_before_server_shutdown ( int  code,
Datum  arg 
)
extern

Definition at line 590 of file pgstat.c.

592{
595
596 /*
597 * Stats should only be reported after pgstat_initialize() and before
598 * pgstat_shutdown(). This is a convenient point to catch most violations
599 * of this rule.
600 */
602
603 /* flush out our own pending changes before writing out */
604 pgstat_report_stat(true);
605
606 /*
607 * Only write out file during normal shutdown. Don't even signal that
608 * we've shutdown during irregular shutdowns, because the shutdown
609 * sequence isn't coordinated to ensure this backend shuts down last.
610 */
611 if (code == 0)
612 {
615 }
static void pgstat_write_statsfile(void)
Definition pgstat.c:1614
long pgstat_report_stat(bool force)
Definition pgstat.c:722
PgStat_LocalState pgStatLocal
Definition pgstat.c:213
PgStat_ShmemControl * shmem

References Assert, fb(), PgStat_ShmemControl::is_shutdown, pgstat_report_stat(), pgstat_write_statsfile(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by CheckpointerMain(), and InitPostgres().

◆ pgstat_bktype_io_stats_valid()

bool pgstat_bktype_io_stats_valid ( PgStat_BktypeIO backend_io,
BackendType  bktype 
)
extern

Definition at line 37 of file pgstat_io.c.

39{
41 {
43 {
44 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
45 {
46 /* we do track it */
48 {
49 /* ensure that if IO times are non-zero, counts are > 0 */
50 if (backend_io->times[io_object][io_context][io_op] != 0 &&
51 backend_io->counts[io_object][io_context][io_op] <= 0)
52 return false;
53
54 continue;
55 }
56
57 /* we don't track it, and it is not 0 */
58 if (backend_io->counts[io_object][io_context][io_op] != 0)
59 return false;
60 }
61 }
62 }
63
64 return true;
65}
#define IOCONTEXT_NUM_TYPES
Definition pgstat.h:297
#define IOOBJECT_NUM_TYPES
Definition pgstat.h:286
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition pgstat_io.c:479

References fb(), IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, and pgstat_tracks_io_op().

Referenced by pg_stat_get_backend_io(), pg_stat_get_io(), and pgstat_io_flush_cb().

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )
extern

Definition at line 930 of file pgstat.c.

932{
934
941
942 /* Release memory, if any was allocated */
944 {
946
947 /* Reset variables */
949 }
950
951 /*
952 * Historically the backend_status.c facilities lived in this file, and
953 * were reset with the same function. For now keep it that way, and
954 * forward the reset request.
955 */
957
958 /* Reset this flag, as it may be possible that a cleanup was forced. */
void pgstat_clear_backend_activity_snapshot(void)
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
static bool force_stats_snapshot_clear
Definition pgstat.c:256
#define pgstat_assert_is_up()
PgStat_Snapshot snapshot
MemoryContext context
bool custom_valid[PGSTAT_KIND_CUSTOM_SIZE]
PgStat_FetchConsistency mode
struct pgstat_snapshot_hash * stats
bool fixed_valid[PGSTAT_KIND_BUILTIN_SIZE]

References PgStat_Snapshot::context, PgStat_Snapshot::custom_valid, fb(), PgStat_Snapshot::fixed_valid, force_stats_snapshot_clear, MemoryContextDelete(), PgStat_Snapshot::mode, pgstat_assert_is_up, pgstat_clear_backend_activity_snapshot(), PGSTAT_FETCH_CONSISTENCY_NONE, pgStatLocal, PgStat_LocalState::snapshot, and PgStat_Snapshot::stats.

Referenced by AtEOXact_PgStat(), pg_stat_clear_snapshot(), pgstat_get_stat_snapshot_timestamp(), pgstat_prep_snapshot(), pgstat_snapshot_fixed(), and PostPrepare_PgStat().

◆ pgstat_copy_relation_stats()

void pgstat_copy_relation_stats ( Relation  dst,
Relation  src 
)
extern

Definition at line 57 of file pgstat_relation.c.

58{
62
65 NULL);
66 if (!srcstats)
67 return;
68
70 dst->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
72 false);
73
75 dstshstats->stats = *srcstats;
76
78}
#define false
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid, bool *may_free)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
PgStatShared_Common * shared_stats

References fb(), InvalidOid, MyDatabaseId, pgstat_fetch_stat_tabentry_ext(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, and PgStat_EntryRef::shared_stats.

Referenced by index_concurrently_swap().

◆ pgstat_count_backend_io_op()

void pgstat_count_backend_io_op ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
uint32  cnt,
uint64  bytes 
)
extern

Definition at line 74 of file pgstat_backend.c.

76{
78 return;
79
81
84
87}
BackendType MyBackendType
Definition miscinit.c:65
bool pgstat_report_fixed
Definition pgstat.c:219
static PgStat_BackendPending PendingBackendStats
bool pgstat_tracks_backend_bktype(BackendType bktype)
static bool backend_has_iostats
PgStat_PendingIO pending_io
Definition pgstat.h:537
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition pgstat.h:339
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition pgstat.h:338

References Assert, backend_has_iostats, PgStat_PendingIO::bytes, PgStat_PendingIO::counts, fb(), MyBackendType, PgStat_BackendPending::pending_io, PendingBackendStats, pgstat_report_fixed, pgstat_tracks_backend_bktype(), and pgstat_tracks_io_op().

Referenced by pgstat_count_io_op().

◆ pgstat_count_backend_io_op_time()

void pgstat_count_backend_io_op_time ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
instr_time  io_time 
)
extern

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)
extern

Definition at line 415 of file pgstat_relation.c.

416{
418 {
419 PgStat_TableStatus *pgstat_info = rel->pgstat_info;
420
421 ensure_tabstat_xact_level(pgstat_info);
422 pgstat_info->trans->tuples_deleted++;
423 }
424}
static void ensure_tabstat_xact_level(PgStat_TableStatus *pgstat_info)
struct PgStat_TableXactStatus * trans
Definition pgstat.h:184
PgStat_Counter tuples_deleted
Definition pgstat.h:197

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_deleted.

Referenced by heap_abort_speculative(), and heap_delete().

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)
extern

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot,
bool  newpage 
)
extern

Definition at line 389 of file pgstat_relation.c.

390{
391 Assert(!(hot && newpage));
392
394 {
395 PgStat_TableStatus *pgstat_info = rel->pgstat_info;
396
397 ensure_tabstat_xact_level(pgstat_info);
398 pgstat_info->trans->tuples_updated++;
399
400 /*
401 * tuples_hot_updated and tuples_newpage_updated counters are
402 * nontransactional, so just advance them
403 */
404 if (hot)
405 pgstat_info->counts.tuples_hot_updated++;
406 else if (newpage)
407 pgstat_info->counts.tuples_newpage_updated++;
408 }
409}
PgStat_Counter tuples_hot_updated
Definition pgstat.h:153
PgStat_Counter tuples_newpage_updated
Definition pgstat.h:154
PgStat_TableCounts counts
Definition pgstat.h:185
PgStat_Counter tuples_updated
Definition pgstat.h:196

References Assert, PgStat_TableStatus::counts, ensure_tabstat_xact_level(), fb(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, PgStat_TableCounts::tuples_hot_updated, PgStat_TableCounts::tuples_newpage_updated, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_update().

◆ pgstat_count_io_op()

void pgstat_count_io_op ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
uint32  cnt,
uint64  bytes 
)
extern

Definition at line 68 of file pgstat_io.c.

70{
71 Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
72 Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
75
78
79 /* Add the per-backend counts */
81
82 have_iostats = true;
84}
#define pgstat_is_ioop_tracked_in_bytes(io_op)
Definition pgstat.h:325
void pgstat_count_backend_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
static PgStat_PendingIO PendingIOStats
Definition pgstat_io.c:23
static bool have_iostats
Definition pgstat_io.c:24

References Assert, PgStat_PendingIO::bytes, PgStat_PendingIO::counts, fb(), have_iostats, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, MyBackendType, PendingIOStats, pgstat_count_backend_io_op(), pgstat_is_ioop_tracked_in_bytes, pgstat_report_fixed, and pgstat_tracks_io_op().

Referenced by GetLocalVictimBuffer(), GetVictimBuffer(), pgstat_count_io_op_time(), and TrackBufferHit().

◆ pgstat_count_io_op_time()

void pgstat_count_io_op_time ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
instr_time  start_time,
uint32  cnt,
uint64  bytes 
)
extern

Definition at line 122 of file pgstat_io.c.

124{
126 {
128
131
132 if (io_object != IOOBJECT_WAL)
133 {
134 if (io_op == IOOP_WRITE || io_op == IOOP_EXTEND)
135 {
141 }
142 else if (io_op == IOOP_READ)
143 {
149 }
150 }
151
153 io_time);
154
155 /* Add the per-backend count */
157 io_time);
158 }
159
161}
#define INSTR_TIME_SET_CURRENT(t)
Definition instr_time.h:426
#define INSTR_TIME_IS_ZERO(t)
Definition instr_time.h:419
#define INSTR_TIME_SUBTRACT(x, y)
Definition instr_time.h:436
#define INSTR_TIME_GET_MICROSEC(t)
Definition instr_time.h:454
BufferUsage pgBufferUsage
Definition instrument.c:25
static time_t start_time
Definition pg_ctl.c:96
#define pgstat_count_buffer_read_time(n)
Definition pgstat.h:658
#define pgstat_count_buffer_write_time(n)
Definition pgstat.h:660
void pgstat_count_backend_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time io_time)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
Definition pgstat_io.c:68
instr_time local_blk_read_time
Definition instrument.h:38
instr_time shared_blk_read_time
Definition instrument.h:36
instr_time shared_blk_write_time
Definition instrument.h:37
instr_time local_blk_write_time
Definition instrument.h:39

References fb(), INSTR_TIME_ADD, INSTR_TIME_GET_MICROSEC, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, IOOBJECT_RELATION, IOOBJECT_TEMP_RELATION, IOOBJECT_WAL, IOOP_EXTEND, IOOP_READ, IOOP_WRITE, BufferUsage::local_blk_read_time, BufferUsage::local_blk_write_time, PgStat_PendingIO::pending_times, PendingIOStats, pgBufferUsage, pgstat_count_backend_io_op_time(), pgstat_count_buffer_read_time, pgstat_count_buffer_write_time, pgstat_count_io_op(), BufferUsage::shared_blk_read_time, BufferUsage::shared_blk_write_time, and start_time.

Referenced by AsyncReadBuffers(), ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushBuffer(), FlushLocalBuffer(), issue_xlog_fsync(), IssuePendingWritebacks(), mdsyncfiletag(), register_dirty_segment(), WaitReadBuffers(), WALRead(), XLogFileInitInternal(), XLogPageRead(), XLogWalRcvWrite(), and XLogWrite().

◆ pgstat_count_lock_fastpath_exceeded()

void pgstat_count_lock_fastpath_exceeded ( uint8  locktag_type)
extern

Definition at line 128 of file pgstat_lock.c.

129{
130 Assert(locktag_type <= LOCKTAG_LAST_TYPE);
132 have_lockstats = true;
133 pgstat_report_fixed = true;
134}
#define LOCKTAG_LAST_TYPE
Definition locktag.h:52
static bool have_lockstats
Definition pgstat_lock.c:23
static PgStat_PendingLock PendingLockStats
Definition pgstat_lock.c:22
PgStat_Counter fastpath_exceeded
Definition pgstat.h:353
PgStat_LockEntry stats[LOCKTAG_LAST_TYPE+1]
Definition pgstat.h:358

References Assert, PgStat_LockEntry::fastpath_exceeded, have_lockstats, LOCKTAG_LAST_TYPE, PendingLockStats, pgstat_report_fixed, and PgStat_PendingLock::stats.

Referenced by LockAcquireExtended().

◆ pgstat_count_lock_waits()

void pgstat_count_lock_waits ( uint8  locktag_type,
long  msecs 
)
extern

Definition at line 143 of file pgstat_lock.c.

144{
145 Assert(locktag_type <= LOCKTAG_LAST_TYPE);
146 PendingLockStats.stats[locktag_type].waits++;
148 have_lockstats = true;
149 pgstat_report_fixed = true;
150}
int64 PgStat_Counter
Definition pgstat.h:71
PgStat_Counter waits
Definition pgstat.h:351
PgStat_Counter wait_time
Definition pgstat.h:352

References Assert, fb(), have_lockstats, LOCKTAG_LAST_TYPE, PendingLockStats, pgstat_report_fixed, PgStat_PendingLock::stats, PgStat_LockEntry::wait_time, and PgStat_LockEntry::waits.

Referenced by ProcSleep().

◆ pgstat_count_slru_blocks_exists()

void pgstat_count_slru_blocks_exists ( int  slru_idx)
extern

◆ pgstat_count_slru_blocks_hit()

void pgstat_count_slru_blocks_hit ( int  slru_idx)
extern

◆ pgstat_count_slru_blocks_read()

void pgstat_count_slru_blocks_read ( int  slru_idx)
extern

Referenced by SimpleLruReadPage().

◆ pgstat_count_slru_blocks_written()

void pgstat_count_slru_blocks_written ( int  slru_idx)
extern

Referenced by SlruPhysicalWritePage().

◆ pgstat_count_slru_blocks_zeroed()

void pgstat_count_slru_blocks_zeroed ( int  slru_idx)
extern

Referenced by SimpleLruZeroPage().

◆ pgstat_count_slru_flush()

void pgstat_count_slru_flush ( int  slru_idx)
extern

Referenced by SimpleLruWriteAll().

◆ pgstat_count_slru_truncate()

void pgstat_count_slru_truncate ( int  slru_idx)
extern

Referenced by SimpleLruTruncate().

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)
extern

Definition at line 430 of file pgstat_relation.c.

431{
433 {
434 PgStat_TableStatus *pgstat_info = rel->pgstat_info;
435
436 ensure_tabstat_xact_level(pgstat_info);
437 save_truncdrop_counters(pgstat_info->trans, false);
438 pgstat_info->trans->tuples_inserted = 0;
439 pgstat_info->trans->tuples_updated = 0;
440 pgstat_info->trans->tuples_deleted = 0;
441 }
442}
static void save_truncdrop_counters(PgStat_TableXactStatus *trans, bool is_drop)

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, save_truncdrop_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by ExecuteTruncateGuts(), and RefreshMatViewByOid().

◆ pgstat_create_backend()

void pgstat_create_backend ( ProcNumber  procnum)
extern

Definition at line 324 of file pgstat_backend.c.

325{
326 PgStat_EntryRef *entry_ref;
328
330 procnum, false);
332
333 /*
334 * NB: need to accept that there might be stats from an older backend,
335 * e.g. if we previously used this proc number.
336 */
337 memset(&shstatent->stats, 0, sizeof(shstatent->stats));
338 pgstat_unlock_entry(entry_ref);
339
341 backend_has_iostats = false;
342
343 /*
344 * Initialize prevBackendWalUsage with pgWalUsage so that
345 * pgstat_backend_flush_cb() can calculate how much pgWalUsage counters
346 * are increased by subtracting prevBackendWalUsage from pgWalUsage.
347 */
349}
#define MemSet(start, val, len)
Definition c.h:1107
WalUsage pgWalUsage
Definition instrument.c:27
static WalUsage prevBackendWalUsage
#define PGSTAT_KIND_BACKEND
Definition pgstat_kind.h:32

References backend_has_iostats, fb(), InvalidOid, MemSet, PendingBackendStats, pgstat_get_entry_ref_locked(), PGSTAT_KIND_BACKEND, pgstat_unlock_entry(), pgWalUsage, prevBackendWalUsage, and PgStat_EntryRef::shared_stats.

Referenced by pgstat_bestart_final().

◆ pgstat_create_function()

void pgstat_create_function ( Oid  proid)
extern

Definition at line 45 of file pgstat_function.c.

46{
49 proid);
50}
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)

References fb(), MyDatabaseId, pgstat_create_transactional(), and PGSTAT_KIND_FUNCTION.

Referenced by ProcedureCreate().

◆ pgstat_create_relation()

void pgstat_create_relation ( Relation  rel)
extern

◆ pgstat_create_replslot()

void pgstat_create_replslot ( struct ReplicationSlot slot)
extern

Definition at line 141 of file pgstat_replslot.c.

142{
143 PgStat_EntryRef *entry_ref;
145
147
149 ReplicationSlotIndex(slot), false);
151
152 /*
153 * NB: need to accept that there might be stats from an older slot, e.g.
154 * if we previously crashed after dropping a slot.
155 */
156 memset(&shstatent->stats, 0, sizeof(shstatent->stats));
157
158 pgstat_unlock_entry(entry_ref);
159}
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1929
@ LW_EXCLUSIVE
Definition lwlock.h:104

References Assert, fb(), InvalidOid, LW_EXCLUSIVE, LWLockHeldByMeInMode(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), and PgStat_EntryRef::shared_stats.

Referenced by ReplicationSlotCreate().

◆ pgstat_create_subscription()

void pgstat_create_subscription ( Oid  subid)
extern

Definition at line 78 of file pgstat_subscription.c.

79{
80 /* Ensures that stats are dropped if transaction rolls back */
82 InvalidOid, subid);
83
84 /* Create and initialize the subscription stats entry */
86 true, NULL);
88}
#define PGSTAT_KIND_SUBSCRIPTION
Definition pgstat_kind.h:31
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, uint64 objid, TimestampTz ts)

References fb(), InvalidOid, pgstat_create_transactional(), pgstat_get_entry_ref(), PGSTAT_KIND_SUBSCRIPTION, and pgstat_reset_entry().

Referenced by CreateSubscription().

◆ pgstat_discard_stats()

void pgstat_discard_stats ( void  )
extern

Definition at line 537 of file pgstat.c.

539{
540 int ret;
541
542 /* NB: this needs to be done even in single user mode */
543
544 /* First, cleanup the main pgstats file */
546 if (ret != 0)
547 {
548 if (errno == ENOENT)
549 elog(DEBUG2,
550 "didn't need to unlink permanent stats file \"%s\" - didn't exist",
552 else
553 ereport(LOG,
555 errmsg("could not unlink permanent statistics file \"%s\": %m",
557 }
558 else
559 {
562 errmsg_internal("unlinked permanent statistics file \"%s\"",
564 }
565
566 /* Finish callbacks, if required */
567 for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
568 {
570
571 if (kind_info && kind_info->finish)
572 kind_info->finish(STATS_DISCARD);
573 }
574
575 /*
576 * Reset stats contents. This will set reset timestamps of fixed-numbered
577 * stats to the current time (no variable stats exist).
578 */
int errcode_for_file_access(void)
Definition elog.c:897
#define LOG
Definition elog.h:32
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define DEBUG2
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
static char * errmsg
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition pgstat.c:1479
static void pgstat_reset_after_failure(void)
Definition pgstat.c:2122
#define PGSTAT_STAT_PERMANENT_FILENAME
Definition pgstat.h:36
@ STATS_DISCARD
#define PgStat_Kind
Definition pgstat_kind.h:17
#define PGSTAT_KIND_MAX
Definition pgstat_kind.h:21
#define PGSTAT_KIND_MIN
Definition pgstat_kind.h:20

References DEBUG2, elog, ereport, errcode_for_file_access(), errmsg, errmsg_internal(), fb(), LOG, pgstat_get_kind_info(), PgStat_Kind, PGSTAT_KIND_MAX, PGSTAT_KIND_MIN, pgstat_reset_after_failure(), PGSTAT_STAT_PERMANENT_FILENAME, and STATS_DISCARD.

Referenced by StartupXLOG().

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)
extern

Definition at line 44 of file pgstat_database.c.

45{
47}
#define PGSTAT_KIND_DATABASE
Definition pgstat_kind.h:27
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)

References fb(), InvalidOid, pgstat_drop_transactional(), and PGSTAT_KIND_DATABASE.

Referenced by dropdb().

◆ pgstat_drop_function()

void pgstat_drop_function ( Oid  proid)
extern

◆ pgstat_drop_relation()

void pgstat_drop_relation ( Relation  rel)
extern

Definition at line 180 of file pgstat_relation.c.

181{
182 int nest_level = GetCurrentTransactionNestLevel();
183 PgStat_TableStatus *pgstat_info;
184
186 rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
187 RelationGetRelid(rel));
188
190 return;
191
192 /*
193 * Transactionally set counters to 0. That ensures that accesses to
194 * pg_stat_xact_all_tables inside the transaction show 0.
195 */
196 pgstat_info = rel->pgstat_info;
197 if (pgstat_info->trans &&
198 pgstat_info->trans->nest_level == nest_level)
199 {
200 save_truncdrop_counters(pgstat_info->trans, true);
201 pgstat_info->trans->tuples_inserted = 0;
202 pgstat_info->trans->tuples_updated = 0;
203 pgstat_info->trans->tuples_deleted = 0;
204 }
205}
int GetCurrentTransactionNestLevel(void)
Definition xact.c:931

References GetCurrentTransactionNestLevel(), InvalidOid, MyDatabaseId, PgStat_TableXactStatus::nest_level, pgstat_drop_transactional(), RelationData::pgstat_info, PGSTAT_KIND_RELATION, pgstat_should_count_relation, RelationData::rd_rel, RelationGetRelid, save_truncdrop_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_drop_with_catalog(), and index_drop().

◆ pgstat_drop_replslot()

void pgstat_drop_replslot ( struct ReplicationSlot slot)
extern

◆ pgstat_drop_subscription()

void pgstat_drop_subscription ( Oid  subid)
extern

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)
extern

Definition at line 146 of file pgstat_function.c.

147{
148 PgStat_FunctionCounts *fs = fcu->fs;
149 instr_time total;
151 instr_time self;
152
153 /* stats not wanted? */
154 if (fs == NULL)
155 return;
156
157 /* total elapsed time in this function call */
159 INSTR_TIME_SUBTRACT(total, fcu->start);
160
161 /* self usage: elapsed minus anything already charged to other calls */
163 INSTR_TIME_SUBTRACT(others, fcu->save_total);
164 self = total;
166
167 /* update backend-wide total time */
169
170 /*
171 * Compute the new total_time as the total elapsed time added to the
172 * pre-call value of total_time. This is necessary to avoid
173 * double-counting any time taken by recursive calls of myself. (We do
174 * not need any similar kluge for self time, since that already excludes
175 * any recursive calls.)
176 */
177 INSTR_TIME_ADD(total, fcu->save_f_total_time);
178
179 /* update counters in function stats table */
180 if (finalize)
181 fs->numcalls++;
182 fs->total_time = total;
183 INSTR_TIME_ADD(fs->self_time, self);
184}
static instr_time total_func_time
PgStat_Counter numcalls
Definition pgstat.h:88
instr_time total_time
Definition pgstat.h:89
instr_time self_time
Definition pgstat.h:90

References fb(), INSTR_TIME_ADD, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, PgStat_FunctionCounts::numcalls, PgStat_FunctionCounts::self_time, total_func_time, and PgStat_FunctionCounts::total_time.

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

◆ pgstat_execute_transactional_drops()

void pgstat_execute_transactional_drops ( int  ndrops,
struct xl_xact_stats_item items,
bool  is_redo 
)
extern

Definition at line 314 of file pgstat_xact.c.

315{
316 int not_freed_count = 0;
317
318 if (ndrops == 0)
319 return;
320
321 for (int i = 0; i < ndrops; i++)
322 {
324 uint64 objid = ((uint64) it->objid_hi) << 32 | it->objid_lo;
325
326 if (!pgstat_drop_entry(it->kind, it->dboid, objid))
328 }
329
330 if (not_freed_count > 0)
332}
uint64_t uint64
Definition c.h:625
int i
Definition isn.c:77
static ItemArray items

References fb(), i, items, pgstat_drop_entry(), and pgstat_request_entry_refs_gc().

Referenced by FinishPreparedTransaction(), xact_redo_abort(), and xact_redo_commit().

◆ pgstat_fetch_replslot()

PgStat_StatReplSlotEntry * pgstat_fetch_replslot ( NameData  slotname)
extern

Definition at line 200 of file pgstat_replslot.c.

201{
202 int idx;
204
206
207 idx = get_replslot_index(NameStr(slotname), false);
208
209 if (idx != -1)
212 NULL);
213
215
216 return slotentry;
217}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262
#define NameStr(name)
Definition c.h:835
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_SHARED
Definition lwlock.h:105
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *may_free)
Definition pgstat.c:962
static int get_replslot_index(const char *name, bool need_lock)

References fb(), get_replslot_index(), idx(), InvalidOid, LW_SHARED, LWLockAcquire(), LWLockRelease(), NameStr, pgstat_fetch_entry(), and PGSTAT_KIND_REPLSLOT.

Referenced by pg_stat_get_replication_slot().

◆ pgstat_fetch_slru()

PgStat_SLRUStats * pgstat_fetch_slru ( void  )
extern

Definition at line 91 of file pgstat_slru.c.

92{
94
96}
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition pgstat.c:1104
#define PGSTAT_KIND_SLRU
Definition pgstat_kind.h:40
PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]

References PGSTAT_KIND_SLRU, pgstat_snapshot_fixed(), pgStatLocal, PgStat_Snapshot::slru, and PgStat_LocalState::snapshot.

Referenced by pg_stat_get_slru().

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats * pgstat_fetch_stat_archiver ( void  )
extern

◆ pgstat_fetch_stat_backend()

PgStat_Backend * pgstat_fetch_stat_backend ( ProcNumber  procNumber)
extern

◆ pgstat_fetch_stat_backend_by_pid()

PgStat_Backend * pgstat_fetch_stat_backend_by_pid ( int  pid,
BackendType bktype 
)
extern

Definition at line 112 of file pgstat_backend.c.

113{
114 PGPROC *proc;
116 ProcNumber procNumber;
118
119 proc = BackendPidGetProc(pid);
120 if (bktype)
121 *bktype = B_INVALID;
122
123 /* this could be an auxiliary process */
124 if (!proc)
125 proc = AuxiliaryPidGetProc(pid);
126
127 if (!proc)
128 return NULL;
129
130 procNumber = GetNumberFromPGProc(proc);
131
133 if (!beentry)
134 return NULL;
135
136 /* check if the backend type tracks statistics */
137 if (!pgstat_tracks_backend_bktype(beentry->st_backendType))
138 return NULL;
139
140 /* if PID does not match, leave */
141 if (beentry->st_procpid != pid)
142 return NULL;
143
144 if (bktype)
145 *bktype = beentry->st_backendType;
146
147 /*
148 * Retrieve the entry. Note that "beentry" may be freed depending on the
149 * value of stats_fetch_consistency, so do not access it from this point.
150 */
152 if (!backend_stats)
153 {
154 if (bktype)
155 *bktype = B_INVALID;
156 return NULL;
157 }
158
159 return backend_stats;
160}
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
@ B_INVALID
Definition miscadmin.h:351
PgStat_Backend * pgstat_fetch_stat_backend(ProcNumber procNumber)
#define GetNumberFromPGProc(proc)
Definition proc.h:505
PGPROC * BackendPidGetProc(int pid)
Definition procarray.c:3169
int ProcNumber
Definition procnumber.h:24
PGPROC * AuxiliaryPidGetProc(int pid)
Definition proc.c:1097
Definition proc.h:179

References AuxiliaryPidGetProc(), B_INVALID, BackendPidGetProc(), fb(), GetNumberFromPGProc, pgstat_fetch_stat_backend(), pgstat_get_beentry_by_proc_number(), and pgstat_tracks_backend_bktype().

Referenced by pg_stat_get_backend_io(), and pg_stat_get_backend_wal().

◆ pgstat_fetch_stat_bgwriter()

◆ pgstat_fetch_stat_checkpointer()

◆ pgstat_fetch_stat_dbentry()

◆ pgstat_fetch_stat_funcentry()

◆ pgstat_fetch_stat_io()

PgStat_IO * pgstat_fetch_stat_io ( void  )
extern

Definition at line 164 of file pgstat_io.c.

165{
167
168 return &pgStatLocal.snapshot.io;
169}
#define PGSTAT_KIND_IO
Definition pgstat_kind.h:38

References PgStat_Snapshot::io, PGSTAT_KIND_IO, pgstat_snapshot_fixed(), pgStatLocal, and PgStat_LocalState::snapshot.

Referenced by pg_stat_get_io().

◆ pgstat_fetch_stat_lock()

PgStat_Lock * pgstat_fetch_stat_lock ( void  )
extern

◆ pgstat_fetch_stat_subscription()

PgStat_StatSubEntry * pgstat_fetch_stat_subscription ( Oid  subid)
extern

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry * pgstat_fetch_stat_tabentry ( Oid  relid)
extern

Definition at line 470 of file pgstat_relation.c.

471{
473}
bool IsSharedRelation(Oid relationId)
Definition catalog.c:304

References fb(), IsSharedRelation(), and pgstat_fetch_stat_tabentry_ext().

◆ pgstat_fetch_stat_tabentry_ext()

PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext ( bool  shared,
Oid  reloid,
bool may_free 
)
extern

Definition at line 481 of file pgstat_relation.c.

482{
483 Oid dboid = (shared ? InvalidOid : MyDatabaseId);
484
485 return (PgStat_StatTabEntry *)
487}
unsigned int Oid

References fb(), InvalidOid, MyDatabaseId, pgstat_fetch_entry(), and PGSTAT_KIND_RELATION.

Referenced by pgstat_copy_relation_stats(), pgstat_fetch_stat_tabentry(), and relation_needs_vacanalyze().

◆ pgstat_fetch_stat_wal()

PgStat_WalStats * pgstat_fetch_stat_wal ( void  )
extern

◆ pgstat_force_next_flush()

void pgstat_force_next_flush ( void  )
extern

Definition at line 842 of file pgstat.c.

844{
static bool pgStatForceNextFlush
Definition pgstat.c:250

References pgStatForceNextFlush.

Referenced by pg_stat_force_next_flush().

◆ pgstat_get_io_context_name()

const char * pgstat_get_io_context_name ( IOContext  io_context)
extern

Definition at line 240 of file pgstat_io.c.

241{
242 switch (io_context)
243 {
245 return "bulkread";
247 return "bulkwrite";
248 case IOCONTEXT_INIT:
249 return "init";
250 case IOCONTEXT_NORMAL:
251 return "normal";
252 case IOCONTEXT_VACUUM:
253 return "vacuum";
254 }
255
256 elog(ERROR, "unrecognized IOContext value: %d", io_context);
258}
#define pg_unreachable()
Definition c.h:367
#define ERROR
Definition elog.h:40

References elog, ERROR, fb(), IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_INIT, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().

◆ pgstat_get_io_object_name()

const char * pgstat_get_io_object_name ( IOObject  io_object)
extern

Definition at line 261 of file pgstat_io.c.

262{
263 switch (io_object)
264 {
266 return "relation";
268 return "temp relation";
269 case IOOBJECT_WAL:
270 return "wal";
271 }
272
273 elog(ERROR, "unrecognized IOObject value: %d", io_object);
275}

References elog, ERROR, fb(), IOOBJECT_RELATION, IOOBJECT_TEMP_RELATION, IOOBJECT_WAL, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().

◆ pgstat_get_kind_from_str()

PgStat_Kind pgstat_get_kind_from_str ( char kind_str)
extern

Definition at line 1445 of file pgstat.c.

1447{
1448 for (PgStat_Kind kind = PGSTAT_KIND_BUILTIN_MIN; kind <= PGSTAT_KIND_BUILTIN_MAX; kind++)
1449 {
1451 return kind;
1452 }
1453
1454 /* Check the custom set of cumulative stats */
1456 {
1457 for (PgStat_Kind kind = PGSTAT_KIND_CUSTOM_MIN; kind <= PGSTAT_KIND_CUSTOM_MAX; kind++)
1458 {
1460
1463 return kind;
1464 }
1465 }
1466
1467 ereport(ERROR,
1469 errmsg("invalid statistics kind: \"%s\"", kind_str)));
1470 return PGSTAT_KIND_INVALID; /* avoid compiler warnings */
uint32_t uint32
Definition c.h:624
int errcode(int sqlerrcode)
Definition elog.c:874
static const PgStat_KindInfo ** pgstat_kind_custom_infos
Definition pgstat.c:512
static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
Definition pgstat.c:282
#define PGSTAT_KIND_CUSTOM_MAX
Definition pgstat_kind.h:51
#define PGSTAT_KIND_CUSTOM_MIN
Definition pgstat_kind.h:50
#define PGSTAT_KIND_BUILTIN_MAX
Definition pgstat_kind.h:44
#define PGSTAT_KIND_INVALID
Definition pgstat_kind.h:24
#define PGSTAT_KIND_BUILTIN_MIN
Definition pgstat_kind.h:43
int pg_strcasecmp(const char *s1, const char *s2)
const char * name

References ereport, errcode(), errmsg, ERROR, fb(), idx(), name, pg_strcasecmp(), PgStat_Kind, pgstat_kind_builtin_infos, PGSTAT_KIND_BUILTIN_MAX, PGSTAT_KIND_BUILTIN_MIN, pgstat_kind_custom_infos, PGSTAT_KIND_CUSTOM_MAX, PGSTAT_KIND_CUSTOM_MIN, and PGSTAT_KIND_INVALID.

Referenced by pg_stat_have_stats().

◆ pgstat_get_slru_index()

int pgstat_get_slru_index ( const char name)
extern

Definition at line 118 of file pgstat_slru.c.

119{
120 int i;
121
122 Assert(name);
123 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
124 {
125 if (strcmp(slru_names[i], name) == 0)
126 return i;
127 }
128
129 /* return index of the last entry (which is the "other" one) */
130 return (SLRU_NUM_ELEMENTS - 1);
131}
static const char *const slru_names[]
#define SLRU_NUM_ELEMENTS

References Assert, fb(), i, name, slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pgstat_reset_slru(), and shmem_slru_init().

◆ pgstat_get_slru_name()

const char * pgstat_get_slru_name ( int  slru_idx)
extern

Definition at line 104 of file pgstat_slru.c.

105{
107 return NULL;
108
109 return slru_names[slru_idx];
110}

References fb(), slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pg_stat_get_slru().

◆ pgstat_get_stat_snapshot_timestamp()

TimestampTz pgstat_get_stat_snapshot_timestamp ( bool have_snapshot)
extern

◆ pgstat_get_transactional_drops()

int pgstat_get_transactional_drops ( bool  isCommit,
struct xl_xact_stats_item **  items 
)
extern

Definition at line 272 of file pgstat_xact.c.

273{
275 int nitems = 0;
276 dlist_iter iter;
277
278 if (xact_state == NULL)
279 return 0;
280
281 /*
282 * We expect to be called for subtransaction abort (which logs a WAL
283 * record), but not for subtransaction commit (which doesn't).
284 */
285 Assert(!isCommit || xact_state->nest_level == 1);
286 Assert(!isCommit || xact_state->prev == NULL);
287
288 *items = palloc(dclist_count(&xact_state->pending_drops)
289 * sizeof(xl_xact_stats_item));
290
291 dclist_foreach(iter, &xact_state->pending_drops)
292 {
295
296 if (isCommit && pending->is_create)
297 continue;
298 if (!isCommit && !pending->is_create)
299 continue;
300
301 Assert(nitems < dclist_count(&xact_state->pending_drops));
302 (*items)[nitems++] = pending->item;
303 }
304
305 return nitems;
306}
#define dclist_container(type, membername, ptr)
Definition ilist.h:947
static uint32 dclist_count(const dclist_head *head)
Definition ilist.h:932
#define dclist_foreach(iter, lhead)
Definition ilist.h:970
#define nitems(x)
Definition indent.h:31
void * palloc(Size size)
Definition mcxt.c:1387
dlist_node * cur
Definition ilist.h:179

References Assert, dlist_iter::cur, dclist_container, dclist_count(), dclist_foreach, fb(), PgStat_PendingDroppedStatsItem::is_create, PgStat_PendingDroppedStatsItem::item, items, PgStat_SubXactStatus::nest_level, nitems, palloc(), PgStat_SubXactStatus::pending_drops, pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by RecordTransactionAbort(), RecordTransactionCommit(), and StartPrepare().

◆ pgstat_have_entry()

bool pgstat_have_entry ( PgStat_Kind  kind,
Oid  dboid,
uint64  objid 
)
extern

Definition at line 1088 of file pgstat.c.

1090{
1091 /* fixed-numbered stats always exist */
1092 if (pgstat_get_kind_info(kind)->fixed_amount)
1093 return true;
1094
1095 return pgstat_get_entry_ref(kind, dboid, objid, false, NULL) != NULL;

References fb(), pgstat_get_entry_ref(), and pgstat_get_kind_info().

Referenced by pg_stat_have_stats().

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( struct FunctionCallInfoBaseData fcinfo,
PgStat_FunctionCallUsage fcu 
)
extern

◆ pgstat_init_relation()

void pgstat_init_relation ( Relation  rel)
extern

Definition at line 92 of file pgstat_relation.c.

93{
94 char relkind = rel->rd_rel->relkind;
95
96 /*
97 * We only count stats for relations with storage and partitioned tables
98 */
99 if (!RELKIND_HAS_STORAGE(relkind) && relkind != RELKIND_PARTITIONED_TABLE)
100 {
101 rel->pgstat_enabled = false;
102 rel->pgstat_info = NULL;
103 return;
104 }
105
107 {
108 if (rel->pgstat_info)
110
111 /* We're not counting at all */
112 rel->pgstat_enabled = false;
113 rel->pgstat_info = NULL;
114 return;
115 }
116
117 rel->pgstat_enabled = true;
118}
bool pgstat_track_counts
Definition pgstat.c:204
void pgstat_unlink_relation(Relation rel)

References fb(), RelationData::pgstat_enabled, RelationData::pgstat_info, pgstat_track_counts, pgstat_unlink_relation(), and RelationData::rd_rel.

Referenced by relation_open(), and try_relation_open().

◆ pgstat_initialize()

void pgstat_initialize ( void  )
extern

Definition at line 669 of file pgstat.c.

671{
673
675
677
678 /* Backend initialization callbacks */
679 for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
680 {
682
683 if (kind_info == NULL || kind_info->init_backend_cb == NULL)
684 continue;
685
686 kind_info->init_backend_cb();
687 }
688
689 /* Set up a process-exit hook to clean up */
691
692#ifdef USE_ASSERT_CHECKING
694#endif
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:344
static void pgstat_init_snapshot_fixed(void)
Definition pgstat.c:1124
static void pgstat_shutdown_hook(int code, Datum arg)
Definition pgstat.c:631
void pgstat_attach_shmem(void)

References Assert, before_shmem_exit(), fb(), pgstat_attach_shmem(), pgstat_get_kind_info(), pgstat_init_snapshot_fixed(), PgStat_Kind, PGSTAT_KIND_MAX, PGSTAT_KIND_MIN, and pgstat_shutdown_hook().

Referenced by BaseInit().

◆ pgstat_lock_flush()

void pgstat_lock_flush ( bool  nowait)
extern

Definition at line 37 of file pgstat_lock.c.

38{
39 (void) pgstat_lock_flush_cb(nowait);
40}
bool pgstat_lock_flush_cb(bool nowait)
Definition pgstat_lock.c:51

References fb(), and pgstat_lock_flush_cb().

◆ pgstat_prepare_io_time()

instr_time pgstat_prepare_io_time ( bool  track_io_guc)
extern

Definition at line 91 of file pgstat_io.c.

92{
94
95 if (track_io_guc)
97 else
98 {
99 /*
100 * There is no need to set io_start when an IO timing GUC is disabled.
101 * Initialize it to zero to avoid compiler warnings and to let
102 * pgstat_count_io_op_time() know that timings should be ignored.
103 */
105 }
106
107 return io_start;
108}
#define INSTR_TIME_SET_ZERO(t)
Definition instr_time.h:421

References fb(), INSTR_TIME_SET_CURRENT, and INSTR_TIME_SET_ZERO.

Referenced by AsyncReadBuffers(), ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushBuffer(), FlushLocalBuffer(), issue_xlog_fsync(), IssuePendingWritebacks(), mdsyncfiletag(), register_dirty_segment(), WaitReadBuffers(), WALRead(), XLogFileInitInternal(), XLogPageRead(), XLogWalRcvWrite(), and XLogWrite().

◆ pgstat_prepare_report_checksum_failure()

void pgstat_prepare_report_checksum_failure ( Oid  dboid)
extern

Definition at line 155 of file pgstat_database.c.

156{
158
159 /*
160 * Just need to ensure this backend has an entry ref for the database.
161 * That will allows us to report checksum failures without e.g. needing to
162 * map in DSM segments.
163 */
165 true, NULL);
166}
volatile uint32 CritSectionCount
Definition globals.c:45

References Assert, CritSectionCount, fb(), InvalidOid, pgstat_get_entry_ref(), and PGSTAT_KIND_DATABASE.

Referenced by AsyncReadBuffers(), read_rel_block_ll(), RelationCopyStorage(), and sendFile().

◆ pgstat_report_analyze()

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

Definition at line 282 of file pgstat_relation.c.

285{
286 PgStat_EntryRef *entry_ref;
289 Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
290 TimestampTz ts;
292
294 return;
295
296 /*
297 * Unlike VACUUM, ANALYZE might be running inside a transaction that has
298 * already inserted and/or deleted rows in the target table. ANALYZE will
299 * have counted such rows as live or dead respectively. Because we will
300 * report our counts of such rows at transaction end, we should subtract
301 * off these counts from the update we're making now, else they'll be
302 * double-counted after commit. (This approach also ensures that the
303 * shared stats entry ends up with the right numbers if we abort instead
304 * of committing.)
305 *
306 * Waste no time on partitioned tables, though.
307 */
309 rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
310 {
312
313 for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
314 {
315 livetuples -= trans->tuples_inserted - trans->tuples_deleted;
316 deadtuples -= trans->tuples_updated + trans->tuples_deleted;
317 }
318 /* count stuff inserted by already-aborted subxacts, too */
320 /* Since ANALYZE's counts are estimates, we could have underflowed */
323 }
324
325 /* Store the data in the table's hash table entry. */
326 ts = GetCurrentTimestamp();
328
329 /* block acquiring lock for the same reason as pgstat_report_autovac() */
331 RelationGetRelid(rel),
332 false);
333 /* can't get dropped while accessed */
334 Assert(entry_ref != NULL && entry_ref->shared_stats != NULL);
335
337 tabentry = &shtabentry->stats;
338
339 tabentry->live_tuples = livetuples;
340 tabentry->dead_tuples = deadtuples;
341
342 /*
343 * If commanded, reset mod_since_analyze to zero. This forgets any
344 * changes that were committed while the ANALYZE was in progress, but we
345 * have no good way to estimate how many of those there were.
346 */
347 if (resetcounter)
348 tabentry->mod_since_analyze = 0;
349
351 {
352 tabentry->last_autoanalyze_time = ts;
353 tabentry->autoanalyze_count++;
354 tabentry->total_autoanalyze_time += elapsedtime;
355 }
356 else
357 {
358 tabentry->last_analyze_time = ts;
359 tabentry->analyze_count++;
360 tabentry->total_analyze_time += elapsedtime;
361 }
362
363 pgstat_unlock_entry(entry_ref);
364
365 /* see pgstat_report_vacuum() */
366 pgstat_flush_io(false);
368}
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
Definition timestamp.c:1751
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1639
#define Max(x, y)
Definition c.h:1085
int64 TimestampTz
Definition timestamp.h:39
#define AmAutoVacuumWorkerProcess()
Definition miscadmin.h:398
bool pgstat_flush_backend(bool nowait, uint32 flags)
#define PGSTAT_BACKEND_FLUSH_IO
void pgstat_flush_io(bool nowait)
Definition pgstat_io.c:175
PgStat_Counter delta_dead_tuples
Definition pgstat.h:158

References AmAutoVacuumWorkerProcess, Assert, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, fb(), GetCurrentTimestamp(), InvalidOid, Max, MyDatabaseId, PGSTAT_BACKEND_FLUSH_IO, pgstat_flush_backend(), pgstat_flush_io(), pgstat_get_entry_ref_locked(), RelationData::pgstat_info, PGSTAT_KIND_RELATION, pgstat_should_count_relation, pgstat_track_counts, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, PgStat_EntryRef::shared_stats, TimestampDifferenceMilliseconds(), PgStat_TableStatus::trans, trans, and PgStat_TableXactStatus::tuples_inserted.

Referenced by do_analyze_rel().

◆ pgstat_report_archiver()

void pgstat_report_archiver ( const char xlog,
bool  failed 
)
extern

Definition at line 28 of file pgstat_archiver.c.

29{
32
34
35 if (failed)
36 {
37 ++stats_shmem->stats.failed_count;
38 memcpy(&stats_shmem->stats.last_failed_wal, xlog,
39 sizeof(stats_shmem->stats.last_failed_wal));
40 stats_shmem->stats.last_failed_timestamp = now;
41 }
42 else
43 {
44 ++stats_shmem->stats.archived_count;
45 memcpy(&stats_shmem->stats.last_archived_wal, xlog,
46 sizeof(stats_shmem->stats.last_archived_wal));
47 stats_shmem->stats.last_archived_timestamp = now;
48 }
49
51}
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1603
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
static void pgstat_end_changecount_write(uint32 *cc)
static void pgstat_begin_changecount_write(uint32 *cc)
PgStatShared_Archiver archiver

References PgStat_ShmemControl::archiver, fb(), GetCurrentTimestamp(), memcpy(), now(), pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by pgarch_ArchiverCopyLoop().

◆ pgstat_report_autovac()

void pgstat_report_autovac ( Oid  dboid)
extern

Definition at line 55 of file pgstat_database.c.

56{
57 PgStat_EntryRef *entry_ref;
59
60 /* can't get here in single user mode */
62
63 /*
64 * End-of-vacuum is reported instantly. Report the start the same way for
65 * consistency. Vacuum doesn't run frequently and is a long-lasting
66 * operation so it doesn't matter if we get blocked here a little.
67 */
69 dboid, InvalidOid, false);
70
72 dbentry->stats.last_autovac_time = GetCurrentTimestamp();
73
74 pgstat_unlock_entry(entry_ref);
75}
bool IsUnderPostmaster
Definition globals.c:122

References Assert, fb(), GetCurrentTimestamp(), InvalidOid, IsUnderPostmaster, pgstat_get_entry_ref_locked(), PGSTAT_KIND_DATABASE, pgstat_unlock_entry(), and PgStat_EntryRef::shared_stats.

Referenced by AutoVacWorkerMain().

◆ pgstat_report_bgwriter()

void pgstat_report_bgwriter ( void  )
extern

Definition at line 31 of file pgstat_bgwriter.c.

32{
34
37
38 /*
39 * This function can be called even if nothing at all has happened. In
40 * this case, avoid unnecessarily modifying the stats entry.
41 */
43 sizeof(struct PgStat_BgWriterStats)))
44 return;
45
47
48#define BGWRITER_ACC(fld) stats_shmem->stats.fld += PendingBgWriterStats.fld
49 BGWRITER_ACC(buf_written_clean);
50 BGWRITER_ACC(maxwritten_clean);
51 BGWRITER_ACC(buf_alloc);
52#undef BGWRITER_ACC
53
55
56 /*
57 * Clear out the statistics buffer, so it can be re-used.
58 */
60
61 /*
62 * Report IO statistics
63 */
64 pgstat_flush_io(false);
65}
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
Definition memutils.h:219
#define BGWRITER_ACC(fld)
PgStat_BgWriterStats PendingBgWriterStats
PgStatShared_BgWriter bgwriter

References Assert, PgStat_ShmemControl::bgwriter, BGWRITER_ACC, fb(), PgStat_ShmemControl::is_shutdown, MemSet, PendingBgWriterStats, pg_memory_is_all_zeros(), pgstat_assert_is_up, pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgstat_flush_io(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by BackgroundWriterMain().

◆ pgstat_report_checkpointer()

void pgstat_report_checkpointer ( void  )
extern

Definition at line 31 of file pgstat_checkpointer.c.

32{
34
37
38 /*
39 * This function can be called even if nothing at all has happened. In
40 * this case, avoid unnecessarily modifying the stats entry.
41 */
43 sizeof(struct PgStat_CheckpointerStats)))
44 return;
45
47
48#define CHECKPOINTER_ACC(fld) stats_shmem->stats.fld += PendingCheckpointerStats.fld
49 CHECKPOINTER_ACC(num_timed);
50 CHECKPOINTER_ACC(num_requested);
51 CHECKPOINTER_ACC(num_performed);
52 CHECKPOINTER_ACC(restartpoints_timed);
53 CHECKPOINTER_ACC(restartpoints_requested);
54 CHECKPOINTER_ACC(restartpoints_performed);
55 CHECKPOINTER_ACC(write_time);
56 CHECKPOINTER_ACC(sync_time);
57 CHECKPOINTER_ACC(buffers_written);
58 CHECKPOINTER_ACC(slru_written);
59#undef CHECKPOINTER_ACC
60
62
63 /*
64 * Clear out the statistics buffer, so it can be re-used.
65 */
67
68 /*
69 * Report IO statistics
70 */
71 pgstat_flush_io(false);
72}
PgStat_CheckpointerStats PendingCheckpointerStats
#define CHECKPOINTER_ACC(fld)
PgStatShared_Checkpointer checkpointer

References Assert, PgStat_ShmemControl::checkpointer, CHECKPOINTER_ACC, fb(), PgStat_ShmemControl::is_shutdown, MemSet, PendingCheckpointerStats, pg_memory_is_all_zeros(), pgstat_assert_is_up, pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgstat_flush_io(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by CheckpointerMain(), and CheckpointWriteDelay().

◆ pgstat_report_checksum_failures_in_db()

void pgstat_report_checksum_failures_in_db ( Oid  dboid,
int  failurecount 
)
extern

Definition at line 176 of file pgstat_database.c.

177{
178 PgStat_EntryRef *entry_ref;
180
182 return;
183
184 /*
185 * Update the shared stats directly - checksum failures should never be
186 * common enough for that to be a problem. Note that we pass create=false
187 * here, as we want to be sure to not require memory allocations, so this
188 * can be called in critical sections.
189 */
191 false, NULL);
192
193 /*
194 * Should always have been created by
195 * pgstat_prepare_report_checksum_failure().
196 *
197 * When not using assertions, we don't want to crash should something have
198 * gone wrong, so just return.
199 */
200 Assert(entry_ref);
201 if (!entry_ref)
202 {
203 elog(WARNING, "could not report %d checksum failures for database %u",
204 failurecount, dboid);
205 return;
206 }
207
208 (void) pgstat_lock_entry(entry_ref, false);
209
211 sharedent->stats.checksum_failures += failurecount;
212 sharedent->stats.last_checksum_failure = GetCurrentTimestamp();
213
214 pgstat_unlock_entry(entry_ref);
215}
#define WARNING
Definition elog.h:37
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)

References Assert, elog, fb(), GetCurrentTimestamp(), InvalidOid, pgstat_get_entry_ref(), PGSTAT_KIND_DATABASE, pgstat_lock_entry(), pgstat_track_counts, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and WARNING.

Referenced by buffer_readv_complete(), RelationCopyStorage(), sendFile(), and shared_buffer_readv_complete_local().

◆ pgstat_report_connect()

void pgstat_report_connect ( Oid  dboid)
extern

Definition at line 237 of file pgstat_database.c.

238{
240
242 return;
243
245
247 dbentry->sessions++;
248}
TimestampTz MyStartTimestamp
Definition globals.c:51
static bool pgstat_should_report_connstat(void)
static PgStat_Counter pgLastSessionReportTime
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)

References fb(), MyStartTimestamp, pgLastSessionReportTime, pgstat_prep_database_pending(), and pgstat_should_report_connstat().

Referenced by PostgresMain().

◆ pgstat_report_deadlock()

void pgstat_report_deadlock ( void  )
extern

Definition at line 135 of file pgstat_database.c.

136{
138
140 return;
141
143 dbent->deadlocks++;
144}

References fb(), MyDatabaseId, pgstat_prep_database_pending(), and pgstat_track_counts.

Referenced by DeadLockReport().

◆ pgstat_report_recovery_conflict()

void pgstat_report_recovery_conflict ( int  reason)
extern

Definition at line 81 of file pgstat_database.c.

82{
84
87 return;
88
90
91 switch ((RecoveryConflictReason) reason)
92 {
94
95 /*
96 * Since we drop the information about the database as soon as it
97 * replicates, there is no point in counting these conflicts.
98 */
99 break;
101 dbentry->conflict_tablespace++;
102 break;
104 dbentry->conflict_lock++;
105 break;
107 dbentry->conflict_snapshot++;
108 break;
110 dbentry->conflict_bufferpin++;
111 break;
113 dbentry->conflict_logicalslot++;
114 break;
116 dbentry->conflict_startup_deadlock++;
117 break;
119
120 /*
121 * The difference between RECOVERY_CONFLICT_STARTUP_DEADLOCK and
122 * RECOVERY_CONFLICT_BUFFERPIN_DEADLOCK is merely whether a buffer
123 * pin was part of the deadlock. We use the same counter for both
124 * reasons.
125 */
126 dbentry->conflict_startup_deadlock++;
127 break;
128 }
129}
RecoveryConflictReason
Definition standby.h:32
@ RECOVERY_CONFLICT_TABLESPACE
Definition standby.h:37
@ RECOVERY_CONFLICT_SNAPSHOT
Definition standby.h:43
@ RECOVERY_CONFLICT_LOCK
Definition standby.h:40
@ RECOVERY_CONFLICT_DATABASE
Definition standby.h:34
@ RECOVERY_CONFLICT_STARTUP_DEADLOCK
Definition standby.h:56
@ RECOVERY_CONFLICT_BUFFERPIN
Definition standby.h:49
@ RECOVERY_CONFLICT_BUFFERPIN_DEADLOCK
Definition standby.h:64
@ RECOVERY_CONFLICT_LOGICALSLOT
Definition standby.h:46

References Assert, fb(), IsUnderPostmaster, MyDatabaseId, pgstat_prep_database_pending(), pgstat_track_counts, RECOVERY_CONFLICT_BUFFERPIN, RECOVERY_CONFLICT_BUFFERPIN_DEADLOCK, RECOVERY_CONFLICT_DATABASE, RECOVERY_CONFLICT_LOCK, RECOVERY_CONFLICT_LOGICALSLOT, RECOVERY_CONFLICT_SNAPSHOT, RECOVERY_CONFLICT_STARTUP_DEADLOCK, and RECOVERY_CONFLICT_TABLESPACE.

Referenced by report_recovery_conflict().

◆ pgstat_report_replslot()

void pgstat_report_replslot ( struct ReplicationSlot slot,
const PgStat_StatReplSlotEntry repSlotStat 
)
extern

Definition at line 77 of file pgstat_replslot.c.

78{
79 PgStat_EntryRef *entry_ref;
82
84 ReplicationSlotIndex(slot), false);
86 statent = &shstatent->stats;
87
88 /* Update the replication slot statistics */
89#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
90 REPLSLOT_ACC(spill_txns);
91 REPLSLOT_ACC(spill_count);
92 REPLSLOT_ACC(spill_bytes);
93 REPLSLOT_ACC(stream_txns);
94 REPLSLOT_ACC(stream_count);
95 REPLSLOT_ACC(stream_bytes);
96 REPLSLOT_ACC(mem_exceeded_count);
97 REPLSLOT_ACC(total_txns);
98 REPLSLOT_ACC(total_bytes);
99#undef REPLSLOT_ACC
100
101 pgstat_unlock_entry(entry_ref);
102}
#define REPLSLOT_ACC(fld)

References fb(), InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), REPLSLOT_ACC, and PgStat_EntryRef::shared_stats.

Referenced by UpdateDecodingStats().

◆ pgstat_report_replslotsync()

void pgstat_report_replslotsync ( struct ReplicationSlot slot)
extern

Definition at line 111 of file pgstat_replslot.c.

112{
113 PgStat_EntryRef *entry_ref;
116
117 /* Slot sync stats are valid only for synced logical slots on standby. */
118 Assert(slot->data.synced);
120
122 ReplicationSlotIndex(slot), false);
123 Assert(entry_ref != NULL);
124
126 statent = &shstatent->stats;
127
128 statent->slotsync_skip_count += 1;
129 statent->slotsync_last_skip = GetCurrentTimestamp();
130
131 pgstat_unlock_entry(entry_ref);
132}
ReplicationSlotPersistentData data
Definition slot.h:213
bool RecoveryInProgress(void)
Definition xlog.c:6830

References Assert, ReplicationSlot::data, fb(), GetCurrentTimestamp(), InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), RecoveryInProgress(), ReplicationSlotIndex(), PgStat_EntryRef::shared_stats, and ReplicationSlotPersistentData::synced.

Referenced by update_slotsync_skip_stats().

◆ pgstat_report_stat()

long pgstat_report_stat ( bool  force)
extern

Definition at line 722 of file pgstat.c.

724{
725 static TimestampTz pending_since = 0;
726 static TimestampTz last_flush = 0;
727 bool partial_flush;
729 bool nowait;
730
733
734 /* "absorb" the forced flush even if there's nothing to flush */
736 {
737 force = true;
738 pgStatForceNextFlush = false;
739 }
740
741 /* Don't expend a clock check if nothing to do */
744 {
745 return 0;
746 }
747
748 /*
749 * There should never be stats to report once stats are shut down. Can't
750 * assert that before the checks above, as there is an unconditional
751 * pgstat_report_stat() call in pgstat_shutdown_hook() - which at least
752 * the process that ran pgstat_before_server_shutdown() will still call.
753 */
755
756 if (force)
757 {
758 /*
759 * Stats reports are forced either when it's been too long since stats
760 * have been reported or in processes that force stats reporting to
761 * happen at specific points (including shutdown). In the former case
762 * the transaction stop time might be quite old, in the latter it
763 * would never get cleared.
764 */
766 }
767 else
768 {
770
771 if (pending_since > 0 &&
773 {
774 /* don't keep pending updates longer than PGSTAT_MAX_INTERVAL */
775 force = true;
776 }
777 else if (last_flush > 0 &&
779 {
780 /* don't flush too frequently */
781 if (pending_since == 0)
783
785 }
786 }
787
789
790 /* don't wait for lock acquisition when !force */
791 nowait = !force;
792
793 partial_flush = false;
794
795 /* flush of variable-numbered stats tracked in pending entries list */
797
798 /* flush of other stats kinds */
800 {
801 for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
802 {
804
805 if (!kind_info)
806 continue;
807 if (!kind_info->flush_static_cb)
808 continue;
809
810 partial_flush |= kind_info->flush_static_cb(nowait);
811 }
812 }
813
814 last_flush = now;
815
816 /*
817 * If some of the pending stats could not be flushed due to lock
818 * contention, let the caller know when to retry.
819 */
820 if (partial_flush)
821 {
822 /* force should have prevented us from getting here */
823 Assert(!force);
824
825 /* remember since when stats have been pending */
826 if (pending_since == 0)
828
830 }
831
832 pending_since = 0;
833 pgstat_report_fixed = false;
834
835 return 0;
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition timestamp.c:1775
static bool dlist_is_empty(const dlist_head *head)
Definition ilist.h:336
#define PGSTAT_MIN_INTERVAL
Definition pgstat.c:127
static bool pgstat_flush_pending_entries(bool nowait)
Definition pgstat.c:1383
static dlist_head pgStatPending
Definition pgstat.c:243
#define PGSTAT_MAX_INTERVAL
Definition pgstat.c:129
#define PGSTAT_IDLE_INTERVAL
Definition pgstat.c:131
void pgstat_update_dbstats(TimestampTz ts)
bool IsTransactionOrTransactionBlock(void)
Definition xact.c:5040
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition xact.c:893

References Assert, dlist_is_empty(), fb(), GetCurrentTimestamp(), GetCurrentTransactionStopTimestamp(), PgStat_ShmemControl::is_shutdown, IsTransactionOrTransactionBlock(), now(), pgstat_assert_is_up, pgstat_flush_pending_entries(), pgstat_get_kind_info(), PGSTAT_IDLE_INTERVAL, PgStat_Kind, PGSTAT_KIND_MAX, PGSTAT_KIND_MIN, PGSTAT_MAX_INTERVAL, PGSTAT_MIN_INTERVAL, pgstat_report_fixed, pgstat_update_dbstats(), pgStatForceNextFlush, pgStatLocal, pgStatPending, PgStat_LocalState::shmem, and TimestampDifferenceExceeds().

Referenced by AllTablesyncsReady(), apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_rollback_prepared(), apply_handle_stream_prepare(), FinishSyncWorker(), HasSubscriptionTablesCached(), LogicalRepApplyLoop(), LogicalRepSyncTableStart(), pgstat_before_server_shutdown(), pgstat_shutdown_hook(), PostgresMain(), ProcessInterrupts(), ProcessSequencesForSync(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), standby_redo(), and worker_spi_main().

◆ pgstat_report_subscription_conflict()

void pgstat_report_subscription_conflict ( Oid  subid,
ConflictType  type 
)
extern

Definition at line 63 of file pgstat_subscription.c.

64{
65 PgStat_EntryRef *entry_ref;
67
69 InvalidOid, subid, NULL);
70 pending = entry_ref->pending;
71 pending->conflict_count[type]++;
72}
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition pgstat.c:1309
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition pgstat.h:118
const char * type

References PgStat_BackendSubEntry::conflict_count, fb(), InvalidOid, PgStat_EntryRef::pending, PGSTAT_KIND_SUBSCRIPTION, pgstat_prep_pending_entry(), and type.

Referenced by ReportApplyConflict().

◆ pgstat_report_subscription_error()

void pgstat_report_subscription_error ( Oid  subid)
extern

Definition at line 28 of file pgstat_subscription.c.

29{
30 PgStat_EntryRef *entry_ref;
33
35 InvalidOid, subid, NULL);
36 pending = entry_ref->pending;
37
38 switch (wtype)
39 {
41 pending->apply_error_count++;
42 break;
43
45 pending->sync_seq_error_count++;
46 break;
47
49 pending->sync_table_error_count++;
50 break;
51
52 default:
53 /* Should never happen. */
54 Assert(0);
55 break;
56 }
57}
PgStat_Counter sync_table_error_count
Definition pgstat.h:117
PgStat_Counter apply_error_count
Definition pgstat.h:115
PgStat_Counter sync_seq_error_count
Definition pgstat.h:116
LogicalRepWorkerType
@ WORKERTYPE_TABLESYNC
@ WORKERTYPE_SEQUENCESYNC
@ WORKERTYPE_APPLY
static LogicalRepWorkerType get_logical_worker_type(void)

References PgStat_BackendSubEntry::apply_error_count, Assert, fb(), get_logical_worker_type(), InvalidOid, PgStat_EntryRef::pending, PGSTAT_KIND_SUBSCRIPTION, pgstat_prep_pending_entry(), PgStat_BackendSubEntry::sync_seq_error_count, PgStat_BackendSubEntry::sync_table_error_count, WORKERTYPE_APPLY, WORKERTYPE_SEQUENCESYNC, and WORKERTYPE_TABLESYNC.

Referenced by DisableSubscriptionAndExit(), start_apply(), start_sequence_sync(), and start_table_sync().

◆ pgstat_report_vacuum()

void pgstat_report_vacuum ( Relation  rel,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples,
TimestampTz  starttime 
)
extern

Definition at line 211 of file pgstat_relation.c.

213{
214 PgStat_EntryRef *entry_ref;
217 Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
218 TimestampTz ts;
220
222 return;
223
224 /* Store the data in the table's hash table entry. */
225 ts = GetCurrentTimestamp();
227
228 /* block acquiring lock for the same reason as pgstat_report_autovac() */
230 RelationGetRelid(rel), false);
231
233 tabentry = &shtabentry->stats;
234
235 tabentry->live_tuples = livetuples;
236 tabentry->dead_tuples = deadtuples;
237
238 /*
239 * It is quite possible that a non-aggressive VACUUM ended up skipping
240 * various pages, however, we'll zero the insert counter here regardless.
241 * It's currently used only to track when we need to perform an "insert"
242 * autovacuum, which are mainly intended to freeze newly inserted tuples.
243 * Zeroing this may just mean we'll not try to vacuum the table again
244 * until enough tuples have been inserted to trigger another insert
245 * autovacuum. An anti-wraparound autovacuum will catch any persistent
246 * stragglers.
247 */
248 tabentry->ins_since_vacuum = 0;
249
251 {
252 tabentry->last_autovacuum_time = ts;
253 tabentry->autovacuum_count++;
254 tabentry->total_autovacuum_time += elapsedtime;
255 }
256 else
257 {
258 tabentry->last_vacuum_time = ts;
259 tabentry->vacuum_count++;
260 tabentry->total_vacuum_time += elapsedtime;
261 }
262
263 pgstat_unlock_entry(entry_ref);
264
265 /*
266 * Flush IO statistics now. pgstat_report_stat() will flush IO stats,
267 * however this will not be called until after an entire autovacuum cycle
268 * is done -- which will likely vacuum many relations -- or until the
269 * VACUUM command has processed all tables and committed.
270 */
271 pgstat_flush_io(false);
273}

References AmAutoVacuumWorkerProcess, fb(), GetCurrentTimestamp(), InvalidOid, MyDatabaseId, PGSTAT_BACKEND_FLUSH_IO, pgstat_flush_backend(), pgstat_flush_io(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_track_counts, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, PgStat_EntryRef::shared_stats, and TimestampDifferenceMilliseconds().

Referenced by heap_vacuum_rel().

◆ pgstat_report_wal()

void pgstat_report_wal ( bool  force)
extern

Definition at line 46 of file pgstat_wal.c.

47{
48 bool nowait;
49
50 /* like in pgstat.c, don't wait for lock acquisition when !force */
51 nowait = !force;
52
53 /* flush wal stats */
54 (void) pgstat_wal_flush_cb(nowait);
56
57 /* flush IO stats */
58 pgstat_flush_io(nowait);
60}
#define PGSTAT_BACKEND_FLUSH_WAL
bool pgstat_wal_flush_cb(bool nowait)
Definition pgstat_wal.c:91

References fb(), PGSTAT_BACKEND_FLUSH_IO, PGSTAT_BACKEND_FLUSH_WAL, pgstat_flush_backend(), pgstat_flush_io(), and pgstat_wal_flush_cb().

Referenced by BackgroundWriterMain(), CheckpointerMain(), summarizer_wait_for_wal(), WalReceiverMain(), and WalWriterMain().

◆ pgstat_reset()

void pgstat_reset ( PgStat_Kind  kind,
Oid  dboid,
uint64  objid 
)
extern

Definition at line 882 of file pgstat.c.

884{
887
888 /* not needed atm, and doesn't make sense with the current signature */
889 Assert(!pgstat_get_kind_info(kind)->fixed_amount);
890
891 /* reset the "single counter" */
892 pgstat_reset_entry(kind, dboid, objid, ts);
893
894 if (!kind_info->accessed_across_databases)
void pgstat_reset_database_timestamp(Oid dboid, TimestampTz ts)

References Assert, fb(), GetCurrentTimestamp(), pgstat_get_kind_info(), pgstat_reset_database_timestamp(), and pgstat_reset_entry().

Referenced by pg_stat_reset_backend_stats(), pg_stat_reset_single_function_counters(), pg_stat_reset_single_table_counters(), pg_stat_reset_subscription_stats(), pgstat_create_transactional(), and pgstat_reset_replslot().

◆ pgstat_reset_counters()

void pgstat_reset_counters ( void  )
extern

Definition at line 863 of file pgstat.c.

865{
867
870 ts);
static bool match_db_entries(PgStatShared_HashEntry *entry, Datum match_data)
Definition pgstat.c:851
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252

References GetCurrentTimestamp(), match_db_entries(), MyDatabaseId, ObjectIdGetDatum(), and pgstat_reset_matching_entries().

Referenced by pg_stat_reset().

◆ pgstat_reset_of_kind()

void pgstat_reset_of_kind ( PgStat_Kind  kind)
extern

◆ pgstat_reset_replslot()

void pgstat_reset_replslot ( const char name)
extern

Definition at line 42 of file pgstat_replslot.c.

43{
44 ReplicationSlot *slot;
45
46 Assert(name != NULL);
47
49
50 /* Check if the slot exists with the given name. */
51 slot = SearchNamedReplicationSlot(name, false);
52 if (!slot)
55 errmsg("replication slot \"%s\" does not exist",
56 name)));
57
58 /*
59 * Reset stats if it is a logical slot. Nothing to do for physical slots
60 * as we collect stats only for logical slots.
61 */
62 if (SlotIsLogical(slot))
65
67}
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:882
ReplicationSlot * SearchNamedReplicationSlot(const char *name, bool need_lock)
Definition slot.c:548
#define SlotIsLogical(slot)
Definition slot.h:288

References Assert, ereport, errcode(), errmsg, ERROR, fb(), InvalidOid, LW_SHARED, LWLockAcquire(), LWLockRelease(), name, PGSTAT_KIND_REPLSLOT, pgstat_reset(), ReplicationSlotIndex(), SearchNamedReplicationSlot(), and SlotIsLogical.

Referenced by pg_stat_reset_replication_slot().

◆ pgstat_reset_slru()

void pgstat_reset_slru ( const char name)
extern

Definition at line 45 of file pgstat_slru.c.

46{
48
49 Assert(name != NULL);
50
52}
int pgstat_get_slru_index(const char *name)
static void pgstat_reset_slru_counter_internal(int index, TimestampTz ts)

References Assert, fb(), GetCurrentTimestamp(), name, pgstat_get_slru_index(), and pgstat_reset_slru_counter_internal().

Referenced by pg_stat_reset_slru().

◆ pgstat_restore_stats()

void pgstat_restore_stats ( void  )
extern

Definition at line 525 of file pgstat.c.

527{
static void pgstat_read_statsfile(void)
Definition pgstat.c:1809

References pgstat_read_statsfile().

Referenced by StartupXLOG().

◆ pgstat_tracks_backend_bktype()

bool pgstat_tracks_backend_bktype ( BackendType  bktype)
extern

Definition at line 367 of file pgstat_backend.c.

368{
369 /*
370 * List every type so that new backend types trigger a warning about
371 * needing to adjust this switch.
372 */
373 switch (bktype)
374 {
375 case B_INVALID:
378 case B_ARCHIVER:
379 case B_LOGGER:
380 case B_BG_WRITER:
381 case B_CHECKPOINTER:
382 case B_IO_WORKER:
383 case B_STARTUP:
386 return false;
387
388 case B_AUTOVAC_WORKER:
389 case B_BACKEND:
390 case B_BG_WORKER:
393 case B_WAL_RECEIVER:
394 case B_WAL_SENDER:
395 case B_WAL_SUMMARIZER:
396 case B_WAL_WRITER:
397 return true;
398 }
399
400 return false;
401}
@ B_WAL_SUMMARIZER
Definition miscadmin.h:379
@ B_WAL_WRITER
Definition miscadmin.h:380
@ B_WAL_RECEIVER
Definition miscadmin.h:378
@ B_CHECKPOINTER
Definition miscadmin.h:375
@ B_DATACHECKSUMSWORKER_WORKER
Definition miscadmin.h:383
@ B_WAL_SENDER
Definition miscadmin.h:359
@ B_IO_WORKER
Definition miscadmin.h:376
@ B_LOGGER
Definition miscadmin.h:389
@ B_STARTUP
Definition miscadmin.h:377
@ B_DATACHECKSUMSWORKER_LAUNCHER
Definition miscadmin.h:382
@ B_BG_WORKER
Definition miscadmin.h:358
@ B_STANDALONE_BACKEND
Definition miscadmin.h:362
@ B_BG_WRITER
Definition miscadmin.h:374
@ B_BACKEND
Definition miscadmin.h:354
@ B_ARCHIVER
Definition miscadmin.h:373
@ B_AUTOVAC_LAUNCHER
Definition miscadmin.h:356
@ B_SLOTSYNC_WORKER
Definition miscadmin.h:360
@ B_DEAD_END_BACKEND
Definition miscadmin.h:355
@ B_AUTOVAC_WORKER
Definition miscadmin.h:357

References B_ARCHIVER, B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_DATACHECKSUMSWORKER_LAUNCHER, B_DATACHECKSUMSWORKER_WORKER, B_DEAD_END_BACKEND, B_INVALID, B_IO_WORKER, B_LOGGER, B_SLOTSYNC_WORKER, B_STANDALONE_BACKEND, B_STARTUP, B_WAL_RECEIVER, B_WAL_SENDER, B_WAL_SUMMARIZER, B_WAL_WRITER, and fb().

Referenced by pg_stat_reset_backend_stats(), pgstat_bestart_final(), pgstat_count_backend_io_op(), pgstat_count_backend_io_op_time(), pgstat_fetch_stat_backend_by_pid(), and pgstat_flush_backend().

◆ pgstat_tracks_io_bktype()

bool pgstat_tracks_io_bktype ( BackendType  bktype)
extern

Definition at line 351 of file pgstat_io.c.

352{
353 /*
354 * List every type so that new backend types trigger a warning about
355 * needing to adjust this switch.
356 */
357 switch (bktype)
358 {
359 case B_INVALID:
361 case B_ARCHIVER:
362 case B_LOGGER:
363 return false;
364
368 case B_AUTOVAC_WORKER:
369 case B_BACKEND:
370 case B_BG_WORKER:
371 case B_BG_WRITER:
372 case B_CHECKPOINTER:
373 case B_IO_WORKER:
376 case B_STARTUP:
377 case B_WAL_RECEIVER:
378 case B_WAL_SENDER:
379 case B_WAL_SUMMARIZER:
380 case B_WAL_WRITER:
381 return true;
382 }
383
384 return false;
385}

References B_ARCHIVER, B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_DATACHECKSUMSWORKER_LAUNCHER, B_DATACHECKSUMSWORKER_WORKER, B_DEAD_END_BACKEND, B_INVALID, B_IO_WORKER, B_LOGGER, B_SLOTSYNC_WORKER, B_STANDALONE_BACKEND, B_STARTUP, B_WAL_RECEIVER, B_WAL_SENDER, B_WAL_SUMMARIZER, B_WAL_WRITER, and fb().

Referenced by pg_stat_get_io(), and pgstat_tracks_io_object().

◆ pgstat_tracks_io_object()

bool pgstat_tracks_io_object ( BackendType  bktype,
IOObject  io_object,
IOContext  io_context 
)
extern

Definition at line 395 of file pgstat_io.c.

397{
398 bool no_temp_rel;
399
400 /*
401 * Some BackendTypes should never track IO statistics.
402 */
404 return false;
405
406 /*
407 * Currently, IO on IOOBJECT_WAL objects can only occur in the
408 * IOCONTEXT_NORMAL and IOCONTEXT_INIT IOContexts.
409 */
410 if (io_object == IOOBJECT_WAL &&
413 return false;
414
415 /*
416 * Currently, IO on temporary relations can only occur in the
417 * IOCONTEXT_NORMAL IOContext.
418 */
421 return false;
422
423 /*
424 * In core Postgres, only regular backends and WAL Sender processes
425 * executing queries will use local buffers and operate on temporary
426 * relations. Parallel workers will not use local buffers (see
427 * InitLocalBuffers()); however, extensions leveraging background workers
428 * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for
429 * BackendType B_BG_WORKER.
430 */
436
439 return false;
440
441 /*
442 * Some BackendTypes only perform IO under IOOBJECT_WAL, hence exclude all
443 * rows for all the other objects for these.
444 */
447 return false;
448
449 /*
450 * Some BackendTypes do not currently perform any IO in certain
451 * IOContexts, and, while it may not be inherently incorrect for them to
452 * do so, excluding those rows from the view makes the view easier to use.
453 */
454 if ((bktype == B_CHECKPOINTER || bktype == B_BG_WRITER) &&
458 return false;
459
461 return false;
462
465 return false;
466
467 return true;
468}
bool pgstat_tracks_io_bktype(BackendType bktype)
Definition pgstat_io.c:351

References B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_STANDALONE_BACKEND, B_STARTUP, B_WAL_RECEIVER, B_WAL_SUMMARIZER, B_WAL_WRITER, fb(), IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_INIT, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, IOOBJECT_TEMP_RELATION, IOOBJECT_WAL, and pgstat_tracks_io_bktype().

Referenced by pg_stat_io_build_tuples(), and pgstat_tracks_io_op().

◆ pgstat_tracks_io_op()

bool pgstat_tracks_io_op ( BackendType  bktype,
IOObject  io_object,
IOContext  io_context,
IOOp  io_op 
)
extern

Definition at line 479 of file pgstat_io.c.

481{
483
484 /* if (io_context, io_object) will never collect stats, we're done */
486 return false;
487
488 /*
489 * Some BackendTypes will not do certain IOOps.
490 */
491 if (bktype == B_BG_WRITER &&
492 (io_op == IOOP_READ || io_op == IOOP_EVICT || io_op == IOOP_HIT))
493 return false;
494
495 if (bktype == B_CHECKPOINTER &&
497 (io_op == IOOP_EVICT || io_op == IOOP_HIT)))
498 return false;
499
502 return false;
503
504 /*
505 * Some BackendTypes do not perform reads with IOOBJECT_WAL.
506 */
507 if (io_object == IOOBJECT_WAL && io_op == IOOP_READ &&
511 return false;
512
513 /*
514 * Temporary tables are not logged and thus do not require fsync'ing.
515 * Writeback is not requested for temporary tables.
516 */
519 return false;
520
521 /*
522 * Some IOOps are not valid in certain IOContexts and some IOOps are only
523 * valid in certain contexts.
524 */
526 return false;
527
530
531 /*
532 * IOOP_REUSE is only relevant when a BufferAccessStrategy is in use.
533 */
535 return false;
536
537 /*
538 * IOOBJECT_WAL IOObject will not do certain IOOps depending on IOContext.
539 */
541 !(io_op == IOOP_WRITE || io_op == IOOP_FSYNC))
542 return false;
543
546 return false;
547
548 /*
549 * IOOP_FSYNC IOOps done by a backend using a BufferAccessStrategy are
550 * counted in the IOCONTEXT_NORMAL IOContext. See comment in
551 * register_dirty_segment() for more details.
552 */
554 return false;
555
556
557 return true;
558}
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition pgstat_io.c:395

References B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_WAL_RECEIVER, B_WAL_WRITER, fb(), IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_INIT, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, IOOBJECT_TEMP_RELATION, IOOBJECT_WAL, IOOP_EVICT, IOOP_EXTEND, IOOP_FSYNC, IOOP_HIT, IOOP_READ, IOOP_REUSE, IOOP_WRITE, IOOP_WRITEBACK, and pgstat_tracks_io_object().

Referenced by pg_stat_io_build_tuples(), pgstat_bktype_io_stats_valid(), pgstat_count_backend_io_op(), pgstat_count_backend_io_op_time(), and pgstat_count_io_op().

◆ pgstat_twophase_postabort()

void pgstat_twophase_postabort ( FullTransactionId  fxid,
uint16  info,
void recdata,
uint32  len 
)
extern

Definition at line 784 of file pgstat_relation.c.

786{
788 PgStat_TableStatus *pgstat_info;
789
790 /* Find or create a tabstat entry for the rel */
791 pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
792
793 /* Same math as in AtEOXact_PgStat, abort case */
794 if (rec->truncdropped)
795 {
799 }
800 pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
801 pgstat_info->counts.tuples_updated += rec->tuples_updated;
802 pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
803 pgstat_info->counts.delta_dead_tuples +=
805}
PgStat_Counter tuples_inserted
Definition pgstat.h:150
PgStat_Counter tuples_updated
Definition pgstat.h:151
PgStat_Counter tuples_deleted
Definition pgstat.h:152
PgStat_Counter deleted_pre_truncdrop
PgStat_Counter inserted_pre_truncdrop
PgStat_Counter updated_pre_truncdrop
PgStat_Counter tuples_deleted
PgStat_Counter tuples_inserted
PgStat_Counter tuples_updated

References PgStat_TableStatus::counts, TwoPhasePgStatRecord::deleted_pre_truncdrop, PgStat_TableCounts::delta_dead_tuples, fb(), TwoPhasePgStatRecord::id, TwoPhasePgStatRecord::inserted_pre_truncdrop, pgstat_prep_relation_pending(), TwoPhasePgStatRecord::shared, TwoPhasePgStatRecord::truncdropped, TwoPhasePgStatRecord::tuples_deleted, PgStat_TableCounts::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, PgStat_TableCounts::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, PgStat_TableCounts::tuples_updated, and TwoPhasePgStatRecord::updated_pre_truncdrop.

◆ pgstat_twophase_postcommit()

void pgstat_twophase_postcommit ( FullTransactionId  fxid,
uint16  info,
void recdata,
uint32  len 
)
extern

Definition at line 748 of file pgstat_relation.c.

750{
752 PgStat_TableStatus *pgstat_info;
753
754 /* Find or create a tabstat entry for the rel */
755 pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
756
757 /* Same math as in AtEOXact_PgStat, commit case */
758 pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
759 pgstat_info->counts.tuples_updated += rec->tuples_updated;
760 pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
761 pgstat_info->counts.truncdropped = rec->truncdropped;
762 if (rec->truncdropped)
763 {
764 /* forget live/dead stats seen by backend thus far */
765 pgstat_info->counts.delta_live_tuples = 0;
766 pgstat_info->counts.delta_dead_tuples = 0;
767 }
768 pgstat_info->counts.delta_live_tuples +=
770 pgstat_info->counts.delta_dead_tuples +=
771 rec->tuples_updated + rec->tuples_deleted;
772 pgstat_info->counts.changed_tuples +=
773 rec->tuples_inserted + rec->tuples_updated +
774 rec->tuples_deleted;
775}
PgStat_Counter delta_live_tuples
Definition pgstat.h:157
PgStat_Counter changed_tuples
Definition pgstat.h:159

References PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, fb(), TwoPhasePgStatRecord::id, pgstat_prep_relation_pending(), TwoPhasePgStatRecord::shared, TwoPhasePgStatRecord::truncdropped, PgStat_TableCounts::truncdropped, TwoPhasePgStatRecord::tuples_deleted, PgStat_TableCounts::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, PgStat_TableCounts::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, and PgStat_TableCounts::tuples_updated.

◆ pgstat_unlink_relation()

void pgstat_unlink_relation ( Relation  rel)
extern

Definition at line 153 of file pgstat_relation.c.

154{
155 /* remove the link to stats info if any */
156 if (rel->pgstat_info == NULL)
157 return;
158
159 /* link sanity check */
160 Assert(rel->pgstat_info->relation == rel);
161 rel->pgstat_info->relation = NULL;
162 rel->pgstat_info = NULL;
163}

References Assert, fb(), RelationData::pgstat_info, and PgStat_TableStatus::relation.

Referenced by pgstat_init_relation(), pgstat_relation_delete_pending_cb(), and RelationDestroyRelation().

◆ pgstat_update_heap_dead_tuples()

void pgstat_update_heap_dead_tuples ( Relation  rel,
int  delta 
)
extern

Definition at line 453 of file pgstat_relation.c.

454{
456 {
457 PgStat_TableStatus *pgstat_info = rel->pgstat_info;
458
459 pgstat_info->counts.delta_dead_tuples -= delta;
460 }
461}

References PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, RelationData::pgstat_info, and pgstat_should_count_relation.

Referenced by heap_page_prune_opt().

◆ pgstat_update_parallel_workers_stats()

void pgstat_update_parallel_workers_stats ( PgStat_Counter  workers_to_launch,
PgStat_Counter  workers_launched 
)
extern

Definition at line 315 of file pgstat_database.c.

317{
319
321 return;
322
324 dbentry->parallel_workers_to_launch += workers_to_launch;
325 dbentry->parallel_workers_launched += workers_launched;
326}
#define OidIsValid(objectId)
Definition c.h:858

References fb(), MyDatabaseId, OidIsValid, and pgstat_prep_database_pending().

Referenced by standard_ExecutorEnd().

◆ PostPrepare_PgStat()

void PostPrepare_PgStat ( void  )
extern

Definition at line 211 of file pgstat_xact.c.

212{
213 PgStat_SubXactStatus *xact_state;
214
215 /*
216 * We don't bother to free any of the transactional state, since it's all
217 * in TopTransactionContext and will go away anyway.
218 */
219 xact_state = pgStatXactStack;
220 if (xact_state != NULL)
221 {
222 Assert(xact_state->nest_level == 1);
223 Assert(xact_state->prev == NULL);
224
226 }
228
229 /* Make sure any stats snapshot is thrown away */
231}
void PostPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)

References Assert, fb(), PgStat_SubXactStatus::nest_level, pgstat_clear_snapshot(), pgStatXactStack, PostPrepare_PgStat_Relations(), and PgStat_SubXactStatus::prev.

Referenced by PrepareTransaction().

Variable Documentation

◆ PendingBgWriterStats

PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
extern

Definition at line 24 of file pgstat_bgwriter.c.

24{0};

Referenced by BgBufferSync(), and pgstat_report_bgwriter().

◆ PendingCheckpointerStats

◆ pgstat_fetch_consistency

◆ pgstat_track_counts

◆ pgstat_track_functions

PGDLLIMPORT int pgstat_track_functions
extern

Definition at line 30 of file pgstat_function.c.

◆ pgStatActiveTime

PGDLLIMPORT PgStat_Counter pgStatActiveTime
extern

Definition at line 30 of file pgstat_database.c.

Referenced by pgstat_update_dbstats().

◆ pgStatBlockReadTime

PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
extern

Definition at line 28 of file pgstat_database.c.

Referenced by do_analyze_rel(), heap_vacuum_rel(), and pgstat_update_dbstats().

◆ pgStatBlockWriteTime

PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
extern

Definition at line 29 of file pgstat_database.c.

Referenced by do_analyze_rel(), heap_vacuum_rel(), and pgstat_update_dbstats().

◆ pgStatSessionEndCause

PGDLLIMPORT SessionEndType pgStatSessionEndCause
extern

Definition at line 32 of file pgstat_database.c.

Referenced by die(), errfinish(), pgstat_report_disconnect(), and PostgresMain().

◆ pgStatTransactionIdleTime

PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
extern

Definition at line 31 of file pgstat_database.c.

Referenced by pgstat_update_dbstats().