PostgreSQL Source Code  git master
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_IO
 
struct  PgStat_StatDBEntry
 
struct  PgStat_StatFuncEntry
 
struct  PgStat_StatReplSlotEntry
 
struct  PgStat_SLRUStats
 
struct  PgStat_StatSubEntry
 
struct  PgStat_StatTabEntry
 
struct  PgStat_WalStats
 
struct  PgStat_PendingWalStats
 

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_KIND_FIRST_VALID   PGSTAT_KIND_DATABASE
 
#define PGSTAT_KIND_LAST   PGSTAT_KIND_WAL
 
#define PGSTAT_NUM_KINDS   (PGSTAT_KIND_LAST + 1)
 
#define PGSTAT_FILE_FORMAT_ID   0x01A5BCAC
 
#define IOOBJECT_NUM_TYPES   (IOOBJECT_TEMP_RELATION + 1)
 
#define IOCONTEXT_NUM_TYPES   (IOCONTEXT_VACUUM + 1)
 
#define IOOP_NUM_TYPES   (IOOP_WRITEBACK + 1)
 
#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 enum PgStat_Kind PgStat_Kind
 
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_IO PgStat_IO
 
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_WalStats PgStat_WalStats
 
typedef struct PgStat_PendingWalStats PgStat_PendingWalStats
 

Enumerations

enum  PgStat_Kind {
  PGSTAT_KIND_INVALID = 0 , PGSTAT_KIND_DATABASE , PGSTAT_KIND_RELATION , PGSTAT_KIND_FUNCTION ,
  PGSTAT_KIND_REPLSLOT , PGSTAT_KIND_SUBSCRIPTION , PGSTAT_KIND_ARCHIVER , PGSTAT_KIND_BGWRITER ,
  PGSTAT_KIND_CHECKPOINTER , PGSTAT_KIND_IO , PGSTAT_KIND_SLRU , PGSTAT_KIND_WAL
}
 
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 }
 
enum  IOContext { IOCONTEXT_BULKREAD , IOCONTEXT_BULKWRITE , IOCONTEXT_NORMAL , IOCONTEXT_VACUUM }
 
enum  IOOp {
  IOOP_EVICT , IOOP_EXTEND , IOOP_FSYNC , IOOP_HIT ,
  IOOP_READ , IOOP_REUSE , IOOP_WRITE , IOOP_WRITEBACK
}
 

Functions

Size StatsShmemSize (void)
 
void StatsShmemInit (void)
 
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, Oid objoid)
 
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, Oid objoid)
 
void pgstat_report_archiver (const char *xlog, bool failed)
 
PgStat_ArchiverStatspgstat_fetch_stat_archiver (void)
 
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)
 
