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-2023, 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 0x01A5BCAB
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 {
265  PgStat_Counter checkpoint_write_time; /* times in milliseconds */
271 
272 
273 /*
274  * Types related to counting IO operations
275  */
276 typedef enum IOObject
277 {
281 
282 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
283 
284 typedef enum IOContext
285 {
291 
292 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
293 
294 typedef enum IOOp
295 {
304 
305 #define IOOP_NUM_TYPES (IOOP_WRITE + 1)
306 
307 typedef struct PgStat_BktypeIO
308 {
311 
312 typedef struct PgStat_IO
313 {
317 
318 
319 typedef struct PgStat_StatDBEntry
320 {
341  PgStat_Counter blk_read_time; /* times in microseconds */
350 
353 
354 typedef struct PgStat_StatFuncEntry
355 {
357 
358  PgStat_Counter total_time; /* times in microseconds */
361 
363 {
374 
375 typedef struct PgStat_SLRUStats
376 {
386 
387 typedef struct PgStat_StatSubEntry
388 {
393 
394 typedef struct PgStat_StatTabEntry
395 {
398 
401 
407 
412 
415 
416  TimestampTz last_vacuum_time; /* user initiated vacuum */
418  TimestampTz last_autovacuum_time; /* autovacuum initiated */
420  TimestampTz last_analyze_time; /* user initiated */
422  TimestampTz last_autoanalyze_time; /* autovacuum initiated */
425 
426 typedef struct PgStat_WalStats
427 {
430  uint64 wal_bytes;
438 
439 /*
440  * This struct stores wal-related durations as instr_time, which makes it
441  * cheaper and easier to accumulate them, by not requiring type
442  * conversions. During stats flush instr_time will be converted into
443  * microseconds.
444  */
446 {
453 
454 
455 /*
456  * Functions in pgstat.c
457  */
458 
459 /* functions called from postmaster */
460 extern Size StatsShmemSize(void);
461 extern void StatsShmemInit(void);
462 
463 /* Functions called during server startup / shutdown */
464 extern void pgstat_restore_stats(void);
465 extern void pgstat_discard_stats(void);
466 extern void pgstat_before_server_shutdown(int code, Datum arg);
467 
468 /* Functions for backend initialization */
469 extern void pgstat_initialize(void);
470 
471 /* Functions called from backends */
472 extern long pgstat_report_stat(bool force);
473 extern void pgstat_force_next_flush(void);
474 
475 extern void pgstat_reset_counters(void);
476 extern void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid);
477 extern void pgstat_reset_of_kind(PgStat_Kind kind);
478 
479 /* stats accessors */
480 extern void pgstat_clear_snapshot(void);
481 extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
482 
483 /* helpers */
484 extern PgStat_Kind pgstat_get_kind_from_str(char *kind_str);
485 extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
486 
487 
488 /*
489  * Functions in pgstat_archiver.c
490  */
491 
492 extern void pgstat_report_archiver(const char *xlog, bool failed);
494 
495 
496 /*
497  * Functions in pgstat_bgwriter.c
498  */
499 
500 extern void pgstat_report_bgwriter(void);
502 
503 
504 /*
505  * Functions in pgstat_checkpointer.c
506  */
507 
508 extern void pgstat_report_checkpointer(void);
510 
511 
512 /*
513  * Functions in pgstat_io.c
514  */
515 
516 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *context_ops,
517  BackendType bktype);
518 extern void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op);
519 extern PgStat_IO *pgstat_fetch_stat_io(void);
520 extern const char *pgstat_get_io_context_name(IOContext io_context);
521 extern const char *pgstat_get_io_object_name(IOObject io_object);
522 
523 extern bool pgstat_tracks_io_bktype(BackendType bktype);
524 extern bool pgstat_tracks_io_object(BackendType bktype,
525  IOObject io_object, IOContext io_context);
526 extern bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object,
527  IOContext io_context, IOOp io_op);
528 
529 
530 /*
531  * Functions in pgstat_database.c
532  */
533 
534 extern void pgstat_drop_database(Oid databaseid);
535 extern void pgstat_report_autovac(Oid dboid);
536 extern void pgstat_report_recovery_conflict(int reason);
537 extern void pgstat_report_deadlock(void);
538 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
539 extern void pgstat_report_checksum_failure(void);
540 extern void pgstat_report_connect(Oid dboid);
541 
542 #define pgstat_count_buffer_read_time(n) \
543  (pgStatBlockReadTime += (n))
544 #define pgstat_count_buffer_write_time(n) \
545  (pgStatBlockWriteTime += (n))
546 #define pgstat_count_conn_active_time(n) \
547  (pgStatActiveTime += (n))
548 #define pgstat_count_conn_txn_idle_time(n) \
549  (pgStatTransactionIdleTime += (n))
550 
552 
553 
554 /*
555  * Functions in pgstat_function.c
556  */
557 
558 extern void pgstat_create_function(Oid proid);
559 extern void pgstat_drop_function(Oid proid);
560 
565  bool finalize);
566 
569 
570 
571 /*
572  * Functions in pgstat_relation.c
573  */
574 
575 extern void pgstat_create_relation(Relation rel);
576 extern void pgstat_drop_relation(Relation rel);
577 extern void pgstat_copy_relation_stats(Relation dst, Relation src);
578 
579 extern void pgstat_init_relation(Relation rel);
580 extern void pgstat_assoc_relation(Relation rel);
581 extern void pgstat_unlink_relation(Relation rel);
582 
583 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
584  PgStat_Counter livetuples, PgStat_Counter deadtuples);
585 extern void pgstat_report_analyze(Relation rel,
586  PgStat_Counter livetuples, PgStat_Counter deadtuples,
587  bool resetcounter);
588 
589 /*
590  * If stats are enabled, but pending data hasn't been prepared yet, call
591  * pgstat_assoc_relation() to do so. See its comment for why this is done
592  * separately from pgstat_init_relation().
593  */
594 #define pgstat_should_count_relation(rel) \
595  (likely((rel)->pgstat_info != NULL) ? true : \
596  ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
597 
598 /* nontransactional event counts are simple enough to inline */
599 
600 #define pgstat_count_heap_scan(rel) \
601  do { \
602  if (pgstat_should_count_relation(rel)) \
603  (rel)->pgstat_info->counts.numscans++; \
604  } while (0)
605 #define pgstat_count_heap_getnext(rel) \
606  do { \
607  if (pgstat_should_count_relation(rel)) \
608  (rel)->pgstat_info->counts.tuples_returned++; \
609  } while (0)
610 #define pgstat_count_heap_fetch(rel) \
611  do { \
612  if (pgstat_should_count_relation(rel)) \
613  (rel)->pgstat_info->counts.tuples_fetched++; \
614  } while (0)
615 #define pgstat_count_index_scan(rel) \
616  do { \
617  if (pgstat_should_count_relation(rel)) \
618  (rel)->pgstat_info->counts.numscans++; \
619  } while (0)
620 #define pgstat_count_index_tuples(rel, n) \
621  do { \
622  if (pgstat_should_count_relation(rel)) \
623  (rel)->pgstat_info->counts.tuples_returned += (n); \
624  } while (0)
625 #define pgstat_count_buffer_read(rel) \
626  do { \
627  if (pgstat_should_count_relation(rel)) \
628  (rel)->pgstat_info->counts.blocks_fetched++; \
629  } while (0)
630 #define pgstat_count_buffer_hit(rel) \
631  do { \
632  if (pgstat_should_count_relation(rel)) \
633  (rel)->pgstat_info->counts.blocks_hit++; \
634  } while (0)
635 
637 extern void pgstat_count_heap_update(Relation rel, bool hot, bool newpage);
638 extern void pgstat_count_heap_delete(Relation rel);
639 extern void pgstat_count_truncate(Relation rel);
640 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
641 
642 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
643  void *recdata, uint32 len);
644 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
645  void *recdata, uint32 len);
646 
649  Oid reloid);
651 
652 
653 /*
654  * Functions in pgstat_replslot.c
655  */
656 
657 extern void pgstat_reset_replslot(const char *name);
658 struct ReplicationSlot;
659 extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
660 extern void pgstat_create_replslot(struct ReplicationSlot *slot);
661 extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
662 extern void pgstat_drop_replslot(struct ReplicationSlot *slot);
664 
665 
666 /*
667  * Functions in pgstat_slru.c
668  */
669 
670 extern void pgstat_reset_slru(const char *);
671 extern void pgstat_count_slru_page_zeroed(int slru_idx);
672 extern void pgstat_count_slru_page_hit(int slru_idx);
673 extern void pgstat_count_slru_page_read(int slru_idx);
674 extern void pgstat_count_slru_page_written(int slru_idx);
675 extern void pgstat_count_slru_page_exists(int slru_idx);
676 extern void pgstat_count_slru_flush(int slru_idx);
677 extern void pgstat_count_slru_truncate(int slru_idx);
678 extern const char *pgstat_get_slru_name(int slru_idx);
679 extern int pgstat_get_slru_index(const char *name);
680 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
681 
682 
683 /*
684  * Functions in pgstat_subscription.c
685  */
686 
687 extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
688 extern void pgstat_create_subscription(Oid subid);
689 extern void pgstat_drop_subscription(Oid subid);
691 
692 
693 /*
694  * Functions in pgstat_xact.c
695  */
696 
697 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
698 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
699 extern void AtPrepare_PgStat(void);
700 extern void PostPrepare_PgStat(void);
701 struct xl_xact_stats_item;
702 extern int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items);
703 extern void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo);
704 
705 
706 /*
707  * Functions in pgstat_wal.c
708  */
709 
710 extern void pgstat_report_wal(bool force);
712 
713 
714 /*
715  * Variables in pgstat.c
716  */
717 
718 /* GUC parameters */
719 extern PGDLLIMPORT bool pgstat_track_counts;
722 
723 
724 /*
725  * Variables in pgstat_bgwriter.c
726  */
727 
728 /* updated directly by bgwriter and bufmgr */
730 
731 
732 /*
733  * Variables in pgstat_checkpointer.c
734  */
735 
736 /*
737  * Checkpointer statistics counters are updated directly by checkpointer and
738  * bufmgr.
739  */
741 
742 
743 /*
744  * Variables in pgstat_database.c
745  */
746 
747 /* Updated by pgstat_count_buffer_*_time macros */
750 
751 /*
752  * Updated by pgstat_count_conn_*_time macros, called by
753  * pgstat_report_activity().
754  */
757 
758 /* updated by the traffic cop and in errfinish() */
760 
761 
762 /*
763  * Variables in pgstat_wal.c
764  */
765 
766 /* updated directly by backends and background processes */
768 
769 
770 #endif /* PGSTAT_H */
unsigned short uint16
Definition: c.h:489
unsigned int uint32
Definition: c.h:490
#define PGDLLIMPORT
Definition: c.h:1303
uint32 TransactionId
Definition: c.h:636
size_t Size
Definition: c.h:589
int64 TimestampTz
Definition: timestamp.h:39
const char * name
Definition: encode.c:571
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:335
BackendType
Definition: miscadmin.h:318
void * arg
const void size_t len
#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:719
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)
IOObject
Definition: pgstat.h:277
@ IOOBJECT_RELATION
Definition: pgstat.h:278
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:279
void AtPrepare_PgStat(void)
Definition: pgstat_xact.c:190
int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items)
Definition: pgstat_xact.c:271
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_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:313
void StatsShmemInit(void)
Definition: pgstat_shmem.c:140
void pgstat_reset_counters(void)
Definition: pgstat.c:700
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:41
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:231
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:533
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:900
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:575
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:741
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:188
struct PgStat_BktypeIO PgStat_BktypeIO
#define IOOP_NUM_TYPES
Definition: pgstat.h:305
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
IOContext
Definition: pgstat.h:285
@ IOCONTEXT_NORMAL
Definition: pgstat.h:288
@ IOCONTEXT_VACUUM
Definition: pgstat.h:289
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:286
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:287
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:292
void pgstat_before_server_shutdown(int code, Datum arg)
Definition: pgstat.c:458
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:153
void pgstat_report_recovery_conflict(int reason)
void pgstat_force_next_flush(void)
Definition: pgstat.c:679
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:295
@ IOOP_EXTEND
Definition: pgstat.h:297
@ IOOP_FSYNC
Definition: pgstat.h:298
@ IOOP_READ
Definition: pgstat.h:300
@ IOOP_HIT
Definition: pgstat.h:299
@ IOOP_EVICT
Definition: pgstat.h:296
@ IOOP_REUSE
Definition: pgstat.h:301
@ IOOP_WRITE
Definition: pgstat.h:302
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat_slru.c:105
void pgstat_clear_snapshot(void)
Definition: pgstat.c:766
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:886
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
Size StatsShmemSize(void)
Definition: pgstat_shmem.c:126
void pgstat_create_relation(Relation rel)
void PostPrepare_PgStat(void)
Definition: pgstat_xact.c:210
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:43
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:403
struct PgStat_StatDBEntry PgStat_StatDBEntry
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
PgStat_IO * pgstat_fetch_stat_io(void)
Definition: pgstat_io.c:79
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:55
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:334
void pgstat_count_truncate(Relation rel)
void pgstat_drop_replslot(struct ReplicationSlot *slot)
PGDLLIMPORT bool pgstat_track_counts
Definition: pgstat.c:187
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:134
void pgstat_discard_stats(void)
Definition: pgstat.c:415
int64 PgStat_Counter
Definition: pgstat.h:89
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition: pgstat_io.c:269
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:282
struct PgStat_TableXactStatus PgStat_TableXactStatus
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1214
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
PGDLLIMPORT SessionEndType pgStatSessionEndCause
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *context_ops, BackendType bktype)
Definition: pgstat_io.c:34
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:66
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 data[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:309
PgStat_Counter buf_written_backend
Definition: pgstat.h:268
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:266
PgStat_Counter checkpoint_write_time
Definition: pgstat.h:265
PgStat_Counter requested_checkpoints
Definition: pgstat.h:264
PgStat_Counter timed_checkpoints
Definition: pgstat.h:263
PgStat_Counter buf_fsync_backend
Definition: pgstat.h:269
PgStat_Counter buf_written_checkpoints
Definition: pgstat.h:267
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:315
TimestampTz stat_reset_timestamp
Definition: pgstat.h:314
instr_time wal_sync_time
Definition: pgstat.h:451
PgStat_Counter wal_write
Definition: pgstat.h:448
PgStat_Counter wal_buffers_full
Definition: pgstat.h:447
PgStat_Counter wal_sync
Definition: pgstat.h:449
instr_time wal_write_time
Definition: pgstat.h:450
PgStat_Counter blocks_read
Definition: pgstat.h:379
PgStat_Counter blocks_exists
Definition: pgstat.h:381
TimestampTz stat_reset_timestamp
Definition: pgstat.h:384
PgStat_Counter blocks_zeroed
Definition: pgstat.h:377
PgStat_Counter blocks_written
Definition: pgstat.h:380
PgStat_Counter blocks_hit
Definition: pgstat.h:378
PgStat_Counter truncate
Definition: pgstat.h:383
PgStat_Counter flush
Definition: pgstat.h:382
PgStat_Counter blk_write_time
Definition: pgstat.h:342
PgStat_Counter xact_rollback
Definition: pgstat.h:322
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:335
PgStat_Counter conflict_lock
Definition: pgstat.h:332
PgStat_Counter tuples_updated
Definition: pgstat.h:328
PgStat_Counter tuples_inserted
Definition: pgstat.h:327
TimestampTz stat_reset_timestamp
Definition: pgstat.h:351
PgStat_Counter conflict_snapshot
Definition: pgstat.h:333
PgStat_Counter sessions_fatal
Definition: pgstat.h:348
TimestampTz last_checksum_failure
Definition: pgstat.h:340
PgStat_Counter tuples_returned
Definition: pgstat.h:325
PgStat_Counter blk_read_time
Definition: pgstat.h:341
PgStat_Counter xact_commit
Definition: pgstat.h:321
TimestampTz last_autovac_time
Definition: pgstat.h:330
PgStat_Counter deadlocks
Definition: pgstat.h:338
PgStat_Counter temp_bytes
Definition: pgstat.h:337
PgStat_Counter session_time
Definition: pgstat.h:344
PgStat_Counter blocks_hit
Definition: pgstat.h:324
PgStat_Counter temp_files
Definition: pgstat.h:336
PgStat_Counter sessions_abandoned
Definition: pgstat.h:347
PgStat_Counter sessions
Definition: pgstat.h:343
PgStat_Counter active_time
Definition: pgstat.h:345
PgStat_Counter blocks_fetched
Definition: pgstat.h:323
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:334
PgStat_Counter idle_in_transaction_time
Definition: pgstat.h:346
PgStat_Counter tuples_deleted
Definition: pgstat.h:329
PgStat_Counter sessions_killed
Definition: pgstat.h:349
PgStat_Counter tuples_fetched
Definition: pgstat.h:326
PgStat_Counter checksum_failures
Definition: pgstat.h:339
PgStat_Counter conflict_tablespace
Definition: pgstat.h:331
PgStat_Counter self_time
Definition: pgstat.h:359
PgStat_Counter numcalls
Definition: pgstat.h:356
PgStat_Counter total_time
Definition: pgstat.h:358
TimestampTz stat_reset_timestamp
Definition: pgstat.h:372
PgStat_Counter stream_count
Definition: pgstat.h:368
PgStat_Counter total_txns
Definition: pgstat.h:370
PgStat_Counter total_bytes
Definition: pgstat.h:371
PgStat_Counter spill_txns
Definition: pgstat.h:364
PgStat_Counter stream_txns
Definition: pgstat.h:367
PgStat_Counter spill_count
Definition: pgstat.h:365
PgStat_Counter stream_bytes
Definition: pgstat.h:369
PgStat_Counter spill_bytes
Definition: pgstat.h:366
PgStat_Counter apply_error_count
Definition: pgstat.h:389
PgStat_Counter sync_error_count
Definition: pgstat.h:390
TimestampTz stat_reset_timestamp
Definition: pgstat.h:391
PgStat_Counter vacuum_count
Definition: pgstat.h:417
PgStat_Counter tuples_fetched
Definition: pgstat.h:400
PgStat_Counter ins_since_vacuum
Definition: pgstat.h:411
PgStat_Counter blocks_hit
Definition: pgstat.h:414
PgStat_Counter mod_since_analyze
Definition: pgstat.h:410
TimestampTz last_autovacuum_time
Definition: pgstat.h:418
PgStat_Counter analyze_count
Definition: pgstat.h:421
PgStat_Counter tuples_deleted
Definition: pgstat.h:404
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:405
PgStat_Counter tuples_updated
Definition: pgstat.h:403
PgStat_Counter live_tuples
Definition: pgstat.h:408
PgStat_Counter numscans
Definition: pgstat.h:396
PgStat_Counter autovacuum_count
Definition: pgstat.h:419
TimestampTz last_analyze_time
Definition: pgstat.h:420
PgStat_Counter dead_tuples
Definition: pgstat.h:409
PgStat_Counter autoanalyze_count
Definition: pgstat.h:423
PgStat_Counter blocks_fetched
Definition: pgstat.h:413
PgStat_Counter tuples_returned
Definition: pgstat.h:399
TimestampTz last_autoanalyze_time
Definition: pgstat.h:422
TimestampTz lastscan
Definition: pgstat.h:397
PgStat_Counter tuples_inserted
Definition: pgstat.h:402
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:406
TimestampTz last_vacuum_time
Definition: pgstat.h:416
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:432
PgStat_Counter wal_buffers_full
Definition: pgstat.h:431
PgStat_Counter wal_write_time
Definition: pgstat.h:434
TimestampTz stat_reset_timestamp
Definition: pgstat.h:436
uint64 wal_bytes
Definition: pgstat.h:430
PgStat_Counter wal_sync_time
Definition: pgstat.h:435
PgStat_Counter wal_fpi
Definition: pgstat.h:429
PgStat_Counter wal_sync
Definition: pgstat.h:433
PgStat_Counter wal_records
Definition: pgstat.h:428
Definition: c.h:725