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 "datatype/timestamp.h"
15 #include "portability/instr_time.h"
16 #include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
17 #include "utils/backend_progress.h" /* for backward compatibility */
18 #include "utils/backend_status.h" /* for backward compatibility */
19 #include "utils/relcache.h"
20 #include "utils/wait_event.h" /* for backward compatibility */
21 
22 
23 /* ----------
24  * Paths for the statistics files (relative to installation's $PGDATA).
25  * ----------
26  */
27 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
28 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/pgstat.stat"
29 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/pgstat.tmp"
30 
31 /* Default directory to store temporary statistics data in */
32 #define PG_STAT_TMP_DIR "pg_stat_tmp"
33 
34 /* The types of statistics entries */
35 typedef enum PgStat_Kind
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 */
55 
56 #define PGSTAT_KIND_FIRST_VALID PGSTAT_KIND_DATABASE
57 #define PGSTAT_KIND_LAST PGSTAT_KIND_WAL
58 #define PGSTAT_NUM_KINDS (PGSTAT_KIND_LAST + 1)
59 
60 /* Values for track_functions GUC variable --- order is significant! */
61 typedef enum TrackFunctionsLevel
62 {
67 
69 {
74 
75 /* Values to track the cause of session termination */
76 typedef enum SessionEndType
77 {
78  DISCONNECT_NOT_YET, /* still active */
84 
85 /* ----------
86  * The data type used for counters.
87  * ----------
88  */
89 typedef int64 PgStat_Counter;
90 
91 
92 /* ------------------------------------------------------------
93  * Structures kept in backend local memory while accumulating counts
94  * ------------------------------------------------------------
95  */
96 
97 /* ----------
98  * PgStat_FunctionCounts The actual per-function counts kept by a backend
99  *
100  * This struct should contain only actual event counters, because we memcmp
101  * it against zeroes to detect whether there are any pending stats.
102  *
103  * Note that the time counters are in instr_time format here. We convert to
104  * microseconds in PgStat_Counter format when flushing out pending statistics.
105  * ----------
106  */
107 typedef struct PgStat_FunctionCounts
108 {
113 
114 /*
115  * Working state needed to accumulate per-function-call timing statistics.
116  */
118 {
119  /* Link to function's hashtable entry (must still be there at exit!) */
120  /* NULL means we are not tracking the current function call */
122  /* Total time previously charged to function, as of function start */
124  /* Backend-wide total time as of function start */
126  /* system clock as of function start */
129 
130 /* ----------
131  * PgStat_BackendSubEntry Non-flushed subscription stats.
132  * ----------
133  */
135 {
139 
140 /* ----------
141  * PgStat_TableCounts The actual per-table counts kept by a backend
142  *
143  * This struct should contain only actual event counters, because we memcmp
144  * it against zeroes to detect whether there are any stats updates to apply.
145  * It is a component of PgStat_TableStatus (within-backend state).
146  *
147  * Note: for a table, tuples_returned is the number of tuples successfully
148  * fetched by heap_getnext, while tuples_fetched is the number of tuples
149  * successfully fetched by heap_fetch under the control of bitmap indexscans.
150  * For an index, tuples_returned is the number of index entries returned by
151  * the index AM, while tuples_fetched is the number of tuples successfully
152  * fetched by heap_fetch under the control of simple indexscans for this index.
153  *
154  * tuples_inserted/updated/deleted/hot_updated/newpage_updated count attempted
155  * actions, regardless of whether the transaction committed. delta_live_tuples,
156  * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
157  * Note that delta_live_tuples and delta_dead_tuples can be negative!
158  * ----------
159  */
160 typedef struct PgStat_TableCounts
161 {
163 
166 
173 
177 
181 
182 /* ----------
183  * PgStat_TableStatus Per-table status within a backend
184  *
185  * Many of the event counters are nontransactional, ie, we count events
186  * in committed and aborted transactions alike. For these, we just count
187  * directly in the PgStat_TableStatus. However, delta_live_tuples,
188  * delta_dead_tuples, and changed_tuples must be derived from event counts
189  * with awareness of whether the transaction or subtransaction committed or
190  * aborted. Hence, we also keep a stack of per-(sub)transaction status
191  * records for every table modified in the current transaction. At commit
192  * or abort, we propagate tuples_inserted/updated/deleted up to the
193  * parent subtransaction level, or out to the parent PgStat_TableStatus,
194  * as appropriate.
195  * ----------
196  */
197 typedef struct PgStat_TableStatus
198 {
199  Oid id; /* table's OID */
200  bool shared; /* is it a shared catalog? */
201  struct PgStat_TableXactStatus *trans; /* lowest subxact's counts */
202  PgStat_TableCounts counts; /* event counts to be sent */
203  Relation relation; /* rel that is using this entry */
205 
206 /* ----------
207  * PgStat_TableXactStatus Per-table, per-subtransaction status
208  * ----------
209  */
211 {
212  PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */
213  PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */
214  PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */
215  bool truncdropped; /* relation truncated/dropped in this
216  * (sub)xact */
217  /* tuples i/u/d prior to truncate/drop */
221  int nest_level; /* subtransaction nest level */
222  /* links to other structs for same relation: */
223  struct PgStat_TableXactStatus *upper; /* next higher subxact if any */
224  PgStat_TableStatus *parent; /* per-table status */
225  /* structs of same subxact level are linked here: */
226  struct PgStat_TableXactStatus *next; /* next of same subxact */
228 
229 
230 /* ------------------------------------------------------------
231  * Data structures on disk and in shared memory follow
232  *
233  * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
234  * data structures change.
235  * ------------------------------------------------------------
236  */
237 
238 #define PGSTAT_FILE_FORMAT_ID 0x01A5BCAC
239 
240 typedef struct PgStat_ArchiverStats
241 {
242  PgStat_Counter archived_count; /* archival successes */
243  char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
244  * archived */
245  TimestampTz last_archived_timestamp; /* last archival success time */
246  PgStat_Counter failed_count; /* failed archival attempts */
247  char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
248  * last failure */
249  TimestampTz last_failed_timestamp; /* last archival failure time */
252 
253 typedef struct PgStat_BgWriterStats
254 {
260 
262 {
268  PgStat_Counter write_time; /* times in milliseconds */
273 
274 
275 /*
276  * Types related to counting IO operations
277  */
278 typedef enum IOObject
279 {
283 
284 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
285 
286 typedef enum IOContext
287 {
293 
294 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
295 
296 typedef enum IOOp
297 {
307 
308 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
309 
310 typedef struct PgStat_BktypeIO
311 {
315 
316 typedef struct PgStat_IO
317 {
321 
322 
323 typedef struct PgStat_StatDBEntry
324 {
346  PgStat_Counter blk_read_time; /* times in microseconds */
355 
358 
359 typedef struct PgStat_StatFuncEntry
360 {
362 
363  PgStat_Counter total_time; /* times in microseconds */
366 
368 {
379 
380 typedef struct PgStat_SLRUStats
381 {
391 
392 typedef struct PgStat_StatSubEntry
393 {
398 
399 typedef struct PgStat_StatTabEntry
400 {
403 
406 
412 
417 
420 
421  TimestampTz last_vacuum_time; /* user initiated vacuum */
423  TimestampTz last_autovacuum_time; /* autovacuum initiated */
425  TimestampTz last_analyze_time; /* user initiated */
427  TimestampTz last_autoanalyze_time; /* autovacuum initiated */
430 
431 typedef struct PgStat_WalStats
432 {
435  uint64 wal_bytes;
443 
444 /*
445  * This struct stores wal-related durations as instr_time, which makes it
446  * cheaper and easier to accumulate them, by not requiring type
447  * conversions. During stats flush instr_time will be converted into
448  * microseconds.
449  */
451 {
458 
459 
460 /*
461  * Functions in pgstat.c
462  */
463 
464 /* functions called from postmaster */
465 extern Size StatsShmemSize(void);
466 extern void StatsShmemInit(void);
467 
468 /* Functions called during server startup / shutdown */
469 extern void pgstat_restore_stats(void);
470 extern void pgstat_discard_stats(void);
471 extern void pgstat_before_server_shutdown(int code, Datum arg);
472 
473 /* Functions for backend initialization */
474 extern void pgstat_initialize(void);
475 
476 /* Functions called from backends */
477 extern long pgstat_report_stat(bool force);
478 extern void pgstat_force_next_flush(void);
479 
480 extern void pgstat_reset_counters(void);
481 extern void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid);
482 extern void pgstat_reset_of_kind(PgStat_Kind kind);
483 
484 /* stats accessors */
485 extern void pgstat_clear_snapshot(void);
486 extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
487 
488 /* helpers */
489 extern PgStat_Kind pgstat_get_kind_from_str(char *kind_str);
490 extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
491 
492 
493 /*
494  * Functions in pgstat_archiver.c
495  */
496 
497 extern void pgstat_report_archiver(const char *xlog, bool failed);
499 
500 
501 /*
502  * Functions in pgstat_bgwriter.c
503  */
504 
505 extern void pgstat_report_bgwriter(void);
507 
508 
509 /*
510  * Functions in pgstat_checkpointer.c
511  */
512 
513 extern void pgstat_report_checkpointer(void);
515 
516 
517 /*
518  * Functions in pgstat_io.c
519  */
520 
521 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
522  BackendType bktype);
523 extern void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op);
524 extern void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt);
525 extern instr_time pgstat_prepare_io_time(bool track_io_guc);
526 extern void pgstat_count_io_op_time(IOObject io_object, IOContext io_context,
527  IOOp io_op, instr_time start_time, uint32 cnt);
528 
529 extern PgStat_IO *pgstat_fetch_stat_io(void);
530 extern const char *pgstat_get_io_context_name(IOContext io_context);
531 extern const char *pgstat_get_io_object_name(IOObject io_object);
532 
533 extern bool pgstat_tracks_io_bktype(BackendType bktype);
534 extern bool pgstat_tracks_io_object(BackendType bktype,
535  IOObject io_object, IOContext io_context);
536 extern bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object,
537  IOContext io_context, IOOp io_op);
538 
539 
540 /*
541  * Functions in pgstat_database.c
542  */
543 
544 extern void pgstat_drop_database(Oid databaseid);
545 extern void pgstat_report_autovac(Oid dboid);
546 extern void pgstat_report_recovery_conflict(int reason);
547 extern void pgstat_report_deadlock(void);
548 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
549 extern void pgstat_report_checksum_failure(void);
550 extern void pgstat_report_connect(Oid dboid);
551 
552 #define pgstat_count_buffer_read_time(n) \
553  (pgStatBlockReadTime += (n))
554 #define pgstat_count_buffer_write_time(n) \
555  (pgStatBlockWriteTime += (n))
556 #define pgstat_count_conn_active_time(n) \
557  (pgStatActiveTime += (n))
558 #define pgstat_count_conn_txn_idle_time(n) \
559  (pgStatTransactionIdleTime += (n))
560 
562 
563 
564 /*
565  * Functions in pgstat_function.c
566  */
567 
568 extern void pgstat_create_function(Oid proid);
569 extern void pgstat_drop_function(Oid proid);
570 
575  bool finalize);
576 
579 
580 
581 /*
582  * Functions in pgstat_relation.c
583  */
584 
585 extern void pgstat_create_relation(Relation rel);
586 extern void pgstat_drop_relation(Relation rel);
587 extern void pgstat_copy_relation_stats(Relation dst, Relation src);
588 
589 extern void pgstat_init_relation(Relation rel);
590 extern void pgstat_assoc_relation(Relation rel);
591 extern void pgstat_unlink_relation(Relation rel);
592 
593 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
594  PgStat_Counter livetuples, PgStat_Counter deadtuples);
595 extern void pgstat_report_analyze(Relation rel,
596  PgStat_Counter livetuples, PgStat_Counter deadtuples,
597  bool resetcounter);
598 
599 /*
600  * If stats are enabled, but pending data hasn't been prepared yet, call
601  * pgstat_assoc_relation() to do so. See its comment for why this is done
602  * separately from pgstat_init_relation().
603  */
604 #define pgstat_should_count_relation(rel) \
605  (likely((rel)->pgstat_info != NULL) ? true : \
606  ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
607 
608 /* nontransactional event counts are simple enough to inline */
609 
610 #define pgstat_count_heap_scan(rel) \
611  do { \
612  if (pgstat_should_count_relation(rel)) \
613  (rel)->pgstat_info->counts.numscans++; \
614  } while (0)
615 #define pgstat_count_heap_getnext(rel) \
616  do { \
617  if (pgstat_should_count_relation(rel)) \
618  (rel)->pgstat_info->counts.tuples_returned++; \
619  } while (0)
620 #define pgstat_count_heap_fetch(rel) \
621  do { \
622  if (pgstat_should_count_relation(rel)) \
623  (rel)->pgstat_info->counts.tuples_fetched++; \
624  } while (0)
625 #define pgstat_count_index_scan(rel) \
626  do { \
627  if (pgstat_should_count_relation(rel)) \
628  (rel)->pgstat_info->counts.numscans++; \
629  } while (0)
630 #define pgstat_count_index_tuples(rel, n) \
631  do { \
632  if (pgstat_should_count_relation(rel)) \
633  (rel)->pgstat_info->counts.tuples_returned += (n); \
634  } while (0)
635 #define pgstat_count_buffer_read(rel) \
636  do { \
637  if (pgstat_should_count_relation(rel)) \
638  (rel)->pgstat_info->counts.blocks_fetched++; \
639  } while (0)
640 #define pgstat_count_buffer_hit(rel) \
641  do { \
642  if (pgstat_should_count_relation(rel)) \
643  (rel)->pgstat_info->counts.blocks_hit++; \
644  } while (0)
645 
647 extern void pgstat_count_heap_update(Relation rel, bool hot, bool newpage);
648 extern void pgstat_count_heap_delete(Relation rel);
649 extern void pgstat_count_truncate(Relation rel);
650 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
651 
652 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
653  void *recdata, uint32 len);
654 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
655  void *recdata, uint32 len);
656 
659  Oid reloid);
661 
662 
663 /*
664  * Functions in pgstat_replslot.c
665  */
666 
667 extern void pgstat_reset_replslot(const char *name);
668 struct ReplicationSlot;
669 extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
670 extern void pgstat_create_replslot(struct ReplicationSlot *slot);
671 extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
672 extern void pgstat_drop_replslot(struct ReplicationSlot *slot);
674 
675 
676 /*
677  * Functions in pgstat_slru.c
678  */
679 
680 extern void pgstat_reset_slru(const char *);
681 extern void pgstat_count_slru_page_zeroed(int slru_idx);
682 extern void pgstat_count_slru_page_hit(int slru_idx);
683 extern void pgstat_count_slru_page_read(int slru_idx);
684 extern void pgstat_count_slru_page_written(int slru_idx);
685 extern void pgstat_count_slru_page_exists(int slru_idx);
686 extern void pgstat_count_slru_flush(int slru_idx);
687 extern void pgstat_count_slru_truncate(int slru_idx);
688 extern const char *pgstat_get_slru_name(int slru_idx);
689 extern int pgstat_get_slru_index(const char *name);
690 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
691 
692 
693 /*
694  * Functions in pgstat_subscription.c
695  */
696 
697 extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
698 extern void pgstat_create_subscription(Oid subid);
699 extern void pgstat_drop_subscription(Oid subid);
701 
702 
703 /*
704  * Functions in pgstat_xact.c
705  */
706 
707 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
708 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
709 extern void AtPrepare_PgStat(void);
710 extern void PostPrepare_PgStat(void);
711 struct xl_xact_stats_item;
712 extern int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items);
713 extern void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo);
714 
715 
716 /*
717  * Functions in pgstat_wal.c
718  */
719 
720 extern void pgstat_report_wal(bool force);
722 
723 
724 /*
725  * Variables in pgstat.c
726  */
727 
728 /* GUC parameters */
729 extern PGDLLIMPORT bool pgstat_track_counts;
732 
733 
734 /*
735  * Variables in pgstat_bgwriter.c
736  */
737 
738 /* updated directly by bgwriter and bufmgr */
740 
741 
742 /*
743  * Variables in pgstat_checkpointer.c
744  */
745 
746 /*
747  * Checkpointer statistics counters are updated directly by checkpointer and
748  * bufmgr.
749  */
751 
752 
753 /*
754  * Variables in pgstat_database.c
755  */
756 
757 /* Updated by pgstat_count_buffer_*_time macros */
760 
761 /*
762  * Updated by pgstat_count_conn_*_time macros, called by
763  * pgstat_report_activity().
764  */
767 
768 /* updated by the traffic cop and in errfinish() */
770 
771 
772 /*
773  * Variables in pgstat_wal.c
774  */
775 
776 /* updated directly by backends and background processes */
778 
779 
780 #endif /* PGSTAT_H */
unsigned short uint16
Definition: c.h:492
unsigned int uint32
Definition: c.h:493
#define PGDLLIMPORT
Definition: c.h:1303
uint32 TransactionId
Definition: c.h:639
size_t Size
Definition: c.h:592
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:94
#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:734
void pgstat_drop_subscription(Oid subid)
struct PgStat_TableStatus PgStat_TableStatus
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
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:279
@ IOOBJECT_RELATION
Definition: pgstat.h:280
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:281
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
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
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: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
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:141
void pgstat_reset_counters(void)
Definition: pgstat.c:715
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:319
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)
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:537
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:922
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:579
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)
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition: pgstat.c:756
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:185
struct PgStat_BktypeIO PgStat_BktypeIO
#define IOOP_NUM_TYPES
Definition: pgstat.h:308
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
IOContext
Definition: pgstat.h:287
@ IOCONTEXT_NORMAL
Definition: pgstat.h:290
@ IOCONTEXT_VACUUM
Definition: pgstat.h:291
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:288
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:289
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:294
void pgstat_before_server_shutdown(int code, Datum arg)
Definition: pgstat.c:462
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
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:240
void pgstat_report_recovery_conflict(int reason)
void pgstat_force_next_flush(void)
Definition: pgstat.c:694
void pgstat_create_function(Oid proid)
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
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:297
@ IOOP_EXTEND
Definition: pgstat.h:299
@ IOOP_FSYNC
Definition: pgstat.h:300
@ IOOP_READ
Definition: pgstat.h:302
@ IOOP_WRITEBACK
Definition: pgstat.h:305
@ IOOP_HIT
Definition: pgstat.h:301
@ IOOP_EVICT
Definition: pgstat.h:298
@ IOOP_REUSE
Definition: pgstat.h:303
@ IOOP_WRITE
Definition: pgstat.h:304
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat_slru.c:105
void pgstat_clear_snapshot(void)
Definition: pgstat.c:782
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:905
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)
void pgstat_restore_stats(void)
Definition: pgstat.c:407
struct PgStat_StatDBEntry PgStat_StatDBEntry
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
PgStat_IO * pgstat_fetch_stat_io(void)
Definition: pgstat_io.c:157
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:424
void pgstat_count_truncate(Relation rel)
void pgstat_drop_replslot(struct ReplicationSlot *slot)
PGDLLIMPORT bool pgstat_track_counts
Definition: pgstat.c:184
void pgstat_drop_relation(Relation rel)
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)
const char * pgstat_get_io_context_name(IOContext io_context)
Definition: pgstat_io.c:221
void pgstat_discard_stats(void)
Definition: pgstat.c:419
int64 PgStat_Counter
Definition: pgstat.h:89
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition: pgstat_io.c:359
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:284
struct PgStat_TableXactStatus PgStat_TableXactStatus
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1242
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:249
TimestampTz stat_reset_timestamp
Definition: pgstat.h:250
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
PgStat_Counter apply_error_count
Definition: pgstat.h:136
PgStat_Counter sync_error_count
Definition: pgstat.h:137
PgStat_Counter buf_written_clean
Definition: pgstat.h:255
PgStat_Counter maxwritten_clean
Definition: pgstat.h:256
PgStat_Counter buf_alloc
Definition: pgstat.h:257
TimestampTz stat_reset_timestamp
Definition: pgstat.h:258
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:313
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:312
PgStat_Counter sync_time
Definition: pgstat.h:269
PgStat_Counter restartpoints_requested
Definition: pgstat.h:266
PgStat_Counter write_time
Definition: pgstat.h:268
PgStat_Counter num_requested
Definition: pgstat.h:264
PgStat_Counter restartpoints_timed
Definition: pgstat.h:265
PgStat_Counter num_timed
Definition: pgstat.h:263
PgStat_Counter restartpoints_performed
Definition: pgstat.h:267
PgStat_Counter buffers_written
Definition: pgstat.h:270
TimestampTz stat_reset_timestamp
Definition: pgstat.h:271
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
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:319
TimestampTz stat_reset_timestamp
Definition: pgstat.h:318
instr_time wal_sync_time
Definition: pgstat.h:456
PgStat_Counter wal_write
Definition: pgstat.h:453
PgStat_Counter wal_buffers_full
Definition: pgstat.h:452
PgStat_Counter wal_sync
Definition: pgstat.h:454
instr_time wal_write_time
Definition: pgstat.h:455
PgStat_Counter blocks_read
Definition: pgstat.h:384
PgStat_Counter blocks_exists
Definition: pgstat.h:386
TimestampTz stat_reset_timestamp
Definition: pgstat.h:389
PgStat_Counter blocks_zeroed
Definition: pgstat.h:382
PgStat_Counter blocks_written
Definition: pgstat.h:385
PgStat_Counter blocks_hit
Definition: pgstat.h:383
PgStat_Counter truncate
Definition: pgstat.h:388
PgStat_Counter flush
Definition: pgstat.h:387
PgStat_Counter blk_write_time
Definition: pgstat.h:347
PgStat_Counter xact_rollback
Definition: pgstat.h:326
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:340
PgStat_Counter conflict_lock
Definition: pgstat.h:336
PgStat_Counter tuples_updated
Definition: pgstat.h:332
PgStat_Counter tuples_inserted
Definition: pgstat.h:331
TimestampTz stat_reset_timestamp
Definition: pgstat.h:356
PgStat_Counter conflict_snapshot
Definition: pgstat.h:337
PgStat_Counter sessions_fatal
Definition: pgstat.h:353
TimestampTz last_checksum_failure
Definition: pgstat.h:345
PgStat_Counter tuples_returned
Definition: pgstat.h:329
PgStat_Counter blk_read_time
Definition: pgstat.h:346
PgStat_Counter xact_commit
Definition: pgstat.h:325
TimestampTz last_autovac_time
Definition: pgstat.h:334
PgStat_Counter deadlocks
Definition: pgstat.h:343
PgStat_Counter temp_bytes
Definition: pgstat.h:342
PgStat_Counter session_time
Definition: pgstat.h:349
PgStat_Counter blocks_hit
Definition: pgstat.h:328
PgStat_Counter temp_files
Definition: pgstat.h:341
PgStat_Counter sessions_abandoned
Definition: pgstat.h:352
PgStat_Counter sessions
Definition: pgstat.h:348
PgStat_Counter active_time
Definition: pgstat.h:350
PgStat_Counter blocks_fetched
Definition: pgstat.h:327
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:339
PgStat_Counter idle_in_transaction_time
Definition: pgstat.h:351
PgStat_Counter conflict_logicalslot
Definition: pgstat.h:338
PgStat_Counter tuples_deleted
Definition: pgstat.h:333
PgStat_Counter sessions_killed
Definition: pgstat.h:354
PgStat_Counter tuples_fetched
Definition: pgstat.h:330
PgStat_Counter checksum_failures
Definition: pgstat.h:344
PgStat_Counter conflict_tablespace
Definition: pgstat.h:335
PgStat_Counter self_time
Definition: pgstat.h:364
PgStat_Counter numcalls
Definition: pgstat.h:361
PgStat_Counter total_time
Definition: pgstat.h:363
TimestampTz stat_reset_timestamp
Definition: pgstat.h:377
PgStat_Counter stream_count
Definition: pgstat.h:373
PgStat_Counter total_txns
Definition: pgstat.h:375
PgStat_Counter total_bytes
Definition: pgstat.h:376
PgStat_Counter spill_txns
Definition: pgstat.h:369
PgStat_Counter stream_txns
Definition: pgstat.h:372
PgStat_Counter spill_count
Definition: pgstat.h:370
PgStat_Counter stream_bytes
Definition: pgstat.h:374
PgStat_Counter spill_bytes
Definition: pgstat.h:371
PgStat_Counter apply_error_count
Definition: pgstat.h:394
PgStat_Counter sync_error_count
Definition: pgstat.h:395
TimestampTz stat_reset_timestamp
Definition: pgstat.h:396
PgStat_Counter vacuum_count
Definition: pgstat.h:422
PgStat_Counter tuples_fetched
Definition: pgstat.h:405
PgStat_Counter ins_since_vacuum
Definition: pgstat.h:416
PgStat_Counter blocks_hit
Definition: pgstat.h:419
PgStat_Counter mod_since_analyze
Definition: pgstat.h:415
TimestampTz last_autovacuum_time
Definition: pgstat.h:423
PgStat_Counter analyze_count
Definition: pgstat.h:426
PgStat_Counter tuples_deleted
Definition: pgstat.h:409
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:410
PgStat_Counter tuples_updated
Definition: pgstat.h:408
PgStat_Counter live_tuples
Definition: pgstat.h:413
PgStat_Counter numscans
Definition: pgstat.h:401
PgStat_Counter autovacuum_count
Definition: pgstat.h:424
TimestampTz last_analyze_time
Definition: pgstat.h:425
PgStat_Counter dead_tuples
Definition: pgstat.h:414
PgStat_Counter autoanalyze_count
Definition: pgstat.h:428
PgStat_Counter blocks_fetched
Definition: pgstat.h:418
PgStat_Counter tuples_returned
Definition: pgstat.h:404
TimestampTz last_autoanalyze_time
Definition: pgstat.h:427
TimestampTz lastscan
Definition: pgstat.h:402
PgStat_Counter tuples_inserted
Definition: pgstat.h:407
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:411
TimestampTz last_vacuum_time
Definition: pgstat.h:421
PgStat_Counter blocks_hit
Definition: pgstat.h:179
PgStat_Counter numscans
Definition: pgstat.h:162
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:170
PgStat_Counter tuples_returned
Definition: pgstat.h:164
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
PgStat_Counter delta_live_tuples
Definition: pgstat.h:174
PgStat_Counter changed_tuples
Definition: pgstat.h:176
PgStat_Counter tuples_updated
Definition: pgstat.h:168
PgStat_Counter blocks_fetched
Definition: pgstat.h:178
PgStat_Counter tuples_fetched
Definition: pgstat.h:165
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:171
PgStat_Counter delta_dead_tuples
Definition: pgstat.h:175
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
PgStat_TableCounts counts
Definition: pgstat.h:202
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:201
Relation relation
Definition: pgstat.h:203
struct PgStat_TableXactStatus * next
Definition: pgstat.h:226
PgStat_Counter deleted_pre_truncdrop
Definition: pgstat.h:220
PgStat_TableStatus * parent
Definition: pgstat.h:224
PgStat_Counter tuples_inserted
Definition: pgstat.h:212
PgStat_Counter tuples_updated
Definition: pgstat.h:213
PgStat_Counter inserted_pre_truncdrop
Definition: pgstat.h:218
PgStat_Counter tuples_deleted
Definition: pgstat.h:214
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:223
PgStat_Counter updated_pre_truncdrop
Definition: pgstat.h:219
PgStat_Counter wal_write
Definition: pgstat.h:437
PgStat_Counter wal_buffers_full
Definition: pgstat.h:436
PgStat_Counter wal_write_time
Definition: pgstat.h:439
TimestampTz stat_reset_timestamp
Definition: pgstat.h:441
uint64 wal_bytes
Definition: pgstat.h:435
PgStat_Counter wal_sync_time
Definition: pgstat.h:440
PgStat_Counter wal_fpi
Definition: pgstat.h:434
PgStat_Counter wal_sync
Definition: pgstat.h:438
PgStat_Counter wal_records
Definition: pgstat.h:433
Definition: c.h:728
const char * name