void pgstat_count_io_op_n (IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
 
instr_time pgstat_prepare_io_time (void)
 
void pgstat_count_io_op_time (IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt)
 
PgStat_IOpgstat_fetch_stat_io (void)
 
const char * pgstat_get_io_context_name (IOContext io_context)
 
const char * pgstat_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_drop_database (Oid databaseid)
 
void pgstat_report_autovac (Oid dboid)
 
void pgstat_report_recovery_conflict (int reason)
 
void pgstat_report_deadlock (void)
 
void pgstat_report_checksum_failures_in_db (Oid dboid, int failurecount)
 
void pgstat_report_checksum_failure (void)
 
void pgstat_report_connect (Oid dboid)
 
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 (Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
 
void pgstat_report_analyze (Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
 
void pgstat_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 (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
void pgstat_twophase_postabort (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry (Oid relid)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry_ext (bool shared, Oid reloid)
 
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_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_page_zeroed (int slru_idx)
 
void pgstat_count_slru_page_hit (int slru_idx)
 
void pgstat_count_slru_page_read (int slru_idx)
 
void pgstat_count_slru_page_written (int slru_idx)
 
void pgstat_count_slru_page_exists (int slru_idx)
 
void pgstat_count_slru_flush (int slru_idx)
 
void pgstat_count_slru_truncate (int slru_idx)
 
const char * pgstat_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, bool is_apply_error)
 
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
 
PGDLLIMPORT PgStat_PendingWalStats PendingWalStats
 

Macro Definition Documentation

◆ IOCONTEXT_NUM_TYPES

#define IOCONTEXT_NUM_TYPES   (IOCONTEXT_VACUUM + 1)

Definition at line 292 of file pgstat.h.

◆ IOOBJECT_NUM_TYPES

#define IOOBJECT_NUM_TYPES   (IOOBJECT_TEMP_RELATION + 1)

Definition at line 282 of file pgstat.h.

◆ IOOP_NUM_TYPES

#define IOOP_NUM_TYPES   (IOOP_WRITEBACK + 1)

Definition at line 306 of file pgstat.h.

◆ PG_STAT_TMP_DIR

#define PG_STAT_TMP_DIR   "pg_stat_tmp"

Definition at line 32 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:602

Definition at line 638 of file pgstat.h.

◆ pgstat_count_buffer_read

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

Definition at line 633 of file pgstat.h.

◆ pgstat_count_buffer_read_time

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

Definition at line 550 of file pgstat.h.

◆ pgstat_count_buffer_write_time

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

Definition at line 552 of file pgstat.h.

◆ pgstat_count_conn_active_time

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

Definition at line 554 of file pgstat.h.

◆ pgstat_count_conn_txn_idle_time

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

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

◆ pgstat_count_heap_getnext

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

Definition at line 613 of file pgstat.h.

◆ pgstat_count_heap_scan

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

Definition at line 608 of file pgstat.h.

◆ pgstat_count_index_scan

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

Definition at line 623 of file pgstat.h.

◆ pgstat_count_index_tuples

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

Definition at line 628 of file pgstat.h.

◆ PGSTAT_FILE_FORMAT_ID

#define PGSTAT_FILE_FORMAT_ID   0x01A5BCAC

Definition at line 238 of file pgstat.h.

◆ PGSTAT_KIND_FIRST_VALID

#define PGSTAT_KIND_FIRST_VALID   PGSTAT_KIND_DATABASE

Definition at line 56 of file pgstat.h.

◆ PGSTAT_KIND_LAST

#define PGSTAT_KIND_LAST   PGSTAT_KIND_WAL

Definition at line 57 of file pgstat.h.

◆ PGSTAT_NUM_KINDS

#define PGSTAT_NUM_KINDS   (PGSTAT_KIND_LAST + 1)

Definition at line 58 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:299
return true
Definition: isn.c:126
void pgstat_assoc_relation(Relation rel)

Definition at line 602 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_DIRECTORY

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"

Definition at line 27 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_FILENAME

#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/pgstat.stat"

Definition at line 28 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_TMPFILE

#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/pgstat.tmp"

Definition at line 29 of file pgstat.h.

Typedef Documentation

◆ IOContext

typedef enum IOContext IOContext

◆ IOObject

typedef enum IOObject IOObject

◆ IOOp

typedef enum IOOp IOOp

◆ PgStat_ArchiverStats

◆ PgStat_BackendSubEntry

◆ PgStat_BgWriterStats

◆ PgStat_BktypeIO

◆ PgStat_CheckpointerStats

◆ PgStat_Counter

typedef int64 PgStat_Counter

Definition at line 89 of file pgstat.h.

◆ PgStat_FetchConsistency

◆ PgStat_FunctionCallUsage

◆ PgStat_FunctionCounts

◆ PgStat_IO

typedef struct PgStat_IO PgStat_IO

◆ PgStat_Kind

typedef enum PgStat_Kind PgStat_Kind

◆ PgStat_PendingWalStats

◆ PgStat_SLRUStats

◆ PgStat_StatDBEntry

◆ PgStat_StatFuncEntry

◆ PgStat_StatReplSlotEntry

◆ PgStat_StatSubEntry

◆ PgStat_StatTabEntry

◆ PgStat_TableCounts

◆ PgStat_TableStatus

◆ PgStat_TableXactStatus

◆ PgStat_WalStats

◆ SessionEndType

◆ TrackFunctionsLevel

Enumeration Type Documentation

◆ IOContext

enum IOContext
Enumerator
IOCONTEXT_BULKREAD 
IOCONTEXT_BULKWRITE 
IOCONTEXT_NORMAL 
IOCONTEXT_VACUUM 

Definition at line 284 of file pgstat.h.

285 {
290 } IOContext;
IOContext
Definition: pgstat.h:285
@ IOCONTEXT_NORMAL
Definition: pgstat.h:288
@ IOCONTEXT_VACUUM
Definition: pgstat.h:289
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:286
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:287

◆ IOObject

enum IOObject
Enumerator
IOOBJECT_RELATION 
IOOBJECT_TEMP_RELATION 

Definition at line 276 of file pgstat.h.

277 {
280 } IOObject;
IOObject
Definition: pgstat.h:277
@ IOOBJECT_RELATION
Definition: pgstat.h:278
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:279

◆ IOOp

enum IOOp
Enumerator
IOOP_EVICT 
IOOP_EXTEND 
IOOP_FSYNC 
IOOP_HIT 
IOOP_READ 
IOOP_REUSE 
IOOP_WRITE 
IOOP_WRITEBACK 

Definition at line 294 of file pgstat.h.

295 {
296  IOOP_EVICT,
297  IOOP_EXTEND,
298  IOOP_FSYNC,
299  IOOP_HIT,
300  IOOP_READ,
301  IOOP_REUSE,
302  IOOP_WRITE,
304 } IOOp;
IOOp
Definition: pgstat.h:295
@ IOOP_EXTEND
Definition: pgstat.h:297
@ IOOP_FSYNC
Definition: pgstat.h:298
@ IOOP_READ
Definition: pgstat.h:300
@ IOOP_WRITEBACK
Definition: pgstat.h:303
@ IOOP_HIT
Definition: pgstat.h:299
@ IOOP_EVICT
Definition: pgstat.h:296
@ IOOP_REUSE
Definition: pgstat.h:301
@ IOOP_WRITE
Definition: pgstat.h:302

◆ PgStat_FetchConsistency

Enumerator
PGSTAT_FETCH_CONSISTENCY_NONE 
PGSTAT_FETCH_CONSISTENCY_CACHE 
PGSTAT_FETCH_CONSISTENCY_SNAPSHOT 

Definition at line 68 of file pgstat.h.

69 {
PgStat_FetchConsistency
Definition: pgstat.h:69
@ PGSTAT_FETCH_CONSISTENCY_NONE
Definition: pgstat.h:70
@ PGSTAT_FETCH_CONSISTENCY_CACHE
Definition: pgstat.h:71
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
Definition: pgstat.h:72

◆ PgStat_Kind

Enumerator
PGSTAT_KIND_INVALID 
PGSTAT_KIND_DATABASE 
PGSTAT_KIND_RELATION 
PGSTAT_KIND_FUNCTION 
PGSTAT_KIND_REPLSLOT 
PGSTAT_KIND_SUBSCRIPTION 
PGSTAT_KIND_ARCHIVER 
PGSTAT_KIND_BGWRITER 
PGSTAT_KIND_CHECKPOINTER 
PGSTAT_KIND_IO 
PGSTAT_KIND_SLRU 
PGSTAT_KIND_WAL 

Definition at line 35 of file pgstat.h.

36 {
37  /* use 0 for INVALID, to catch zero-initialized data */
39 
40  /* stats for variable-numbered objects */
41  PGSTAT_KIND_DATABASE, /* database-wide statistics */
42  PGSTAT_KIND_RELATION, /* per-table statistics */
43  PGSTAT_KIND_FUNCTION, /* per-function statistics */
44  PGSTAT_KIND_REPLSLOT, /* per-slot statistics */
45  PGSTAT_KIND_SUBSCRIPTION, /* per-subscription statistics */
46 
47  /* stats for fixed-numbered objects */
54 } PgStat_Kind;
PgStat_Kind
Definition: pgstat.h:36
@ PGSTAT_KIND_DATABASE
Definition: pgstat.h:41
@ PGSTAT_KIND_REPLSLOT
Definition: pgstat.h:44
@ PGSTAT_KIND_ARCHIVER
Definition: pgstat.h:48
@ PGSTAT_KIND_SLRU
Definition: pgstat.h:52
@ PGSTAT_KIND_IO
Definition: pgstat.h:51
@ PGSTAT_KIND_BGWRITER
Definition: pgstat.h:49
@ PGSTAT_KIND_INVALID
Definition: pgstat.h:38
@ PGSTAT_KIND_SUBSCRIPTION
Definition: pgstat.h:45
@ PGSTAT_KIND_CHECKPOINTER
Definition: pgstat.h:50
@ PGSTAT_KIND_FUNCTION
Definition: pgstat.h:43
@ PGSTAT_KIND_WAL
Definition: pgstat.h:53
@ PGSTAT_KIND_RELATION
Definition: pgstat.h:42

◆ SessionEndType

Enumerator
DISCONNECT_NOT_YET 
DISCONNECT_NORMAL 
DISCONNECT_CLIENT_EOF 
DISCONNECT_FATAL 
DISCONNECT_KILLED 

Definition at line 76 of file pgstat.h.

77 {
78  DISCONNECT_NOT_YET, /* still active */
SessionEndType
Definition: pgstat.h:77
@ DISCONNECT_NOT_YET
Definition: pgstat.h:78
@ DISCONNECT_FATAL
Definition: pgstat.h:81
@ DISCONNECT_KILLED
Definition: pgstat.h:82
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:80
@ DISCONNECT_NORMAL
Definition: pgstat.h:79

◆ TrackFunctionsLevel

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 61 of file pgstat.h.

62 {
TrackFunctionsLevel
Definition: pgstat.h:62
@ TRACK_FUNC_PL
Definition: pgstat.h:64
@ TRACK_FUNC_ALL
Definition: pgstat.h:65
@ TRACK_FUNC_OFF
Definition: pgstat.h:63

Function Documentation

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

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 
125  AtEOSubXact_PgStat_Relations(xact_state, isCommit, nestDepth);
126  AtEOSubXact_PgStat_DroppedStats(xact_state, isCommit, nestDepth);
127 
128  pfree(xact_state);
129  }
130 }
void pfree(void *pointer)
Definition: mcxt.c:1456
void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat_xact.c:34
static void AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
Definition: pgstat_xact.c:136
struct PgStat_SubXactStatus * prev

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

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)

Definition at line 41 of file pgstat_xact.c.

42 {
43  PgStat_SubXactStatus *xact_state;
44 
45  AtEOXact_PgStat_Database(isCommit, parallel);
46 
47  /* handle transactional stats information */
48  xact_state = pgStatXactStack;
49  if (xact_state != NULL)
50  {
51  Assert(xact_state->nest_level == 1);
52  Assert(xact_state->prev == NULL);
53 
54  AtEOXact_PgStat_Relations(xact_state, isCommit);
55  AtEOXact_PgStat_DroppedStats(xact_state, isCommit);
56  }
57  pgStatXactStack = NULL;
58 
59  /* Make sure any stats snapshot is thrown away */
61 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void pgstat_clear_snapshot(void)
Definition: pgstat.c:785
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:68

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

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

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )

Definition at line 190 of file pgstat_xact.c.

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

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

Referenced by PrepareTransaction().

◆ find_funcstat_entry()

PgStat_FunctionCounts* find_funcstat_entry ( Oid  func_id)

Definition at line 223 of file pgstat_function.c.

224 {
225  PgStat_EntryRef *entry_ref;
226 
228 
229  if (entry_ref)
230  return entry_ref->pending;
231  return NULL;
232 }
Oid MyDatabaseId
Definition: globals.c:89
PgStat_EntryRef * pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:1143

References 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)

Definition at line 484 of file pgstat_relation.c.

485 {
486  PgStat_EntryRef *entry_ref;
487 
489  if (!entry_ref)
491 
492  if (entry_ref)
493  return entry_ref->pending;
494  return NULL;
495 }
#define InvalidOid
Definition: postgres_ext.h:36

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

Referenced by pg_stat_get_xact_tuples_deleted(), pg_stat_get_xact_tuples_inserted(), and pg_stat_get_xact_tuples_updated().

◆ pgstat_acquire_replslot()

void pgstat_acquire_replslot ( struct ReplicationSlot slot)

Definition at line 144 of file pgstat_replslot.c.

145 {
147  ReplicationSlotIndex(slot), true, NULL);
148 }
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:397
int ReplicationSlotIndex(ReplicationSlot *slot)
Definition: slot.c:409

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

Referenced by ReplicationSlotAcquire().

◆ pgstat_assoc_relation()

void pgstat_assoc_relation ( Relation  rel)

Definition at line 133 of file pgstat_relation.c.

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

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

Definition at line 465 of file pgstat.c.

466 {
467  Assert(pgStatLocal.shmem != NULL);
469 
470  /*
471  * Stats should only be reported after pgstat_initialize() and before
472  * pgstat_shutdown(). This is a convenient point to catch most violations
473  * of this rule.
474  */
475  Assert(pgstat_is_initialized && !pgstat_is_shutdown);
476 
477  /* flush out our own pending changes before writing out */
478  pgstat_report_stat(true);
479 
480  /*
481  * Only write out file during normal shutdown. Don't even signal that
482  * we've shutdown during irregular shutdowns, because the shutdown
483  * sequence isn't coordinated to ensure this backend shuts down last.
484  */
485  if (code == 0)
486  {
487  pgStatLocal.shmem->is_shutdown = true;
489  }
490 }
static void pgstat_write_statsfile(void)
Definition: pgstat.c:1308
long pgstat_report_stat(bool force)
Definition: pgstat.c:582
PgStat_LocalState pgStatLocal
Definition: pgstat.c:196
PgStat_ShmemControl * shmem

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

Definition at line 46 of file pgstat_io.c.

48 {
49  for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
50  {
51  for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
52  {
53  for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
54  {
55  /* we do track it */
56  if (pgstat_tracks_io_op(bktype, io_object, io_context, io_op))
57  {
58  /* ensure that if IO times are non-zero, counts are > 0 */
59  if (backend_io->times[io_object][io_context][io_op] != 0 &&
60  backend_io->counts[io_object][io_context][io_op] <= 0)
61  return false;
62 
63  continue;
64  }
65 
66  /* we don't track it, and it is not 0 */
67  if (backend_io->counts[io_object][io_context][io_op] != 0)
68  return false;
69  }
70  }
71  }
72 
73  return true;
74 }
#define IOOP_NUM_TYPES
Definition: pgstat.h:306
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:292
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:282
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition: pgstat_io.c:407
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:311
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:310

References PgStat_BktypeIO::counts, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, pgstat_tracks_io_op(), and PgStat_BktypeIO::times.

Referenced by pg_stat_get_io(), and pgstat_flush_io().

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 785 of file pgstat.c.

786 {
788 
789  memset(&pgStatLocal.snapshot.fixed_valid, 0,
791  pgStatLocal.snapshot.stats = NULL;
793 
794  /* Release memory, if any was allocated */
796  {
798 
799  /* Reset variables */
801  }
802 
803  /*
804  * Historically the backend_status.c facilities lived in this file, and
805  * were reset with the same function. For now keep it that way, and
806  * forward the reset request.
807  */
809 
810  /* Reset this flag, as it may be possible that a cleanup was forced. */
812 }
void pgstat_clear_backend_activity_snapshot(void)
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
static bool force_stats_snapshot_clear
Definition: pgstat.c:234
#define pgstat_assert_is_up()
PgStat_Snapshot snapshot
MemoryContext context
bool fixed_valid[PGSTAT_NUM_KINDS]
PgStat_FetchConsistency mode
struct pgstat_snapshot_hash * stats

References PgStat_Snapshot::context, 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(), and PostPrepare_PgStat().

◆ pgstat_copy_relation_stats()

void pgstat_copy_relation_stats ( Relation  dst,
Relation  src 
)

Definition at line 59 of file pgstat_relation.c.

60 {
61  PgStat_StatTabEntry *srcstats;
62  PgStatShared_Relation *dstshstats;
63  PgStat_EntryRef *dst_ref;
64 
65  srcstats = pgstat_fetch_stat_tabentry_ext(src->rd_rel->relisshared,
66  RelationGetRelid(src));
67  if (!srcstats)
68  return;
69 
71  dst->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
72  RelationGetRelid(dst),
73  false);
74 
75  dstshstats = (PgStatShared_Relation *) dst_ref->shared_stats;
76  dstshstats->stats = *srcstats;
77 
78  pgstat_unlock_entry(dst_ref);
79 }
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:603
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
Definition: pgstat_shmem.c:612
PgStat_StatTabEntry stats
PgStatShared_Common * shared_stats

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

Referenced by index_concurrently_swap().

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

Definition at line 402 of file pgstat_relation.c.

403 {
405  {
406  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
407 
408  ensure_tabstat_xact_level(pgstat_info);
409  pgstat_info->trans->tuples_deleted++;
410  }
411 }
static void ensure_tabstat_xact_level(PgStat_TableStatus *pgstat_info)
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:201
PgStat_Counter tuples_deleted
Definition: pgstat.h:214

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 
)

Definition at line 361 of file pgstat_relation.c.

362 {
364  {
365  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
366 
367  ensure_tabstat_xact_level(pgstat_info);
368  pgstat_info->trans->tuples_inserted += n;
369  }
370 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:212

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

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

◆ pgstat_count_heap_update()

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

Definition at line 376 of file pgstat_relation.c.

377 {
378  Assert(!(hot && newpage));
379 
381  {
382  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
383 
384  ensure_tabstat_xact_level(pgstat_info);
385  pgstat_info->trans->tuples_updated++;
386 
387  /*
388  * tuples_hot_updated and tuples_newpage_updated counters are
389  * nontransactional, so just advance them
390  */
391  if (hot)
392  pgstat_info->counts.tuples_hot_updated++;
393  else if (newpage)
394  pgstat_info->counts.tuples_newpage_updated++;
395  }
396 }
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:170
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:171
PgStat_TableCounts counts
Definition: pgstat.h:202
PgStat_Counter tuples_updated
Definition: pgstat.h:213

References Assert(), PgStat_TableStatus::counts, ensure_tabstat_xact_level(), 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 
)

Definition at line 77 of file pgstat_io.c.

78 {
79  pgstat_count_io_op_n(io_object, io_context, io_op, 1);
80 }
void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
Definition: pgstat_io.c:83

References pgstat_count_io_op_n().

Referenced by GetLocalVictimBuffer(), GetVictimBuffer(), and ReadBuffer_common().

◆ pgstat_count_io_op_n()

void pgstat_count_io_op_n ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
uint32  cnt 
)

