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  Oid objoid; /* object ID, either table or function. */
58 
59 /*
60  * Shared statistics hash entry. Doesn't itself contain any stats, but points
61  * to them (with ->body). That allows the stats entries themselves to be of
62  * variable size.
63  */
64 typedef struct PgStatShared_HashEntry
65 {
66  PgStat_HashKey key; /* hash key */
67 
68  /*
69  * If dropped is set, backends need to release their references so that
70  * the memory for the entry can be freed. No new references may be made
71  * once marked as dropped.
72  */
73  bool dropped;
74 
75  /*
76  * Refcount managing lifetime of the entry itself (as opposed to the
77  * dshash entry pointing to it). The stats lifetime has to be separate
78  * from the hash table entry lifetime because we allow backends to point
79  * to a stats entry without holding a hash table lock (and some other
80  * reasons).
81  *
82  * As long as the entry is not dropped, 1 is added to the refcount
83  * representing that the entry should not be dropped. In addition each
84  * backend that has a reference to the entry needs to increment the
85  * refcount as long as it does.
86  *
87  * May only be incremented / decremented while holding at least a shared
88  * lock on the dshash partition containing the entry. It needs to be an
89  * atomic variable because multiple backends can increment the refcount
90  * with just a shared lock.
91  *
92  * When the refcount reaches 0 the entry needs to be freed.
93  */
95 
96  /*
97  * Pointer to shared stats. The stats entry always starts with
98  * PgStatShared_Common, embedded in a larger struct containing the
99  * PgStat_Kind specific stats fields.
100  */
103 
104 /*
105  * Common header struct for PgStatShared_*.
106  */
107 typedef struct PgStatShared_Common
108 {
109  uint32 magic; /* just a validity cross-check */
110  /* lock protecting stats contents (i.e. data following the header) */
113 
114 /*
115  * A backend local reference to a shared stats entry. As long as at least one
116  * such reference exists, the shared stats entry will not be released.
117  *
118  * If there are pending stats update to the shared stats, these are stored in
119  * ->pending.
120  */
121 typedef struct PgStat_EntryRef
122 {
123  /*
124  * Pointer to the PgStatShared_HashEntry entry in the shared stats
125  * hashtable.
126  */
128 
129  /*
130  * Pointer to the stats data (i.e. PgStatShared_HashEntry->body), resolved
131  * as a local pointer, to avoid repeated dsa_get_address() calls.
132  */
134 
135  /*
136  * Pending statistics data that will need to be flushed to shared memory
137  * stats eventually. Each stats kind utilizing pending data defines what
138  * format its pending data has and needs to provide a
139  * PgStat_KindInfo->flush_pending_cb callback to merge pending into shared
140  * stats.
141  */
142  void *pending;
143  dlist_node pending_node; /* membership in pgStatPending list */
145 
146 
147 /*
148  * Some stats changes are transactional. To maintain those, a stack of
149  * PgStat_SubXactStatus entries is maintained, which contain data pertaining
150  * to the current transaction and its active subtransactions.
151  */
152 typedef struct PgStat_SubXactStatus
153 {
154  int nest_level; /* subtransaction nest level */
155 
156  struct PgStat_SubXactStatus *prev; /* higher-level subxact if any */
157 
158  /*
159  * Statistics for transactionally dropped objects need to be
160  * transactionally dropped as well. Collect the stats dropped in the
161  * current (sub-)transaction and only execute the stats drop when we know
162  * if the transaction commits/aborts. To handle replicas and crashes,
163  * stats drops are included in commit / abort records.
164  */
166 
167  /*
168  * Tuple insertion/deletion counts for an open transaction can't be
169  * propagated into PgStat_TableStatus counters until we know if it is
170  * going to commit or abort. Hence, we keep these counts in per-subxact
171  * structs that live in TopTransactionContext. This data structure is
172  * designed on the assumption that subxacts won't usually modify very many
173  * tables.
174  */
175  PgStat_TableXactStatus *first; /* head of list for this subxact */
177 
178 
179 /*
180  * Metadata for a specific kind of statistics.
181  */
182 typedef struct PgStat_KindInfo
183 {
184  /*
185  * Do a fixed number of stats objects exist for this kind of stats (e.g.
186  * bgwriter stats) or not (e.g. tables).
187  */
188  bool fixed_amount:1;
189 
190  /*
191  * Can stats of this kind be accessed from another database? Determines
192  * whether a stats object gets included in stats snapshots.
193  */
195 
196  /*
197  * The size of an entry in the shared stats hash table (pointed to by
198  * PgStatShared_HashEntry->body).
199  */
201 
202  /*
203  * The offset of the statistics struct in the cached statistics snapshot
204  * PgStat_Snapshot, for fixed-numbered statistics.
205  */
207 
208  /*
209  * The offset of the statistics struct in the containing shared memory
210  * control structure PgStat_ShmemControl, for fixed-numbered statistics.
211  */
213 
214  /*
215  * The offset/size of statistics inside the shared stats entry. Used when
216  * [de-]serializing statistics to / from disk respectively. Separate from
217  * shared_size because [de-]serialization may not include in-memory state
218  * like lwlocks.
219  */
222 
223  /*
224  * The size of the pending data for this kind. E.g. how large
225  * PgStat_EntryRef->pending is. Used for allocations.
226  *
227  * 0 signals that an entry of this kind should never have a pending entry.
228  */
230 
231  /*
232  * For variable-numbered stats: flush pending stats. Required if pending
233  * data is used.
234  */
235  bool (*flush_pending_cb) (PgStat_EntryRef *sr, bool nowait);
236 
237  /*
238  * For variable-numbered stats: delete pending stats. Optional.
239  */
241 
242  /*
243  * For variable-numbered stats: reset the reset timestamp. Optional.
244  */
246 
247  /*
248  * For variable-numbered stats. Optional.
249  */
251  const PgStatShared_Common *header, NameData *name);
253 
254  /*
255  * For fixed-numbered statistics: Initialize shared memory state.
256  *
257  * "stats" is the pointer to the allocated shared memory area.
258  */
259  void (*init_shmem_cb) (void *stats);
260 
261  /*
262  * For fixed-numbered statistics: Reset All.
263  */
264  void (*reset_all_cb) (TimestampTz ts);
265 
266  /*
267  * For fixed-numbered statistics: Build snapshot for entry
268  */
269  void (*snapshot_cb) (void);
270 
271  /* name of the kind of stats */
272  const char *const name;
274 
275 
276 /*
277  * List of SLRU names that we keep stats for. There is no central registry of
278  * SLRUs, so we use this fixed list instead. The "other" entry is used for
279  * all SLRUs without an explicit entry (e.g. SLRUs in extensions).
280  *
281  * This is only defined here so that SLRU_NUM_ELEMENTS is known for later type
282  * definitions.
283  */
284 static const char *const slru_names[] = {
285  "commit_timestamp",
286  "multixact_member",
287  "multixact_offset",
288  "notify",
289  "serializable",
290  "subtransaction",
291  "transaction",
292  "other" /* has to be last */
293 };
294 
295 #define SLRU_NUM_ELEMENTS lengthof(slru_names)
296 
297 
298 /* ----------
299  * Types and definitions for different kinds of fixed-amount stats.
300  *
301  * Single-writer stats use the changecount mechanism to achieve low-overhead
302  * writes - they're obviously more performance critical than reads. Check the
303  * definition of struct PgBackendStatus for some explanation of the
304  * changecount mechanism.
305  *
306  * Because the obvious implementation of resetting single-writer stats isn't
307  * compatible with that (another backend needs to write), we don't scribble on
308  * shared stats while resetting. Instead, just record the current counter
309  * values in a copy of the stats data, which is protected by ->lock. See
310  * pgstat_fetch_stat_(archiver|bgwriter|checkpointer) for the reader side.
311  *
312  * The only exception to that is the stat_reset_timestamp in these structs,
313  * which is protected by ->lock, because it has to be written by another
314  * backend while resetting.
315  * ----------
316  */
317 
318 typedef struct PgStatShared_Archiver
319 {
320  /* lock protects ->reset_offset as well as stats->stat_reset_timestamp */
326 
327 typedef struct PgStatShared_BgWriter
328 {
329  /* lock protects ->reset_offset as well as stats->stat_reset_timestamp */
335 
337 {
338  /* lock protects ->reset_offset as well as stats->stat_reset_timestamp */
344 
345 /* Shared-memory ready PgStat_IO */
346 typedef struct PgStatShared_IO
347 {
348  /*
349  * locks[i] protects stats.stats[i]. locks[0] also protects
350  * stats.stat_reset_timestamp.
351  */
355 
356 typedef struct PgStatShared_SLRU
357 {
358  /* lock protects ->stats */
362 
363 typedef struct PgStatShared_Wal
364 {
365  /* lock protects ->stats */
369 
370 
371 
372 /* ----------
373  * Types and definitions for different kinds of variable-amount stats.
374  *
375  * Each struct has to start with PgStatShared_Common, containing information
376  * common across the different types of stats. Kind-specific data follows.
377  * ----------
378  */
379 
380 typedef struct PgStatShared_Database
381 {
385 
386 typedef struct PgStatShared_Relation
387 {
391 
392 typedef struct PgStatShared_Function
393 {
397 
399 {
403 
404 typedef struct PgStatShared_ReplSlot
405 {
409 
410 
411 /*
412  * Central shared memory entry for the cumulative stats system.
413  *
414  * Fixed amount stats, the dynamic shared memory hash table for
415  * non-fixed-amount stats, as well as remaining bits and pieces are all
416  * reached from here.
417  */
418 typedef struct PgStat_ShmemControl
419 {
421 
422  /*
423  * Stats for variable-numbered objects are kept in this shared hash table.
424  * See comment above PgStat_Kind for details.
425  */
426  dshash_table_handle hash_handle; /* shared dbstat hash */
427 
428  /* Has the stats system already been shut down? Just a debugging check. */
430 
431  /*
432  * Whenever statistics for dropped objects could not be freed - because
433  * backends still have references - the dropping backend calls
434  * pgstat_request_entry_refs_gc() incrementing this counter. Eventually
435  * that causes backends to run pgstat_gc_entry_refs(), allowing memory to
436  * be reclaimed.
437  */
439 
440  /*
441  * Stats data for fixed-numbered objects.
442  */
450 
451 
452 /*
453  * Cached statistics snapshot
454  */
455 typedef struct PgStat_Snapshot
456 {
458 
459  /* time at which snapshot was taken */
461 
463 
465 
467 
469 
471 
473 
475 
476  /* to free snapshot in bulk */
478  struct pgstat_snapshot_hash *stats;
480 
481 
482 /*
483  * Collection of backend-local stats state.
484  */
485 typedef struct PgStat_LocalState
486 {
490 
491  /* the current statistics snapshot */
494 
495 
496 /*
497  * Inline functions defined further below.
498  */
499 
500 static inline void pgstat_begin_changecount_write(uint32 *cc);
501 static inline void pgstat_end_changecount_write(uint32 *cc);
502 static inline uint32 pgstat_begin_changecount_read(uint32 *cc);
503 static inline bool pgstat_end_changecount_read(uint32 *cc, uint32 cc_before);
504 
505 static inline void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len,
506  uint32 *cc);
507 
508 static inline int pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg);
509 static inline uint32 pgstat_hash_hash_key(const void *d, size_t size, void *arg);
510 static inline size_t pgstat_get_entry_len(PgStat_Kind kind);
511 static inline void *pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry);
512 
513 
514 /*
515  * Functions in pgstat.c
516  */
517 
519 
520 #ifdef USE_ASSERT_CHECKING
521 extern void pgstat_assert_is_up(void);
522 #else
523 #define pgstat_assert_is_up() ((void)true)
524 #endif
525 
526 extern void pgstat_delete_pending_entry(PgStat_EntryRef *entry_ref);
527 extern PgStat_EntryRef *pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry);
528 extern PgStat_EntryRef *pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
529 
530 extern void *pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
531 extern void pgstat_snapshot_fixed(PgStat_Kind kind);
532 
533 
534 /*
535  * Functions in pgstat_archiver.c
536  */
537 
538 extern void pgstat_archiver_init_shmem_cb(void *stats);
540 extern void pgstat_archiver_snapshot_cb(void);
541 
542 
543 /*
544  * Functions in pgstat_bgwriter.c
545  */
546 
547 extern void pgstat_bgwriter_init_shmem_cb(void *stats);
549 extern void pgstat_bgwriter_snapshot_cb(void);
550 
551 
552 /*
553  * Functions in pgstat_checkpointer.c
554  */
555 
556 extern void pgstat_checkpointer_init_shmem_cb(void *stats);
558 extern void pgstat_checkpointer_snapshot_cb(void);
559 
560 
561 /*
562  * Functions in pgstat_database.c
563  */
564 
565 extern void pgstat_report_disconnect(Oid dboid);
566 extern void pgstat_update_dbstats(TimestampTz ts);
567 extern void AtEOXact_PgStat_Database(bool isCommit, bool parallel);
568 
570 extern void pgstat_reset_database_timestamp(Oid dboid, TimestampTz ts);
571 extern bool pgstat_database_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
573 
574 
575 /*
576  * Functions in pgstat_function.c
577  */
578 
579 extern bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
580 
581 
582 /*
583  * Functions in pgstat_io.c
584  */
585 
586 extern bool pgstat_flush_io(bool nowait);
587 extern void pgstat_io_init_shmem_cb(void *stats);
588 extern void pgstat_io_reset_all_cb(TimestampTz ts);
589 extern void pgstat_io_snapshot_cb(void);
590 
591 
592 /*
593  * Functions in pgstat_relation.c
594  */
595 
596 extern void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit);
597 extern void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth);
598 extern void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state);
599 extern void PostPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state);
600 
601 extern bool pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
602 extern void pgstat_relation_delete_pending_cb(PgStat_EntryRef *entry_ref);
603 
604 
605 /*
606  * Functions in pgstat_replslot.c
607  */
608 
612 
613 
614 /*
615  * Functions in pgstat_shmem.c
616  */
617 
618 extern void pgstat_attach_shmem(void);
619 extern void pgstat_detach_shmem(void);
620 
621 extern PgStat_EntryRef *pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid,
622  bool create, bool *created_entry);
623 extern bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait);
624 extern bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait);
625 extern void pgstat_unlock_entry(PgStat_EntryRef *entry_ref);
626 extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
627 extern void pgstat_drop_all_entries(void);
629  bool nowait);
630 extern void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts);
632 extern void pgstat_reset_matching_entries(bool (*do_reset) (PgStatShared_HashEntry *, Datum),
633  Datum match_data,
634  TimestampTz ts);
635 
636 extern void pgstat_request_entry_refs_gc(void);
638  PgStatShared_HashEntry *shhashent);
639 
640 
641 /*
642  * Functions in pgstat_slru.c
643  */
644 
645 extern bool pgstat_slru_flush(bool nowait);
646 extern void pgstat_slru_init_shmem_cb(void *stats);
647 extern void pgstat_slru_reset_all_cb(TimestampTz ts);
648 extern void pgstat_slru_snapshot_cb(void);
649 
650 
651 /*
652  * Functions in pgstat_wal.c
653  */
654 
655 extern bool pgstat_flush_wal(bool nowait);
656 extern void pgstat_init_wal(void);
657 extern bool pgstat_have_pending_wal(void);
658 
659 extern void pgstat_wal_init_shmem_cb(void *stats);
660 extern void pgstat_wal_reset_all_cb(TimestampTz ts);
661 extern void pgstat_wal_snapshot_cb(void);
662 
663 
664 /*
665  * Functions in pgstat_subscription.c
666  */
667 
668 extern bool pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
670 
671 
672 /*
673  * Functions in pgstat_xact.c
674  */
675 
676 extern PgStat_SubXactStatus *pgstat_get_xact_stack_level(int nest_level);
677 extern void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, Oid objoid);
678 extern void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid);
679 
680 
681 /*
682  * Variables in pgstat.c
683  */
684 
686 
687 
688 /*
689  * Variables in pgstat_io.c
690  */
691 
692 extern PGDLLIMPORT bool have_iostats;
693 
694 
695 /*
696  * Variables in pgstat_slru.c
697  */
698 
699 extern PGDLLIMPORT bool have_slrustats;
700 
701 
702 /*
703  * Implementation of inline functions declared above.
704  */
705 
706 /*
707  * Helpers for changecount manipulation. See comments around struct
708  * PgBackendStatus for details.
709  */
710 
711 static inline void
713 {
714  Assert((*cc & 1) == 0);
715 
717  (*cc)++;
719 }
720 
721 static inline void
723 {
724  Assert((*cc & 1) == 1);
725 
727 
728  (*cc)++;
729 
731 }
732 
733 static inline uint32
735 {
736  uint32 before_cc = *cc;
737 
739 
740  pg_read_barrier();
741 
742  return before_cc;
743 }
744 
745 /*
746  * Returns true if the read succeeded, false if it needs to be repeated.
747  */
748 static inline bool
750 {
751  uint32 after_cc;
752 
753  pg_read_barrier();
754 
755  after_cc = *cc;
756 
757  /* was a write in progress when we started? */
758  if (before_cc & 1)
759  return false;
760 
761  /* did writes start and complete while we read? */
762  return before_cc == after_cc;
763 }
764 
765 
766 /*
767  * helper function for PgStat_KindInfo->snapshot_cb
768  * PgStat_KindInfo->reset_all_cb callbacks.
769  *
770  * Copies out the specified memory area following change-count protocol.
771  */
772 static inline void
773 pgstat_copy_changecounted_stats(void *dst, void *src, size_t len,
774  uint32 *cc)
775 {
776  uint32 cc_before;
777 
778  do
779  {
780  cc_before = pgstat_begin_changecount_read(cc);
781 
782  memcpy(dst, src, len);
783  }
784  while (!pgstat_end_changecount_read(cc, cc_before));
785 }
786 
787 /* helpers for dshash / simplehash hashtables */
788 static inline int
789 pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg)
790 {
791  Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
792  return memcmp(a, b, sizeof(PgStat_HashKey));
793 }
794 
795 static inline uint32
796 pgstat_hash_hash_key(const void *d, size_t size, void *arg)
797 {
798  const char *key = (const char *) d;
799 
800  Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
801  return fasthash32(key, size, 0);
802 }
803 
804 /*
805  * The length of the data portion of a shared memory stats entry (i.e. without
806  * transient data such as refcounts, lwlocks, ...).
807  */
808 static inline size_t
810 {
812 }
813 
814 /*
815  * Returns a pointer to the data portion of a shared memory stats entry.
816  */
817 static inline void *
819 {
820  size_t off = pgstat_get_kind_info(kind)->shared_data_off;
821 
822  Assert(off != 0 && off < PG_UINT32_MAX);
823 
824  return ((char *) (entry)) + off;
825 }
826 
827 #endif /* PGSTAT_INTERNAL_H */
#define pg_read_barrier()
Definition: atomics.h:149
#define pg_write_barrier()
Definition: atomics.h:150
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:370
#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_Kind
Definition: pgstat.h:36
PgStat_FetchConsistency
Definition: pgstat.h:69
#define PGSTAT_NUM_KINDS
Definition: pgstat.h:58
bool pgstat_replslot_from_serialized_name_cb(const NameData *name, PgStat_HashKey *key)
void pgstat_slru_snapshot_cb(void)
Definition: pgstat_slru.c:211
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:638
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:981
struct PgStat_EntryRef PgStat_EntryRef
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1306
PgStatShared_Common * pgstat_init_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
Definition: pgstat_shmem.c:268
PGDLLIMPORT bool have_slrustats
Definition: pgstat_slru.c:35
PGDLLIMPORT bool have_iostats
Definition: pgstat_io.c:32
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:1199
bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:601
void pgstat_attach_shmem(void)
Definition: pgstat_shmem.c:219
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_flush_io(bool nowait)
Definition: pgstat_io.c:173
static void * pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry)
void pgstat_wal_reset_all_cb(TimestampTz ts)
Definition: pgstat_wal.c:175
struct PgStatShared_Subscription PgStatShared_Subscription
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()
bool pgstat_have_pending_wal(void)
Definition: pgstat_wal.c:159
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_xact.c:357
PGDLLIMPORT PgStat_LocalState pgStatLocal
Definition: pgstat.c:201
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_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_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:855
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_xact.c:379
void pgstat_init_wal(void)
Definition: pgstat_wal.c:141
bool pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
void pgstat_wal_init_shmem_cb(void *stats)
Definition: pgstat_wal.c:167
void pgstat_io_reset_all_cb(TimestampTz ts)
Definition: pgstat_io.c:264
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts)
Definition: pgstat_shmem.c:958
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)
bool pgstat_slru_flush(bool nowait)
Definition: pgstat_slru.c:156
void pgstat_bgwriter_init_shmem_cb(void *stats)
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
Definition: pgstat_shmem.c:978
void pgstat_slru_reset_all_cb(TimestampTz ts)
Definition: pgstat_slru.c:204
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry)
Definition: pgstat.c:1148
struct PgStat_SubXactStatus PgStat_SubXactStatus
void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit)
struct PgStatShared_Relation PgStatShared_Relation
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
void pgstat_drop_all_entries(void)
Definition: pgstat_shmem.c:920
static bool pgstat_end_changecount_read(uint32 *cc, uint32 cc_before)
PgStat_EntryRef * pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:1186
void pgstat_bgwriter_snapshot_cb(void)
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:407
struct PgStatShared_Checkpointer PgStatShared_Checkpointer
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:613
bool pgstat_flush_wal(bool nowait)
Definition: pgstat_wal.c:82
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:236
bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_shmem.c:883
void pgstat_report_disconnect(Oid dboid)
void pgstat_slru_init_shmem_cb(void *stats)
Definition: pgstat_slru.c:196
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
struct PgStatShared_Database PgStatShared_Database
void pgstat_wal_snapshot_cb(void)
Definition: pgstat_wal.c:186
static void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len, uint32 *cc)
struct PgStatShared_BgWriter PgStatShared_BgWriter
void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
void pgstat_io_snapshot_cb(void)
Definition: pgstat_io.c:286
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:585
static size_t pgstat_get_entry_len(PgStat_Kind kind)
void pgstat_io_init_shmem_cb(void *stats)
Definition: pgstat_io.c:255
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:239
struct PgStat_Snapshot PgStat_Snapshot
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
Definition: pgstat_shmem.c:622
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
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(* 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)
PgStat_Snapshot snapshot
dshash_table * shared_hash
PgStat_ShmemControl * shmem
dshash_table_handle hash_handle
PgStatShared_SLRU slru
PgStatShared_IO io
pg_atomic_uint64 gc_request_count
PgStatShared_Wal wal
PgStatShared_Archiver archiver
PgStatShared_Checkpointer checkpointer
PgStatShared_BgWriter bgwriter
PgStat_CheckpointerStats checkpointer
TimestampTz snapshot_timestamp
MemoryContext context
PgStat_WalStats wal
bool fixed_valid[PGSTAT_NUM_KINDS]
PgStat_ArchiverStats archiver
PgStat_FetchConsistency mode
PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]
struct pgstat_snapshot_hash * stats
PgStat_BgWriterStats bgwriter
PgStat_TableXactStatus * first
struct PgStat_SubXactStatus * prev
Definition: dsa.c:348
Definition: c.h:741
const char * name