PostgreSQL Source Code  git master
pgstat_internal.h
Go to the documentation of this file.
1 /* ----------
2  * pgstat_internal.h
3  *
4  * Definitions for the PostgreSQL cumulative statistics system that should
5  * only be needed by files implementing statistics support (rather than ones
6  * reporting / querying stats).
7  *
8  * Copyright (c) 2001-2024, PostgreSQL Global Development Group
9  *
10  * src/include/utils/pgstat_internal.h
11  * ----------
12  */
13 #ifndef PGSTAT_INTERNAL_H
14 #define PGSTAT_INTERNAL_H
15 
16 
17 #include "common/hashfn_unstable.h"
18 #include "lib/dshash.h"
19 #include "lib/ilist.h"
20 #include "pgstat.h"
21 #include "storage/lwlock.h"
22 #include "utils/dsa.h"
23 
24 
25 /*
26  * Types related to shared memory storage of statistics.
27  *
28  * Per-object statistics are stored in the "shared stats" hashtable. That
29  * table's entries (PgStatShared_HashEntry) contain a pointer to the actual stats
30  * data for the object (the size of the stats data varies depending on the
31  * kind of stats). The table is keyed by PgStat_HashKey.
32  *
33  * Once a backend has a reference to a shared stats entry, it increments the
34  * entry's refcount. Even after stats data is dropped (e.g., due to a DROP
35  * TABLE), the entry itself can only be deleted once all references have been
36  * released.
37  *
38  * These refcounts, in combination with a backend local hashtable
39  * (pgStatEntryRefHash, with entries pointing to PgStat_EntryRef) in front of
40  * the shared hash table, mean that most stats work can happen without
41  * touching the shared hash table, reducing contention.
42  *
43  * Once there are pending stats updates for a table PgStat_EntryRef->pending
44  * is allocated to contain a working space for as-of-yet-unapplied stats
45  * updates. Once the stats are flushed, PgStat_EntryRef->pending is freed.
46  *
47  * Each stat kind in the shared hash table has a fixed member
48  * PgStatShared_Common as the first element.
49  */
50 
51 /* struct for shared statistics hash entry key. */
52 typedef struct PgStat_HashKey
53 {
54  PgStat_Kind kind; /* statistics entry kind */
55  Oid dboid; /* database ID. InvalidOid for shared objects. */
56  uint64 objid; /* object ID (table, function, etc.), or
57  * identifier. */
59 
60 /*
61  * Shared statistics hash entry. Doesn't itself contain any stats, but points
62  * to them (with ->body). That allows the stats entries themselves to be of
63  * variable size.
64  */
65 typedef struct PgStatShared_HashEntry
66 {
67  PgStat_HashKey key; /* hash key */
68 
69  /*
70  * If dropped is set, backends need to release their references so that
71  * the memory for the entry can be freed. No new references may be made
72  * once marked as dropped.
73  */
74  bool dropped;
75 
76  /*
77  * Refcount managing lifetime of the entry itself (as opposed to the
78  * dshash entry pointing to it). The stats lifetime has to be separate
79  * from the hash table entry lifetime because we allow backends to point
80  * to a stats entry without holding a hash table lock (and some other
81  * reasons).
82  *
83  * As long as the entry is not dropped, 1 is added to the refcount
84  * representing that the entry should not be dropped. In addition each
85  * backend that has a reference to the entry needs to increment the
86  * refcount as long as it does.
87  *
88  * May only be incremented / decremented while holding at least a shared
89  * lock on the dshash partition containing the entry. It needs to be an
90  * atomic variable because multiple backends can increment the refcount
91  * with just a shared lock.
92  *
93  * When the refcount reaches 0 the entry needs to be freed.
94  */
96 
97  /*
98  * Pointer to shared stats. The stats entry always starts with
99  * PgStatShared_Common, embedded in a larger struct containing the
100  * PgStat_Kind specific stats fields.
101  */
104 
105 /*
106  * Common header struct for PgStatShared_*.
107  */
108 typedef struct PgStatShared_Common
109 {
110  uint32 magic; /* just a validity cross-check */
111  /* lock protecting stats contents (i.e. data following the header) */
114 
115 /*
116  * A backend local reference to a shared stats entry. As long as at least one
117  * such reference exists, the shared stats entry will not be released.
118  *
119  * If there are pending stats update to the shared stats, these are stored in
120  * ->pending.
121  */
122 typedef struct PgStat_EntryRef
123 {
124  /*
125  * Pointer to the PgStatShared_HashEntry entry in the shared stats
126  * hashtable.
127  */
129 
130  /*
131  * Pointer to the stats data (i.e. PgStatShared_HashEntry->body), resolved
132  * as a local pointer, to avoid repeated dsa_get_address() calls.
133  */
135 
136  /*
137  * Pending statistics data that will need to be flushed to shared memory
138  * stats eventually. Each stats kind utilizing pending data defines what
139  * format its pending data has and needs to provide a
140  * PgStat_KindInfo->flush_pending_cb callback to merge pending into shared
141  * stats.
142  */
143  void *pending;
144  dlist_node pending_node; /* membership in pgStatPending list */
146 
147 
148 /*
149  * Some stats changes are transactional. To maintain those, a stack of
150  * PgStat_SubXactStatus entries is maintained, which contain data pertaining
151  * to the current transaction and its active subtransactions.
152  */
153 typedef struct PgStat_SubXactStatus
154 {
155  int nest_level; /* subtransaction nest level */
156 
157  struct PgStat_SubXactStatus *prev; /* higher-level subxact if any */
158 
159  /*
160  * Statistics for transactionally dropped objects need to be
161  * transactionally dropped as well. Collect the stats dropped in the
162  * current (sub-)transaction and only execute the stats drop when we know
163  * if the transaction commits/aborts. To handle replicas and crashes,
164  * stats drops are included in commit / abort records.
165  */
167 
168  /*
169  * Tuple insertion/deletion counts for an open transaction can't be
170  * propagated into PgStat_TableStatus counters until we know if it is
171  * going to commit or abort. Hence, we keep these counts in per-subxact
172  * structs that live in TopTransactionContext. This data structure is
173  * designed on the assumption that subxacts won't usually modify very many
174  * tables.
175  */
176  PgStat_TableXactStatus *first; /* head of list for this subxact */
178 
179 
180 /*
181  * Metadata for a specific kind of statistics.
182  */
183 typedef struct PgStat_KindInfo
184 {
185  /*
186  * Do a fixed number of stats objects exist for this kind of stats (e.g.
187  * bgwriter stats) or not (e.g. tables).
188  */
189  bool fixed_amount:1;
190 
191  /*
192  * Can stats of this kind be accessed from another database? Determines
193  * whether a stats object gets included in stats snapshots.
194  */
196 
197  /*
198  * The size of an entry in the shared stats hash table (pointed to by
199  * PgStatShared_HashEntry->body). For fixed-numbered statistics, this is
200  * the size of an entry in PgStat_ShmemControl->custom_data.
201  */
203 
204  /*
205  * The offset of the statistics struct in the cached statistics snapshot
206  * PgStat_Snapshot, for fixed-numbered statistics.
207  */
209 
210  /*
211  * The offset of the statistics struct in the containing shared memory
212  * control structure PgStat_ShmemControl, for fixed-numbered statistics.
213  */
215 
216  /*
217  * The offset/size of statistics inside the shared stats entry. Used when
218  * [de-]serializing statistics to / from disk respectively. Separate from
219  * shared_size because [de-]serialization may not include in-memory state
220  * like lwlocks.
221  */
224 
225  /*
226  * The size of the pending data for this kind. E.g. how large
227  * PgStat_EntryRef->pending is. Used for allocations.
228  *
229  * 0 signals that an entry of this kind should never have a pending entry.
230  */
232 
233  /*
234  * Perform custom actions when initializing a backend (standalone or under
235  * postmaster). Optional.
236  */
237  void (*init_backend_cb) (void);
238 
239  /*
240  * For variable-numbered stats: flush pending stats. Required if pending
241  * data is used. See flush_fixed_cb for fixed-numbered stats.
242  */
243  bool (*flush_pending_cb) (PgStat_EntryRef *sr, bool nowait);
244 
245  /*
246  * For variable-numbered stats: delete pending stats. Optional.
247  */
249 
250  /*
251  * For variable-numbered stats: reset the reset timestamp. Optional.
252  */
254 
255  /*
256  * For variable-numbered stats. Optional.
257  */
259  const PgStatShared_Common *header, NameData *name);
261 
262  /*
263  * For fixed-numbered statistics: Initialize shared memory state.
264  *
265  * "stats" is the pointer to the allocated shared memory area.
266  */
267  void (*init_shmem_cb) (void *stats);
268 
269  /*
270  * For fixed-numbered statistics: Flush pending stats. Returns true if
271  * some of the stats could not be flushed, due to lock contention for
272  * example. Optional.
273  */
274  bool (*flush_fixed_cb) (bool nowait);
275 
276  /*
277  * For fixed-numbered statistics: Check for pending stats in need of
278  * flush. Returns true if there are any stats pending for flush. Optional.
279  */
281 
282  /*
283  * For fixed-numbered statistics: Reset All.
284  */
285  void (*reset_all_cb) (TimestampTz ts);
286 
287  /*
288  * For fixed-numbered statistics: Build snapshot for entry
289  */
290  void (*snapshot_cb) (void);
291 
292  /* name of the kind of stats */
293  const char *const name;
295 
296 
297 /*
298  * List of SLRU names that we keep stats for. There is no central registry of
299  * SLRUs, so we use this fixed list instead. The "other" entry is used for
300  * all SLRUs without an explicit entry (e.g. SLRUs in extensions).
301  *
302  * This is only defined here so that SLRU_NUM_ELEMENTS is known for later type
303  * definitions.
304  */
305 static const char *const slru_names[] = {
306  "commit_timestamp",
307  "multixact_member",
308  "multixact_offset",
309  "notify",
310  "serializable",
311  "subtransaction",
312  "transaction",
313  "other" /* has to be last */
314 };
315 
316 #define SLRU_NUM_ELEMENTS lengthof(slru_names)
317 
318 
319 /* ----------
320  * Types and definitions for different kinds of fixed-amount stats.
321  *
322  * Single-writer stats use the changecount mechanism to achieve low-overhead
323  * writes - they're obviously more performance critical than reads. Check the
324  * definition of struct PgBackendStatus for some explanation of the
325  * changecount mechanism.
326  *
327  * Because the obvious implementation of resetting single-writer stats isn't
328  * compatible with that (another backend needs to write), we don't scribble on
329  * shared stats while resetting. Instead, just record the current counter
330  * values in a copy of the stats data, which is protected by ->lock. See
331  * pgstat_fetch_stat_(archiver|bgwriter|checkpointer) for the reader side.
332  *
333  * The only exception to that is the stat_reset_timestamp in these structs,
334  * which is protected by ->lock, because it has to be written by another
335  * backend while resetting.
336  * ----------
337  */
338 
339 typedef struct PgStatShared_Archiver
340 {
341  /* lock protects ->reset_offset as well as stats->stat_reset_timestamp */
347 
348 typedef struct PgStatShared_BgWriter
349 {
350  /* lock protects ->reset_offset as well as stats->stat_reset_timestamp */
356 
358 {
359  /* lock protects ->reset_offset as well as stats->stat_reset_timestamp */
365 
366 /* Shared-memory ready PgStat_IO */
367 typedef struct PgStatShared_IO
368 {
369  /*
370  * locks[i] protects stats.stats[i]. locks[0] also protects
371  * stats.stat_reset_timestamp.
372  */
376 
377 typedef struct PgStatShared_SLRU
378 {
379  /* lock protects ->stats */
383 
384 typedef struct PgStatShared_Wal
385 {
386  /* lock protects ->stats */
390 
391 
392 
393 /* ----------
394  * Types and definitions for different kinds of variable-amount stats.
395  *
396  * Each struct has to start with PgStatShared_Common, containing information
397  * common across the different types of stats. Kind-specific data follows.
398  * ----------
399  */
400 
401 typedef struct PgStatShared_Database
402 {
406 
407 typedef struct PgStatShared_Relation
408 {
412 
413 typedef struct PgStatShared_Function
414 {
418 
420 {
424 
425 typedef struct PgStatShared_ReplSlot
426 {
430 
431 
432 /*
433  * Central shared memory entry for the cumulative stats system.
434  *
435  * Fixed amount stats, the dynamic shared memory hash table for
436  * non-fixed-amount stats, as well as remaining bits and pieces are all
437  * reached from here.
438  */
439 typedef struct PgStat_ShmemControl
440 {
442 
443  /*
444  * Stats for variable-numbered objects are kept in this shared hash table.
445  * See comment above PgStat_Kind for details.
446  */
447  dshash_table_handle hash_handle; /* shared dbstat hash */
448 
449  /* Has the stats system already been shut down? Just a debugging check. */
451 
452  /*
453  * Whenever statistics for dropped objects could not be freed - because
454  * backends still have references - the dropping backend calls
455  * pgstat_request_entry_refs_gc() incrementing this counter. Eventually
456  * that causes backends to run pgstat_gc_entry_refs(), allowing memory to
457  * be reclaimed.
458  */
460 
461  /*
462  * Stats data for fixed-numbered objects.
463  */
470 
471  /*
472  * Custom stats data with fixed-numbered objects, indexed by (PgStat_Kind
473  * - PGSTAT_KIND_CUSTOM_MIN).
474  */
476 
478 
479 
480 /*
481  * Cached statistics snapshot
482  */
483 typedef struct PgStat_Snapshot
484 {
486 
487  /* time at which snapshot was taken */
489 
491 
493 
495 
497 
499 
501 
503 
504  /*
505  * Data in snapshot for custom fixed-numbered statistics, indexed by
506  * (PgStat_Kind - PGSTAT_KIND_CUSTOM_MIN). Each entry is allocated in
507  * TopMemoryContext, for a size of PgStat_KindInfo->shared_data_len.
508  */
511 
512  /* to free snapshot in bulk */
514  struct pgstat_snapshot_hash *stats;
516 
517 
518 /*
519  * Collection of backend-local stats state.
520  */
521 typedef struct PgStat_LocalState
522 {
526 
527  /* the current statistics snapshot */
530 
531 
532 /*
533  * Inline functions defined further below.
534  */
535 
536 static inline void pgstat_begin_changecount_write(uint32 *cc);
537 static inline void pgstat_end_changecount_write(uint32 *cc);
538 static inline uint32 pgstat_begin_changecount_read(uint32 *cc);
539 static inline bool pgstat_end_changecount_read(uint32 *cc, uint32 cc_before);
540 
541 static inline void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len,
542  uint32 *cc);
543 
544 static inline int pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg);
545 static inline uint32 pgstat_hash_hash_key(const void *d, size_t size, void *arg);
546 static inline size_t pgstat_get_entry_len(PgStat_Kind kind);
547 static inline void *pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry);
548 static inline void *pgstat_get_custom_shmem_data(PgStat_Kind kind);
549 static inline void *pgstat_get_custom_snapshot_data(PgStat_Kind kind);
550 
551 
552 /*
553  * Functions in pgstat.c
554  */
555 
557 extern void pgstat_register_kind(PgStat_Kind kind,
558  const PgStat_KindInfo *kind_info);
559 
560 #ifdef USE_ASSERT_CHECKING
561 extern void pgstat_assert_is_up(void);
562 #else
563 #define pgstat_assert_is_up() ((void)true)
564 #endif
565 
566 extern void pgstat_delete_pending_entry(PgStat_EntryRef *entry_ref);
568  uint64 objid,
569  bool *created_entry);
571  Oid dboid, uint64 objid);
572 
573 extern void *pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid);
574 extern void pgstat_snapshot_fixed(PgStat_Kind kind);
575 
576 
577 /*
578  * Functions in pgstat_archiver.c
579  */
580 
581 extern void pgstat_archiver_init_shmem_cb(void *stats);
583 extern void pgstat_archiver_snapshot_cb(void);
584 
585 
586 /*
587  * Functions in pgstat_bgwriter.c
588  */
589 
590 extern void pgstat_bgwriter_init_shmem_cb(void *stats);
592 extern void pgstat_bgwriter_snapshot_cb(void);
593 
594 
595 /*
596  * Functions in pgstat_checkpointer.c
597  */
598 
599 extern void pgstat_checkpointer_init_shmem_cb(void *stats);
601 extern void pgstat_checkpointer_snapshot_cb(void);
602 
603 
604 /*
605  * Functions in pgstat_database.c
606  */
607 
608 extern void pgstat_report_disconnect(Oid dboid);
609 extern void pgstat_update_dbstats(TimestampTz ts);
610 extern void AtEOXact_PgStat_Database(bool isCommit, bool parallel);
611 
613 extern void pgstat_reset_database_timestamp(Oid dboid, TimestampTz ts);
614 extern bool pgstat_database_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
616 
617 
618 /*
619  * Functions in pgstat_function.c
620  */
621 
622 extern bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
623 
624 
625 /*
626  * Functions in pgstat_io.c
627  */
628 
629 extern void pgstat_flush_io(bool nowait);
630 
631 extern bool pgstat_io_have_pending_cb(void);
632 extern bool pgstat_io_flush_cb(bool nowait);
633 extern void pgstat_io_init_shmem_cb(void *stats);
634 extern void pgstat_io_reset_all_cb(TimestampTz ts);
635 extern void pgstat_io_snapshot_cb(void);
636 
637 
638 /*
639  * Functions in pgstat_relation.c
640  */
641 
642 extern void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit);
643 extern void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth);
644 extern void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state);
645 extern void PostPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state);
646 
647 extern bool pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
648 extern void pgstat_relation_delete_pending_cb(PgStat_EntryRef *entry_ref);
649 
650 
651 /*
652  * Functions in pgstat_replslot.c
653  */
654 
658 
659 
660 /*
661  * Functions in pgstat_shmem.c
662  */
663 
664 extern void pgstat_attach_shmem(void);
665 extern void pgstat_detach_shmem(void);
666 
667 extern PgStat_EntryRef *pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid,
668  bool create, bool *created_entry);
669 extern bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait);
670 extern bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait);
671 extern void pgstat_unlock_entry(PgStat_EntryRef *entry_ref);
672 extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid);
673 extern void pgstat_drop_all_entries(void);
674 extern PgStat_EntryRef *pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid,
675  bool nowait);
676 extern void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, uint64 objid, TimestampTz ts);
678 extern void pgstat_reset_matching_entries(bool (*do_reset) (PgStatShared_HashEntry *, Datum),
679  Datum match_data,
680  TimestampTz ts);
681 
682 extern void pgstat_request_entry_refs_gc(void);
684  PgStatShared_HashEntry *shhashent);
685 
686 
687 /*
688  * Functions in pgstat_slru.c
689  */
690 
691 extern bool pgstat_slru_have_pending_cb(void);
692 extern bool pgstat_slru_flush_cb(bool nowait);
693 extern void pgstat_slru_init_shmem_cb(void *stats);
694 extern void pgstat_slru_reset_all_cb(TimestampTz ts);
695 extern void pgstat_slru_snapshot_cb(void);
696 
697 
698 /*
699  * Functions in pgstat_wal.c
700  */
701 
702 extern void pgstat_flush_wal(bool nowait);
703 
704 extern void pgstat_wal_init_backend_cb(void);
705 extern bool pgstat_wal_have_pending_cb(void);
706 extern bool pgstat_wal_flush_cb(bool nowait);
707 extern void pgstat_wal_init_shmem_cb(void *stats);
708 extern void pgstat_wal_reset_all_cb(TimestampTz ts);
709 extern void pgstat_wal_snapshot_cb(void);
710 
711 
712 /*
713  * Functions in pgstat_subscription.c
714  */
715 
716 extern bool pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
718 
719 
720 /*
721  * Functions in pgstat_xact.c
722  */
723 
724 extern PgStat_SubXactStatus *pgstat_get_xact_stack_level(int nest_level);
725 extern void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid);
726 extern void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid);
727 
728 
729 /*
730  * Variables in pgstat.c
731  */
732 
734 
735 
736 /*
737  * Implementation of inline functions declared above.
738  */
739 
740 /*
741  * Helpers for changecount manipulation. See comments around struct
742  * PgBackendStatus for details.
743  */
744 
745 static inline void
747 {
748  Assert((*cc & 1) == 0);
749 
751  (*cc)++;
753 }
754 
755 static inline void
757 {
758  Assert((*cc & 1) == 1);
759 
761 
762  (*cc)++;
763 
765 }
766 
767 static inline uint32
769 {
770  uint32 before_cc = *cc;
771 
773 
774  pg_read_barrier();
775 
776  return before_cc;
777 }
778 
779 /*
780  * Returns true if the read succeeded, false if it needs to be repeated.
781  */
782 static inline bool
784 {
785  uint32 after_cc;
786 
787  pg_read_barrier();
788 
789  after_cc = *cc;
790 
791  /* was a write in progress when we started? */
792  if (before_cc & 1)
793  return false;
794 
795  /* did writes start and complete while we read? */
796  return before_cc == after_cc;
797 }
798 
799 
800 /*
801  * helper function for PgStat_KindInfo->snapshot_cb
802  * PgStat_KindInfo->reset_all_cb callbacks.
803  *
804  * Copies out the specified memory area following change-count protocol.
805  */
806 static inline void
807 pgstat_copy_changecounted_stats(void *dst, void *src, size_t len,
808  uint32 *cc)
809 {
810  uint32 cc_before;
811 
812  do
813  {
814  cc_before = pgstat_begin_changecount_read(cc);
815 
816  memcpy(dst, src, len);
817  }
818  while (!pgstat_end_changecount_read(cc, cc_before));
819 }
820 
821 /* helpers for dshash / simplehash hashtables */
822 static inline int
823 pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg)
824 {
825  Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
826  return memcmp(a, b, sizeof(PgStat_HashKey));
827 }
828 
829 static inline uint32
830 pgstat_hash_hash_key(const void *d, size_t size, void *arg)
831 {
832  const char *key = (const char *) d;
833 
834  Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
835  return fasthash32(key, size, 0);
836 }
837 
838 /*
839  * The length of the data portion of a shared memory stats entry (i.e. without
840  * transient data such as refcounts, lwlocks, ...).
841  */
842 static inline size_t
844 {
846 }
847 
848 /*
849  * Returns a pointer to the data portion of a shared memory stats entry.
850  */
851 static inline void *
853 {
854  size_t off = pgstat_get_kind_info(kind)->shared_data_off;
855 
856  Assert(off != 0 && off < PG_UINT32_MAX);
857 
858  return ((char *) (entry)) + off;
859 }
860 
861 /*
862  * Returns a pointer to the shared memory area of custom stats for
863  * fixed-numbered statistics.
864  */
865 static inline void *
867 {
868  int idx = kind - PGSTAT_KIND_CUSTOM_MIN;
869 
871  Assert(pgstat_get_kind_info(kind)->fixed_amount);
872 
873  return pgStatLocal.shmem->custom_data[idx];
874 }
875 
876 /*
877  * Returns a pointer to the portion of custom data for fixed-numbered
878  * statistics in the current snapshot.
879  */
880 static inline void *
882 {
883  int idx = kind - PGSTAT_KIND_CUSTOM_MIN;
884 
886  Assert(pgstat_get_kind_info(kind)->fixed_amount);
887 
889 }
890 
891 #endif /* PGSTAT_INTERNAL_H */
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
#define pg_read_barrier()
Definition: atomics.h:156
#define pg_write_barrier()
Definition: atomics.h:157
unsigned int uint32
Definition: c.h:506
#define PGDLLIMPORT
Definition: c.h:1316
#define PG_UINT32_MAX
Definition: c.h:590
#define Assert(condition)
Definition: c.h:858
unsigned char bool
Definition: c.h:456
int64 TimestampTz
Definition: timestamp.h:39
uint64 dsa_pointer
Definition: dsa.h:62
dsa_pointer dshash_table_handle
Definition: dshash.h:24
static uint32 fasthash32(const char *k, size_t len, uint64 seed)
int b
Definition: isn.c:70
int a
Definition: isn.c:69
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:367
#define START_CRIT_SECTION()
Definition: miscadmin.h:149
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
#define END_CRIT_SECTION()
Definition: miscadmin.h:151
void * arg
const void size_t len
PgStat_FetchConsistency
Definition: pgstat.h:100
static bool pgstat_is_kind_custom(PgStat_Kind kind)
Definition: pgstat.h:86
#define PgStat_Kind
Definition: pgstat.h:37
#define PGSTAT_KIND_CUSTOM_MIN
Definition: pgstat.h:68
#define PGSTAT_KIND_CUSTOM_SIZE
Definition: pgstat.h:70
#define PGSTAT_KIND_BUILTIN_SIZE
Definition: pgstat.h:63
bool pgstat_replslot_from_serialized_name_cb(const NameData *name, PgStat_HashKey *key)
void pgstat_flush_wal(bool nowait)
Definition: pgstat_wal.c:78
void pgstat_slru_snapshot_cb(void)
Definition: pgstat_slru.c:220
void pgstat_reset_entries_of_kind(PgStat_Kind kind, TimestampTz ts)
struct PgStatShared_Wal PgStatShared_Wal
void pgstat_archiver_init_shmem_cb(void *stats)
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:663
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1054
struct PgStat_EntryRef PgStat_EntryRef
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1430
PgStatShared_Common * pgstat_init_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
Definition: pgstat_shmem.c:293
static void * pgstat_get_custom_snapshot_data(PgStat_Kind kind)
void pgstat_flush_io(bool nowait)
Definition: pgstat_io.c:177
static void * pgstat_get_custom_shmem_data(PgStat_Kind kind)
static uint32 pgstat_hash_hash_key(const void *d, size_t size, void *arg)
struct PgStatShared_SLRU PgStatShared_SLRU
void pgstat_delete_pending_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat.c:1310
bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:626
void pgstat_attach_shmem(void)
Definition: pgstat_shmem.c:244
static void pgstat_end_changecount_write(uint32 *cc)
static const char *const slru_names[]
static int pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg)
struct PgStat_KindInfo PgStat_KindInfo
void pgstat_database_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
struct PgStatShared_Function PgStatShared_Function
void pgstat_checkpointer_snapshot_cb(void)
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_shmem.c:909
static void * pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry)
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, uint64 objid, TimestampTz ts)
Definition: pgstat_shmem.c:984
bool pgstat_slru_flush_cb(bool nowait)
Definition: pgstat_slru.c:165
void pgstat_wal_reset_all_cb(TimestampTz ts)
Definition: pgstat_wal.c:184
struct PgStatShared_Subscription PgStatShared_Subscription
bool pgstat_io_have_pending_cb(void)
Definition: pgstat_io.c:168
bool pgstat_io_flush_cb(bool nowait)
Definition: pgstat_io.c:191
void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)
struct PgStatShared_IO PgStatShared_IO
void AtEOXact_PgStat_Database(bool isCommit, bool parallel)
#define pgstat_assert_is_up()
PGDLLIMPORT PgStat_LocalState pgStatLocal
Definition: pgstat.c:212
void pgstat_archiver_reset_all_cb(TimestampTz ts)
void pgstat_checkpointer_init_shmem_cb(void *stats)
void pgstat_bgwriter_reset_all_cb(TimestampTz ts)
struct PgStat_HashKey PgStat_HashKey
struct PgStatShared_Archiver PgStatShared_Archiver
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_xact.c:384
void pgstat_replslot_to_serialized_name_cb(const PgStat_HashKey *key, const PgStatShared_Common *header, NameData *name)
bool pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
struct PgStatShared_HashEntry PgStatShared_HashEntry
struct PgStat_LocalState PgStat_LocalState
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_xact.c:361
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:432
bool pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
void pgstat_wal_init_shmem_cb(void *stats)
Definition: pgstat_wal.c:176
void pgstat_io_reset_all_cb(TimestampTz ts)
Definition: pgstat_io.c:282
static uint32 pgstat_begin_changecount_read(uint32 *cc)
void pgstat_update_dbstats(TimestampTz ts)
void pgstat_replslot_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
void pgstat_bgwriter_init_shmem_cb(void *stats)
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
void pgstat_slru_reset_all_cb(TimestampTz ts)
Definition: pgstat_slru.c:213
struct PgStat_SubXactStatus PgStat_SubXactStatus
void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit)
void pgstat_wal_init_backend_cb(void)
Definition: pgstat_wal.c:150
struct PgStatShared_Relation PgStatShared_Relation
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
bool pgstat_wal_flush_cb(bool nowait)
Definition: pgstat_wal.c:91
void pgstat_drop_all_entries(void)
Definition: pgstat_shmem.c:946
static bool pgstat_end_changecount_read(uint32 *cc, uint32 cc_before)
PgStat_EntryRef * pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:1297
void pgstat_bgwriter_snapshot_cb(void)
struct PgStatShared_Checkpointer PgStatShared_Checkpointer
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:638
void pgstat_checkpointer_reset_all_cb(TimestampTz ts)
void pgstat_reset_database_timestamp(Oid dboid, TimestampTz ts)
static void pgstat_begin_changecount_write(uint32 *cc)
PgStat_SubXactStatus * pgstat_get_xact_stack_level(int nest_level)
Definition: pgstat_xact.c:238
bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:928
void pgstat_report_disconnect(Oid dboid)
void pgstat_slru_init_shmem_cb(void *stats)
Definition: pgstat_slru.c:205
void PostPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)
bool pgstat_database_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
struct PgStat_ShmemControl PgStat_ShmemControl
#define SLRU_NUM_ELEMENTS
bool pgstat_wal_have_pending_cb(void)
Definition: pgstat_wal.c:168
struct PgStatShared_Database PgStatShared_Database
void pgstat_wal_snapshot_cb(void)
Definition: pgstat_wal.c:195
static void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len, uint32 *cc)
struct PgStatShared_BgWriter PgStatShared_BgWriter
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
Definition: pgstat_shmem.c:647
bool pgstat_slru_have_pending_cb(void)
Definition: pgstat_slru.c:150
void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
void pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
Definition: pgstat.c:1458
void pgstat_io_snapshot_cb(void)
Definition: pgstat_io.c:304
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:610
static size_t pgstat_get_entry_len(PgStat_Kind kind)
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition: pgstat.c:1259
void pgstat_io_init_shmem_cb(void *stats)
Definition: pgstat_io.c:273
struct PgStatShared_Common PgStatShared_Common
void pgstat_subscription_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
struct PgStatShared_ReplSlot PgStatShared_ReplSlot
void pgstat_archiver_snapshot_cb(void)
void pgstat_detach_shmem(void)
Definition: pgstat_shmem.c:264
struct PgStat_Snapshot PgStat_Snapshot
void pgstat_relation_delete_pending_cb(PgStat_EntryRef *entry_ref)
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
static pg_noinline void Size size
Definition: slab.c:607
Definition: lwlock.h:42
PgStat_ArchiverStats reset_offset
PgStat_ArchiverStats stats
PgStat_BgWriterStats reset_offset
PgStat_BgWriterStats stats
PgStat_CheckpointerStats reset_offset
PgStat_CheckpointerStats stats
PgStat_StatDBEntry stats
PgStatShared_Common header
PgStatShared_Common header
PgStat_StatFuncEntry stats
pg_atomic_uint32 refcount
LWLock locks[BACKEND_NUM_TYPES]
PgStatShared_Common header
PgStat_StatTabEntry stats
PgStatShared_Common header
PgStat_StatReplSlotEntry stats
PgStat_SLRUStats stats[SLRU_NUM_ELEMENTS]
PgStat_StatSubEntry stats
PgStatShared_Common header
PgStat_WalStats stats
PgStatShared_Common * shared_stats
PgStatShared_HashEntry * shared_entry
dlist_node pending_node
PgStat_Kind kind
bool accessed_across_databases
bool(* have_fixed_pending_cb)(void)
void(* to_serialized_name)(const PgStat_HashKey *key, const PgStatShared_Common *header, NameData *name)
bool(* from_serialized_name)(const NameData *name, PgStat_HashKey *key)
bool(* flush_pending_cb)(PgStat_EntryRef *sr, bool nowait)
void(* reset_all_cb)(TimestampTz ts)
void(* init_backend_cb)(void)
void(* reset_timestamp_cb)(PgStatShared_Common *header, TimestampTz ts)
const char *const name
void(* init_shmem_cb)(void *stats)
void(* delete_pending_cb)(PgStat_EntryRef *sr)
void(* snapshot_cb)(void)
bool(* flush_fixed_cb)(bool nowait)
PgStat_Snapshot snapshot
dshash_table * shared_hash
PgStat_ShmemControl * shmem
dshash_table_handle hash_handle
PgStatShared_SLRU slru
PgStatShared_IO io
void * custom_data[PGSTAT_KIND_CUSTOM_SIZE]
pg_atomic_uint64 gc_request_count
PgStatShared_Wal wal
PgStatShared_Archiver archiver
PgStatShared_Checkpointer checkpointer
PgStatShared_BgWriter bgwriter
PgStat_CheckpointerStats checkpointer
void * custom_data[PGSTAT_KIND_CUSTOM_SIZE]
TimestampTz snapshot_timestamp
MemoryContext context
PgStat_WalStats wal
bool custom_valid[PGSTAT_KIND_CUSTOM_SIZE]
PgStat_ArchiverStats archiver
PgStat_FetchConsistency mode
PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]
struct pgstat_snapshot_hash * stats
bool fixed_valid[PGSTAT_KIND_BUILTIN_SIZE]
PgStat_BgWriterStats bgwriter
PgStat_TableXactStatus * first
struct PgStat_SubXactStatus * prev
Definition: dsa.c:348
Definition: c.h:741
const char * name