Definition at line 83 of file pgstat_io.c.

84 {
85  Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
86  Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
87  Assert((unsigned int) io_op < IOOP_NUM_TYPES);
88  Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
89 
90  PendingIOStats.counts[io_object][io_context][io_op] += cnt;
91 
92  have_iostats = true;
93 }
BackendType MyBackendType
Definition: miscinit.c:63
static PgStat_PendingIO PendingIOStats
Definition: pgstat_io.c:31
bool have_iostats
Definition: pgstat_io.c:32
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat_io.c:26

References Assert(), PgStat_PendingIO::counts, have_iostats, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, MyBackendType, PendingIOStats, and pgstat_tracks_io_op().

Referenced by pgstat_count_io_op(), and pgstat_count_io_op_time().

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

Definition at line 112 of file pgstat_io.c.

114 {
115  if (track_io_timing)
116  {
117  instr_time io_time;
118 
119  INSTR_TIME_SET_CURRENT(io_time);
121 
122  if (io_op == IOOP_WRITE)
123  {
125  if (io_object == IOOBJECT_RELATION)
127  }
128  else if (io_op == IOOP_READ)
129  {
131  if (io_object == IOOBJECT_RELATION)
133  }
134 
135  INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
136  io_time);
137  }
138 
139  pgstat_count_io_op_n(io_object, io_context, io_op, cnt);
140 }
bool track_io_timing
Definition: bufmgr.c:138
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:122
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:178
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:181
#define INSTR_TIME_GET_MICROSEC(t)
Definition: instr_time.h:194
BufferUsage pgBufferUsage
Definition: instrument.c:20
static time_t start_time
Definition: pg_ctl.c:94
#define pgstat_count_buffer_read_time(n)
Definition: pgstat.h:550
#define pgstat_count_buffer_write_time(n)
Definition: pgstat.h:552
instr_time blk_write_time
Definition: instrument.h:37
instr_time blk_read_time
Definition: instrument.h:36
instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat_io.c:27

References BufferUsage::blk_read_time, BufferUsage::blk_write_time, INSTR_TIME_ADD, INSTR_TIME_GET_MICROSEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, IOOBJECT_RELATION, IOOP_READ, IOOP_WRITE, PgStat_PendingIO::pending_times, PendingIOStats, pgBufferUsage, pgstat_count_buffer_read_time, pgstat_count_buffer_write_time, pgstat_count_io_op_n(), start_time, and track_io_timing.

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), IssuePendingWritebacks(), mdsyncfiletag(), ReadBuffer_common(), and register_dirty_segment().

◆ pgstat_count_slru_flush()

void pgstat_count_slru_flush ( int  slru_idx)

Definition at line 89 of file pgstat_slru.c.

90 {
91  get_slru_entry(slru_idx)->flush += 1;
92 }
static PgStat_SLRUStats * get_slru_entry(int slru_idx)
Definition: pgstat_slru.c:220
PgStat_Counter flush
Definition: pgstat.h:385

References PgStat_SLRUStats::flush, and get_slru_entry().

Referenced by SimpleLruWriteAll().

◆ pgstat_count_slru_page_exists()

void pgstat_count_slru_page_exists ( int  slru_idx)

Definition at line 71 of file pgstat_slru.c.

72 {
73  get_slru_entry(slru_idx)->blocks_exists += 1;
74 }
PgStat_Counter blocks_exists
Definition: pgstat.h:384

References PgStat_SLRUStats::blocks_exists, and get_slru_entry().

Referenced by SimpleLruDoesPhysicalPageExist().

◆ pgstat_count_slru_page_hit()

void pgstat_count_slru_page_hit ( int  slru_idx)

Definition at line 65 of file pgstat_slru.c.

66 {
67  get_slru_entry(slru_idx)->blocks_hit += 1;
68 }
PgStat_Counter blocks_hit
Definition: pgstat.h:381

References PgStat_SLRUStats::blocks_hit, and get_slru_entry().

Referenced by SimpleLruReadPage(), and SimpleLruReadPage_ReadOnly().

◆ pgstat_count_slru_page_read()

void pgstat_count_slru_page_read ( int  slru_idx)

Definition at line 77 of file pgstat_slru.c.

78 {
79  get_slru_entry(slru_idx)->blocks_read += 1;
80 }
PgStat_Counter blocks_read
Definition: pgstat.h:382

References PgStat_SLRUStats::blocks_read, and get_slru_entry().

Referenced by SimpleLruReadPage().

◆ pgstat_count_slru_page_written()

void pgstat_count_slru_page_written ( int  slru_idx)

Definition at line 83 of file pgstat_slru.c.

84 {
85  get_slru_entry(slru_idx)->blocks_written += 1;
86 }
PgStat_Counter blocks_written
Definition: pgstat.h:383

References PgStat_SLRUStats::blocks_written, and get_slru_entry().

Referenced by SlruPhysicalWritePage().

◆ pgstat_count_slru_page_zeroed()

void pgstat_count_slru_page_zeroed ( int  slru_idx)

Definition at line 59 of file pgstat_slru.c.

60 {
61  get_slru_entry(slru_idx)->blocks_zeroed += 1;
62 }
PgStat_Counter blocks_zeroed
Definition: pgstat.h:380

References PgStat_SLRUStats::blocks_zeroed, and get_slru_entry().

Referenced by SimpleLruZeroPage().

◆ pgstat_count_slru_truncate()

void pgstat_count_slru_truncate ( int  slru_idx)

Definition at line 95 of file pgstat_slru.c.

96 {
97  get_slru_entry(slru_idx)->truncate += 1;
98 }
PgStat_Counter truncate
Definition: pgstat.h:386

References get_slru_entry(), and PgStat_SLRUStats::truncate.

Referenced by SimpleLruTruncate().

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

Definition at line 417 of file pgstat_relation.c.

418 {
420  {
421  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
422 
423  ensure_tabstat_xact_level(pgstat_info);
424  save_truncdrop_counters(pgstat_info->trans, false);
425  pgstat_info->trans->tuples_inserted = 0;
426  pgstat_info->trans->tuples_updated = 0;
427  pgstat_info->trans->tuples_deleted = 0;
428  }
429 }
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 ExecRefreshMatView(), and ExecuteTruncateGuts().

◆ pgstat_create_function()

void pgstat_create_function ( Oid  proid)

Definition at line 45 of file pgstat_function.c.

46 {
49  proid);
50 }
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_xact.c:358

References MyDatabaseId, pgstat_create_transactional(), and PGSTAT_KIND_FUNCTION.

Referenced by ProcedureCreate().

◆ pgstat_create_relation()

void pgstat_create_relation ( Relation  rel)

◆ pgstat_create_replslot()

void pgstat_create_replslot ( struct ReplicationSlot slot)

Definition at line 111 of file pgstat_replslot.c.

112 {
113  PgStat_EntryRef *entry_ref;
114  PgStatShared_ReplSlot *shstatent;
115 
117  ReplicationSlotIndex(slot), false);
118  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
119 
120  /*
121  * NB: need to accept that there might be stats from an older slot, e.g.
122  * if we previously crashed after dropping a slot.
123  */
124  memset(&shstatent->stats, 0, sizeof(shstatent->stats));
125 
126  pgstat_unlock_entry(entry_ref);
127 }
PgStat_StatReplSlotEntry stats

References InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), PgStat_EntryRef::shared_stats, and PgStatShared_ReplSlot::stats.

Referenced by ReplicationSlotCreate().

◆ pgstat_create_subscription()

void pgstat_create_subscription ( Oid  subid)

Definition at line 46 of file pgstat_subscription.c.

47 {
48  /* Ensures that stats are dropped if transaction rolls back */
50  InvalidOid, subid);
51 
52  /* Create and initialize the subscription stats entry */
54  true, NULL);
56 }
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts)
Definition: pgstat_shmem.c:933

References 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  )

Definition at line 422 of file pgstat.c.

