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  */
120 typedef int64 PgStat_Counter;
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 0x01A5BCAE
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 {
300  PgStat_Counter write_time; /* times in milliseconds */
305 
306 
307 /*
308  * Types related to counting IO operations
309  */
310 typedef enum IOObject
311 {
315 
316 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
317 
318 typedef enum IOContext
319 {
325 
326 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
327 
328 typedef enum IOOp
329 {
339 
340 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
341 
342 typedef struct PgStat_BktypeIO
343 {
347 
348 typedef struct PgStat_IO
349 {
353 
354 
355 typedef struct PgStat_StatDBEntry
356 {
378  PgStat_Counter blk_read_time; /* times in microseconds */
387 
390 
391 typedef struct PgStat_StatFuncEntry
392 {
394 
395  PgStat_Counter total_time; /* times in microseconds */
398 
400 {
411 
412 typedef struct PgStat_SLRUStats
413 {
423 
424 typedef struct PgStat_StatSubEntry
425 {
431 
432 typedef struct PgStat_StatTabEntry
433 {
436 
439 
445 
450 
453 
454  TimestampTz last_vacuum_time; /* user initiated vacuum */
456  TimestampTz last_autovacuum_time; /* autovacuum initiated */
458  TimestampTz last_analyze_time; /* user initiated */
460  TimestampTz last_autoanalyze_time; /* autovacuum initiated */
463 
464 typedef struct PgStat_WalStats
465 {
468  uint64 wal_bytes;
476 
477 /*
478  * This struct stores wal-related durations as instr_time, which makes it
479  * cheaper and easier to accumulate them, by not requiring type
480  * conversions. During stats flush instr_time will be converted into
481  * microseconds.
482  */
484 {
491 
492 
493 /*
494  * Functions in pgstat.c
495  */
496 
497 /* functions called from postmaster */
498 extern Size StatsShmemSize(void);
499 extern void StatsShmemInit(void);
500 
501 /* Functions called during server startup / shutdown */
502 extern void pgstat_restore_stats(XLogRecPtr redo);
503 extern void pgstat_discard_stats(void);
504 extern void pgstat_before_server_shutdown(int code, Datum arg);
505 
506 /* Functions for backend initialization */
507 extern void pgstat_initialize(void);
508 
509 /* Functions called from backends */
510 extern long pgstat_report_stat(bool force);
511 extern void pgstat_force_next_flush(void);
512 
513 extern void pgstat_reset_counters(void);
514 extern void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid);
515 extern void pgstat_reset_of_kind(PgStat_Kind kind);
516 
517 /* stats accessors */
518 extern void pgstat_clear_snapshot(void);
519 extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
520 
521 /* helpers */
522 extern PgStat_Kind pgstat_get_kind_from_str(char *kind_str);
523 extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
524 
525 
526 /*
527  * Functions in pgstat_archiver.c
528  */
529 
530 extern void pgstat_report_archiver(const char *xlog, bool failed);
532 
533 
534 /*
535  * Functions in pgstat_bgwriter.c
536  */
537 
538 extern void pgstat_report_bgwriter(void);
540 
541 
542 /*
543  * Functions in pgstat_checkpointer.c
544  */
545 
546 extern void pgstat_report_checkpointer(void);
548 
549 
550 /*
551  * Functions in pgstat_io.c
552  */
553 
554 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
555  BackendType bktype);
556 extern void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op);
557 extern void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt);
558 extern instr_time pgstat_prepare_io_time(bool track_io_guc);
559 extern void pgstat_count_io_op_time(IOObject io_object, IOContext io_context,
560  IOOp io_op, instr_time start_time, uint32 cnt);
561 
562 extern PgStat_IO *pgstat_fetch_stat_io(void);
563 extern const char *pgstat_get_io_context_name(IOContext io_context);
564 extern const char *pgstat_get_io_object_name(IOObject io_object);
565 
566 extern bool pgstat_tracks_io_bktype(BackendType bktype);
567 extern bool pgstat_tracks_io_object(BackendType bktype,
568  IOObject io_object, IOContext io_context);
569 extern bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object,
570  IOContext io_context, IOOp io_op);
571 
572 
573 /*
574  * Functions in pgstat_database.c
575  */
576 
577 extern void pgstat_drop_database(Oid databaseid);
578 extern void pgstat_report_autovac(Oid dboid);
579 extern void pgstat_report_recovery_conflict(int reason);
580 extern void pgstat_report_deadlock(void);
581 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
582 extern void pgstat_report_checksum_failure(void);
583 extern void pgstat_report_connect(Oid dboid);
584 
585 #define pgstat_count_buffer_read_time(n) \
586  (pgStatBlockReadTime += (n))
587 #define pgstat_count_buffer_write_time(n) \
588  (pgStatBlockWriteTime += (n))
589 #define pgstat_count_conn_active_time(n) \
590  (pgStatActiveTime += (n))
591 #define pgstat_count_conn_txn_idle_time(n) \
592  (pgStatTransactionIdleTime += (n))
593 
595 
596 
597 /*
598  * Functions in pgstat_function.c
599  */
600 
601 extern void pgstat_create_function(Oid proid);
602 extern void pgstat_drop_function(Oid proid);
603 
608  bool finalize);
609 
612 
613 
614 /*
615  * Functions in pgstat_relation.c
616  */
617 
618 extern void pgstat_create_relation(Relation rel);
619 extern void pgstat_drop_relation(Relation rel);
620 extern void pgstat_copy_relation_stats(Relation dst, Relation src);
621 
622 extern void pgstat_init_relation(Relation rel);
623 extern void pgstat_assoc_relation(Relation rel);
624 extern void pgstat_unlink_relation(Relation rel);
625 
626 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
627  PgStat_Counter livetuples, PgStat_Counter deadtuples);
628 extern void pgstat_report_analyze(Relation rel,
629  PgStat_Counter livetuples, PgStat_Counter deadtuples,
630  bool resetcounter);
631 
632 /*
633  * If stats are enabled, but pending data hasn't been prepared yet, call
634  * pgstat_assoc_relation() to do so. See its comment for why this is done
635  * separately from pgstat_init_relation().
636  */
637 #define pgstat_should_count_relation(rel) \
638  (likely((rel)->pgstat_info != NULL) ? true : \
639  ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
640 
641 /* nontransactional event counts are simple enough to inline */
642 
643 #define pgstat_count_heap_scan(rel) \
644  do { \
645  if (pgstat_should_count_relation(rel)) \
646  (rel)->pgstat_info->counts.numscans++; \
647  } while (0)
648 #define pgstat_count_heap_getnext(rel) \
649  do { \
650  if (pgstat_should_count_relation(rel)) \
651  (rel)->pgstat_info->counts.tuples_returned++; \
652  } while (0)
653 #define pgstat_count_heap_fetch(rel) \
654  do { \
655  if (pgstat_should_count_relation(rel)) \
656  (rel)->pgstat_info->counts.tuples_fetched++; \
657  } while (0)
658 #define pgstat_count_index_scan(rel) \
659  do { \
660  if (pgstat_should_count_relation(rel)) \
661  (rel)->pgstat_info->counts.numscans++; \
662  } while (0)
663 #define pgstat_count_index_tuples(rel, n) \
664  do { \
665  if (pgstat_should_count_relation(rel)) \
666  (rel)->pgstat_info->counts.tuples_returned += (n); \
667  } while (0)
668 #define pgstat_count_buffer_read(rel) \
669  do { \
670  if (pgstat_should_count_relation(rel)) \
671  (rel)->pgstat_info->counts.blocks_fetched++; \
672  } while (0)
673 #define pgstat_count_buffer_hit(rel) \
674  do { \
675  if (pgstat_should_count_relation(rel)) \
676  (rel)->pgstat_info->counts.blocks_hit++; \
677  } while (0)
678 
680 extern void pgstat_count_heap_update(Relation rel, bool hot, bool newpage);
681 extern void pgstat_count_heap_delete(Relation rel);
682 extern void pgstat_count_truncate(Relation rel);
683 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
684 
685 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
686  void *recdata, uint32 len);
687 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
688  void *recdata, uint32 len);
689 
692  Oid reloid);
694 
695 
696 /*
697  * Functions in pgstat_replslot.c
698  */
699 
700 extern void pgstat_reset_replslot(const char *name);
701 struct ReplicationSlot;
702 extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
703 extern void pgstat_create_replslot(struct ReplicationSlot *slot);
704 extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
705 extern void pgstat_drop_replslot(struct ReplicationSlot *slot);
707 
708 
709 /*
710  * Functions in pgstat_slru.c
711  */
712 
713 extern void pgstat_reset_slru(const char *);
714 extern void pgstat_count_slru_page_zeroed(int slru_idx);
715 extern void pgstat_count_slru_page_hit(int slru_idx);
716 extern void pgstat_count_slru_page_read(int slru_idx);
717 extern void pgstat_count_slru_page_written(int slru_idx);
718 extern void pgstat_count_slru_page_exists(int slru_idx);
719 extern void pgstat_count_slru_flush(int slru_idx);
720 extern void pgstat_count_slru_truncate(int slru_idx);
721 extern const char *pgstat_get_slru_name(int slru_idx);
722 extern int pgstat_get_slru_index(const char *name);
723 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
724 
725 
726 /*
727  * Functions in pgstat_subscription.c
728  */
729 
730 extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
732 extern void pgstat_create_subscription(Oid subid);
733 extern void pgstat_drop_subscription(Oid subid);
735 
736 
737 /*
738  * Functions in pgstat_xact.c
739  */
740 
741 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
742 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
743 extern void AtPrepare_PgStat(void);
744 extern void PostPrepare_PgStat(void);
745 struct xl_xact_stats_item;
746 extern int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items);
747 extern void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo);
748 
749 
750 /*
751  * Functions in pgstat_wal.c
752  */
753 
754 extern void pgstat_report_wal(bool force);
756 
757 
758 /*
759  * Variables in pgstat.c
760  */
761 
762 /* GUC parameters */
763 extern PGDLLIMPORT bool pgstat_track_counts;
766 
767 
768 /*
769  * Variables in pgstat_bgwriter.c
770  */
771 
772 /* updated directly by bgwriter and bufmgr */
774 
775 
776 /*
777  * Variables in pgstat_checkpointer.c
778  */
779 
780 /*
781  * Checkpointer statistics counters are updated directly by checkpointer and
782  * bufmgr.
783  */
785 
786 
787 /*
788  * Variables in pgstat_database.c
789  */
790 
791 /* Updated by pgstat_count_buffer_*_time macros */
794 
795 /*
796  * Updated by pgstat_count_conn_*_time macros, called by
797  * pgstat_report_activity().
798  */
801 
802 /* updated by the traffic cop and in errfinish() */
804 
805 
806 /*
807  * Variables in pgstat_wal.c
808  */
809 
810 /* updated directly by backends and background processes */
812 
813 
814 #endif /* PGSTAT_H */
unsigned short uint16
Definition: c.h:505
unsigned int uint32
Definition: c.h:506
#define PGDLLIMPORT
Definition: c.h:1316
uint32 TransactionId
Definition: c.h:652
size_t Size
Definition: c.h:605
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:367
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_drop_function(Oid proid)
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:848
#define PGSTAT_KIND_CUSTOM_MAX
Definition: pgstat.h:69
void pgstat_drop_subscription(Oid subid)
struct PgStat_TableStatus PgStat_TableStatus
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:311
@ IOOBJECT_RELATION
Definition: pgstat.h:312
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:313
static bool pgstat_is_kind_builtin(PgStat_Kind kind)
Definition: pgstat.h:80
void AtPrepare_PgStat(void)
Definition: pgstat_xact.c:189
int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items)
Definition: pgstat_xact.c:270
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:312
void StatsShmemInit(void)
Definition: pgstat_shmem.c:156
void pgstat_reset_counters(void)
Definition: pgstat.c:829
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:346
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:607
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:1038
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:660
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:870
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:340
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
IOContext
Definition: pgstat.h:319
@ IOCONTEXT_NORMAL
Definition: pgstat.h:322
@ IOCONTEXT_VACUUM
Definition: pgstat.h:323
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:320
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:321
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:326
void pgstat_before_server_shutdown(int code, Datum arg)
Definition: pgstat.c:532
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:808
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:329
@ IOOP_EXTEND
Definition: pgstat.h:331
@ IOOP_FSYNC
Definition: pgstat.h:332
@ IOOP_READ
Definition: pgstat.h:334
@ IOOP_WRITEBACK
Definition: pgstat.h:337
@ IOOP_HIT
Definition: pgstat.h:333
@ IOOP_EVICT
Definition: pgstat.h:330
@ IOOP_REUSE
Definition: pgstat.h:335
@ IOOP_WRITE
Definition: pgstat.h:336
#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:896
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:1021
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:209
PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
struct PgStat_FunctionCounts PgStat_FunctionCounts
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:477
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:112
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:451
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:489
int64 PgStat_Counter
Definition: pgstat.h:120
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition: pgstat_io.c:386
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:316
struct PgStat_TableXactStatus PgStat_TableXactStatus
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1396
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:345
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:344
PgStat_Counter sync_time
Definition: pgstat.h:301
PgStat_Counter restartpoints_requested
Definition: pgstat.h:298
PgStat_Counter write_time
Definition: pgstat.h:300
PgStat_Counter num_requested
Definition: pgstat.h:296
PgStat_Counter restartpoints_timed
Definition: pgstat.h:297
PgStat_Counter num_timed
Definition: pgstat.h:295
PgStat_Counter restartpoints_performed
Definition: pgstat.h:299
PgStat_Counter buffers_written
Definition: pgstat.h:302
TimestampTz stat_reset_timestamp
Definition: pgstat.h:303
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:351
TimestampTz stat_reset_timestamp
Definition: pgstat.h:350
instr_time wal_sync_time
Definition: pgstat.h:489
PgStat_Counter wal_write
Definition: pgstat.h:486
PgStat_Counter wal_buffers_full
Definition: pgstat.h:485
PgStat_Counter wal_sync
Definition: pgstat.h:487
instr_time wal_write_time
Definition: pgstat.h:488
PgStat_Counter blocks_read
Definition: pgstat.h:416
PgStat_Counter blocks_exists
Definition: pgstat.h:418
TimestampTz stat_reset_timestamp
Definition: pgstat.h:421
PgStat_Counter blocks_zeroed
Definition: pgstat.h:414
PgStat_Counter blocks_written
Definition: pgstat.h:417
PgStat_Counter blocks_hit
Definition: pgstat.h:415
PgStat_Counter truncate
Definition: pgstat.h:420
PgStat_Counter flush
Definition: pgstat.h:419
PgStat_Counter blk_write_time
Definition: pgstat.h:379
PgStat_Counter xact_rollback
Definition: pgstat.h:358
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:372
PgStat_Counter conflict_lock
Definition: pgstat.h:368
PgStat_Counter tuples_updated
Definition: pgstat.h:364
PgStat_Counter tuples_inserted
Definition: pgstat.h:363
TimestampTz stat_reset_timestamp
Definition: pgstat.h:388
PgStat_Counter conflict_snapshot
Definition: pgstat.h:369
PgStat_Counter sessions_fatal
Definition: pgstat.h:385
TimestampTz last_checksum_failure
Definition: pgstat.h:377
PgStat_Counter tuples_returned
Definition: pgstat.h:361
PgStat_Counter blk_read_time
Definition: pgstat.h:378
PgStat_Counter xact_commit
Definition: pgstat.h:357
TimestampTz last_autovac_time
Definition: pgstat.h:366
PgStat_Counter deadlocks
Definition: pgstat.h:375
PgStat_Counter temp_bytes
Definition: pgstat.h:374
PgStat_Counter session_time
Definition: pgstat.h:381
PgStat_Counter blocks_hit
Definition: pgstat.h:360
PgStat_Counter temp_files
Definition: pgstat.h:373
PgStat_Counter sessions_abandoned
Definition: pgstat.h:384
PgStat_Counter sessions
Definition: pgstat.h:380
PgStat_Counter active_time
Definition: pgstat.h:382
PgStat_Counter blocks_fetched
Definition: pgstat.h:359
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:371
PgStat_Counter idle_in_transaction_time
Definition: pgstat.h:383
PgStat_Counter conflict_logicalslot
Definition: pgstat.h:370
PgStat_Counter tuples_deleted
Definition: pgstat.h:365
PgStat_Counter sessions_killed
Definition: pgstat.h:386
PgStat_Counter tuples_fetched
Definition: pgstat.h:362
PgStat_Counter checksum_failures
Definition: pgstat.h:376
PgStat_Counter conflict_tablespace
Definition: pgstat.h:367
PgStat_Counter self_time
Definition: pgstat.h:396
PgStat_Counter numcalls
Definition: pgstat.h:393
PgStat_Counter total_time
Definition: pgstat.h:395
TimestampTz stat_reset_timestamp
Definition: pgstat.h:409
PgStat_Counter stream_count
Definition: pgstat.h:405
PgStat_Counter total_txns
Definition: pgstat.h:407
PgStat_Counter total_bytes
Definition: pgstat.h:408
PgStat_Counter spill_txns
Definition: pgstat.h:401
PgStat_Counter stream_txns
Definition: pgstat.h:404
PgStat_Counter spill_count
Definition: pgstat.h:402
PgStat_Counter stream_bytes
Definition: pgstat.h:406
PgStat_Counter spill_bytes
Definition: pgstat.h:403
PgStat_Counter apply_error_count
Definition: pgstat.h:426
PgStat_Counter sync_error_count
Definition: pgstat.h:427
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition: pgstat.h:428
TimestampTz stat_reset_timestamp
Definition: pgstat.h:429
PgStat_Counter vacuum_count
Definition: pgstat.h:455
PgStat_Counter tuples_fetched
Definition: pgstat.h:438
PgStat_Counter ins_since_vacuum
Definition: pgstat.h:449
PgStat_Counter blocks_hit
Definition: pgstat.h:452
PgStat_Counter mod_since_analyze
Definition: pgstat.h:448
TimestampTz last_autovacuum_time
Definition: pgstat.h:456
PgStat_Counter analyze_count
Definition: pgstat.h:459
PgStat_Counter tuples_deleted
Definition: pgstat.h:442
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:443
PgStat_Counter tuples_updated
Definition: pgstat.h:441
PgStat_Counter live_tuples
Definition: pgstat.h:446
PgStat_Counter numscans
Definition: pgstat.h:434
PgStat_Counter autovacuum_count
Definition: pgstat.h:457
TimestampTz last_analyze_time
Definition: pgstat.h:458
PgStat_Counter dead_tuples
Definition: pgstat.h:447
PgStat_Counter autoanalyze_count
Definition: pgstat.h:461
PgStat_Counter blocks_fetched
Definition: pgstat.h:451
PgStat_Counter tuples_returned
Definition: pgstat.h:437
TimestampTz last_autoanalyze_time
Definition: pgstat.h:460
TimestampTz lastscan
Definition: pgstat.h:435
PgStat_Counter tuples_inserted
Definition: pgstat.h:440
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:444
TimestampTz last_vacuum_time
Definition: pgstat.h:454
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:470
PgStat_Counter wal_buffers_full
Definition: pgstat.h:469
PgStat_Counter wal_write_time
Definition: pgstat.h:472
TimestampTz stat_reset_timestamp
Definition: pgstat.h:474
uint64 wal_bytes
Definition: pgstat.h:468
PgStat_Counter wal_sync_time
Definition: pgstat.h:473
PgStat_Counter wal_fpi
Definition: pgstat.h:467
PgStat_Counter wal_sync
Definition: pgstat.h:471
PgStat_Counter wal_records
Definition: pgstat.h:466
Definition: c.h:741
static ItemArray items
Definition: test_tidstore.c:49
const char * type
const char * name
uint64 XLogRecPtr
Definition: xlogdefs.h:21