PostgreSQL Source Code  git master
pgstat.h
Go to the documentation of this file.
1 /* ----------
2  * pgstat.h
3  *
4  * Definitions for the PostgreSQL cumulative statistics system.
5  *
6  * Copyright (c) 2001-2024, PostgreSQL Global Development Group
7  *
8  * src/include/pgstat.h
9  * ----------
10  */
11 #ifndef PGSTAT_H
12 #define PGSTAT_H
13 
14 #include "access/xlogdefs.h"
15 #include "datatype/timestamp.h"
16 #include "portability/instr_time.h"
17 #include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
18 #include "replication/conflict.h"
19 #include "utils/backend_progress.h" /* for backward compatibility */
20 #include "utils/backend_status.h" /* for backward compatibility */
21 #include "utils/relcache.h"
22 #include "utils/wait_event.h" /* for backward compatibility */
23 
24 
25 /* ----------
26  * Paths for the statistics files (relative to installation's $PGDATA).
27  * ----------
28  */
29 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
30 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/pgstat.stat"
31 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/pgstat.tmp"
32 
33 /* Default directory to store temporary statistics data in */
34 #define PG_STAT_TMP_DIR "pg_stat_tmp"
35 
36 /* The types of statistics entries */
37 #define PgStat_Kind uint32
38 
39 /* Range of IDs allowed, for built-in and custom kinds */
40 #define PGSTAT_KIND_MIN 1 /* Minimum ID allowed */
41 #define PGSTAT_KIND_MAX 256 /* Maximum ID allowed */
42 
43 /* use 0 for INVALID, to catch zero-initialized data */
44 #define PGSTAT_KIND_INVALID 0
45 
46 /* stats for variable-numbered objects */
47 #define PGSTAT_KIND_DATABASE 1 /* database-wide statistics */
48 #define PGSTAT_KIND_RELATION 2 /* per-table statistics */
49 #define PGSTAT_KIND_FUNCTION 3 /* per-function statistics */
50 #define PGSTAT_KIND_REPLSLOT 4 /* per-slot statistics */
51 #define PGSTAT_KIND_SUBSCRIPTION 5 /* per-subscription statistics */
52 
53 /* stats for fixed-numbered objects */
54 #define PGSTAT_KIND_ARCHIVER 6
55 #define PGSTAT_KIND_BGWRITER 7
56 #define PGSTAT_KIND_CHECKPOINTER 8
57 #define PGSTAT_KIND_IO 9
58 #define PGSTAT_KIND_SLRU 10
59 #define PGSTAT_KIND_WAL 11
60 
61 #define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE
62 #define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL
63 #define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1)
64 
65 /* Custom stats kinds */
66 
67 /* Range of IDs allowed for custom stats kinds */
68 #define PGSTAT_KIND_CUSTOM_MIN 128
69 #define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX
70 #define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1)
71 
72 /*
73  * PgStat_Kind to use for extensions that require an ID, but are still in
74  * development and have not reserved their own unique kind ID yet. See:
75  * https://wiki.postgresql.org/wiki/CustomCumulativeStats
76  */
77 #define PGSTAT_KIND_EXPERIMENTAL 128
78 
79 static inline bool
81 {
82  return kind >= PGSTAT_KIND_BUILTIN_MIN && kind <= PGSTAT_KIND_BUILTIN_MAX;
83 }
84 
85 static inline bool
87 {
88  return kind >= PGSTAT_KIND_CUSTOM_MIN && kind <= PGSTAT_KIND_CUSTOM_MAX;
89 }
90 
91 /* Values for track_functions GUC variable --- order is significant! */
92 typedef enum TrackFunctionsLevel
93 {
98 
100 {
105 
106 /* Values to track the cause of session termination */
107 typedef enum SessionEndType
108 {
109  DISCONNECT_NOT_YET, /* still active */
115 
116 /* ----------
117  * The data type used for counters.
118  * ----------
119  */
121 
122 
123 /* ------------------------------------------------------------
124  * Structures kept in backend local memory while accumulating counts
125  * ------------------------------------------------------------
126  */
127 
128 /* ----------
129  * PgStat_FunctionCounts The actual per-function counts kept by a backend
130  *
131  * This struct should contain only actual event counters, because we memcmp
132  * it against zeroes to detect whether there are any pending stats.
133  *
134  * Note that the time counters are in instr_time format here. We convert to
135  * microseconds in PgStat_Counter format when flushing out pending statistics.
136  * ----------
137  */
138 typedef struct PgStat_FunctionCounts
139 {
144 
145 /*
146  * Working state needed to accumulate per-function-call timing statistics.
147  */
149 {
150  /* Link to function's hashtable entry (must still be there at exit!) */
151  /* NULL means we are not tracking the current function call */
153  /* Total time previously charged to function, as of function start */
155  /* Backend-wide total time as of function start */
157  /* system clock as of function start */
160 
161 /* ----------
162  * PgStat_BackendSubEntry Non-flushed subscription stats.
163  * ----------
164  */
166 {
171 
172 /* ----------
173  * PgStat_TableCounts The actual per-table counts kept by a backend
174  *
175  * This struct should contain only actual event counters, because we memcmp
176  * it against zeroes to detect whether there are any stats updates to apply.
177  * It is a component of PgStat_TableStatus (within-backend state).
178  *
179  * Note: for a table, tuples_returned is the number of tuples successfully
180  * fetched by heap_getnext, while tuples_fetched is the number of tuples
181  * successfully fetched by heap_fetch under the control of bitmap indexscans.
182  * For an index, tuples_returned is the number of index entries returned by
183  * the index AM, while tuples_fetched is the number of tuples successfully
184  * fetched by heap_fetch under the control of simple indexscans for this index.
185  *
186  * tuples_inserted/updated/deleted/hot_updated/newpage_updated count attempted
187  * actions, regardless of whether the transaction committed. delta_live_tuples,
188  * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
189  * Note that delta_live_tuples and delta_dead_tuples can be negative!
190  * ----------
191  */
192 typedef struct PgStat_TableCounts
193 {
195 
198 
205 
209 
213 
214 /* ----------
215  * PgStat_TableStatus Per-table status within a backend
216  *
217  * Many of the event counters are nontransactional, ie, we count events
218  * in committed and aborted transactions alike. For these, we just count
219  * directly in the PgStat_TableStatus. However, delta_live_tuples,
220  * delta_dead_tuples, and changed_tuples must be derived from event counts
221  * with awareness of whether the transaction or subtransaction committed or
222  * aborted. Hence, we also keep a stack of per-(sub)transaction status
223  * records for every table modified in the current transaction. At commit
224  * or abort, we propagate tuples_inserted/updated/deleted up to the
225  * parent subtransaction level, or out to the parent PgStat_TableStatus,
226  * as appropriate.
227  * ----------
228  */
229 typedef struct PgStat_TableStatus
230 {
231  Oid id; /* table's OID */
232  bool shared; /* is it a shared catalog? */
233  struct PgStat_TableXactStatus *trans; /* lowest subxact's counts */
234  PgStat_TableCounts counts; /* event counts to be sent */
235  Relation relation; /* rel that is using this entry */
237 
238 /* ----------
239  * PgStat_TableXactStatus Per-table, per-subtransaction status
240  * ----------
241  */
243 {
244  PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */
245  PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */
246  PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */
247  bool truncdropped; /* relation truncated/dropped in this
248  * (sub)xact */
249  /* tuples i/u/d prior to truncate/drop */
253  int nest_level; /* subtransaction nest level */
254  /* links to other structs for same relation: */
255  struct PgStat_TableXactStatus *upper; /* next higher subxact if any */
256  PgStat_TableStatus *parent; /* per-table status */
257  /* structs of same subxact level are linked here: */
258  struct PgStat_TableXactStatus *next; /* next of same subxact */
260 
261 
262 /* ------------------------------------------------------------
263  * Data structures on disk and in shared memory follow
264  *
265  * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
266  * data structures change.
267  * ------------------------------------------------------------
268  */
269 
270 #define PGSTAT_FILE_FORMAT_ID 0x01A5BCAF
271 
272 typedef struct PgStat_ArchiverStats
273 {
274  PgStat_Counter archived_count; /* archival successes */
275  char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
276  * archived */
277  TimestampTz last_archived_timestamp; /* last archival success time */
278  PgStat_Counter failed_count; /* failed archival attempts */
279  char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
280  * last failure */
281  TimestampTz last_failed_timestamp; /* last archival failure time */
284 
285 typedef struct PgStat_BgWriterStats
286 {
292 
294 {
301  PgStat_Counter write_time; /* times in milliseconds */
307 
308 
309 /*
310  * Types related to counting IO operations
311  */
312 typedef enum IOObject
313 {
317 
318 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
319 
320 typedef enum IOContext
321 {
327 
328 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
329 
330 typedef enum IOOp
331 {
341 
342 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
343 
344 typedef struct PgStat_BktypeIO
345 {
349 
350 typedef struct PgStat_IO
351 {
355 
356 
357 typedef struct PgStat_StatDBEntry
358 {
380  PgStat_Counter blk_read_time; /* times in microseconds */
391 
394 
395 typedef struct PgStat_StatFuncEntry
396 {
398 
399  PgStat_Counter total_time; /* times in microseconds */
402 
404 {
415 
416 typedef struct PgStat_SLRUStats
417 {
427 
428 typedef struct PgStat_StatSubEntry
429 {
435 
436 typedef struct PgStat_StatTabEntry
437 {
440 
443 
449 
454 
457 
458  TimestampTz last_vacuum_time; /* user initiated vacuum */
460  TimestampTz last_autovacuum_time; /* autovacuum initiated */
462  TimestampTz last_analyze_time; /* user initiated */
464  TimestampTz last_autoanalyze_time; /* autovacuum initiated */
467 
468 typedef struct PgStat_WalStats
469 {
480 
481 /*
482  * This struct stores wal-related durations as instr_time, which makes it
483  * cheaper and easier to accumulate them, by not requiring type
484  * conversions. During stats flush instr_time will be converted into
485  * microseconds.
486  */
488 {
495 
496 
497 /*
498  * Functions in pgstat.c
499  */
500 
501 /* functions called from postmaster */
502 extern Size StatsShmemSize(void);
503 extern void StatsShmemInit(void);
504 
505 /* Functions called during server startup / shutdown */
506 extern void pgstat_restore_stats(XLogRecPtr redo);
507 extern void pgstat_discard_stats(void);
508 extern void pgstat_before_server_shutdown(int code, Datum arg);
509 
510 /* Functions for backend initialization */
511 extern void pgstat_initialize(void);
512 
513 /* Functions called from backends */
514 extern long pgstat_report_stat(bool force);
515 extern void pgstat_force_next_flush(void);
516 
517 extern void pgstat_reset_counters(void);
518 extern void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid);
519 extern void pgstat_reset_of_kind(PgStat_Kind kind);
520 
521 /* stats accessors */
522 extern void pgstat_clear_snapshot(void);
523 extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
524 
525 /* helpers */
526 extern PgStat_Kind pgstat_get_kind_from_str(char *kind_str);
527 extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid);
528 
529 
530 /*
531  * Functions in pgstat_archiver.c
532  */
533 
534 extern void pgstat_report_archiver(const char *xlog, bool failed);
536 
537 
538 /*
539  * Functions in pgstat_bgwriter.c
540  */
541 
542 extern void pgstat_report_bgwriter(void);
544 
545 
546 /*
547  * Functions in pgstat_checkpointer.c
548  */
549 
550 extern void pgstat_report_checkpointer(void);
552 
553 
554 /*
555  * Functions in pgstat_io.c
556  */
557 
558 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
559  BackendType bktype);
560 extern void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op);
561 extern void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt);
562 extern instr_time pgstat_prepare_io_time(bool track_io_guc);
563 extern void pgstat_count_io_op_time(IOObject io_object, IOContext io_context,
564  IOOp io_op, instr_time start_time, uint32 cnt);
565 
566 extern PgStat_IO *pgstat_fetch_stat_io(void);
567 extern const char *pgstat_get_io_context_name(IOContext io_context);
568 extern const char *pgstat_get_io_object_name(IOObject io_object);
569 
570 extern bool pgstat_tracks_io_bktype(BackendType bktype);
571 extern bool pgstat_tracks_io_object(BackendType bktype,
572  IOObject io_object, IOContext io_context);
573 extern bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object,
574  IOContext io_context, IOOp io_op);
575 
576 
577 /*
578  * Functions in pgstat_database.c
579  */
580 
581 extern void pgstat_drop_database(Oid databaseid);
582 extern void pgstat_report_autovac(Oid dboid);
583 extern void pgstat_report_recovery_conflict(int reason);
584 extern void pgstat_report_deadlock(void);
585 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
586 extern void pgstat_report_checksum_failure(void);
587 extern void pgstat_report_connect(Oid dboid);
588 extern void pgstat_update_parallel_workers_stats(PgStat_Counter workers_to_launch,
589  PgStat_Counter workers_launched);
590 
591 #define pgstat_count_buffer_read_time(n) \
592  (pgStatBlockReadTime += (n))
593 #define pgstat_count_buffer_write_time(n) \
594  (pgStatBlockWriteTime += (n))
595 #define pgstat_count_conn_active_time(n) \
596  (pgStatActiveTime += (n))
597 #define pgstat_count_conn_txn_idle_time(n) \
598  (pgStatTransactionIdleTime += (n))
599 
601 
602 
603 /*
604  * Functions in pgstat_function.c
605  */
606 
607 extern void pgstat_create_function(Oid proid);
608 extern void pgstat_drop_function(Oid proid);
609 
614  bool finalize);
615 
618 
619 
620 /*
621  * Functions in pgstat_relation.c
622  */
623 
624 extern void pgstat_create_relation(Relation rel);
625 extern void pgstat_drop_relation(Relation rel);
626 extern void pgstat_copy_relation_stats(Relation dst, Relation src);
627 
628 extern void pgstat_init_relation(Relation rel);
629 extern void pgstat_assoc_relation(Relation rel);
630 extern void pgstat_unlink_relation(Relation rel);
631 
632 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
633  PgStat_Counter livetuples, PgStat_Counter deadtuples);
634 extern void pgstat_report_analyze(Relation rel,
635  PgStat_Counter livetuples, PgStat_Counter deadtuples,
636  bool resetcounter);
637 
638 /*
639  * If stats are enabled, but pending data hasn't been prepared yet, call
640  * pgstat_assoc_relation() to do so. See its comment for why this is done
641  * separately from pgstat_init_relation().
642  */
643 #define pgstat_should_count_relation(rel) \
644  (likely((rel)->pgstat_info != NULL) ? true : \
645  ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
646 
647 /* nontransactional event counts are simple enough to inline */
648 
649 #define pgstat_count_heap_scan(rel) \
650  do { \
651  if (pgstat_should_count_relation(rel)) \
652  (rel)->pgstat_info->counts.numscans++; \
653  } while (0)
654 #define pgstat_count_heap_getnext(rel) \
655  do { \
656  if (pgstat_should_count_relation(rel)) \
657  (rel)->pgstat_info->counts.tuples_returned++; \
658  } while (0)
659 #define pgstat_count_heap_fetch(rel) \
660  do { \
661  if (pgstat_should_count_relation(rel)) \
662  (rel)->pgstat_info->counts.tuples_fetched++; \
663  } while (0)
664 #define pgstat_count_index_scan(rel) \
665  do { \
666  if (pgstat_should_count_relation(rel)) \
667  (rel)->pgstat_info->counts.numscans++; \
668  } while (0)
669 #define pgstat_count_index_tuples(rel, n) \
670  do { \
671  if (pgstat_should_count_relation(rel)) \
672  (rel)->pgstat_info->counts.tuples_returned += (n); \
673  } while (0)
674 #define pgstat_count_buffer_read(rel) \
675  do { \
676  if (pgstat_should_count_relation(rel)) \
677  (rel)->pgstat_info->counts.blocks_fetched++; \
678  } while (0)
679 #define pgstat_count_buffer_hit(rel) \
680  do { \
681  if (pgstat_should_count_relation(rel)) \
682  (rel)->pgstat_info->counts.blocks_hit++; \
683  } while (0)
684 
686 extern void pgstat_count_heap_update(Relation rel, bool hot, bool newpage);
687 extern void pgstat_count_heap_delete(Relation rel);
688 extern void pgstat_count_truncate(Relation rel);
689 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
690 
691 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
692  void *recdata, uint32 len);
693 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
694  void *recdata, uint32 len);
695 
698  Oid reloid);
700 
701 
702 /*
703  * Functions in pgstat_replslot.c
704  */
705 
706 extern void pgstat_reset_replslot(const char *name);
707 struct ReplicationSlot;
708 extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
709 extern void pgstat_create_replslot(struct ReplicationSlot *slot);
710 extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
711 extern void pgstat_drop_replslot(struct ReplicationSlot *slot);
713 
714 
715 /*
716  * Functions in pgstat_slru.c
717  */
718 
719 extern void pgstat_reset_slru(const char *);
720 extern void pgstat_count_slru_page_zeroed(int slru_idx);
721 extern void pgstat_count_slru_page_hit(int slru_idx);
722 extern void pgstat_count_slru_page_read(int slru_idx);
723 extern void pgstat_count_slru_page_written(int slru_idx);
724 extern void pgstat_count_slru_page_exists(int slru_idx);
725 extern void pgstat_count_slru_flush(int slru_idx);
726 extern void pgstat_count_slru_truncate(int slru_idx);
727 extern const char *pgstat_get_slru_name(int slru_idx);
728 extern int pgstat_get_slru_index(const char *name);
729 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
730 
731 
732 /*
733  * Functions in pgstat_subscription.c
734  */
735 
736 extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
738 extern void pgstat_create_subscription(Oid subid);
739 extern void pgstat_drop_subscription(Oid subid);
741 
742 
743 /*
744  * Functions in pgstat_xact.c
745  */
746 
747 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
748 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
749 extern void AtPrepare_PgStat(void);
750 extern void PostPrepare_PgStat(void);
751 struct xl_xact_stats_item;
752 extern int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items);
753 extern void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo);
754 
755 
756 /*
757  * Functions in pgstat_wal.c
758  */
759 
760 extern void pgstat_report_wal(bool force);
762 
763 
764 /*
765  * Variables in pgstat.c
766  */
767 
768 /* GUC parameters */
769 extern PGDLLIMPORT bool pgstat_track_counts;
772 
773 
774 /*
775  * Variables in pgstat_bgwriter.c
776  */
777 
778 /* updated directly by bgwriter and bufmgr */
780 
781 
782 /*
783  * Variables in pgstat_checkpointer.c
784  */
785 
786 /*
787  * Checkpointer statistics counters are updated directly by checkpointer and
788  * bufmgr.
789  */
791 
792 
793 /*
794  * Variables in pgstat_database.c
795  */
796 
797 /* Updated by pgstat_count_buffer_*_time macros */
800 
801 /*
802  * Updated by pgstat_count_conn_*_time macros, called by
803  * pgstat_report_activity().
804  */
807 
808 /* updated by the traffic cop and in errfinish() */
810 
811 
812 /*
813  * Variables in pgstat_wal.c
814  */
815 
816 /* updated directly by backends and background processes */
818 
819 
820 #endif /* PGSTAT_H */
#define PGDLLIMPORT
Definition: c.h:1274
int64_t int64
Definition: c.h:482
uint64_t uint64
Definition: c.h:486
uint16_t uint16
Definition: c.h:484
uint32_t uint32
Definition: c.h:485
uint32 TransactionId
Definition: c.h:606
size_t Size
Definition: c.h:559
ConflictType
Definition: conflict.h:25
#define CONFLICT_NUM_TYPES
Definition: conflict.h:51
int64 TimestampTz
Definition: timestamp.h:39
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:368
BackendType
Definition: miscadmin.h:331
void * arg
const void size_t len
static time_t start_time
Definition: pg_ctl.c:95
#define MAX_XFN_CHARS
Definition: pgarch.h:26
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:859
void pgstat_drop_function(Oid proid)
#define PGSTAT_KIND_CUSTOM_MAX
Definition: pgstat.h:69
void pgstat_drop_subscription(Oid subid)
struct PgStat_TableStatus PgStat_TableStatus
void pgstat_update_parallel_workers_stats(PgStat_Counter workers_to_launch, PgStat_Counter workers_launched)
SessionEndType
Definition: pgstat.h:108
@ DISCONNECT_NOT_YET
Definition: pgstat.h:109
@ DISCONNECT_FATAL
Definition: pgstat.h:112
@ DISCONNECT_KILLED
Definition: pgstat.h:113
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:111
@ DISCONNECT_NORMAL
Definition: pgstat.h:110
void pgstat_reset_replslot(const char *name)
instr_time pgstat_prepare_io_time(bool track_io_guc)
Definition: pgstat_io.c:100
IOObject
Definition: pgstat.h:313
@ IOOBJECT_RELATION
Definition: pgstat.h:314
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:315
static bool pgstat_is_kind_builtin(PgStat_Kind kind)
Definition: pgstat.h:80
void AtPrepare_PgStat(void)
Definition: pgstat_xact.c:191
int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items)
Definition: pgstat_xact.c:272
void pgstat_copy_relation_stats(Relation dst, Relation src)
void pgstat_unlink_relation(Relation rel)
struct PgStat_CheckpointerStats PgStat_CheckpointerStats
void pgstat_reset_slru(const char *)
Definition: pgstat_slru.c:45
void pgstat_count_slru_page_exists(int slru_idx)
Definition: pgstat_slru.c:71
void pgstat_create_subscription(Oid subid)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt)
Definition: pgstat_io.c:122
void pgstat_count_slru_page_read(int slru_idx)
Definition: pgstat_slru.c:77
void pgstat_count_heap_update(Relation rel, bool hot, bool newpage)
PgStat_FetchConsistency
Definition: pgstat.h:100
@ PGSTAT_FETCH_CONSISTENCY_NONE
Definition: pgstat.h:101
@ PGSTAT_FETCH_CONSISTENCY_CACHE
Definition: pgstat.h:102
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
Definition: pgstat.h:103
void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo)
Definition: pgstat_xact.c:314
void StatsShmemInit(void)
Definition: pgstat_shmem.c:156
void pgstat_reset_counters(void)
Definition: pgstat.c:840
void pgstat_report_subscription_conflict(Oid subid, ConflictType type)
struct PgStat_StatSubEntry PgStat_StatSubEntry
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
void AtEOXact_PgStat(bool isCommit, bool parallel)
Definition: pgstat_xact.c:40
int pgstat_get_slru_index(const char *name)
Definition: pgstat_slru.c:132
void pgstat_count_slru_page_hit(int slru_idx)
Definition: pgstat_slru.c:65
bool pgstat_tracks_io_bktype(BackendType bktype)
Definition: pgstat_io.c:348
void pgstat_report_subscription_error(Oid subid, bool is_apply_error)
void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
void pgstat_report_autovac(Oid dboid)
static bool pgstat_is_kind_custom(PgStat_Kind kind)
Definition: pgstat.h:86
struct PgStat_TableCounts PgStat_TableCounts
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
void pgstat_report_connect(Oid dboid)
void pgstat_initialize(void)
Definition: pgstat.c:618
struct PgStat_BackendSubEntry PgStat_BackendSubEntry
void pgstat_assoc_relation(Relation rel)
void pgstat_count_slru_page_zeroed(int slru_idx)
Definition: pgstat_slru.c:59
long pgstat_report_stat(bool force)
Definition: pgstat.c:671
struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
void pgstat_count_slru_truncate(int slru_idx)
Definition: pgstat_slru.c:95
void pgstat_report_checksum_failure(void)
#define PgStat_Kind
Definition: pgstat.h:37
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition: pgstat.c:881
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
struct PgStat_SLRUStats PgStat_SLRUStats
PGDLLIMPORT int pgstat_fetch_consistency
Definition: pgstat.c:204
struct PgStat_BktypeIO PgStat_BktypeIO
#define IOOP_NUM_TYPES
Definition: pgstat.h:342
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
IOContext
Definition: pgstat.h:321
@ IOCONTEXT_NORMAL
Definition: pgstat.h:324
@ IOCONTEXT_VACUUM
Definition: pgstat.h:325
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:322
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:323
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:328
void pgstat_before_server_shutdown(int code, Datum arg)
Definition: pgstat.c:543
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
#define PGSTAT_KIND_CUSTOM_MIN
Definition: pgstat.h:68
void pgstat_report_deadlock(void)
void pgstat_acquire_replslot(struct ReplicationSlot *slot)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
const char * pgstat_get_io_object_name(IOObject io_object)
Definition: pgstat_io.c:258
void pgstat_report_recovery_conflict(int reason)
void pgstat_force_next_flush(void)
Definition: pgstat.c:819
void pgstat_create_function(Oid proid)
TrackFunctionsLevel
Definition: pgstat.h:93
@ TRACK_FUNC_PL
Definition: pgstat.h:95
@ TRACK_FUNC_ALL
Definition: pgstat.h:96
@ TRACK_FUNC_OFF
Definition: pgstat.h:94
void pgstat_count_slru_page_written(int slru_idx)
Definition: pgstat_slru.c:83
struct PgStat_ArchiverStats PgStat_ArchiverStats
PGDLLIMPORT PgStat_Counter pgStatActiveTime
IOOp
Definition: pgstat.h:331
@ IOOP_EXTEND
Definition: pgstat.h:333
@ IOOP_FSYNC
Definition: pgstat.h:334
@ IOOP_READ
Definition: pgstat.h:336
@ IOOP_WRITEBACK
Definition: pgstat.h:339
@ IOOP_HIT
Definition: pgstat.h:335
@ IOOP_EVICT
Definition: pgstat.h:332
@ IOOP_REUSE
Definition: pgstat.h:337
@ IOOP_WRITE
Definition: pgstat.h:338
#define PGSTAT_KIND_BUILTIN_MAX
Definition: pgstat.h:62
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat_slru.c:105
void pgstat_clear_snapshot(void)
Definition: pgstat.c:907
const char * pgstat_get_slru_name(int slru_idx)
Definition: pgstat_slru.c:118
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition: pgstat.c:1035
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
Definition: pgstat_io.c:46
PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
Size StatsShmemSize(void)
Definition: pgstat_shmem.c:127
void pgstat_create_relation(Relation rel)
void PostPrepare_PgStat(void)
Definition: pgstat_xact.c:211
PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
struct PgStat_FunctionCounts PgStat_FunctionCounts
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:1052
struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
struct PgStat_PendingWalStats PgStat_PendingWalStats
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
void pgstat_report_wal(bool force)
Definition: pgstat_wal.c:48
PGDLLIMPORT int pgstat_track_functions
void pgstat_count_heap_delete(Relation rel)
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
struct PgStat_StatDBEntry PgStat_StatDBEntry
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
PgStat_IO * pgstat_fetch_stat_io(void)
Definition: pgstat_io.c:157
void pgstat_restore_stats(XLogRecPtr redo)
Definition: pgstat.c:488
void pgstat_count_slru_flush(int slru_idx)
Definition: pgstat_slru.c:89
PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
void pgstat_report_checkpointer(void)
void AtEOSubXact_PgStat(bool isCommit, int nestDepth)
Definition: pgstat_xact.c:113
struct PgStat_WalStats PgStat_WalStats
void pgstat_create_replslot(struct ReplicationSlot *slot)
void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition: pgstat_wal.c:67
void pgstat_drop_database(Oid databaseid)
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
struct PgStat_BgWriterStats PgStat_BgWriterStats
struct PgStat_StatTabEntry PgStat_StatTabEntry
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition: pgstat_io.c:454
void pgstat_count_truncate(Relation rel)
void pgstat_drop_replslot(struct ReplicationSlot *slot)
PGDLLIMPORT bool pgstat_track_counts
Definition: pgstat.c:203
void pgstat_drop_relation(Relation rel)
#define PGSTAT_KIND_BUILTIN_MIN
Definition: pgstat.h:61
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)
const char * pgstat_get_io_context_name(IOContext io_context)
Definition: pgstat_io.c:239
void pgstat_discard_stats(void)
Definition: pgstat.c:500
int64 PgStat_Counter
Definition: pgstat.h:120
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition: pgstat_io.c:389
void pgstat_report_bgwriter(void)
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)
void pgstat_report_archiver(const char *xlog, bool failed)
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:318
struct PgStat_TableXactStatus PgStat_TableXactStatus
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1410
void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
Definition: pgstat_io.c:83
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
PGDLLIMPORT SessionEndType pgStatSessionEndCause
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op)
Definition: pgstat_io.c:77
void pgstat_init_relation(Relation rel)
PGDLLIMPORT PgStat_PendingWalStats PendingWalStats
Definition: pgstat_wal.c:24
struct PgStat_IO PgStat_IO
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
TimestampTz last_failed_timestamp
Definition: pgstat.h:281
TimestampTz stat_reset_timestamp
Definition: pgstat.h:282
TimestampTz last_archived_timestamp
Definition: pgstat.h:277
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:279
PgStat_Counter failed_count
Definition: pgstat.h:278
PgStat_Counter archived_count
Definition: pgstat.h:274
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:275
PgStat_Counter apply_error_count
Definition: pgstat.h:167
PgStat_Counter sync_error_count
Definition: pgstat.h:168
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition: pgstat.h:169
PgStat_Counter buf_written_clean
Definition: pgstat.h:287
PgStat_Counter maxwritten_clean
Definition: pgstat.h:288
PgStat_Counter buf_alloc
Definition: pgstat.h:289
TimestampTz stat_reset_timestamp
Definition: pgstat.h:290
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:347
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:346
PgStat_Counter sync_time
Definition: pgstat.h:302
PgStat_Counter restartpoints_requested
Definition: pgstat.h:299
PgStat_Counter write_time
Definition: pgstat.h:301
PgStat_Counter num_requested
Definition: pgstat.h:296
PgStat_Counter num_performed
Definition: pgstat.h:297
PgStat_Counter restartpoints_timed
Definition: pgstat.h:298
PgStat_Counter num_timed
Definition: pgstat.h:295
PgStat_Counter restartpoints_performed
Definition: pgstat.h:300
PgStat_Counter buffers_written
Definition: pgstat.h:303
TimestampTz stat_reset_timestamp
Definition: pgstat.h:305
PgStat_Counter slru_written
Definition: pgstat.h:304
instr_time save_total
Definition: pgstat.h:156
PgStat_FunctionCounts * fs
Definition: pgstat.h:152
instr_time save_f_total_time
Definition: pgstat.h:154
PgStat_Counter numcalls
Definition: pgstat.h:140
instr_time total_time
Definition: pgstat.h:141
instr_time self_time
Definition: pgstat.h:142
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:353
TimestampTz stat_reset_timestamp
Definition: pgstat.h:352
instr_time wal_sync_time
Definition: pgstat.h:493
PgStat_Counter wal_write
Definition: pgstat.h:490
PgStat_Counter wal_buffers_full
Definition: pgstat.h:489
PgStat_Counter wal_sync
Definition: pgstat.h:491
instr_time wal_write_time
Definition: pgstat.h:492
PgStat_Counter blocks_read
Definition: pgstat.h:420
PgStat_Counter blocks_exists
Definition: pgstat.h:422
TimestampTz stat_reset_timestamp
Definition: pgstat.h:425
PgStat_Counter blocks_zeroed
Definition: pgstat.h:418
PgStat_Counter blocks_written
Definition: pgstat.h:421
PgStat_Counter blocks_hit
Definition: pgstat.h:419
PgStat_Counter truncate
Definition: pgstat.h:424
PgStat_Counter flush
Definition: pgstat.h:423
PgStat_Counter blk_write_time
Definition: pgstat.h:381
PgStat_Counter xact_rollback
Definition: pgstat.h:360
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:374
PgStat_Counter conflict_lock
Definition: pgstat.h:370
PgStat_Counter tuples_updated
Definition: pgstat.h:366
PgStat_Counter parallel_workers_to_launch
Definition: pgstat.h:389
PgStat_Counter tuples_inserted
Definition: pgstat.h:365
TimestampTz stat_reset_timestamp
Definition: pgstat.h:392
PgStat_Counter conflict_snapshot
Definition: pgstat.h:371
PgStat_Counter sessions_fatal
Definition: pgstat.h:387
TimestampTz last_checksum_failure
Definition: pgstat.h:379
PgStat_Counter tuples_returned
Definition: pgstat.h:363
PgStat_Counter blk_read_time
Definition: pgstat.h:380
PgStat_Counter parallel_workers_launched
Definition: pgstat.h:390
PgStat_Counter xact_commit
Definition: pgstat.h:359
TimestampTz last_autovac_time
Definition: pgstat.h:368
PgStat_Counter deadlocks
Definition: pgstat.h:377
PgStat_Counter temp_bytes
Definition: pgstat.h:376
PgStat_Counter session_time
Definition: pgstat.h:383
PgStat_Counter blocks_hit
Definition: pgstat.h:362
PgStat_Counter temp_files
Definition: pgstat.h:375
PgStat_Counter sessions_abandoned
Definition: pgstat.h:386
PgStat_Counter sessions
Definition: pgstat.h:382
PgStat_Counter active_time
Definition: pgstat.h:384
PgStat_Counter blocks_fetched
Definition: pgstat.h:361
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:373
PgStat_Counter idle_in_transaction_time
Definition: pgstat.h:385
PgStat_Counter conflict_logicalslot
Definition: pgstat.h:372
PgStat_Counter tuples_deleted
Definition: pgstat.h:367
PgStat_Counter sessions_killed
Definition: pgstat.h:388
PgStat_Counter tuples_fetched
Definition: pgstat.h:364
PgStat_Counter checksum_failures
Definition: pgstat.h:378
PgStat_Counter conflict_tablespace
Definition: pgstat.h:369
PgStat_Counter self_time
Definition: pgstat.h:400
PgStat_Counter numcalls
Definition: pgstat.h:397
PgStat_Counter total_time
Definition: pgstat.h:399
TimestampTz stat_reset_timestamp
Definition: pgstat.h:413
PgStat_Counter stream_count
Definition: pgstat.h:409
PgStat_Counter total_txns
Definition: pgstat.h:411
PgStat_Counter total_bytes
Definition: pgstat.h:412
PgStat_Counter spill_txns
Definition: pgstat.h:405
PgStat_Counter stream_txns
Definition: pgstat.h:408
PgStat_Counter spill_count
Definition: pgstat.h:406
PgStat_Counter stream_bytes
Definition: pgstat.h:410
PgStat_Counter spill_bytes
Definition: pgstat.h:407
PgStat_Counter apply_error_count
Definition: pgstat.h:430
PgStat_Counter sync_error_count
Definition: pgstat.h:431
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition: pgstat.h:432
TimestampTz stat_reset_timestamp
Definition: pgstat.h:433
PgStat_Counter vacuum_count
Definition: pgstat.h:459
PgStat_Counter tuples_fetched
Definition: pgstat.h:442
PgStat_Counter ins_since_vacuum
Definition: pgstat.h:453
PgStat_Counter blocks_hit
Definition: pgstat.h:456
PgStat_Counter mod_since_analyze
Definition: pgstat.h:452
TimestampTz last_autovacuum_time
Definition: pgstat.h:460
PgStat_Counter analyze_count
Definition: pgstat.h:463
PgStat_Counter tuples_deleted
Definition: pgstat.h:446
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:447
PgStat_Counter tuples_updated
Definition: pgstat.h:445
PgStat_Counter live_tuples
Definition: pgstat.h:450
PgStat_Counter numscans
Definition: pgstat.h:438
PgStat_Counter autovacuum_count
Definition: pgstat.h:461
TimestampTz last_analyze_time
Definition: pgstat.h:462
PgStat_Counter dead_tuples
Definition: pgstat.h:451
PgStat_Counter autoanalyze_count
Definition: pgstat.h:465
PgStat_Counter blocks_fetched
Definition: pgstat.h:455
PgStat_Counter tuples_returned
Definition: pgstat.h:441
TimestampTz last_autoanalyze_time
Definition: pgstat.h:464
TimestampTz lastscan
Definition: pgstat.h:439
PgStat_Counter tuples_inserted
Definition: pgstat.h:444
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:448
TimestampTz last_vacuum_time
Definition: pgstat.h:458
PgStat_Counter blocks_hit
Definition: pgstat.h:211
PgStat_Counter numscans
Definition: pgstat.h:194
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:202
PgStat_Counter tuples_returned
Definition: pgstat.h:196
PgStat_Counter tuples_inserted
Definition: pgstat.h:199
PgStat_Counter delta_live_tuples
Definition: pgstat.h:206
PgStat_Counter changed_tuples
Definition: pgstat.h:208
PgStat_Counter tuples_updated
Definition: pgstat.h:200
PgStat_Counter blocks_fetched
Definition: pgstat.h:210
PgStat_Counter tuples_fetched
Definition: pgstat.h:197
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:203
PgStat_Counter delta_dead_tuples
Definition: pgstat.h:207
PgStat_Counter tuples_deleted
Definition: pgstat.h:201
PgStat_TableCounts counts
Definition: pgstat.h:234
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:233
Relation relation
Definition: pgstat.h:235
struct PgStat_TableXactStatus * next
Definition: pgstat.h:258
PgStat_Counter deleted_pre_truncdrop
Definition: pgstat.h:252
PgStat_TableStatus * parent
Definition: pgstat.h:256
PgStat_Counter tuples_inserted
Definition: pgstat.h:244
PgStat_Counter tuples_updated
Definition: pgstat.h:245
PgStat_Counter inserted_pre_truncdrop
Definition: pgstat.h:250
PgStat_Counter tuples_deleted
Definition: pgstat.h:246
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:255
PgStat_Counter updated_pre_truncdrop
Definition: pgstat.h:251
PgStat_Counter wal_write
Definition: pgstat.h:474
PgStat_Counter wal_buffers_full
Definition: pgstat.h:473
PgStat_Counter wal_write_time
Definition: pgstat.h:476
TimestampTz stat_reset_timestamp
Definition: pgstat.h:478
uint64 wal_bytes
Definition: pgstat.h:472
PgStat_Counter wal_sync_time
Definition: pgstat.h:477
PgStat_Counter wal_fpi
Definition: pgstat.h:471
PgStat_Counter wal_sync
Definition: pgstat.h:475
PgStat_Counter wal_records
Definition: pgstat.h:470
Definition: c.h:695
static ItemArray items
Definition: test_tidstore.c:48
const char * type
const char * name
uint64 XLogRecPtr
Definition: xlogdefs.h:21