423 {
424  int ret;
425 
426  /* NB: this needs to be done even in single user mode */
427 
428  ret = unlink(PGSTAT_STAT_PERMANENT_FILENAME);
429  if (ret != 0)
430  {
431  if (errno == ENOENT)
432  elog(DEBUG2,
433  "didn't need to unlink permanent stats file \"%s\" - didn't exist",
435  else
436  ereport(LOG,
438  errmsg("could not unlink permanent statistics file \"%s\": %m",
440  }
441  else
442  {
443  ereport(DEBUG2,
445  errmsg_internal("unlinked permanent statistics file \"%s\"",
447  }
448 
449  /*
450  * Reset stats contents. This will set reset timestamps of fixed-numbered
451  * stats to the current time (no variable stats exist).
452  */
454 }
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1156
int errcode_for_file_access(void)
Definition: elog.c:881
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define LOG
Definition: elog.h:31
#define DEBUG2
Definition: elog.h:29
#define ereport(elevel,...)
Definition: elog.h:149
static void pgstat_reset_after_failure(void)
Definition: pgstat.c:1684
#define PGSTAT_STAT_PERMANENT_FILENAME
Definition: pgstat.h:28

References DEBUG2, elog(), ereport, errcode_for_file_access(), errmsg(), errmsg_internal(), LOG, pgstat_reset_after_failure(), and PGSTAT_STAT_PERMANENT_FILENAME.

Referenced by StartupXLOG().

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)

Definition at line 44 of file pgstat_database.c.

45 {
47 }
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_xact.c:380

References InvalidOid, pgstat_drop_transactional(), and PGSTAT_KIND_DATABASE.

Referenced by dropdb().

◆ pgstat_drop_function()

void pgstat_drop_function ( Oid  proid)

Definition at line 60 of file pgstat_function.c.

61 {
64  proid);
65 }

References MyDatabaseId, pgstat_drop_transactional(), and PGSTAT_KIND_FUNCTION.

Referenced by RemoveFunctionById().

◆ pgstat_drop_relation()

void pgstat_drop_relation ( Relation  rel)

Definition at line 181 of file pgstat_relation.c.

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

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)

Definition at line 154 of file pgstat_replslot.c.

155 {
157  ReplicationSlotIndex(slot));
158 }
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_shmem.c:858

References InvalidOid, pgstat_drop_entry(), PGSTAT_KIND_REPLSLOT, and ReplicationSlotIndex().

Referenced by InvalidatePossiblyObsoleteSlot(), and ReplicationSlotDropPtr().

◆ pgstat_drop_subscription()

void pgstat_drop_subscription ( Oid  subid)

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 146 of file pgstat_function.c.

147 {
148  PgStat_FunctionCounts *fs = fcu->fs;
149  instr_time total;
150  instr_time others;
151  instr_time self;
152 
153  /* stats not wanted? */
154  if (fs == NULL)
155  return;
156 
157  /* total elapsed time in this function call */
158  INSTR_TIME_SET_CURRENT(total);
159  INSTR_TIME_SUBTRACT(total, fcu->start);
160 
161  /* self usage: elapsed minus anything already charged to other calls */
162  others = total_func_time;
163  INSTR_TIME_SUBTRACT(others, fcu->save_total);
164  self = total;
165  INSTR_TIME_SUBTRACT(self, others);
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
instr_time save_total
Definition: pgstat.h:125
PgStat_FunctionCounts * fs
Definition: pgstat.h:121
instr_time save_f_total_time
Definition: pgstat.h:123
PgStat_Counter numcalls
Definition: pgstat.h:109
instr_time total_time
Definition: pgstat.h:110
instr_time self_time
Definition: pgstat.h:111

References PgStat_FunctionCallUsage::fs, INSTR_TIME_ADD, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, PgStat_FunctionCounts::numcalls, PgStat_FunctionCallUsage::save_f_total_time, PgStat_FunctionCallUsage::save_total, PgStat_FunctionCounts::self_time, PgStat_FunctionCallUsage::start, 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 
)

Definition at line 313 of file pgstat_xact.c.

314 {
315  int not_freed_count = 0;
316 
317  if (ndrops == 0)
318  return;
319 
320  for (int i = 0; i < ndrops; i++)
321  {
322  xl_xact_stats_item *it = &items[i];
323 
324  if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid))
325  not_freed_count++;
326  }
327 
328  if (not_freed_count > 0)
330 }
int i
Definition: isn.c:73
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:628

References xl_xact_stats_item::dboid, i, xl_xact_stats_item::kind, xl_xact_stats_item::objoid, 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)

Definition at line 165 of file pgstat_replslot.c.

166 {
167  int idx = get_replslot_index(NameStr(slotname));
168 
169  if (idx == -1)
170  return NULL;
171 
172  return (PgStat_StatReplSlotEntry *)
174 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
#define NameStr(name)
Definition: c.h:735
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:815
static int get_replslot_index(const char *name)

References get_replslot_index(), idx(), InvalidOid, NameStr, pgstat_fetch_entry(), and PGSTAT_KIND_REPLSLOT.

Referenced by pg_stat_get_replication_slot().

◆ pgstat_fetch_slru()

PgStat_SLRUStats* pgstat_fetch_slru ( void  )

Definition at line 105 of file pgstat_slru.c.

106 {
108 
109  return pgStatLocal.snapshot.slru;
110 }
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:941
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  )

◆ pgstat_fetch_stat_bgwriter()

◆ pgstat_fetch_stat_checkpointer()

◆ pgstat_fetch_stat_dbentry()

◆ pgstat_fetch_stat_funcentry()

PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  func_id)

◆ pgstat_fetch_stat_io()

PgStat_IO* pgstat_fetch_stat_io ( void  )

◆ pgstat_fetch_stat_subscription()

PgStat_StatSubEntry* pgstat_fetch_stat_subscription ( Oid  subid)

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 457 of file pgstat_relation.c.

458 {
459  return pgstat_fetch_stat_tabentry_ext(IsSharedRelation(relid), relid);
460 }
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:245

References IsSharedRelation(), and pgstat_fetch_stat_tabentry_ext().

◆ pgstat_fetch_stat_tabentry_ext()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry_ext ( bool  shared,
Oid  reloid 
)

Definition at line 467 of file pgstat_relation.c.

468 {
469  Oid dboid = (shared ? InvalidOid : MyDatabaseId);
470 
471  return (PgStat_StatTabEntry *)
473 }
unsigned int Oid
Definition: postgres_ext.h:31

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

Referenced by do_autovacuum(), pgstat_copy_relation_stats(), pgstat_fetch_stat_tabentry(), and recheck_relation_needs_vacanalyze().

◆ pgstat_fetch_stat_wal()

PgStat_WalStats* pgstat_fetch_stat_wal ( void  )

◆ pgstat_force_next_flush()

void pgstat_force_next_flush ( void  )

Definition at line 697 of file pgstat.c.

698 {
699  pgStatForceNextFlush = true;
700 }
static bool pgStatForceNextFlush
Definition: pgstat.c:228

References pgStatForceNextFlush.

Referenced by pg_stat_force_next_flush().

◆ pgstat_get_io_context_name()

const char* pgstat_get_io_context_name ( IOContext  io_context)

Definition at line 207 of file pgstat_io.c.

208 {
209  switch (io_context)
210  {
211  case IOCONTEXT_BULKREAD:
212  return "bulkread";
213  case IOCONTEXT_BULKWRITE:
214  return "bulkwrite";
215  case IOCONTEXT_NORMAL:
216  return "normal";
217  case IOCONTEXT_VACUUM:
218  return "vacuum";
219  }
220 
221  elog(ERROR, "unrecognized IOContext value: %d", io_context);
222  pg_unreachable();
223 }
#define pg_unreachable()
Definition: c.h:285
#define ERROR
Definition: elog.h:39

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

Referenced by pg_stat_get_io().

◆ pgstat_get_io_object_name()

const char* pgstat_get_io_object_name ( IOObject  io_object)

Definition at line 226 of file pgstat_io.c.

227 {
228  switch (io_object)
229  {
230  case IOOBJECT_RELATION:
231  return "relation";
233  return "temp relation";
234  }
235 
236  elog(ERROR, "unrecognized IOObject value: %d", io_object);
237  pg_unreachable();
238 }

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

Referenced by pg_stat_get_io().

◆ pgstat_get_kind_from_str()

PgStat_Kind pgstat_get_kind_from_str ( char *  kind_str)

Definition at line 1242 of file pgstat.c.

1243 {
1244  for (int kind = PGSTAT_KIND_FIRST_VALID; kind <= PGSTAT_KIND_LAST; kind++)
1245  {
1246  if (pg_strcasecmp(kind_str, pgstat_kind_infos[kind].name) == 0)
1247  return kind;
1248  }
1249 
1250  ereport(ERROR,
1251  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1252  errmsg("invalid statistics kind: \"%s\"", kind_str)));
1253  return PGSTAT_KIND_DATABASE; /* avoid compiler warnings */
1254 }
int errcode(int sqlerrcode)
Definition: elog.c:858
static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS]
Definition: pgstat.c:260
#define PGSTAT_KIND_LAST
Definition: pgstat.h:57
#define PGSTAT_KIND_FIRST_VALID
Definition: pgstat.h:56
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name

References ereport, errcode(), errmsg(), ERROR, name, pg_strcasecmp(), PGSTAT_KIND_DATABASE, PGSTAT_KIND_FIRST_VALID, pgstat_kind_infos, and PGSTAT_KIND_LAST.

Referenced by pg_stat_have_stats().

◆ pgstat_get_slru_index()

int pgstat_get_slru_index ( const char *  name)

Definition at line 132 of file pgstat_slru.c.

133 {
134  int i;
135 
136  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
137  {
138  if (strcmp(slru_names[i], name) == 0)
139  return i;
140  }
141 
142  /* return index of the last entry (which is the "other" one) */
143  return (SLRU_NUM_ELEMENTS - 1);
144 }
static const char *const slru_names[]
#define SLRU_NUM_ELEMENTS

References i, name, slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pgstat_reset_slru(), and SimpleLruInit().

◆ pgstat_get_slru_name()

const char* pgstat_get_slru_name ( int  slru_idx)

Definition at line 118 of file pgstat_slru.c.

119 {
120  if (slru_idx < 0 || slru_idx >= SLRU_NUM_ELEMENTS)
121  return NULL;
122 
123  return slru_names[slru_idx];
124 }

References 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)

Definition at line 908 of file pgstat.c.

909 {
912 
914  {
915  *have_snapshot = true;
917  }
918 
919  *have_snapshot = false;
920 
921  return 0;
922 }
TimestampTz snapshot_timestamp

References force_stats_snapshot_clear, PgStat_Snapshot::mode, pgstat_clear_snapshot(), PGSTAT_FETCH_CONSISTENCY_SNAPSHOT, pgStatLocal, PgStat_LocalState::snapshot, and PgStat_Snapshot::snapshot_timestamp.

Referenced by pg_stat_get_snapshot_timestamp().

◆ pgstat_get_transactional_drops()

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

Definition at line 271 of file pgstat_xact.c.

272 {
274  int nitems = 0;
275  dlist_iter iter;
276 
277  if (xact_state == NULL)
278  return 0;
279 
280  /*
281  * We expect to be called for subtransaction abort (which logs a WAL
282  * record), but not for subtransaction commit (which doesn't).
283  */
284  Assert(!isCommit || xact_state->nest_level == 1);
285  Assert(!isCommit || xact_state->prev == NULL);
286 
287  *items = palloc(dclist_count(&xact_state->pending_drops)
288  * sizeof(xl_xact_stats_item));
289 
290  dclist_foreach(iter, &xact_state->pending_drops)
291  {
294 
295  if (isCommit && pending->is_create)
296  continue;
297  if (!isCommit && !pending->is_create)
298  continue;
299 
300  Assert(nitems < dclist_count(&xact_state->pending_drops));
301  (*items)[nitems++] = pending->item;
302  }
303 
304  return nitems;
305 }
#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:1226
xl_xact_stats_item item
Definition: pgstat_xact.c:24
dlist_node * cur
Definition: ilist.h:179

References Assert(), dlist_iter::cur, dclist_container, dclist_count(), dclist_foreach, PgStat_PendingDroppedStatsItem::is_create, PgStat_PendingDroppedStatsItem::item, 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,
Oid  objoid 
)

Definition at line 925 of file pgstat.c.

926 {
927  /* fixed-numbered stats always exist */
928  if (pgstat_get_kind_info(kind)->fixed_amount)
929  return true;
930 
931  return pgstat_get_entry_ref(kind, dboid, objoid, false, NULL) != NULL;
932 }
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1263

References 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 
)

◆ pgstat_init_relation()

void pgstat_init_relation ( Relation  rel)

Definition at line 93 of file pgstat_relation.c.

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

References 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  )

Definition at line 540 of file pgstat.c.

541 {
542  Assert(!pgstat_is_initialized);
543 
545 
546  pgstat_init_wal();
547 
548  /* Set up a process-exit hook to clean up */
550 
551 #ifdef USE_ASSERT_CHECKING
552  pgstat_is_initialized = true;
553 #endif
554 }
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
static void pgstat_shutdown_hook(int code, Datum arg)
Definition: pgstat.c:506
void pgstat_attach_shmem(void)
Definition: pgstat_shmem.c:217
void pgstat_init_wal(void)
Definition: pgstat_wal.c:141

References Assert(), before_shmem_exit(), pgstat_attach_shmem(), pgstat_init_wal(), and pgstat_shutdown_hook().

Referenced by BaseInit().

◆ pgstat_prepare_io_time()

instr_time pgstat_prepare_io_time ( void  )

Definition at line 96 of file pgstat_io.c.

97 {
98  instr_time io_start;
99 
100  if (track_io_timing)
101  INSTR_TIME_SET_CURRENT(io_start);
102  else
103  INSTR_TIME_SET_ZERO(io_start);
104 
105  return io_start;
106 }
#define INSTR_TIME_SET_ZERO(t)
Definition: instr_time.h:172

References INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, and track_io_timing.

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), IssuePendingWritebacks(), mdsyncfiletag(), ReadBuffer_common(), and register_dirty_segment().

◆ pgstat_report_analyze()

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

Definition at line 278 of file pgstat_relation.c.

281 {
282  PgStat_EntryRef *entry_ref;
283  PgStatShared_Relation *shtabentry;
284  PgStat_StatTabEntry *tabentry;
285  Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
286 
287  if (!pgstat_track_counts)
288  return;
289 
290  /*
291  * Unlike VACUUM, ANALYZE might be running inside a transaction that has
292  * already inserted and/or deleted rows in the target table. ANALYZE will
293  * have counted such rows as live or dead respectively. Because we will
294  * report our counts of such rows at transaction end, we should subtract
295  * off these counts from the update we're making now, else they'll be
296  * double-counted after commit. (This approach also ensures that the
297  * shared stats entry ends up with the right numbers if we abort instead
298  * of committing.)
299  *
300  * Waste no time on partitioned tables, though.
301  */
302  if (pgstat_should_count_relation(rel) &&
303  rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
304  {
306 
307  for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
308  {
309  livetuples -= trans->tuples_inserted - trans->tuples_deleted;
310  deadtuples -= trans->tuples_updated + trans->tuples_deleted;
311  }
312  /* count stuff inserted by already-aborted subxacts, too */
313  deadtuples -= rel->pgstat_info->counts.delta_dead_tuples;
314  /* Since ANALYZE's counts are estimates, we could have underflowed */
315  livetuples = Max(livetuples, 0);
316  deadtuples = Max(deadtuples, 0);
317  }
318 
319  /* block acquiring lock for the same reason as pgstat_report_autovac() */
321  RelationGetRelid(rel),
322  false);
323  /* can't get dropped while accessed */
324  Assert(entry_ref != NULL && entry_ref->shared_stats != NULL);
325 
326  shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
327  tabentry = &shtabentry->stats;
328 
329  tabentry->live_tuples = livetuples;
330  tabentry->dead_tuples = deadtuples;
331 
332  /*
333  * If commanded, reset mod_since_analyze to zero. This forgets any
334  * changes that were committed while the ANALYZE was in progress, but we
335  * have no good way to estimate how many of those there were.
336  */
337  if (resetcounter)
338  tabentry->mod_since_analyze = 0;
339 
341  {
343  tabentry->autoanalyze_count++;
344  }
345  else
346  {
348  tabentry->analyze_count++;
349  }
350 
351  pgstat_unlock_entry(entry_ref);
352 
353  /* see pgstat_report_vacuum() */
354  pgstat_flush_io(false);
355 }
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3397
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
#define Max(x, y)
Definition: c.h:987
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
bool pgstat_flush_io(bool nowait)
Definition: pgstat_io.c:159
PgStat_Counter mod_since_analyze
Definition: pgstat.h:413
PgStat_Counter analyze_count
Definition: pgstat.h:424
PgStat_Counter live_tuples
Definition: pgstat.h:411
TimestampTz last_analyze_time
Definition: pgstat.h:423
PgStat_Counter dead_tuples
Definition: pgstat.h:412
PgStat_Counter autoanalyze_count
Definition: pgstat.h:426
TimestampTz last_autoanalyze_time
Definition: pgstat.h:425
PgStat_Counter delta_dead_tuples
Definition: pgstat.h:175
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:402

References PgStat_StatTabEntry::analyze_count, Assert(), PgStat_StatTabEntry::autoanalyze_count, PgStat_TableStatus::counts, PgStat_StatTabEntry::dead_tuples, PgStat_TableCounts::delta_dead_tuples, GetCurrentTimestamp(), if(), InvalidOid, IsAutoVacuumWorkerProcess(), PgStat_StatTabEntry::last_analyze_time, PgStat_StatTabEntry::last_autoanalyze_time, PgStat_StatTabEntry::live_tuples, Max, PgStat_StatTabEntry::mod_since_analyze, MyDatabaseId, 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, PgStatShared_Relation::stats, PgStat_TableStatus::trans, and trans.

Referenced by do_analyze_rel().

◆ pgstat_report_archiver()

void pgstat_report_archiver ( const char *  xlog,
bool  failed 
)

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:1547
int64 TimestampTz
Definition: timestamp.h:39
static void pgstat_end_changecount_write(uint32 *cc)
static void pgstat_begin_changecount_write(uint32 *cc)
PgStat_ArchiverStats stats
TimestampTz last_failed_timestamp
Definition: pgstat.h:249
TimestampTz last_archived_timestamp
Definition: pgstat.h:245
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:247
PgStat_Counter failed_count
Definition: pgstat.h:246
PgStat_Counter archived_count
Definition: pgstat.h:242
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:243
PgStatShared_Archiver archiver

References PgStat_ArchiverStats::archived_count, PgStat_ShmemControl::archiver, PgStatShared_Archiver::changecount, PgStat_ArchiverStats::failed_count, GetCurrentTimestamp(), PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, now(), pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgStatLocal, PgStat_LocalState::shmem, and PgStatShared_Archiver::stats.

Referenced by pgarch_ArchiverCopyLoop().

◆ pgstat_report_autovac()

void pgstat_report_autovac ( Oid  dboid)

Definition at line 55 of file pgstat_database.c.

56 {
57  PgStat_EntryRef *entry_ref;
58  PgStatShared_Database *dbentry;
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 
71  dbentry = (PgStatShared_Database *) entry_ref->shared_stats;
73 
74  pgstat_unlock_entry(entry_ref);
75 }
bool IsUnderPostmaster
Definition: globals.c:113
PgStat_StatDBEntry stats
TimestampTz last_autovac_time
Definition: pgstat.h:332

References Assert(), GetCurrentTimestamp(), InvalidOid, IsUnderPostmaster, PgStat_StatDBEntry::last_autovac_time, pgstat_get_entry_ref_locked(), PGSTAT_KIND_DATABASE, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_Database::stats.

Referenced by AutoVacWorkerMain().

◆ pgstat_report_bgwriter()

void pgstat_report_bgwriter ( void  )

Definition at line 30 of file pgstat_bgwriter.c.

31 {
33  static const PgStat_BgWriterStats all_zeroes;
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  */
42  if (memcmp(&PendingBgWriterStats, &all_zeroes, sizeof(all_zeroes)) == 0)
43  return;
44 
46 
47 #define BGWRITER_ACC(fld) stats_shmem->stats.fld += PendingBgWriterStats.fld
48  BGWRITER_ACC(buf_written_clean);
49  BGWRITER_ACC(maxwritten_clean);
50  BGWRITER_ACC(buf_alloc);
51 #undef BGWRITER_ACC
52 
54 
55  /*
56  * Clear out the statistics buffer, so it can be re-used.
57  */
59 
60  /*
61  * Report IO statistics
62  */
63  pgstat_flush_io(false);
64 }
#define MemSet(start, val, len)
Definition: c.h:1009
#define BGWRITER_ACC(fld)
PgStat_BgWriterStats PendingBgWriterStats
PgStatShared_BgWriter bgwriter

References Assert(), PgStat_ShmemControl::bgwriter, BGWRITER_ACC, PgStatShared_BgWriter::changecount, PgStat_ShmemControl::is_shutdown, MemSet, PendingBgWriterStats, 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  )

Definition at line 30 of file pgstat_checkpointer.c.

31 {
32  /* We assume this initializes to zeroes */
33  static const PgStat_CheckpointerStats all_zeroes;
35 
38 
39  /*
40  * This function can be called even if nothing at all has happened. In
41  * this case, avoid unnecessarily modifying the stats entry.
42  */
43  if (memcmp(&PendingCheckpointerStats, &all_zeroes,
44  sizeof(all_zeroes)) == 0)
45  return;
46 
48 
49 #define CHECKPOINTER_ACC(fld) stats_shmem->stats.fld += PendingCheckpointerStats.fld
50  CHECKPOINTER_ACC(timed_checkpoints);
51  CHECKPOINTER_ACC(requested_checkpoints);
52  CHECKPOINTER_ACC(checkpoint_write_time);
53  CHECKPOINTER_ACC(checkpoint_sync_time);
54  CHECKPOINTER_ACC(buf_written_checkpoints);
55  CHECKPOINTER_ACC(buf_written_backend);
56  CHECKPOINTER_ACC(buf_fsync_backend);
57 #undef CHECKPOINTER_ACC
58 
60 
61  /*
62  * Clear out the statistics buffer, so it can be re-used.
63  */
65 
66  /*
67  * Report IO statistics
68  */
69  pgstat_flush_io(false);
70 }
PgStat_CheckpointerStats PendingCheckpointerStats
#define CHECKPOINTER_ACC(fld)
PgStatShared_Checkpointer checkpointer

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

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

◆ pgstat_report_checksum_failure()

void pgstat_report_checksum_failure ( void  )

Definition at line 166 of file pgstat_database.c.

167 {
169 }
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)

References MyDatabaseId, and pgstat_report_checksum_failures_in_db().

Referenced by PageIsVerifiedExtended().

◆ pgstat_report_checksum_failures_in_db()

void pgstat_report_checksum_failures_in_db ( Oid  dboid,
int  failurecount 
)

Definition at line 140 of file pgstat_database.c.

141 {
142  PgStat_EntryRef *entry_ref;
143  PgStatShared_Database *sharedent;
144 
145  if (!pgstat_track_counts)
146  return;
147 
148  /*
149  * Update the shared stats directly - checksum failures should never be
150  * common enough for that to be a problem.
151  */
152  entry_ref =
154 
155  sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
156  sharedent->stats.checksum_failures += failurecount;
158 
159  pgstat_unlock_entry(entry_ref);
160 }
TimestampTz last_checksum_failure
Definition: pgstat.h:343
PgStat_Counter checksum_failures
Definition: pgstat.h:342

References PgStat_StatDBEntry::checksum_failures, GetCurrentTimestamp(), InvalidOid, PgStat_StatDBEntry::last_checksum_failure, pgstat_get_entry_ref_locked(), PGSTAT_KIND_DATABASE, pgstat_track_counts, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_Database::stats.

Referenced by pgstat_report_checksum_failure(), and sendFile().

◆ pgstat_report_connect()

void pgstat_report_connect ( Oid  dboid)

Definition at line 191 of file pgstat_database.c.

192 {
193  PgStat_StatDBEntry *dbentry;
194 
196  return;
197 
199 
201  dbentry->sessions++;
202 }
TimestampTz MyStartTimestamp
Definition: globals.c:46
static bool pgstat_should_report_connstat(void)
static PgStat_Counter pgLastSessionReportTime
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
PgStat_Counter sessions
Definition: pgstat.h:346

References MyDatabaseId, MyStartTimestamp, pgLastSessionReportTime, pgstat_prep_database_pending(), pgstat_should_report_connstat(), and PgStat_StatDBEntry::sessions.

Referenced by PostgresMain().

◆ pgstat_report_deadlock()

void pgstat_report_deadlock ( void  )

Definition at line 125 of file pgstat_database.c.

126 {
127  PgStat_StatDBEntry *dbent;
128 
129  if (!pgstat_track_counts)
130  return;
131 
133  dbent->deadlocks++;
134 }
PgStat_Counter deadlocks
Definition: pgstat.h:341

References PgStat_StatDBEntry::deadlocks, MyDatabaseId, pgstat_prep_database_pending(), and pgstat_track_counts.

Referenced by DeadLockReport().

◆ pgstat_report_recovery_conflict()

void pgstat_report_recovery_conflict ( int  reason)

Definition at line 81 of file pgstat_database.c.

82 {
83  PgStat_StatDBEntry *dbentry;
84 
87  return;
88 
90 
91  switch (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;
118  }
119 }
@ PROCSIG_RECOVERY_CONFLICT_BUFFERPIN
Definition: procsignal.h:47
@ PROCSIG_RECOVERY_CONFLICT_LOCK
Definition: procsignal.h:44
@ PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT
Definition: procsignal.h:46
@ PROCSIG_RECOVERY_CONFLICT_DATABASE
Definition: procsignal.h:42
@ PROCSIG_RECOVERY_CONFLICT_SNAPSHOT
Definition: procsignal.h:45
@ PROCSIG_RECOVERY_CONFLICT_TABLESPACE
Definition: procsignal.h:43
@ PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK
Definition: procsignal.h:48
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:338
PgStat_Counter conflict_lock
Definition: pgstat.h:334
PgStat_Counter conflict_snapshot
Definition: pgstat.h:335
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:337
PgStat_Counter conflict_logicalslot
Definition: pgstat.h:336
PgStat_Counter conflict_tablespace
Definition: pgstat.h:333

References Assert(), PgStat_StatDBEntry::conflict_bufferpin, PgStat_StatDBEntry::conflict_lock, PgStat_StatDBEntry::conflict_logicalslot, PgStat_StatDBEntry::conflict_snapshot, PgStat_StatDBEntry::conflict_startup_deadlock, PgStat_StatDBEntry::conflict_tablespace, IsUnderPostmaster, MyDatabaseId, pgstat_prep_database_pending(), pgstat_track_counts, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, and PROCSIG_RECOVERY_CONFLICT_TABLESPACE.

Referenced by ProcessRecoveryConflictInterrupt().

◆ pgstat_report_replslot()

void pgstat_report_replslot ( struct ReplicationSlot slot,
const PgStat_StatReplSlotEntry repSlotStat 
)

Definition at line 78 of file pgstat_replslot.c.

79 {
80  PgStat_EntryRef *entry_ref;
81  PgStatShared_ReplSlot *shstatent;
82  PgStat_StatReplSlotEntry *statent;
83 
85  ReplicationSlotIndex(slot), false);
86  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
87  statent = &shstatent->stats;
88 
89  /* Update the replication slot statistics */
90 #define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
91  REPLSLOT_ACC(spill_txns);
92  REPLSLOT_ACC(spill_count);
93  REPLSLOT_ACC(spill_bytes);
94  REPLSLOT_ACC(stream_txns);
95  REPLSLOT_ACC(stream_count);
96  REPLSLOT_ACC(stream_bytes);
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 InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), REPLSLOT_ACC, PgStat_EntryRef::shared_stats, and PgStatShared_ReplSlot::stats.

Referenced by UpdateDecodingStats().

◆ pgstat_report_stat()

long pgstat_report_stat ( bool  force)

Definition at line 582 of file pgstat.c.

583 {
584  static TimestampTz pending_since = 0;
585  static TimestampTz last_flush = 0;
586  bool partial_flush;
588  bool nowait;
589 
592 
593  /* "absorb" the forced flush even if there's nothing to flush */
595  {
596  force = true;
597  pgStatForceNextFlush = false;
598  }
599 
600  /* Don't expend a clock check if nothing to do */
602  !have_iostats &&
603  !have_slrustats &&
605  {
606  Assert(pending_since == 0);
607  return 0;
608  }
609 
610  /*
611  * There should never be stats to report once stats are shut down. Can't
612  * assert that before the checks above, as there is an unconditional
613  * pgstat_report_stat() call in pgstat_shutdown_hook() - which at least
614  * the process that ran pgstat_before_server_shutdown() will still call.
615  */
617 
618  if (force)
619  {
620  /*
621  * Stats reports are forced either when it's been too long since stats
622  * have been reported or in processes that force stats reporting to
623  * happen at specific points (including shutdown). In the former case
624  * the transaction stop time might be quite old, in the latter it
625  * would never get cleared.
626  */
628  }
629  else
630  {
632 
633  if (pending_since > 0 &&
635  {
636  /* don't keep pending updates longer than PGSTAT_MAX_INTERVAL */
637  force = true;
638  }
639  else if (last_flush > 0 &&
641  {
642  /* don't flush too frequently */
643  if (pending_since == 0)
644  pending_since = now;
645 
646  return PGSTAT_IDLE_INTERVAL;
647  }
648  }
649 
651 
652  /* don't wait for lock acquisition when !force */
653  nowait = !force;
654 
655  partial_flush = false;
656 
657  /* flush database / relation / function / ... stats */
658  partial_flush |= pgstat_flush_pending_entries(nowait);
659 
660  /* flush IO stats */
661  partial_flush |= pgstat_flush_io(nowait);
662 
663  /* flush wal stats */
664  partial_flush |= pgstat_flush_wal(nowait);
665 
666  /* flush SLRU stats */
667  partial_flush |= pgstat_slru_flush(nowait);
668 
669  last_flush = now;
670 
671  /*
672  * If some of the pending stats could not be flushed due to lock
673  * contention, let the caller know when to retry.
674  */
675  if (partial_flush)
676  {
677  /* force should have prevented us from getting here */
678  Assert(!force);
679 
680  /* remember since when stats have been pending */
681  if (pending_since == 0)
682  pending_since = now;
683 
684  return PGSTAT_IDLE_INTERVAL;
685  }
686 
687  pending_since = 0;
688 
689  return 0;
690 }
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1719
static bool dlist_is_empty(const dlist_head *head)
Definition: ilist.h:336
#define PGSTAT_MIN_INTERVAL
Definition: pgstat.c:120
static bool pgstat_flush_pending_entries(bool nowait)
Definition: pgstat.c:1180
static dlist_head pgStatPending
Definition: pgstat.c:221
#define PGSTAT_MAX_INTERVAL
Definition: pgstat.c:122
#define PGSTAT_IDLE_INTERVAL
Definition: pgstat.c:124
void pgstat_update_dbstats(TimestampTz ts)
bool have_slrustats
Definition: pgstat_slru.c:35
bool pgstat_slru_flush(bool nowait)
Definition: pgstat_slru.c:156
bool pgstat_have_pending_wal(void)
Definition: pgstat_wal.c:159
bool pgstat_flush_wal(bool nowait)
Definition: pgstat_wal.c:82
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4834
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition: xact.c:876

References Assert(), dlist_is_empty(), GetCurrentTimestamp(), GetCurrentTransactionStopTimestamp(), have_iostats, have_slrustats, PgStat_ShmemControl::is_shutdown, IsTransactionOrTransactionBlock(), now(), pgstat_assert_is_up, pgstat_flush_io(), pgstat_flush_pending_entries(), pgstat_flush_wal(), pgstat_have_pending_wal(), PGSTAT_IDLE_INTERVAL, PGSTAT_MAX_INTERVAL, PGSTAT_MIN_INTERVAL, pgstat_slru_flush(), 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(), LogicalRepApplyLoop(), LogicalRepSyncTableStart(), pg_attribute_noreturn(), pgstat_before_server_shutdown(), pgstat_shutdown_hook(), PostgresMain(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessInterrupts(), standby_redo(), and worker_spi_main().

◆ pgstat_report_subscription_error()

void pgstat_report_subscription_error ( Oid  subid,
bool  is_apply_error 
)

Definition at line 27 of file pgstat_subscription.c.

28 {
29  PgStat_EntryRef *entry_ref;
30  PgStat_BackendSubEntry *pending;
31 
33  InvalidOid, subid, NULL);
34  pending = entry_ref->pending;
35 
36  if (is_apply_error)
37  pending->apply_error_count++;
38  else
39  pending->sync_error_count++;
40 }
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry)
Definition: pgstat.c:1105
PgStat_Counter apply_error_count
Definition: pgstat.h:136
PgStat_Counter sync_error_count
Definition: pgstat.h:137

References PgStat_BackendSubEntry::apply_error_count, InvalidOid, PgStat_EntryRef::pending, PGSTAT_KIND_SUBSCRIPTION, pgstat_prep_pending_entry(), and PgStat_BackendSubEntry::sync_error_count.

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

◆ pgstat_report_vacuum()

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

Definition at line 212 of file pgstat_relation.c.

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

References PgStat_StatTabEntry::autovacuum_count, PgStat_StatTabEntry::dead_tuples, GetCurrentTimestamp(), if(), PgStat_StatTabEntry::ins_since_vacuum, InvalidOid, IsAutoVacuumWorkerProcess(), PgStat_StatTabEntry::last_autovacuum_time, PgStat_StatTabEntry::last_vacuum_time, PgStat_StatTabEntry::live_tuples, MyDatabaseId, pgstat_flush_io(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_track_counts, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, and PgStat_StatTabEntry::vacuum_count.

Referenced by heap_vacuum_rel().

◆ pgstat_report_wal()

void pgstat_report_wal ( bool  force)

Definition at line 48 of file pgstat_wal.c.

49 {
50  bool nowait;
51 
52  /* like in pgstat.c, don't wait for lock acquisition when !force */
53  nowait = !force;
54 
55  /* flush wal stats */
56  pgstat_flush_wal(nowait);
57 
58  /* flush IO stats */
59  pgstat_flush_io(nowait);
60 }

References pgstat_flush_io(), and pgstat_flush_wal().

Referenced by CheckpointerMain(), HandleCheckpointerInterrupts(), and WalWriterMain().

◆ pgstat_reset()

void pgstat_reset ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid 
)

Definition at line 737 of file pgstat.c.

738 {
739  const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
741 
742  /* not needed atm, and doesn't make sense with the current signature */
743  Assert(!pgstat_get_kind_info(kind)->fixed_amount);
744 
745  /* reset the "single counter" */
746  pgstat_reset_entry(kind, dboid, objoid, ts);
747 
748  if (!kind_info->accessed_across_databases)
750 }
void pgstat_reset_database_timestamp(Oid dboid, TimestampTz ts)
bool accessed_across_databases

References PgStat_KindInfo::accessed_across_databases, Assert(), GetCurrentTimestamp(), pgstat_get_kind_info(), pgstat_reset_database_timestamp(), and pgstat_reset_entry().

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

Definition at line 718 of file pgstat.c.

719 {
721 
724  ts);
725 }
static bool match_db_entries(PgStatShared_HashEntry *entry, Datum match_data)
Definition: pgstat.c:706
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
Definition: pgstat_shmem.c:953
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)

Definition at line 759 of file pgstat.c.

760 {
761  const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
763 
764  if (kind_info->fixed_amount)
765  kind_info->reset_all_cb(ts);
766  else
768 }
void pgstat_reset_entries_of_kind(PgStat_Kind kind, TimestampTz ts)
Definition: pgstat_shmem.c:989
void(* reset_all_cb)(TimestampTz ts)

References PgStat_KindInfo::fixed_amount, GetCurrentTimestamp(), pgstat_get_kind_info(), pgstat_reset_entries_of_kind(), and PgStat_KindInfo::reset_all_cb.

Referenced by pg_stat_reset_replication_slot(), pg_stat_reset_shared(), pg_stat_reset_slru(), and pg_stat_reset_subscription_stats().

◆ pgstat_reset_replslot()

void pgstat_reset_replslot ( const char *  name)

Definition at line 43 of file pgstat_replslot.c.

44 {
45  ReplicationSlot *slot;
46 
47  Assert(name != NULL);
48 
49  /* Check if the slot exits with the given name. */
50  slot = SearchNamedReplicationSlot(name, true);
51 
52  if (!slot)
53  ereport(ERROR,
54  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
55  errmsg("replication slot \"%s\" does not exist",
56  name)));
57 
58  /*
59  * Nothing to do for physical slots as we collect stats only for logical
60  * slots.
61  */
62  if (SlotIsPhysical(slot))
63  return;
64 
65  /* reset this one entry */
67  ReplicationSlotIndex(slot));
68 }
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:737
ReplicationSlot * SearchNamedReplicationSlot(const char *name, bool need_lock)
Definition: slot.c:376
#define SlotIsPhysical(slot)
Definition: slot.h:190

References Assert(), ereport, errcode(), errmsg(), ERROR, InvalidOid, name, PGSTAT_KIND_REPLSLOT, pgstat_reset(), ReplicationSlotIndex(), SearchNamedReplicationSlot(), and SlotIsPhysical.

Referenced by pg_stat_reset_replication_slot().

◆ pgstat_reset_slru()

void pgstat_reset_slru ( const char *  name)

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)
Definition: pgstat_slru.c:132
static void pgstat_reset_slru_counter_internal(int index, TimestampTz ts)
Definition: pgstat_slru.c:238

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

Definition at line 410 of file pgstat.c.

411 {
413 }
static void pgstat_read_statsfile(void)
Definition: pgstat.c:1483

References pgstat_read_statsfile().

Referenced by StartupXLOG().

◆ pgstat_tracks_io_bktype()

bool pgstat_tracks_io_bktype ( BackendType  bktype)

Definition at line 304 of file pgstat_io.c.

305 {
306  /*
307  * List every type so that new backend types trigger a warning about
308  * needing to adjust this switch.
309  */
310  switch (bktype)
311  {
312  case B_INVALID:
313  case B_ARCHIVER:
314  case B_LOGGER:
315  case B_WAL_RECEIVER:
316  case B_WAL_WRITER:
317  return false;
318 
319  case B_AUTOVAC_LAUNCHER:
320  case B_AUTOVAC_WORKER:
321  case B_BACKEND:
322  case B_BG_WORKER:
323  case B_BG_WRITER:
324  case B_CHECKPOINTER:
326  case B_STARTUP:
327  case B_WAL_SENDER:
328  return true;
329  }
330 
331  return false;
332 }
@ B_WAL_WRITER
Definition: miscadmin.h:341
@ B_WAL_RECEIVER
Definition: miscadmin.h:339
@ B_CHECKPOINTER
Definition: miscadmin.h:335
@ B_WAL_SENDER
Definition: miscadmin.h:340
@ B_LOGGER
Definition: miscadmin.h:336
@ B_STARTUP
Definition: miscadmin.h:338
@ B_BG_WORKER
Definition: miscadmin.h:333
@ B_INVALID
Definition: miscadmin.h:328
@ B_STANDALONE_BACKEND
Definition: miscadmin.h:337
@ B_BG_WRITER
Definition: miscadmin.h:334
@ B_BACKEND
Definition: miscadmin.h:332
@ B_ARCHIVER
Definition: miscadmin.h:329
@ B_AUTOVAC_LAUNCHER
Definition: miscadmin.h:330
@ B_AUTOVAC_WORKER
Definition: miscadmin.h:331

References B_ARCHIVER, B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_INVALID, B_LOGGER, B_STANDALONE_BACKEND, B_STARTUP, B_WAL_RECEIVER, B_WAL_SENDER, and B_WAL_WRITER.

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 
)

Definition at line 342 of file pgstat_io.c.

344 {
345  bool no_temp_rel;
346 
347  /*
348  * Some BackendTypes should never track IO statistics.
349  */
350  if (!pgstat_tracks_io_bktype(bktype))
351  return false;
352 
353  /*
354  * Currently, IO on temporary relations can only occur in the
355  * IOCONTEXT_NORMAL IOContext.
356  */
357  if (io_context != IOCONTEXT_NORMAL &&
358  io_object == IOOBJECT_TEMP_RELATION)
359  return false;
360 
361  /*
362  * In core Postgres, only regular backends and WAL Sender processes
363  * executing queries will use local buffers and operate on temporary
364  * relations. Parallel workers will not use local buffers (see
365  * InitLocalBuffers()); however, extensions leveraging background workers
366  * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for
367  * BackendType B_BG_WORKER.
368  */
369  no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
370  bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
371  bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP;
372 
373  if (no_temp_rel && io_context == IOCONTEXT_NORMAL &&
374  io_object == IOOBJECT_TEMP_RELATION)
375  return false;
376 
377  /*
378  * Some BackendTypes do not currently perform any IO in certain
379  * IOContexts, and, while it may not be inherently incorrect for them to
380  * do so, excluding those rows from the view makes the view easier to use.
381  */
382  if ((bktype == B_CHECKPOINTER || bktype == B_BG_WRITER) &&
383  (io_context == IOCONTEXT_BULKREAD ||
384  io_context == IOCONTEXT_BULKWRITE ||
385  io_context == IOCONTEXT_VACUUM))
386  return false;
387 
388  if (bktype == B_AUTOVAC_LAUNCHER && io_context == IOCONTEXT_VACUUM)
389  return false;
390 
391  if ((bktype == B_AUTOVAC_WORKER || bktype == B_AUTOVAC_LAUNCHER) &&
392  io_context == IOCONTEXT_BULKWRITE)
393  return false;
394 
395  return true;
396 }
bool pgstat_tracks_io_bktype(BackendType bktype)
Definition: pgstat_io.c:304

References B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_STANDALONE_BACKEND, B_STARTUP, IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, IOOBJECT_TEMP_RELATION, and pgstat_tracks_io_bktype().

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

Definition at line 407 of file pgstat_io.c.

409 {
410  bool strategy_io_context;
411 
412  /* if (io_context, io_object) will never collect stats, we're done */
413  if (!pgstat_tracks_io_object(bktype, io_object, io_context))
414  return false;
415 
416  /*
417  * Some BackendTypes will not do certain IOOps.
418  */
419  if ((bktype == B_BG_WRITER || bktype == B_CHECKPOINTER) &&
420  (io_op == IOOP_READ || io_op == IOOP_EVICT || io_op == IOOP_HIT))
421  return false;
422 
423  if ((bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
424  bktype == B_CHECKPOINTER) && io_op == IOOP_EXTEND)
425  return false;
426 
427  /*
428  * Temporary tables are not logged and thus do not require fsync'ing.
429  * Writeback is not requested for temporary tables.
430  */
431  if (io_object == IOOBJECT_TEMP_RELATION &&
432  (io_op == IOOP_FSYNC || io_op == IOOP_WRITEBACK))
433  return false;
434 
435  /*
436  * Some IOOps are not valid in certain IOContexts and some IOOps are only
437  * valid in certain contexts.
438  */
439  if (io_context == IOCONTEXT_BULKREAD && io_op == IOOP_EXTEND)
440  return false;
441 
442  strategy_io_context = io_context == IOCONTEXT_BULKREAD ||
443  io_context == IOCONTEXT_BULKWRITE || io_context == IOCONTEXT_VACUUM;
444 
445  /*
446  * IOOP_REUSE is only relevant when a BufferAccessStrategy is in use.
447  */
448  if (!strategy_io_context && io_op == IOOP_REUSE)
449  return false;
450 
451  /*
452  * IOOP_FSYNC IOOps done by a backend using a BufferAccessStrategy are
453  * counted in the IOCONTEXT_NORMAL IOContext. See comment in
454  * register_dirty_segment() for more details.
455  */
456  if (strategy_io_context && io_op == IOOP_FSYNC)
457  return false;
458 
459 
460  return true;
461 }
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition: pgstat_io.c:342

References B_AUTOVAC_LAUNCHER, B_BG_WRITER, B_CHECKPOINTER, IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_VACUUM, IOOBJECT_TEMP_RELATION, IOOP_EVICT, IOOP_EXTEND, IOOP_FSYNC, IOOP_HIT, IOOP_READ, IOOP_REUSE, IOOP_WRITEBACK, and pgstat_tracks_io_object().

Referenced by pg_stat_get_io(), pgstat_bktype_io_stats_valid(), and pgstat_count_io_op_n().

◆ pgstat_twophase_postabort()

void pgstat_twophase_postabort ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 738 of file pgstat_relation.c.

740 {
741  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
742  PgStat_TableStatus *pgstat_info;
743 
744  /* Find or create a tabstat entry for the rel */
745  pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
746 
747  /* Same math as in AtEOXact_PgStat, abort case */
748  if (rec->truncdropped)
749  {
753  }
754  pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
755  pgstat_info->counts.tuples_updated += rec->tuples_updated;
756  pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
757  pgstat_info->counts.delta_dead_tuples +=
758  rec->tuples_inserted + rec->tuples_updated;
759 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter tuples_updated
Definition: pgstat.h:168
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
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, 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 ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 702 of file pgstat_relation.c.

704 {
705  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
706  PgStat_TableStatus *pgstat_info;
707 
708  /* Find or create a tabstat entry for the rel */
709  pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
710 
711  /* Same math as in AtEOXact_PgStat, commit case */
712  pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
713  pgstat_info->counts.tuples_updated += rec->tuples_updated;
714  pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
715  pgstat_info->counts.truncdropped = rec->truncdropped;
716  if (rec->truncdropped)
717  {
718  /* forget live/dead stats seen by backend thus far */
719  pgstat_info->counts.delta_live_tuples = 0;
720  pgstat_info->counts.delta_dead_tuples = 0;
721  }
722  pgstat_info->counts.delta_live_tuples +=
723  rec->tuples_inserted - rec->tuples_deleted;
724  pgstat_info->counts.delta_dead_tuples +=
725  rec->tuples_updated + rec->tuples_deleted;
726  pgstat_info->counts.changed_tuples +=
727  rec->tuples_inserted + rec->tuples_updated +
728  rec->tuples_deleted;
729 }
PgStat_Counter delta_live_tuples
Definition: pgstat.h:174
PgStat_Counter changed_tuples
Definition: pgstat.h:176

References PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, 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)

Definition at line 154 of file pgstat_relation.c.

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

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

Definition at line 440 of file pgstat_relation.c.

441 {
443  {
444  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
445 
446  pgstat_info->counts.delta_dead_tuples -= delta;
447  }
448 }

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

Referenced by heap_page_prune_opt().

◆ PostPrepare_PgStat()

void PostPrepare_PgStat ( void  )

Definition at line 210 of file pgstat_xact.c.

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

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

Referenced by PrepareTransaction().

◆ StatsShmemInit()

void StatsShmemInit ( void  )

Definition at line 140 of file pgstat_shmem.c.

141 {
142  bool found;
143  Size sz;
144 
145  sz = StatsShmemSize();
147  ShmemInitStruct("Shared Memory Stats", sz, &found);
148 
149  if (!IsUnderPostmaster)
150  {
151  dsa_area *dsa;
152  dshash_table *dsh;
154  char *p = (char *) ctl;
155 
156  Assert(!found);
157 
158  /* the allocation of pgStatLocal.shmem itself */
159  p += MAXALIGN(sizeof(PgStat_ShmemControl));
160 
161  /*
162  * Create a small dsa allocation in plain shared memory. This is
163  * required because postmaster cannot use dsm segments. It also
164  * provides a small efficiency win.
165  */
166  ctl->raw_dsa_area = p;
171  dsa_pin(dsa);
172 
173  /*
174  * To ensure dshash is created in "plain" shared memory, temporarily
175  * limit size of dsa to the initial size of the dsa.
176  */
178 
179  /*
180  * With the limit in place, create the dshash table. XXX: It'd be nice
181  * if there were dshash_create_in_place().
182  */
183  dsh = dshash_create(dsa, &dsh_params, 0);
185 
186  /* lift limit set above */
187  dsa_set_size_limit(dsa, -1);
188 
189  /*
190  * Postmaster will never access these again, thus free the local
191  * dsa/dshash references.
192  */
193  dshash_detach(dsh);
194  dsa_detach(dsa);
195 
197 
198 
199  /* initialize fixed-numbered stats */
205 
206  for (int i = 0; i < BACKEND_NUM_TYPES; i++)
207  LWLockInitialize(&ctl->io.locks[i],
209  }
210  else
211  {
212  Assert(found);
213  }
214 }
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:410
#define MAXALIGN(LEN)
Definition: c.h:800
size_t Size
Definition: c.h:594
dsa_area * dsa_create_in_place(void *place, size_t size, int tranche_id, dsm_segment *segment)
Definition: dsa.c:482
void dsa_set_size_limit(dsa_area *area, size_t limit)
Definition: dsa.c:1025
void dsa_detach(dsa_area *area)
Definition: dsa.c:1932
void dsa_pin(dsa_area *area)
Definition: dsa.c:982
void dshash_detach(dshash_table *hash_table)
Definition: dshash.c:307
dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table)
Definition: dshash.c:367
dshash_table * dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
Definition: dshash.c:206
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:730
@ LWTRANCHE_PGSTATS_DSA
Definition: lwlock.h:205
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:207
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:344
static Size pgstat_dsa_init_size(void)
Definition: pgstat_shmem.c:105
Size StatsShmemSize(void)
Definition: pgstat_shmem.c:126
static const dshash_parameters dsh_params
Definition: pgstat_shmem.c:62
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
LWLock locks[BACKEND_NUM_TYPES]
dshash_table_handle hash_handle
PgStatShared_SLRU slru
PgStatShared_IO io
pg_atomic_uint64 gc_request_count
PgStatShared_Wal wal
Definition: dsa.c:367

References PgStat_ShmemControl::archiver, Assert(), BACKEND_NUM_TYPES, PgStat_ShmemControl::bgwriter, PgStat_ShmemControl::checkpointer, dsa_create_in_place(), dsa_detach(), dsa_pin(), dsa_set_size_limit(), dsh_params, dshash_create(), dshash_detach(), dshash_get_hash_table_handle(), PgStat_ShmemControl::gc_request_count, PgStat_ShmemControl::hash_handle, i, PgStat_ShmemControl::io, IsUnderPostmaster, PgStatShared_Archiver::lock, PgStatShared_BgWriter::lock, PgStatShared_Checkpointer::lock, PgStatShared_SLRU::lock, PgStatShared_Wal::lock, PgStatShared_IO::locks, LWLockInitialize(), LWTRANCHE_PGSTATS_DATA, LWTRANCHE_PGSTATS_DSA, MAXALIGN, pg_atomic_init_u64(), pgstat_dsa_init_size(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shmem, ShmemInitStruct(), PgStat_ShmemControl::slru, StatsShmemSize(), and PgStat_ShmemControl::wal.

Referenced by CreateSharedMemoryAndSemaphores().

◆ StatsShmemSize()

Size StatsShmemSize ( void  )

Definition at line 126 of file pgstat_shmem.c.

127 {
128  Size sz;
129 
130  sz = MAXALIGN(sizeof(PgStat_ShmemControl));
131  sz = add_size(sz, pgstat_dsa_init_size());
132 
133  return sz;
134 }
Size add_size(Size s1, Size s2)
Definition: shmem.c:502

References add_size(), MAXALIGN, and pgstat_dsa_init_size().

Referenced by CalculateShmemSize(), and StatsShmemInit().

Variable Documentation

◆ PendingBgWriterStats

PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
extern

Definition at line 23 of file pgstat_bgwriter.c.

Referenced by BgBufferSync(), and pgstat_report_bgwriter().

◆ PendingCheckpointerStats

◆ PendingWalStats

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