PostgreSQL Source Code  git master
pgstat_internal.h File Reference
#include "common/hashfn.h"
#include "lib/dshash.h"
#include "lib/ilist.h"
#include "pgstat.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
Include dependency graph for pgstat_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PgStat_HashKey
 
struct  PgStatShared_HashEntry
 
struct  PgStatShared_Common
 
struct  PgStat_EntryRef
 
struct  PgStat_SubXactStatus
 
struct  PgStat_KindInfo
 
struct  PgStatShared_Archiver
 
struct  PgStatShared_BgWriter
 
struct  PgStatShared_Checkpointer
 
struct  PgStatShared_SLRU
 
struct  PgStatShared_Wal
 
struct  PgStatShared_Database
 
struct  PgStatShared_Relation
 
struct  PgStatShared_Function
 
struct  PgStatShared_Subscription
 
struct  PgStatShared_ReplSlot
 
struct  PgStat_ShmemControl
 
struct  PgStat_Snapshot
 
struct  PgStat_LocalState
 

Macros

#define SLRU_NUM_ELEMENTS   lengthof(slru_names)
 
#define pgstat_assert_is_up()   ((void)true)
 

Typedefs

typedef struct PgStat_HashKey PgStat_HashKey
 
typedef struct PgStatShared_HashEntry PgStatShared_HashEntry
 
typedef struct PgStatShared_Common PgStatShared_Common
 
typedef struct PgStat_EntryRef PgStat_EntryRef
 
typedef struct PgStat_SubXactStatus PgStat_SubXactStatus
 
typedef struct PgStat_KindInfo PgStat_KindInfo
 
typedef struct PgStatShared_Archiver PgStatShared_Archiver
 
typedef struct PgStatShared_BgWriter PgStatShared_BgWriter
 
typedef struct PgStatShared_Checkpointer PgStatShared_Checkpointer
 
typedef struct PgStatShared_SLRU PgStatShared_SLRU
 
typedef struct PgStatShared_Wal PgStatShared_Wal
 
typedef struct PgStatShared_Database PgStatShared_Database
 
typedef struct PgStatShared_Relation PgStatShared_Relation
 
typedef struct PgStatShared_Function PgStatShared_Function
 
typedef struct PgStatShared_Subscription PgStatShared_Subscription
 
typedef struct PgStatShared_ReplSlot PgStatShared_ReplSlot
 
typedef struct PgStat_ShmemControl PgStat_ShmemControl
 
typedef struct PgStat_Snapshot PgStat_Snapshot
 
typedef struct PgStat_LocalState PgStat_LocalState
 

Functions

static void pgstat_begin_changecount_write (uint32 *cc)
 
static void pgstat_end_changecount_write (uint32 *cc)
 
static uint32 pgstat_begin_changecount_read (uint32 *cc)
 
static bool pgstat_end_changecount_read (uint32 *cc, uint32 cc_before)
 
static void pgstat_copy_changecounted_stats (void *dst, void *src, size_t len, uint32 *cc)
 
static int pgstat_cmp_hash_key (const void *a, const void *b, size_t size, void *arg)
 
static uint32 pgstat_hash_hash_key (const void *d, size_t size, void *arg)
 
static size_t pgstat_get_entry_len (PgStat_Kind kind)
 
static void * pgstat_get_entry_data (PgStat_Kind kind, PgStatShared_Common *entry)
 
const PgStat_KindInfopgstat_get_kind_info (PgStat_Kind kind)
 
void pgstat_delete_pending_entry (PgStat_EntryRef *entry_ref)
 
PgStat_EntryRefpgstat_prep_pending_entry (PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry)
 
PgStat_EntryRefpgstat_fetch_pending_entry (PgStat_Kind kind, Oid dboid, Oid objoid)
 
void * pgstat_fetch_entry (PgStat_Kind kind, Oid dboid, Oid objoid)
 
void pgstat_snapshot_fixed (PgStat_Kind kind)
 
void pgstat_archiver_reset_all_cb (TimestampTz ts)
 
void pgstat_archiver_snapshot_cb (void)
 
void pgstat_bgwriter_reset_all_cb (TimestampTz ts)
 
void pgstat_bgwriter_snapshot_cb (void)
 
void pgstat_checkpointer_reset_all_cb (TimestampTz ts)
 
void pgstat_checkpointer_snapshot_cb (void)
 
void pgstat_report_disconnect (Oid dboid)
 
void pgstat_update_dbstats (TimestampTz ts)
 
void AtEOXact_PgStat_Database (bool isCommit, bool parallel)
 
PgStat_StatDBEntrypgstat_prep_database_pending (Oid dboid)
 
void pgstat_reset_database_timestamp (Oid dboid, TimestampTz ts)
 
bool pgstat_database_flush_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
void pgstat_database_reset_timestamp_cb (PgStatShared_Common *header, TimestampTz ts)
 
bool pgstat_function_flush_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
void AtEOXact_PgStat_Relations (PgStat_SubXactStatus *xact_state, bool isCommit)
 
void AtEOSubXact_PgStat_Relations (PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
 
void AtPrepare_PgStat_Relations (PgStat_SubXactStatus *xact_state)
 
void PostPrepare_PgStat_Relations (PgStat_SubXactStatus *xact_state)
 
bool pgstat_relation_flush_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
void pgstat_relation_delete_pending_cb (PgStat_EntryRef *entry_ref)
 
void pgstat_replslot_reset_timestamp_cb (PgStatShared_Common *header, TimestampTz ts)
 
void pgstat_replslot_to_serialized_name_cb (const PgStatShared_Common *tmp, NameData *name)
 
bool pgstat_replslot_from_serialized_name_cb (const NameData *name, PgStat_HashKey *key)
 
void pgstat_attach_shmem (void)
 
void pgstat_detach_shmem (void)
 
PgStat_EntryRefpgstat_get_entry_ref (PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *found)
 
bool pgstat_lock_entry (PgStat_EntryRef *entry_ref, bool nowait)
 
void pgstat_unlock_entry (PgStat_EntryRef *entry_ref)
 
bool pgstat_drop_entry (PgStat_Kind kind, Oid dboid, Oid objoid)
 
void pgstat_drop_all_entries (void)
 
PgStat_EntryRefpgstat_get_entry_ref_locked (PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
 
void pgstat_reset_entry (PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts)
 
void pgstat_reset_entries_of_kind (PgStat_Kind kind, TimestampTz ts)
 
void pgstat_reset_matching_entries (bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
 
void pgstat_request_entry_refs_gc (void)
 
PgStatShared_Commonpgstat_init_entry (PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
 
bool pgstat_slru_flush (bool nowait)
 
void pgstat_slru_reset_all_cb (TimestampTz ts)
 
void pgstat_slru_snapshot_cb (void)
 
bool pgstat_flush_wal (bool nowait)
 
void pgstat_init_wal (void)
 
bool pgstat_have_pending_wal (void)
 
void pgstat_wal_reset_all_cb (TimestampTz ts)
 
void pgstat_wal_snapshot_cb (void)
 
bool pgstat_subscription_flush_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
void pgstat_subscription_reset_timestamp_cb (PgStatShared_Common *header, TimestampTz ts)
 
PgStat_SubXactStatuspgstat_get_xact_stack_level (int nest_level)
 
void pgstat_drop_transactional (PgStat_Kind kind, Oid dboid, Oid objoid)
 
void pgstat_create_transactional (PgStat_Kind kind, Oid dboid, Oid objoid)
 

Variables

static const char *const slru_names []
 
PGDLLIMPORT PgStat_LocalState pgStatLocal
 
PGDLLIMPORT bool have_slrustats
 

Macro Definition Documentation

◆ pgstat_assert_is_up

#define pgstat_assert_is_up ( )    ((void)true)

Definition at line 496 of file pgstat_internal.h.

◆ SLRU_NUM_ELEMENTS

#define SLRU_NUM_ELEMENTS   lengthof(slru_names)

Definition at line 282 of file pgstat_internal.h.

Typedef Documentation

◆ PgStat_EntryRef

◆ PgStat_HashKey

◆ PgStat_KindInfo

◆ PgStat_LocalState

◆ PgStat_ShmemControl

◆ PgStat_Snapshot

◆ PgStat_SubXactStatus

◆ PgStatShared_Archiver

◆ PgStatShared_BgWriter

◆ PgStatShared_Checkpointer

◆ PgStatShared_Common

◆ PgStatShared_Database

◆ PgStatShared_Function

◆ PgStatShared_HashEntry

◆ PgStatShared_Relation

◆ PgStatShared_ReplSlot

◆ PgStatShared_SLRU

◆ PgStatShared_Subscription

◆ PgStatShared_Wal

Function Documentation

◆ AtEOSubXact_PgStat_Relations()

void AtEOSubXact_PgStat_Relations ( PgStat_SubXactStatus xact_state,
bool  isCommit,
int  nestDepth 
)

Definition at line 555 of file pgstat_relation.c.

556 {
558  PgStat_TableXactStatus *next_trans;
559 
560  for (trans = xact_state->first; trans != NULL; trans = next_trans)
561  {
562  PgStat_TableStatus *tabstat;
563 
564  next_trans = trans->next;
565  Assert(trans->nest_level == nestDepth);
566  tabstat = trans->parent;
567  Assert(tabstat->trans == trans);
568 
569  if (isCommit)
570  {
571  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
572  {
573  if (trans->truncdropped)
574  {
575  /* propagate the truncate/drop status one level up */
576  save_truncdrop_counters(trans->upper, false);
577  /* replace upper xact stats with ours */
578  trans->upper->tuples_inserted = trans->tuples_inserted;
579  trans->upper->tuples_updated = trans->tuples_updated;
580  trans->upper->tuples_deleted = trans->tuples_deleted;
581  }
582  else
583  {
584  trans->upper->tuples_inserted += trans->tuples_inserted;
585  trans->upper->tuples_updated += trans->tuples_updated;
586  trans->upper->tuples_deleted += trans->tuples_deleted;
587  }
588  tabstat->trans = trans->upper;
589  pfree(trans);
590  }
591  else
592  {
593  /*
594  * When there isn't an immediate parent state, we can just
595  * reuse the record instead of going through a palloc/pfree
596  * pushup (this works since it's all in TopTransactionContext
597  * anyway). We have to re-link it into the parent level,
598  * though, and that might mean pushing a new entry into the
599  * pgStatXactStack.
600  */
601  PgStat_SubXactStatus *upper_xact_state;
602 
603  upper_xact_state = pgstat_get_xact_stack_level(nestDepth - 1);
604  trans->next = upper_xact_state->first;
605  upper_xact_state->first = trans;
606  trans->nest_level = nestDepth - 1;
607  }
608  }
609  else
610  {
611  /*
612  * On abort, update top-level tabstat counts, then forget the
613  * subtransaction
614  */
615 
616  /* first restore values obliterated by truncate/drop */
618  /* count attempted actions regardless of commit/abort */
619  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
620  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
621  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
622  /* inserted tuples are dead, deleted tuples are unaffected */
623  tabstat->t_counts.t_delta_dead_tuples +=
624  trans->tuples_inserted + trans->tuples_updated;
625  tabstat->trans = trans->upper;
626  pfree(trans);
627  }
628  }
629 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
Definition: mcxt.c:1175
static void save_truncdrop_counters(PgStat_TableXactStatus *trans, bool is_drop)
static void restore_truncdrop_counters(PgStat_TableXactStatus *trans)
PgStat_SubXactStatus * pgstat_get_xact_stack_level(int nest_level)
Definition: pgstat_xact.c:243
PgStat_TableXactStatus * first
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:182
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:175
PgStat_Counter t_tuples_updated
Definition: pgstat.h:176
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:177
PgStat_TableCounts t_counts
Definition: pgstat.h:209
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:208
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400

References Assert(), PgStat_SubXactStatus::first, pfree(), pgstat_get_xact_stack_level(), restore_truncdrop_counters(), save_truncdrop_counters(), PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, and trans.

Referenced by AtEOSubXact_PgStat().

◆ AtEOXact_PgStat_Database()

void AtEOXact_PgStat_Database ( bool  isCommit,
bool  parallel 
)

Definition at line 246 of file pgstat_database.c.

247 {
248  /* Don't count parallel worker transaction stats */
249  if (!parallel)
250  {
251  /*
252  * Count transaction commit or abort. (We use counters, not just
253  * bools, in case the reporting message isn't sent right away.)
254  */
255  if (isCommit)
257  else
259  }
260 }
static int pgStatXactCommit
static int pgStatXactRollback

References pgStatXactCommit, and pgStatXactRollback.

Referenced by AtEOXact_PgStat().

◆ AtEOXact_PgStat_Relations()

void AtEOXact_PgStat_Relations ( PgStat_SubXactStatus xact_state,
bool  isCommit 
)

Definition at line 497 of file pgstat_relation.c.

498 {
500 
501  for (trans = xact_state->first; trans != NULL; trans = trans->next)
502  {
503  PgStat_TableStatus *tabstat;
504 
505  Assert(trans->nest_level == 1);
506  Assert(trans->upper == NULL);
507  tabstat = trans->parent;
508  Assert(tabstat->trans == trans);
509  /* restore pre-truncate/drop stats (if any) in case of aborted xact */
510  if (!isCommit)
512  /* count attempted actions regardless of commit/abort */
513  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
514  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
515  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
516  if (isCommit)
517  {
518  tabstat->t_counts.t_truncdropped = trans->truncdropped;
519  if (trans->truncdropped)
520  {
521  /* forget live/dead stats seen by backend thus far */
522  tabstat->t_counts.t_delta_live_tuples = 0;
523  tabstat->t_counts.t_delta_dead_tuples = 0;
524  }
525  /* insert adds a live tuple, delete removes one */
526  tabstat->t_counts.t_delta_live_tuples +=
527  trans->tuples_inserted - trans->tuples_deleted;
528  /* update and delete each create a dead tuple */
529  tabstat->t_counts.t_delta_dead_tuples +=
530  trans->tuples_updated + trans->tuples_deleted;
531  /* insert, update, delete each count as one change event */
532  tabstat->t_counts.t_changed_tuples +=
533  trans->tuples_inserted + trans->tuples_updated +
534  trans->tuples_deleted;
535  }
536  else
537  {
538  /* inserted tuples are dead, deleted tuples are unaffected */
539  tabstat->t_counts.t_delta_dead_tuples +=
540  trans->tuples_inserted + trans->tuples_updated;
541  /* an aborted xact generates no changed_tuple events */
542  }
543  tabstat->trans = NULL;
544  }
545 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:181
bool t_truncdropped
Definition: pgstat.h:179
PgStat_Counter t_changed_tuples
Definition: pgstat.h:183

References Assert(), PgStat_SubXactStatus::first, restore_truncdrop_counters(), PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, PgStat_TableCounts::t_truncdropped, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, and trans.

Referenced by AtEOXact_PgStat().

◆ AtPrepare_PgStat_Relations()

void AtPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)

Definition at line 636 of file pgstat_relation.c.

637 {
639 
640  for (trans = xact_state->first; trans != NULL; trans = trans->next)
641  {
643  TwoPhasePgStatRecord record;
644 
645  Assert(trans->nest_level == 1);
646  Assert(trans->upper == NULL);
647  tabstat = trans->parent;
648  Assert(tabstat->trans == trans);
649 
650  record.tuples_inserted = trans->tuples_inserted;
651  record.tuples_updated = trans->tuples_updated;
652  record.tuples_deleted = trans->tuples_deleted;
653  record.inserted_pre_truncdrop = trans->inserted_pre_truncdrop;
654  record.updated_pre_truncdrop = trans->updated_pre_truncdrop;
655  record.deleted_pre_truncdrop = trans->deleted_pre_truncdrop;
656  record.t_id = tabstat->t_id;
657  record.t_shared = tabstat->t_shared;
658  record.t_truncdropped = trans->truncdropped;
659 
661  &record, sizeof(TwoPhasePgStatRecord));
662  }
663 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:155
PgStat_Counter deleted_pre_truncdrop
PgStat_Counter inserted_pre_truncdrop
PgStat_Counter updated_pre_truncdrop
PgStat_Counter tuples_deleted
PgStat_Counter tuples_inserted
PgStat_Counter tuples_updated
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1259
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26

References Assert(), TwoPhasePgStatRecord::deleted_pre_truncdrop, PgStat_SubXactStatus::first, TwoPhasePgStatRecord::inserted_pre_truncdrop, PG_USED_FOR_ASSERTS_ONLY, RegisterTwoPhaseRecord(), TwoPhasePgStatRecord::t_id, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncdropped, trans, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, TWOPHASE_RM_PGSTAT_ID, and TwoPhasePgStatRecord::updated_pre_truncdrop.

Referenced by AtPrepare_PgStat().

◆ pgstat_archiver_reset_all_cb()

void pgstat_archiver_reset_all_cb ( TimestampTz  ts)

Definition at line 66 of file pgstat_archiver.c.

67 {
69 
70  /* see explanation above PgStatShared_Archiver for the reset protocol */
71  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
73  &stats_shmem->stats,
74  sizeof(stats_shmem->stats),
75  &stats_shmem->changecount);
76  stats_shmem->stats.stat_reset_timestamp = ts;
77  LWLockRelease(&stats_shmem->lock);
78 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_EXCLUSIVE
Definition: lwlock.h:104
PgStat_LocalState pgStatLocal
Definition: pgstat.c:195
static void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len, uint32 *cc)
PgStat_ArchiverStats reset_offset
PgStat_ArchiverStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:257
PgStat_ShmemControl * shmem
PgStatShared_Archiver archiver

References PgStat_ShmemControl::archiver, PgStatShared_Archiver::changecount, PgStatShared_Archiver::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, PgStatShared_Archiver::reset_offset, PgStat_LocalState::shmem, PgStat_ArchiverStats::stat_reset_timestamp, and PgStatShared_Archiver::stats.

◆ pgstat_archiver_snapshot_cb()

void pgstat_archiver_snapshot_cb ( void  )

Definition at line 81 of file pgstat_archiver.c.

82 {
85  PgStat_ArchiverStats *reset_offset = &stats_shmem->reset_offset;
87 
89  &stats_shmem->stats,
90  sizeof(stats_shmem->stats),
91  &stats_shmem->changecount);
92 
93  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
94  memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
95  LWLockRelease(&stats_shmem->lock);
96 
97  /* compensate by reset offsets */
98  if (stat_snap->archived_count == reset.archived_count)
99  {
100  stat_snap->last_archived_wal[0] = 0;
101  stat_snap->last_archived_timestamp = 0;
102  }
103  stat_snap->archived_count -= reset.archived_count;
104 
105  if (stat_snap->failed_count == reset.failed_count)
106  {
107  stat_snap->last_failed_wal[0] = 0;
108  stat_snap->last_failed_timestamp = 0;
109  }
110  stat_snap->failed_count -= reset.failed_count;
111 }
@ LW_SHARED
Definition: lwlock.h:105
void reset(void)
Definition: sql-declare.c:600
TimestampTz last_failed_timestamp
Definition: pgstat.h:256
TimestampTz last_archived_timestamp
Definition: pgstat.h:252
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:254
PgStat_Counter failed_count
Definition: pgstat.h:253
PgStat_Counter archived_count
Definition: pgstat.h:249
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:250
PgStat_Snapshot snapshot
PgStat_ArchiverStats archiver

References PgStat_ArchiverStats::archived_count, PgStat_ShmemControl::archiver, PgStat_Snapshot::archiver, PgStatShared_Archiver::changecount, PgStat_ArchiverStats::failed_count, PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, PgStatShared_Archiver::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, reset(), PgStatShared_Archiver::reset_offset, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, and PgStatShared_Archiver::stats.

◆ pgstat_attach_shmem()

void pgstat_attach_shmem ( void  )

Definition at line 213 of file pgstat_shmem.c.

214 {
215  MemoryContext oldcontext;
216 
217  Assert(pgStatLocal.dsa == NULL);
218 
219  /* stats shared memory persists for the backend lifetime */
221 
223  NULL);
225 
228 
229  MemoryContextSwitchTo(oldcontext);
230 }
void dsa_pin_mapping(dsa_area *area)
Definition: dsa.c:631
dsa_area * dsa_attach_in_place(void *place, dsm_segment *segment)
Definition: dsa.c:541
dshash_table * dshash_attach(dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg)
Definition: dshash.c:271
MemoryContext TopMemoryContext
Definition: mcxt.c:48
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static const dshash_parameters dsh_params
Definition: pgstat_shmem.c:62
dshash_table * shared_hash
dshash_table_handle hash_handle

References Assert(), PgStat_LocalState::dsa, dsa_attach_in_place(), dsa_pin_mapping(), dsh_params, dshash_attach(), PgStat_ShmemControl::hash_handle, MemoryContextSwitchTo(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shared_hash, PgStat_LocalState::shmem, and TopMemoryContext.

Referenced by pgstat_initialize().

◆ pgstat_begin_changecount_read()

static uint32 pgstat_begin_changecount_read ( uint32 cc)
inlinestatic

Definition at line 683 of file pgstat_internal.h.

684 {
685  uint32 before_cc = *cc;
686 
688 
689  pg_read_barrier();
690 
691  return before_cc;
692 }
#define pg_read_barrier()
Definition: atomics.h:158
unsigned int uint32
Definition: c.h:441
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121

References CHECK_FOR_INTERRUPTS, and pg_read_barrier.

Referenced by pgstat_copy_changecounted_stats().

◆ pgstat_begin_changecount_write()

static void pgstat_begin_changecount_write ( uint32 cc)
inlinestatic

Definition at line 661 of file pgstat_internal.h.

662 {
663  Assert((*cc & 1) == 0);
664 
666  (*cc)++;
668 }
#define pg_write_barrier()
Definition: atomics.h:159
#define START_CRIT_SECTION()
Definition: miscadmin.h:148

References Assert(), pg_write_barrier, and START_CRIT_SECTION.

Referenced by pgstat_report_archiver(), pgstat_report_bgwriter(), and pgstat_report_checkpointer().

◆ pgstat_bgwriter_reset_all_cb()

void pgstat_bgwriter_reset_all_cb ( TimestampTz  ts)

Definition at line 74 of file pgstat_bgwriter.c.

75 {
77 
78  /* see explanation above PgStatShared_BgWriter for the reset protocol */
79  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
81  &stats_shmem->stats,
82  sizeof(stats_shmem->stats),
83  &stats_shmem->changecount);
84  stats_shmem->stats.stat_reset_timestamp = ts;
85  LWLockRelease(&stats_shmem->lock);
86 }
PgStat_BgWriterStats reset_offset
PgStat_BgWriterStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:265
PgStatShared_BgWriter bgwriter

References PgStat_ShmemControl::bgwriter, PgStatShared_BgWriter::changecount, PgStatShared_BgWriter::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, PgStatShared_BgWriter::reset_offset, PgStat_LocalState::shmem, PgStat_BgWriterStats::stat_reset_timestamp, and PgStatShared_BgWriter::stats.

◆ pgstat_bgwriter_snapshot_cb()

void pgstat_bgwriter_snapshot_cb ( void  )

Definition at line 89 of file pgstat_bgwriter.c.

90 {
92  PgStat_BgWriterStats *reset_offset = &stats_shmem->reset_offset;
94 
96  &stats_shmem->stats,
97  sizeof(stats_shmem->stats),
98  &stats_shmem->changecount);
99 
100  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
101  memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
102  LWLockRelease(&stats_shmem->lock);
103 
104  /* compensate by reset offsets */
105 #define BGWRITER_COMP(fld) pgStatLocal.snapshot.bgwriter.fld -= reset.fld;
106  BGWRITER_COMP(buf_written_clean);
107  BGWRITER_COMP(maxwritten_clean);
108  BGWRITER_COMP(buf_alloc);
109 #undef BGWRITER_COMP
110 }
#define BGWRITER_COMP(fld)
PgStat_BgWriterStats bgwriter

References PgStat_ShmemControl::bgwriter, PgStat_Snapshot::bgwriter, BGWRITER_COMP, PgStatShared_BgWriter::changecount, PgStatShared_BgWriter::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, reset(), PgStatShared_BgWriter::reset_offset, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, and PgStatShared_BgWriter::stats.

◆ pgstat_checkpointer_reset_all_cb()

void pgstat_checkpointer_reset_all_cb ( TimestampTz  ts)

Definition at line 82 of file pgstat_checkpointer.c.

83 {
85 
86  /* see explanation above PgStatShared_Checkpointer for the reset protocol */
87  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
89  &stats_shmem->stats,
90  sizeof(stats_shmem->stats),
91  &stats_shmem->changecount);
92  LWLockRelease(&stats_shmem->lock);
93 }
PgStat_CheckpointerStats reset_offset
PgStat_CheckpointerStats stats
PgStatShared_Checkpointer checkpointer

References PgStatShared_Checkpointer::changecount, PgStat_ShmemControl::checkpointer, PgStatShared_Checkpointer::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, PgStatShared_Checkpointer::reset_offset, PgStat_LocalState::shmem, and PgStatShared_Checkpointer::stats.

◆ pgstat_checkpointer_snapshot_cb()

void pgstat_checkpointer_snapshot_cb ( void  )

Definition at line 96 of file pgstat_checkpointer.c.

97 {
99  PgStat_CheckpointerStats *reset_offset = &stats_shmem->reset_offset;
101 
103  &stats_shmem->stats,
104  sizeof(stats_shmem->stats),
105  &stats_shmem->changecount);
106 
107  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
108  memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
109  LWLockRelease(&stats_shmem->lock);
110 
111  /* compensate by reset offsets */
112 #define CHECKPOINTER_COMP(fld) pgStatLocal.snapshot.checkpointer.fld -= reset.fld;
113  CHECKPOINTER_COMP(timed_checkpoints);
114  CHECKPOINTER_COMP(requested_checkpoints);
115  CHECKPOINTER_COMP(checkpoint_write_time);
116  CHECKPOINTER_COMP(checkpoint_sync_time);
117  CHECKPOINTER_COMP(buf_written_checkpoints);
118  CHECKPOINTER_COMP(buf_written_backend);
119  CHECKPOINTER_COMP(buf_fsync_backend);
120 #undef CHECKPOINTER_COMP
121 }
#define CHECKPOINTER_COMP(fld)
PgStat_CheckpointerStats checkpointer

References PgStatShared_Checkpointer::changecount, PgStat_ShmemControl::checkpointer, PgStat_Snapshot::checkpointer, CHECKPOINTER_COMP, PgStatShared_Checkpointer::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, reset(), PgStatShared_Checkpointer::reset_offset, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, and PgStatShared_Checkpointer::stats.

◆ pgstat_cmp_hash_key()

static int pgstat_cmp_hash_key ( const void *  a,
const void *  b,
size_t  size,
void *  arg 
)
inlinestatic

Definition at line 738 of file pgstat_internal.h.

739 {
740  AssertArg(size == sizeof(PgStat_HashKey) && arg == NULL);
741  return memcmp(a, b, sizeof(PgStat_HashKey));
742 }
#define AssertArg(condition)
Definition: c.h:806
int b
Definition: isn.c:70
int a
Definition: isn.c:69
void * arg

References a, arg, AssertArg, and b.

◆ pgstat_copy_changecounted_stats()

static void pgstat_copy_changecounted_stats ( void *  dst,
void *  src,
size_t  len,
uint32 cc 
)
inlinestatic

Definition at line 722 of file pgstat_internal.h.

724 {
725  uint32 cc_before;
726 
727  do
728  {
729  cc_before = pgstat_begin_changecount_read(cc);
730 
731  memcpy(dst, src, len);
732  }
733  while (!pgstat_end_changecount_read(cc, cc_before));
734 }
const void size_t len
static uint32 pgstat_begin_changecount_read(uint32 *cc)
static bool pgstat_end_changecount_read(uint32 *cc, uint32 cc_before)

References len, pgstat_begin_changecount_read(), and pgstat_end_changecount_read().

Referenced by pgstat_archiver_reset_all_cb(), pgstat_archiver_snapshot_cb(), pgstat_bgwriter_reset_all_cb(), pgstat_bgwriter_snapshot_cb(), pgstat_checkpointer_reset_all_cb(), and pgstat_checkpointer_snapshot_cb().

◆ pgstat_create_transactional()

void pgstat_create_transactional ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid 
)

Definition at line 366 of file pgstat_xact.c.

367 {
368  if (pgstat_get_entry_ref(kind, dboid, objoid, false, NULL))
369  {
371  errmsg("resetting existing stats for type %s, db=%u, oid=%u",
372  (pgstat_get_kind_info(kind))->name, dboid, objoid));
373 
374  pgstat_reset(kind, dboid, objoid);
375  }
376 
377  create_drop_transactional_internal(kind, dboid, objoid, /* create */ true);
378 }
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define WARNING
Definition: elog.h:30
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:705
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1211
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:393
static void create_drop_transactional_internal(PgStat_Kind kind, Oid dboid, Oid objoid, bool is_create)
Definition: pgstat_xact.c:340

References create_drop_transactional_internal(), ereport, errmsg(), name, pgstat_get_entry_ref(), pgstat_get_kind_info(), pgstat_reset(), and WARNING.

Referenced by pgstat_create_function(), pgstat_create_relation(), and pgstat_create_subscription().

◆ pgstat_database_flush_cb()

bool pgstat_database_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 359 of file pgstat_database.c.

360 {
361  PgStatShared_Database *sharedent;
362  PgStat_StatDBEntry *pendingent;
363 
364  pendingent = (PgStat_StatDBEntry *) entry_ref->pending;
365  sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
366 
367  if (!pgstat_lock_entry(entry_ref, nowait))
368  return false;
369 
370 #define PGSTAT_ACCUM_DBCOUNT(item) \
371  (sharedent)->stats.item += (pendingent)->item
372 
373  PGSTAT_ACCUM_DBCOUNT(n_xact_commit);
374  PGSTAT_ACCUM_DBCOUNT(n_xact_rollback);
375  PGSTAT_ACCUM_DBCOUNT(n_blocks_fetched);
376  PGSTAT_ACCUM_DBCOUNT(n_blocks_hit);
377 
378  PGSTAT_ACCUM_DBCOUNT(n_tuples_returned);
379  PGSTAT_ACCUM_DBCOUNT(n_tuples_fetched);
380  PGSTAT_ACCUM_DBCOUNT(n_tuples_inserted);
381  PGSTAT_ACCUM_DBCOUNT(n_tuples_updated);
382  PGSTAT_ACCUM_DBCOUNT(n_tuples_deleted);
383 
384  /* last_autovac_time is reported immediately */
385  Assert(pendingent->last_autovac_time == 0);
386 
387  PGSTAT_ACCUM_DBCOUNT(n_conflict_tablespace);
388  PGSTAT_ACCUM_DBCOUNT(n_conflict_lock);
389  PGSTAT_ACCUM_DBCOUNT(n_conflict_snapshot);
390  PGSTAT_ACCUM_DBCOUNT(n_conflict_bufferpin);
391  PGSTAT_ACCUM_DBCOUNT(n_conflict_startup_deadlock);
392 
393  PGSTAT_ACCUM_DBCOUNT(n_temp_bytes);
394  PGSTAT_ACCUM_DBCOUNT(n_temp_files);
395  PGSTAT_ACCUM_DBCOUNT(n_deadlocks);
396 
397  /* checksum failures are reported immediately */
398  Assert(pendingent->n_checksum_failures == 0);
399  Assert(pendingent->last_checksum_failure == 0);
400 
401  PGSTAT_ACCUM_DBCOUNT(n_block_read_time);
402  PGSTAT_ACCUM_DBCOUNT(n_block_write_time);
403 
404  PGSTAT_ACCUM_DBCOUNT(n_sessions);
405  PGSTAT_ACCUM_DBCOUNT(total_session_time);
406  PGSTAT_ACCUM_DBCOUNT(total_active_time);
407  PGSTAT_ACCUM_DBCOUNT(total_idle_in_xact_time);
408  PGSTAT_ACCUM_DBCOUNT(n_sessions_abandoned);
409  PGSTAT_ACCUM_DBCOUNT(n_sessions_fatal);
410  PGSTAT_ACCUM_DBCOUNT(n_sessions_killed);
411 #undef PGSTAT_ACCUM_DBCOUNT
412 
413  pgstat_unlock_entry(entry_ref);
414 
415  memset(pendingent, 0, sizeof(*pendingent));
416 
417  return true;
418 }
#define PGSTAT_ACCUM_DBCOUNT(item)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:583
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:571
PgStatShared_Common * shared_stats
TimestampTz last_checksum_failure
Definition: pgstat.h:300
TimestampTz last_autovac_time
Definition: pgstat.h:290
PgStat_Counter n_checksum_failures
Definition: pgstat.h:299

References Assert(), PgStat_StatDBEntry::last_autovac_time, PgStat_StatDBEntry::last_checksum_failure, PgStat_StatDBEntry::n_checksum_failures, PgStat_EntryRef::pending, PGSTAT_ACCUM_DBCOUNT, pgstat_lock_entry(), pgstat_unlock_entry(), and PgStat_EntryRef::shared_stats.

◆ pgstat_database_reset_timestamp_cb()

void pgstat_database_reset_timestamp_cb ( PgStatShared_Common header,
TimestampTz  ts 
)

Definition at line 421 of file pgstat_database.c.

422 {
423  ((PgStatShared_Database *) header)->stats.stat_reset_timestamp = ts;
424 }
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:212

References header().

◆ pgstat_delete_pending_entry()

void pgstat_delete_pending_entry ( PgStat_EntryRef entry_ref)

Definition at line 1104 of file pgstat.c.

1105 {
1106  PgStat_Kind kind = entry_ref->shared_entry->key.kind;
1107  const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
1108  void *pending_data = entry_ref->pending;
1109 
1110  Assert(pending_data != NULL);
1111  /* !fixed_amount stats should be handled explicitly */
1112  Assert(!pgstat_get_kind_info(kind)->fixed_amount);
1113 
1114  if (kind_info->delete_pending_cb)
1115  kind_info->delete_pending_cb(entry_ref);
1116 
1117  pfree(pending_data);
1118  entry_ref->pending = NULL;
1119 
1120  dlist_delete(&entry_ref->pending_node);
1121 }
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
PgStat_Kind
Definition: pgstat.h:36
PgStatShared_HashEntry * shared_entry
dlist_node pending_node
PgStat_Kind kind
void(* delete_pending_cb)(PgStat_EntryRef *sr)

References Assert(), PgStat_KindInfo::delete_pending_cb, dlist_delete(), PgStatShared_HashEntry::key, PgStat_HashKey::kind, PgStat_EntryRef::pending, PgStat_EntryRef::pending_node, pfree(), pgstat_get_kind_info(), and PgStat_EntryRef::shared_entry.

Referenced by pgstat_flush_pending_entries(), and pgstat_release_entry_ref().

◆ pgstat_detach_shmem()

void pgstat_detach_shmem ( void  )

Definition at line 233 of file pgstat_shmem.c.

234 {
236 
237  /* we shouldn't leave references to shared stats */
239 
241  pgStatLocal.shared_hash = NULL;
242 
244  pgStatLocal.dsa = NULL;
245 }
void dsa_detach(dsa_area *area)
Definition: dsa.c:1910
void dshash_detach(dshash_table *hash_table)
Definition: dshash.c:310
static void pgstat_release_all_entry_refs(bool discard_pending)
Definition: pgstat_shmem.c:694

References Assert(), PgStat_LocalState::dsa, dsa_detach(), dshash_detach(), pgstat_release_all_entry_refs(), pgStatLocal, and PgStat_LocalState::shared_hash.

Referenced by pgstat_shutdown_hook().

◆ pgstat_drop_all_entries()

void pgstat_drop_all_entries ( void  )

Definition at line 875 of file pgstat_shmem.c.

876 {
877  dshash_seq_status hstat;
879  uint64 not_freed_count = 0;
880 
881  dshash_seq_init(&hstat, pgStatLocal.shared_hash, true);
882  while ((ps = dshash_seq_next(&hstat)) != NULL)
883  {
884  if (ps->dropped)
885  continue;
886 
887  if (!pgstat_drop_entry_internal(ps, &hstat))
888  not_freed_count++;
889  }
890  dshash_seq_term(&hstat);
891 
892  if (not_freed_count > 0)
894 }
void dshash_seq_init(dshash_seq_status *status, dshash_table *hash_table, bool exclusive)
Definition: dshash.c:612
void dshash_seq_term(dshash_seq_status *status)
Definition: dshash.c:723
void * dshash_seq_next(dshash_seq_status *status)
Definition: dshash.c:631
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:608
static bool pgstat_drop_entry_internal(PgStatShared_HashEntry *shent, dshash_seq_status *hstat)
Definition: pgstat_shmem.c:753

References PgStatShared_HashEntry::dropped, dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), pgstat_drop_entry_internal(), pgstat_request_entry_refs_gc(), pgStatLocal, and PgStat_LocalState::shared_hash.

Referenced by pgstat_reset_after_failure().

◆ pgstat_drop_entry()

bool pgstat_drop_entry ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid 
)

Definition at line 838 of file pgstat_shmem.c.

839 {
840  PgStat_HashKey key = {.kind = kind,.dboid = dboid,.objoid = objoid};
841  PgStatShared_HashEntry *shent;
842  bool freed = true;
843 
844  /* delete local reference */
845  if (pgStatEntryRefHash)
846  {
847  PgStat_EntryRefHashEntry *lohashent =
848  pgstat_entry_ref_hash_lookup(pgStatEntryRefHash, key);
849 
850  if (lohashent)
851  pgstat_release_entry_ref(lohashent->key, lohashent->entry_ref,
852  true);
853  }
854 
855  /* mark entry in shared hashtable as deleted, drop if possible */
856  shent = dshash_find(pgStatLocal.shared_hash, &key, true);
857  if (shent)
858  {
859  freed = pgstat_drop_entry_internal(shent, NULL);
860 
861  /*
862  * Database stats contain other stats. Drop those as well when
863  * dropping the database. XXX: Perhaps this should be done in a
864  * slightly more principled way? But not obvious what that'd look
865  * like, and so far this is the only case...
866  */
867  if (key.kind == PGSTAT_KIND_DATABASE)
869  }
870 
871  return freed;
872 }
void * dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
Definition: dshash.c:393
@ PGSTAT_KIND_DATABASE
Definition: pgstat.h:41
static void pgstat_release_entry_ref(PgStat_HashKey key, PgStat_EntryRef *entry_ref, bool discard_pending)
Definition: pgstat_shmem.c:517
static void pgstat_drop_database_and_contents(Oid dboid)
Definition: pgstat_shmem.c:788
static pgstat_entry_ref_hash_hash * pgStatEntryRefHash
Definition: pgstat_shmem.c:81
PgStat_EntryRef * entry_ref
Definition: pgstat_shmem.c:28

References dshash_find(), PgStat_EntryRefHashEntry::entry_ref, PgStat_EntryRefHashEntry::key, sort-test::key, pgstat_drop_database_and_contents(), pgstat_drop_entry_internal(), PGSTAT_KIND_DATABASE, pgstat_release_entry_ref(), pgStatEntryRefHash, pgStatLocal, and PgStat_LocalState::shared_hash.

Referenced by AtEOSubXact_PgStat_DroppedStats(), AtEOXact_PgStat_DroppedStats(), pgstat_drop_replslot(), pgstat_execute_transactional_drops(), and pgstat_init_function_usage().

◆ pgstat_drop_transactional()

void pgstat_drop_transactional ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid 
)

Definition at line 388 of file pgstat_xact.c.

389 {
390  create_drop_transactional_internal(kind, dboid, objoid, /* create */ false);
391 }

References create_drop_transactional_internal().

Referenced by pgstat_drop_database(), pgstat_drop_function(), pgstat_drop_relation(), and pgstat_drop_subscription().

◆ pgstat_end_changecount_read()

static bool pgstat_end_changecount_read ( uint32 cc,
uint32  cc_before 
)
inlinestatic

Definition at line 698 of file pgstat_internal.h.

699 {
700  uint32 after_cc;
701 
702  pg_read_barrier();
703 
704  after_cc = *cc;
705 
706  /* was a write in progress when we started? */
707  if (before_cc & 1)
708  return false;
709 
710  /* did writes start and complete while we read? */
711  return before_cc == after_cc;
712 }

References pg_read_barrier.

Referenced by pgstat_copy_changecounted_stats().

◆ pgstat_end_changecount_write()

static void pgstat_end_changecount_write ( uint32 cc)
inlinestatic

Definition at line 671 of file pgstat_internal.h.

672 {
673  Assert((*cc & 1) == 1);
674 
676 
677  (*cc)++;
678 
680 }
#define END_CRIT_SECTION()
Definition: miscadmin.h:150

References Assert(), END_CRIT_SECTION, and pg_write_barrier.

Referenced by pgstat_report_archiver(), pgstat_report_bgwriter(), and pgstat_report_checkpointer().

◆ pgstat_fetch_entry()

void* pgstat_fetch_entry ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid 
)

Definition at line 779 of file pgstat.c.

780 {
782  PgStat_EntryRef *entry_ref;
783  void *stats_data;
784  const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
785 
786  /* should be called from backends */
788  AssertArg(!kind_info->fixed_amount);
789 
791 
792  key.kind = kind;
793  key.dboid = dboid;
794  key.objoid = objoid;
795 
796  /* if we need to build a full snapshot, do so */
799 
800  /* if caching is desired, look up in cache */
802  {
803  PgStat_SnapshotEntry *entry = NULL;
804 
805  entry = pgstat_snapshot_lookup(pgStatLocal.snapshot.stats, key);
806 
807  if (entry)
808  return entry->data;
809 
810  /*
811  * If we built a full snapshot and the key is not in
812  * pgStatLocal.snapshot.stats, there are no matching stats.
813  */
815  return NULL;
816  }
817 
819 
820  entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL);
821 
822  if (entry_ref == NULL || entry_ref->shared_entry->dropped)
823  {
824  /* create empty entry when using PGSTAT_FETCH_CONSISTENCY_CACHE */
826  {
827  PgStat_SnapshotEntry *entry = NULL;
828  bool found;
829 
830  entry = pgstat_snapshot_insert(pgStatLocal.snapshot.stats, key, &found);
831  Assert(!found);
832  entry->data = NULL;
833  }
834  return NULL;
835  }
836 
837  /*
838  * Allocate in caller's context for PGSTAT_FETCH_CONSISTENCY_NONE,
839  * otherwise we could quickly end up with a fair bit of memory used due to
840  * repeated accesses.
841  */
843  stats_data = palloc(kind_info->shared_data_len);
844  else
846  kind_info->shared_data_len);
847  memcpy(stats_data,
848  pgstat_get_entry_data(kind, entry_ref->shared_stats),
849  kind_info->shared_data_len);
850 
852  {
853  PgStat_SnapshotEntry *entry = NULL;
854  bool found;
855 
856  entry = pgstat_snapshot_insert(pgStatLocal.snapshot.stats, key, &found);
857  entry->data = stats_data;
858  }
859 
860  return stats_data;
861 }
bool IsUnderPostmaster
Definition: globals.c:113
bool IsPostmasterEnvironment
Definition: globals.c:112
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
void * palloc(Size size)
Definition: mcxt.c:1068
int pgstat_fetch_consistency
Definition: pgstat.c:187
static void pgstat_prep_snapshot(void)
Definition: pgstat.c:913
static void pgstat_build_snapshot(void)
Definition: pgstat.c:931
@ PGSTAT_FETCH_CONSISTENCY_NONE
Definition: pgstat.h:69
@ PGSTAT_FETCH_CONSISTENCY_CACHE
Definition: pgstat.h:70
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
Definition: pgstat.h:71
static void * pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry)
MemoryContext context
PgStat_FetchConsistency mode
struct pgstat_snapshot_hash * stats

References Assert(), AssertArg, PgStat_Snapshot::context, PgStat_SnapshotEntry::data, PgStatShared_HashEntry::dropped, PgStat_KindInfo::fixed_amount, IsPostmasterEnvironment, IsUnderPostmaster, sort-test::key, MemoryContextAlloc(), PgStat_Snapshot::mode, palloc(), pgstat_build_snapshot(), pgstat_fetch_consistency, PGSTAT_FETCH_CONSISTENCY_CACHE, PGSTAT_FETCH_CONSISTENCY_NONE, PGSTAT_FETCH_CONSISTENCY_SNAPSHOT, pgstat_get_entry_data(), pgstat_get_entry_ref(), pgstat_get_kind_info(), pgstat_prep_snapshot(), pgStatLocal, PgStat_KindInfo::shared_data_len, PgStat_EntryRef::shared_entry, PgStat_EntryRef::shared_stats, PgStat_LocalState::snapshot, and PgStat_Snapshot::stats.

Referenced by pgstat_fetch_replslot(), pgstat_fetch_stat_dbentry(), pgstat_fetch_stat_funcentry(), pgstat_fetch_stat_subscription(), and pgstat_fetch_stat_tabentry_ext().

◆ pgstat_fetch_pending_entry()

PgStat_EntryRef* pgstat_fetch_pending_entry ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid 
)

Definition at line 1091 of file pgstat.c.

1092 {
1093  PgStat_EntryRef *entry_ref;
1094 
1095  entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL);
1096 
1097  if (entry_ref == NULL || entry_ref->pending == NULL)
1098  return NULL;
1099 
1100  return entry_ref;
1101 }

References PgStat_EntryRef::pending, and pgstat_get_entry_ref().

Referenced by find_funcstat_entry(), and find_tabstat_entry().

◆ pgstat_flush_wal()

bool pgstat_flush_wal ( bool  nowait)

Definition at line 68 of file pgstat_wal.c.

69 {
70  PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal;
71  WalUsage diff = {0};
72 
74  Assert(pgStatLocal.shmem != NULL &&
76 
77  /*
78  * This function can be called even if nothing at all has happened. Avoid
79  * taking lock for nothing in that case.
80  */
82  return false;
83 
84  /*
85  * We don't update the WAL usage portion of the local WalStats elsewhere.
86  * Calculate how much WAL usage counters were increased by subtracting the
87  * previous counters from the current ones.
88  */
93 
94  if (!nowait)
95  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
96  else if (!LWLockConditionalAcquire(&stats_shmem->lock, LW_EXCLUSIVE))
97  return true;
98 
99 #define WALSTAT_ACC(fld) stats_shmem->stats.fld += PendingWalStats.fld
100  WALSTAT_ACC(wal_records);
101  WALSTAT_ACC(wal_fpi);
102  WALSTAT_ACC(wal_bytes);
103  WALSTAT_ACC(wal_buffers_full);
104  WALSTAT_ACC(wal_write);
105  WALSTAT_ACC(wal_sync);
106  WALSTAT_ACC(wal_write_time);
107  WALSTAT_ACC(wal_sync_time);
108 #undef WALSTAT_ACC
109 
110  LWLockRelease(&stats_shmem->lock);
111 
112  /*
113  * Save the current counters for the subsequent calculation of WAL usage.
114  */
116 
117  /*
118  * Clear out the statistics buffer, so it can be re-used.
119  */
120  MemSet(&PendingWalStats, 0, sizeof(PendingWalStats));
121 
122  return false;
123 }
#define MemSet(start, val, len)
Definition: c.h:1008
WalUsage pgWalUsage
Definition: instrument.c:22
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
Definition: instrument.c:280
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1367
#define WALSTAT_ACC(fld)
PgStat_WalStats PendingWalStats
Definition: pgstat_wal.c:24
bool pgstat_have_pending_wal(void)
Definition: pgstat_wal.c:144
static WalUsage prevWalUsage
Definition: pgstat_wal.c:32
PgStatShared_Wal wal
uint64 wal_bytes
Definition: pgstat.h:389
PgStat_Counter wal_fpi
Definition: pgstat.h:388
PgStat_Counter wal_records
Definition: pgstat.h:387
uint64 wal_bytes
Definition: instrument.h:53
int64 wal_fpi
Definition: instrument.h:52
int64 wal_records
Definition: instrument.h:51

References Assert(), PgStat_ShmemControl::is_shutdown, IsPostmasterEnvironment, IsUnderPostmaster, PgStatShared_Wal::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockRelease(), MemSet, PendingWalStats, pgstat_have_pending_wal(), pgStatLocal, pgWalUsage, prevWalUsage, PgStat_LocalState::shmem, PgStat_ShmemControl::wal, WalUsage::wal_bytes, PgStat_WalStats::wal_bytes, WalUsage::wal_fpi, PgStat_WalStats::wal_fpi, WalUsage::wal_records, PgStat_WalStats::wal_records, WALSTAT_ACC, and WalUsageAccumDiff().

Referenced by pgstat_report_stat(), and pgstat_report_wal().

◆ pgstat_function_flush_cb()

bool pgstat_function_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 193 of file pgstat_function.c.

194 {
195  PgStat_BackendFunctionEntry *localent;
196  PgStatShared_Function *shfuncent;
197 
198  localent = (PgStat_BackendFunctionEntry *) entry_ref->pending;
199  shfuncent = (PgStatShared_Function *) entry_ref->shared_stats;
200 
201  /* localent always has non-zero content */
202 
203  if (!pgstat_lock_entry(entry_ref, nowait))
204  return false;
205 
206  shfuncent->stats.f_numcalls += localent->f_counts.f_numcalls;
207  shfuncent->stats.f_total_time +=
209  shfuncent->stats.f_self_time +=
211 
212  pgstat_unlock_entry(entry_ref);
213 
214  return true;
215 }
#define INSTR_TIME_GET_MICROSEC(t)
Definition: instr_time.h:205
PgStat_StatFuncEntry stats
PgStat_FunctionCounts f_counts
Definition: pgstat.h:119
instr_time f_total_time
Definition: pgstat.h:109
PgStat_Counter f_numcalls
Definition: pgstat.h:108
instr_time f_self_time
Definition: pgstat.h:110
PgStat_Counter f_self_time
Definition: pgstat.h:319
PgStat_Counter f_total_time
Definition: pgstat.h:318
PgStat_Counter f_numcalls
Definition: pgstat.h:316

References PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCounts::f_numcalls, PgStat_StatFuncEntry::f_numcalls, PgStat_FunctionCounts::f_self_time, PgStat_StatFuncEntry::f_self_time, PgStat_FunctionCounts::f_total_time, PgStat_StatFuncEntry::f_total_time, INSTR_TIME_GET_MICROSEC, PgStat_EntryRef::pending, pgstat_lock_entry(), pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_Function::stats.

◆ pgstat_get_entry_data()

static void * pgstat_get_entry_data ( PgStat_Kind  kind,
PgStatShared_Common entry 
)
inlinestatic

Definition at line 773 of file pgstat_internal.h.

774 {
775  size_t off = pgstat_get_kind_info(kind)->shared_data_off;
776 
777  Assert(off != 0 && off < PG_UINT32_MAX);
778 
779  return ((char *) (entry)) + off;
780 }
#define PG_UINT32_MAX
Definition: c.h:525
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1211

References Assert(), PG_UINT32_MAX, pgstat_get_kind_info(), and PgStat_KindInfo::shared_data_off.

Referenced by pgstat_build_snapshot(), pgstat_fetch_entry(), pgstat_read_statsfile(), pgstat_reinit_entry(), pgstat_write_statsfile(), and shared_stat_reset_contents().

◆ pgstat_get_entry_len()

static size_t pgstat_get_entry_len ( PgStat_Kind  kind)
inlinestatic

◆ pgstat_get_entry_ref()

PgStat_EntryRef* pgstat_get_entry_ref ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid,
bool  create,
bool found 
)

Definition at line 393 of file pgstat_shmem.c.

395 {
396  PgStat_HashKey key = {.kind = kind,.dboid = dboid,.objoid = objoid};
397  PgStatShared_HashEntry *shhashent;
398  PgStatShared_Common *shheader = NULL;
399  PgStat_EntryRef *entry_ref;
400 
401  /*
402  * passing in created_entry only makes sense if we possibly could create
403  * entry.
404  */
405  AssertArg(create || created_entry == NULL);
407  Assert(pgStatLocal.shared_hash != NULL);
409 
412 
413  if (created_entry != NULL)
414  *created_entry = false;
415 
416  /*
417  * Check if other backends dropped stats that could not be deleted because
418  * somebody held references to it. If so, check this backend's references.
419  * This is not expected to happen often. The location of the check is a
420  * bit random, but this is a relatively frequently called path, so better
421  * than most.
422  */
425 
426  /*
427  * First check the lookup cache hashtable in local memory. If we find a
428  * match here we can avoid taking locks / causing contention.
429  */
430  if (pgstat_get_entry_ref_cached(key, &entry_ref))
431  return entry_ref;
432 
433  Assert(entry_ref != NULL);
434 
435  /*
436  * Do a lookup in the hash table first - it's quite likely that the entry
437  * already exists, and that way we only need a shared lock.
438  */
439  shhashent = dshash_find(pgStatLocal.shared_hash, &key, false);
440 
441  if (create && !shhashent)
442  {
443  bool shfound;
444 
445  /*
446  * It's possible that somebody created the entry since the above
447  * lookup. If so, fall through to the same path as if we'd have if it
448  * already had been created before the dshash_find() calls.
449  */
450  shhashent = dshash_find_or_insert(pgStatLocal.shared_hash, &key, &shfound);
451  if (!shfound)
452  {
453  shheader = pgstat_init_entry(kind, shhashent);
454  pgstat_acquire_entry_ref(entry_ref, shhashent, shheader);
455 
456  if (created_entry != NULL)
457  *created_entry = true;
458 
459  return entry_ref;
460  }
461  }
462 
463  if (!shhashent)
464  {
465  /*
466  * If we're not creating, delete the reference again. In all
467  * likelihood it's just a stats lookup - no point wasting memory for a
468  * shared ref to nothing...
469  */
470  pgstat_release_entry_ref(key, entry_ref, false);
471 
472  return NULL;
473  }
474  else
475  {
476  /*
477  * Can get here either because dshash_find() found a match, or if
478  * dshash_find_or_insert() found a concurrently inserted entry.
479  */
480 
481  if (shhashent->dropped && create)
482  {
483  /*
484  * There are legitimate cases where the old stats entry might not
485  * yet have been dropped by the time it's reused. The most obvious
486  * case are replication slot stats, where a new slot can be
487  * created with the same index just after dropping. But oid
488  * wraparound can lead to other cases as well. We just reset the
489  * stats to their plain state.
490  */
491  shheader = pgstat_reinit_entry(kind, shhashent);
492  pgstat_acquire_entry_ref(entry_ref, shhashent, shheader);
493 
494  if (created_entry != NULL)
495  *created_entry = true;
496 
497  return entry_ref;
498  }
499  else if (shhashent->dropped)
500  {
502  pgstat_release_entry_ref(key, entry_ref, false);
503 
504  return NULL;
505  }
506  else
507  {
508  shheader = dsa_get_address(pgStatLocal.dsa, shhashent->body);
509  pgstat_acquire_entry_ref(entry_ref, shhashent, shheader);
510 
511  return entry_ref;
512  }
513  }
514 }
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition: dsa.c:932
void dshash_release_lock(dshash_table *hash_table, void *entry)
Definition: dshash.c:569
void * dshash_find_or_insert(dshash_table *hash_table, const void *key, bool *found)
Definition: dshash.c:438
#define pgstat_assert_is_up()
static void pgstat_setup_memcxt(void)
Definition: pgstat_shmem.c:975
PgStatShared_Common * pgstat_init_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
Definition: pgstat_shmem.c:254
static void pgstat_setup_shared_refs(void)
Definition: pgstat_shmem.c:302
static PgStatShared_Common * pgstat_reinit_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
Definition: pgstat_shmem.c:283
static void pgstat_acquire_entry_ref(PgStat_EntryRef *entry_ref, PgStatShared_HashEntry *shhashent, PgStatShared_Common *shheader)
Definition: pgstat_shmem.c:318
static bool pgstat_get_entry_ref_cached(PgStat_HashKey key, PgStat_EntryRef **entry_ref_p)
Definition: pgstat_shmem.c:337
static void pgstat_gc_entry_refs(void)
Definition: pgstat_shmem.c:630
static bool pgstat_need_entry_refs_gc(void)
Definition: pgstat_shmem.c:614

References Assert(), AssertArg, PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), dshash_find(), dshash_find_or_insert(), dshash_release_lock(), PgStat_ShmemControl::is_shutdown, sort-test::key, pgstat_acquire_entry_ref(), pgstat_assert_is_up, pgstat_gc_entry_refs(), pgstat_get_entry_ref_cached(), pgstat_init_entry(), pgstat_need_entry_refs_gc(), pgstat_reinit_entry(), pgstat_release_entry_ref(), pgstat_setup_memcxt(), pgstat_setup_shared_refs(), pgStatLocal, PgStat_LocalState::shared_hash, and PgStat_LocalState::shmem.

Referenced by pgstat_create_transactional(), pgstat_fetch_entry(), pgstat_fetch_pending_entry(), pgstat_get_entry_ref_locked(), pgstat_have_entry(), pgstat_prep_pending_entry(), and pgstat_reset_entry().

◆ pgstat_get_entry_ref_locked()

PgStat_EntryRef* pgstat_get_entry_ref_locked ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid,
bool  nowait 
)

Definition at line 592 of file pgstat_shmem.c.

594 {
595  PgStat_EntryRef *entry_ref;
596 
597  /* find shared table stats entry corresponding to the local entry */
598  entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, true, NULL);
599 
600  /* lock the shared entry to protect the content, skip if failed */
601  if (!pgstat_lock_entry(entry_ref, nowait))
602  return NULL;
603 
604  return entry_ref;
605 }

References pgstat_get_entry_ref(), and pgstat_lock_entry().

Referenced by pgstat_acquire_replslot(), pgstat_copy_relation_stats(), pgstat_create_replslot(), pgstat_report_analyze(), pgstat_report_autovac(), pgstat_report_checksum_failures_in_db(), pgstat_report_replslot(), pgstat_report_vacuum(), and pgstat_reset_database_timestamp().

◆ pgstat_get_kind_info()

◆ pgstat_get_xact_stack_level()

PgStat_SubXactStatus* pgstat_get_xact_stack_level ( int  nest_level)

Definition at line 243 of file pgstat_xact.c.

244 {
245  PgStat_SubXactStatus *xact_state;
246 
247  xact_state = pgStatXactStack;
248  if (xact_state == NULL || xact_state->nest_level != nest_level)
249  {
250  xact_state = (PgStat_SubXactStatus *)
252  sizeof(PgStat_SubXactStatus));
253  dlist_init(&xact_state->pending_drops);
254  xact_state->pending_drops_count = 0;
255  xact_state->nest_level = nest_level;
256  xact_state->prev = pgStatXactStack;
257  xact_state->first = NULL;
258  pgStatXactStack = xact_state;
259  }
260  return xact_state;
261 }
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
MemoryContext TopTransactionContext
Definition: mcxt.c:53
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat_xact.c:34
struct PgStat_SubXactStatus * prev

References dlist_init(), PgStat_SubXactStatus::first, MemoryContextAlloc(), PgStat_SubXactStatus::nest_level, PgStat_SubXactStatus::pending_drops, PgStat_SubXactStatus::pending_drops_count, pgStatXactStack, PgStat_SubXactStatus::prev, and TopTransactionContext.

Referenced by add_tabstat_xact_level(), AtEOSubXact_PgStat_DroppedStats(), AtEOSubXact_PgStat_Relations(), and create_drop_transactional_internal().

◆ pgstat_hash_hash_key()

static uint32 pgstat_hash_hash_key ( const void *  d,
size_t  size,
void *  arg 
)
inlinestatic

Definition at line 745 of file pgstat_internal.h.

746 {
747  const PgStat_HashKey *key = (PgStat_HashKey *) d;
748  uint32 hash;
749 
750  AssertArg(size == sizeof(PgStat_HashKey) && arg == NULL);
751 
752  hash = murmurhash32(key->kind);
753  hash = hash_combine(hash, murmurhash32(key->dboid));
754  hash = hash_combine(hash, murmurhash32(key->objoid));
755 
756  return hash;
757 }
static uint32 hash_combine(uint32 a, uint32 b)
Definition: hashfn.h:68
static uint32 murmurhash32(uint32 data)
Definition: hashfn.h:92
static unsigned hash(unsigned *uv, int n)
Definition: rege_dfa.c:715

References arg, AssertArg, hash(), hash_combine(), sort-test::key, and murmurhash32().

◆ pgstat_have_pending_wal()

bool pgstat_have_pending_wal ( void  )

Definition at line 144 of file pgstat_wal.c.

145 {
147  PendingWalStats.wal_write != 0 ||
149 }
PgStat_Counter wal_write
Definition: pgstat.h:391
PgStat_Counter wal_sync
Definition: pgstat.h:392

References PendingWalStats, pgWalUsage, prevWalUsage, WalUsage::wal_records, PgStat_WalStats::wal_sync, and PgStat_WalStats::wal_write.

Referenced by pgstat_flush_wal(), and pgstat_report_stat().

◆ pgstat_init_entry()

PgStatShared_Common* pgstat_init_entry ( PgStat_Kind  kind,
PgStatShared_HashEntry shhashent 
)

Definition at line 254 of file pgstat_shmem.c.

256 {
257  /* Create new stats entry. */
258  dsa_pointer chunk;
259  PgStatShared_Common *shheader;
260 
261  /*
262  * Initialize refcount to 1, marking it as valid / not dropped. The entry
263  * can't be freed before the initialization because it can't be found as
264  * long as we hold the dshash partition lock. Caller needs to increase
265  * further if a longer lived reference is needed.
266  */
267  pg_atomic_init_u32(&shhashent->refcount, 1);
268  shhashent->dropped = false;
269 
270  chunk = dsa_allocate0(pgStatLocal.dsa, pgstat_get_kind_info(kind)->shared_size);
271  shheader = dsa_get_address(pgStatLocal.dsa, chunk);
272  shheader->magic = 0xdeadbeef;
273 
274  /* Link the new entry from the hash entry. */
275  shhashent->body = chunk;
276 
278 
279  return shheader;
280 }
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:223
#define dsa_allocate0(area, size)
Definition: dsa.h:88
uint64 dsa_pointer
Definition: dsa.h:62
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:734
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:195
pg_atomic_uint32 refcount

References PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_allocate0, dsa_get_address(), PgStatShared_Common::lock, LWLockInitialize(), LWTRANCHE_PGSTATS_DATA, PgStatShared_Common::magic, pg_atomic_init_u32(), pgstat_get_kind_info(), pgStatLocal, and PgStatShared_HashEntry::refcount.

Referenced by pgstat_get_entry_ref(), and pgstat_read_statsfile().

◆ pgstat_init_wal()

void pgstat_init_wal ( void  )

Definition at line 126 of file pgstat_wal.c.

127 {
128  /*
129  * Initialize prevWalUsage with pgWalUsage so that pgstat_flush_wal() can
130  * calculate how much pgWalUsage counters are increased by subtracting
131  * prevWalUsage from pgWalUsage.
132  */
134 }

References pgWalUsage, and prevWalUsage.

Referenced by pgstat_initialize().

◆ pgstat_lock_entry()

bool pgstat_lock_entry ( PgStat_EntryRef entry_ref,
bool  nowait 
)

◆ pgstat_prep_database_pending()

PgStat_StatDBEntry* pgstat_prep_database_pending ( Oid  dboid)

Definition at line 323 of file pgstat_database.c.

324 {
325  PgStat_EntryRef *entry_ref;
326 
328  NULL);
329 
330  return entry_ref->pending;
331 }
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry)
Definition: pgstat.c:1053
#define InvalidOid
Definition: postgres_ext.h:36

References InvalidOid, PgStat_EntryRef::pending, PGSTAT_KIND_DATABASE, and pgstat_prep_pending_entry().

Referenced by pgstat_relation_flush_cb(), pgstat_report_connect(), pgstat_report_deadlock(), pgstat_report_disconnect(), pgstat_report_recovery_conflict(), pgstat_report_tempfile(), and pgstat_update_dbstats().

◆ pgstat_prep_pending_entry()

PgStat_EntryRef* pgstat_prep_pending_entry ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid,
bool created_entry 
)

Definition at line 1053 of file pgstat.c.

1054 {
1055  PgStat_EntryRef *entry_ref;
1056 
1057  /* need to be able to flush out */
1058  Assert(pgstat_get_kind_info(kind)->flush_pending_cb != NULL);
1059 
1061  {
1064  "PgStat Pending",
1066  }
1067 
1068  entry_ref = pgstat_get_entry_ref(kind, dboid, objoid,
1069  true, created_entry);
1070 
1071  if (entry_ref->pending == NULL)
1072  {
1073  size_t entrysize = pgstat_get_kind_info(kind)->pending_size;
1074 
1075  Assert(entrysize != (size_t) -1);
1076 
1077  entry_ref->pending = MemoryContextAllocZero(pgStatPendingContext, entrysize);
1079  }
1080 
1081  return entry_ref;
1082 }
#define unlikely(x)
Definition: c.h:273
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
MemoryContext CacheMemoryContext
Definition: mcxt.c:51
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_SMALL_SIZES
Definition: memutils.h:207
static MemoryContext pgStatPendingContext
Definition: pgstat.c:212
static dlist_head pgStatPending
Definition: pgstat.c:220

References ALLOCSET_SMALL_SIZES, AllocSetContextCreate, Assert(), CacheMemoryContext, dlist_push_tail(), MemoryContextAllocZero(), PgStat_EntryRef::pending, PgStat_EntryRef::pending_node, PgStat_KindInfo::pending_size, pgstat_get_entry_ref(), pgstat_get_kind_info(), pgStatPending, pgStatPendingContext, and unlikely.

Referenced by pgstat_init_function_usage(), pgstat_prep_database_pending(), pgstat_prep_relation_pending(), and pgstat_report_subscription_error().

◆ pgstat_relation_delete_pending_cb()

void pgstat_relation_delete_pending_cb ( PgStat_EntryRef entry_ref)

Definition at line 837 of file pgstat_relation.c.

838 {
839  PgStat_TableStatus *pending = (PgStat_TableStatus *) entry_ref->pending;
840 
841  if (pending->relation)
843 }
void pgstat_unlink_relation(Relation rel)
Relation relation
Definition: pgstat.h:210

References if(), PgStat_EntryRef::pending, pgstat_unlink_relation(), and PgStat_TableStatus::relation.

◆ pgstat_relation_flush_cb()

bool pgstat_relation_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 762 of file pgstat_relation.c.

763 {
764  static const PgStat_TableCounts all_zeroes;
765  Oid dboid;
766  PgStat_TableStatus *lstats; /* pending stats entry */
767  PgStatShared_Relation *shtabstats;
768  PgStat_StatTabEntry *tabentry; /* table entry of shared stats */
769  PgStat_StatDBEntry *dbentry; /* pending database entry */
770 
771  dboid = entry_ref->shared_entry->key.dboid;
772  lstats = (PgStat_TableStatus *) entry_ref->pending;
773  shtabstats = (PgStatShared_Relation *) entry_ref->shared_stats;
774 
775  /*
776  * Ignore entries that didn't accumulate any actual counts, such as
777  * indexes that were opened by the planner but not used.
778  */
779  if (memcmp(&lstats->t_counts, &all_zeroes,
780  sizeof(PgStat_TableCounts)) == 0)
781  {
782  return true;
783  }
784 
785  if (!pgstat_lock_entry(entry_ref, nowait))
786  return false;
787 
788  /* add the values to the shared entry. */
789  tabentry = &shtabstats->stats;
790 
791  tabentry->numscans += lstats->t_counts.t_numscans;
792  tabentry->tuples_returned += lstats->t_counts.t_tuples_returned;
793  tabentry->tuples_fetched += lstats->t_counts.t_tuples_fetched;
794  tabentry->tuples_inserted += lstats->t_counts.t_tuples_inserted;
795  tabentry->tuples_updated += lstats->t_counts.t_tuples_updated;
796  tabentry->tuples_deleted += lstats->t_counts.t_tuples_deleted;
797  tabentry->tuples_hot_updated += lstats->t_counts.t_tuples_hot_updated;
798 
799  /*
800  * If table was truncated/dropped, first reset the live/dead counters.
801  */
802  if (lstats->t_counts.t_truncdropped)
803  {
804  tabentry->n_live_tuples = 0;
805  tabentry->n_dead_tuples = 0;
806  tabentry->inserts_since_vacuum = 0;
807  }
808 
809  tabentry->n_live_tuples += lstats->t_counts.t_delta_live_tuples;
810  tabentry->n_dead_tuples += lstats->t_counts.t_delta_dead_tuples;
811  tabentry->changes_since_analyze += lstats->t_counts.t_changed_tuples;
812  tabentry->inserts_since_vacuum += lstats->t_counts.t_tuples_inserted;
813  tabentry->blocks_fetched += lstats->t_counts.t_blocks_fetched;
814  tabentry->blocks_hit += lstats->t_counts.t_blocks_hit;
815 
816  /* Clamp n_live_tuples in case of negative delta_live_tuples */
817  tabentry->n_live_tuples = Max(tabentry->n_live_tuples, 0);
818  /* Likewise for n_dead_tuples */
819  tabentry->n_dead_tuples = Max(tabentry->n_dead_tuples, 0);
820 
821  pgstat_unlock_entry(entry_ref);
822 
823  /* The entry was successfully flushed, add the same to database stats */
824  dbentry = pgstat_prep_database_pending(dboid);
825  dbentry->n_tuples_returned += lstats->t_counts.t_tuples_returned;
826  dbentry->n_tuples_fetched += lstats->t_counts.t_tuples_fetched;
827  dbentry->n_tuples_inserted += lstats->t_counts.t_tuples_inserted;
828  dbentry->n_tuples_updated += lstats->t_counts.t_tuples_updated;
829  dbentry->n_tuples_deleted += lstats->t_counts.t_tuples_deleted;
830  dbentry->n_blocks_fetched += lstats->t_counts.t_blocks_fetched;
831  dbentry->n_blocks_hit += lstats->t_counts.t_blocks_hit;
832 
833  return true;
834 }
#define Max(x, y)
Definition: c.h:980
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry stats
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:289
PgStat_Counter n_tuples_updated
Definition: pgstat.h:288
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:283
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:286
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:287
PgStat_Counter n_tuples_returned
Definition: pgstat.h:285
PgStat_Counter n_blocks_hit
Definition: pgstat.h:284
PgStat_Counter tuples_fetched
Definition: pgstat.h:360
PgStat_Counter blocks_hit
Definition: pgstat.h:373
PgStat_Counter tuples_deleted
Definition: pgstat.h:364
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:365
PgStat_Counter tuples_updated
Definition: pgstat.h:363
PgStat_Counter changes_since_analyze
Definition: pgstat.h:369
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:370
PgStat_Counter numscans
Definition: pgstat.h:357
PgStat_Counter blocks_fetched
Definition: pgstat.h:372
PgStat_Counter tuples_returned
Definition: pgstat.h:359
PgStat_Counter n_live_tuples
Definition: pgstat.h:367
PgStat_Counter n_dead_tuples
Definition: pgstat.h:368
PgStat_Counter tuples_inserted
Definition: pgstat.h:362
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:178
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:173
PgStat_Counter t_numscans
Definition: pgstat.h:170
PgStat_Counter t_blocks_hit
Definition: pgstat.h:186
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:185
PgStat_Counter t_tuples_returned
Definition: pgstat.h:172

References PgStat_StatTabEntry::blocks_fetched, PgStat_StatTabEntry::blocks_hit, PgStat_StatTabEntry::changes_since_analyze, PgStat_HashKey::dboid, PgStat_StatTabEntry::inserts_since_vacuum, PgStatShared_HashEntry::key, Max, PgStat_StatDBEntry::n_blocks_fetched, PgStat_StatDBEntry::n_blocks_hit, PgStat_StatTabEntry::n_dead_tuples, PgStat_StatTabEntry::n_live_tuples, PgStat_StatDBEntry::n_tuples_deleted, PgStat_StatDBEntry::n_tuples_fetched, PgStat_StatDBEntry::n_tuples_inserted, PgStat_StatDBEntry::n_tuples_returned, PgStat_StatDBEntry::n_tuples_updated, PgStat_StatTabEntry::numscans, PgStat_EntryRef::pending, pgstat_lock_entry(), pgstat_prep_database_pending(), pgstat_unlock_entry(), PgStat_EntryRef::shared_entry, PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, PgStat_TableCounts::t_blocks_fetched, PgStat_TableCounts::t_blocks_hit, PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, PgStat_TableCounts::t_numscans, PgStat_TableCounts::t_truncdropped, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_fetched, PgStat_TableCounts::t_tuples_hot_updated, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_returned, PgStat_TableCounts::t_tuples_updated, PgStat_StatTabEntry::tuples_deleted, PgStat_StatTabEntry::tuples_fetched, PgStat_StatTabEntry::tuples_hot_updated, PgStat_StatTabEntry::tuples_inserted, PgStat_StatTabEntry::tuples_returned, and PgStat_StatTabEntry::tuples_updated.

◆ pgstat_replslot_from_serialized_name_cb()

bool pgstat_replslot_from_serialized_name_cb ( const NameData name,
PgStat_HashKey key 
)

Definition at line 194 of file pgstat_replslot.c.

195 {
197 
198  /* slot might have been deleted */
199  if (idx == -1)
200  return false;
201 
202  key->kind = PGSTAT_KIND_REPLSLOT;
203  key->dboid = InvalidOid;
204  key->objoid = idx;
205 
206  return true;
207 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
#define NameStr(name)
Definition: c.h:681
@ PGSTAT_KIND_REPLSLOT
Definition: pgstat.h:44
static int get_replslot_index(const char *name)

References get_replslot_index(), idx(), InvalidOid, sort-test::key, name, NameStr, and PGSTAT_KIND_REPLSLOT.

◆ pgstat_replslot_reset_timestamp_cb()

void pgstat_replslot_reset_timestamp_cb ( PgStatShared_Common header,
TimestampTz  ts 
)

Definition at line 210 of file pgstat_replslot.c.

211 {
212  ((PgStatShared_ReplSlot *) header)->stats.stat_reset_timestamp = ts;
213 }

References header().

◆ pgstat_replslot_to_serialized_name_cb()

void pgstat_replslot_to_serialized_name_cb ( const PgStatShared_Common tmp,
NameData name 
)

Definition at line 188 of file pgstat_replslot.c.

189 {
190  namestrcpy(name, NameStr(((PgStatShared_ReplSlot *) header)->stats.slotname));
191 }
void namestrcpy(Name name, const char *str)
Definition: name.c:233

References header(), name, NameStr, and namestrcpy().

◆ pgstat_report_disconnect()

void pgstat_report_disconnect ( Oid  dboid)

Definition at line 205 of file pgstat_database.c.

206 {
207  PgStat_StatDBEntry *dbentry;
208 
210  return;
211 
213 
214  switch (pgStatSessionEndCause)
215  {
216  case DISCONNECT_NOT_YET:
217  case DISCONNECT_NORMAL:
218  /* we don't collect these */
219  break;
221  dbentry->n_sessions_abandoned++;
222  break;
223  case DISCONNECT_FATAL:
224  dbentry->n_sessions_fatal++;
225  break;
226  case DISCONNECT_KILLED:
227  dbentry->n_sessions_killed++;
228  break;
229  }
230 }
Oid MyDatabaseId
Definition: globals.c:89
@ DISCONNECT_NOT_YET
Definition: pgstat.h:77
@ DISCONNECT_FATAL
Definition: pgstat.h:80
@ DISCONNECT_KILLED
Definition: pgstat.h:81
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:79
@ DISCONNECT_NORMAL
Definition: pgstat.h:78
static bool pgstat_should_report_connstat(void)
SessionEndType pgStatSessionEndCause
PgStat_Counter n_sessions_killed
Definition: pgstat.h:309
PgStat_Counter n_sessions_fatal
Definition: pgstat.h:308
PgStat_Counter n_sessions_abandoned
Definition: pgstat.h:307

References DISCONNECT_CLIENT_EOF, DISCONNECT_FATAL, DISCONNECT_KILLED, DISCONNECT_NORMAL, DISCONNECT_NOT_YET, MyDatabaseId, PgStat_StatDBEntry::n_sessions_abandoned, PgStat_StatDBEntry::n_sessions_fatal, PgStat_StatDBEntry::n_sessions_killed, pgstat_prep_database_pending(), pgstat_should_report_connstat(), and pgStatSessionEndCause.

Referenced by pgstat_shutdown_hook().

◆ pgstat_request_entry_refs_gc()

void pgstat_request_entry_refs_gc ( void  )

◆ pgstat_reset_database_timestamp()

void pgstat_reset_database_timestamp ( Oid  dboid,
TimestampTz  ts 
)

Definition at line 338 of file pgstat_database.c.

339 {
340  PgStat_EntryRef *dbref;
341  PgStatShared_Database *dbentry;
342 
344  false);
345 
346  dbentry = (PgStatShared_Database *) dbref->shared_stats;
347  dbentry->stats.stat_reset_timestamp = ts;
348 
349  pgstat_unlock_entry(dbref);
350 }
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
Definition: pgstat_shmem.c:592
PgStat_StatDBEntry stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:311

References InvalidOid, MyDatabaseId, pgstat_get_entry_ref_locked(), PGSTAT_KIND_DATABASE, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, PgStat_StatDBEntry::stat_reset_timestamp, and PgStatShared_Database::stats.

Referenced by pgstat_reset().

◆ pgstat_reset_entries_of_kind()

void pgstat_reset_entries_of_kind ( PgStat_Kind  kind,
TimestampTz  ts 
)

Definition at line 969 of file pgstat_shmem.c.

970 {
972 }
static bool match_kind(PgStatShared_HashEntry *p, Datum match_data)
Definition: pgstat_shmem.c:963
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
Definition: pgstat_shmem.c:933
#define Int32GetDatum(X)
Definition: postgres.h:523

References Int32GetDatum, match_kind(), and pgstat_reset_matching_entries().

Referenced by pgstat_reset_of_kind().

◆ pgstat_reset_entry()

void pgstat_reset_entry ( PgStat_Kind  kind,
Oid  dboid,
Oid  objoid,
TimestampTz  ts 
)

Definition at line 913 of file pgstat_shmem.c.

914 {
915  PgStat_EntryRef *entry_ref;
916 
917  Assert(!pgstat_get_kind_info(kind)->fixed_amount);
918 
919  entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL);
920  if (!entry_ref || entry_ref->shared_entry->dropped)
921  return;
922 
923  (void) pgstat_lock_entry(entry_ref, false);
924  shared_stat_reset_contents(kind, entry_ref->shared_stats, ts);
925  pgstat_unlock_entry(entry_ref);
926 }
static void shared_stat_reset_contents(PgStat_Kind kind, PgStatShared_Common *header, TimestampTz ts)
Definition: pgstat_shmem.c:897

References Assert(), PgStatShared_HashEntry::dropped, pgstat_get_entry_ref(), pgstat_get_kind_info(), pgstat_lock_entry(), pgstat_unlock_entry(), PgStat_EntryRef::shared_entry, shared_stat_reset_contents(), and PgStat_EntryRef::shared_stats.

Referenced by pgstat_reset().

◆ pgstat_reset_matching_entries()

void pgstat_reset_matching_entries ( bool(*)(PgStatShared_HashEntry *, Datum do_reset,
Datum  match_data,
TimestampTz  ts 
)

Definition at line 933 of file pgstat_shmem.c.

935 {
936  dshash_seq_status hstat;
938 
939  /* dshash entry is not modified, take shared lock */
940  dshash_seq_init(&hstat, pgStatLocal.shared_hash, false);
941  while ((p = dshash_seq_next(&hstat)) != NULL)
942  {
944 
945  if (p->dropped)
946  continue;
947 
948  if (!do_reset(p, match_data))
949  continue;
950 
952 
954 
956 
957  LWLockRelease(&header->lock);
958  }
959  dshash_seq_term(&hstat);
960 }

References PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), header(), PgStatShared_HashEntry::key, PgStat_HashKey::kind, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shared_hash, and shared_stat_reset_contents().

Referenced by pgstat_reset_counters(), and pgstat_reset_entries_of_kind().

◆ pgstat_slru_flush()

bool pgstat_slru_flush ( bool  nowait)

Definition at line 158 of file pgstat_slru.c.

159 {
160  PgStatShared_SLRU *stats_shmem = &pgStatLocal.shmem->slru;
161  int i;
162 
163  if (!have_slrustats)
164  return false;
165 
166  if (!nowait)
167  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
168  else if (!LWLockConditionalAcquire(&stats_shmem->lock, LW_EXCLUSIVE))
169  return true;
170 
171  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
172  {
173  PgStat_SLRUStats *sharedent = &stats_shmem->stats[i];
174  PgStat_SLRUStats *pendingent = &pending_SLRUStats[i];
175 
176 #define SLRU_ACC(fld) sharedent->fld += pendingent->fld
177  SLRU_ACC(blocks_zeroed);
178  SLRU_ACC(blocks_hit);
179  SLRU_ACC(blocks_read);
181  SLRU_ACC(blocks_exists);
182  SLRU_ACC(flush);
183  SLRU_ACC(truncate);
184 #undef SLRU_ACC
185  }
186 
187  /* done, clear the pending entry */
189 
190  LWLockRelease(&stats_shmem->lock);
191 
192  have_slrustats = false;
193 
194  return false;
195 }
int i
Definition: isn.c:73
static int64 blocks_written
Definition: pg_checksums.c:39
#define SLRU_NUM_ELEMENTS
bool have_slrustats
Definition: pgstat_slru.c:35
static PgStat_SLRUStats pending_SLRUStats[SLRU_NUM_ELEMENTS]
Definition: pgstat_slru.c:34
#define SLRU_ACC(fld)
PgStat_SLRUStats stats[SLRU_NUM_ELEMENTS]
PgStatShared_SLRU slru

References blocks_written, have_slrustats, i, PgStatShared_SLRU::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockRelease(), MemSet, pending_SLRUStats, pgStatLocal, PgStat_LocalState::shmem, PgStat_ShmemControl::slru, SLRU_ACC, SLRU_NUM_ELEMENTS, and PgStatShared_SLRU::stats.

Referenced by pgstat_report_stat().

◆ pgstat_slru_reset_all_cb()

void pgstat_slru_reset_all_cb ( TimestampTz  ts)

Definition at line 198 of file pgstat_slru.c.

199 {
200  for (int i = 0; i < SLRU_NUM_ELEMENTS; i++)
202 }
static void pgstat_reset_slru_counter_internal(int index, TimestampTz ts)
Definition: pgstat_slru.c:240

References i, pgstat_reset_slru_counter_internal(), and SLRU_NUM_ELEMENTS.

◆ pgstat_slru_snapshot_cb()

void pgstat_slru_snapshot_cb ( void  )

Definition at line 205 of file pgstat_slru.c.

206 {
207  PgStatShared_SLRU *stats_shmem = &pgStatLocal.shmem->slru;
208 
209  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
210 
211  memcpy(pgStatLocal.snapshot.slru, &stats_shmem->stats,
212  sizeof(stats_shmem->stats));
213 
214  LWLockRelease(&stats_shmem->lock);
215 }
PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]

References PgStatShared_SLRU::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_ShmemControl::slru, PgStat_Snapshot::slru, PgStat_LocalState::snapshot, and PgStatShared_SLRU::stats.

◆ pgstat_snapshot_fixed()

◆ pgstat_subscription_flush_cb()

bool pgstat_subscription_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 84 of file pgstat_subscription.c.

85 {
86  PgStat_BackendSubEntry *localent;
87  PgStatShared_Subscription *shsubent;
88 
89  localent = (PgStat_BackendSubEntry *) entry_ref->pending;
90  shsubent = (PgStatShared_Subscription *) entry_ref->shared_stats;
91 
92  /* localent always has non-zero content */
93 
94  if (!pgstat_lock_entry(entry_ref, nowait))
95  return false;
96 
97 #define SUB_ACC(fld) shsubent->stats.fld += localent->fld
98  SUB_ACC(apply_error_count);
99  SUB_ACC(sync_error_count);
100 #undef SUB_ACC
101 
102  pgstat_unlock_entry(entry_ref);
103  return true;
104 }
#define SUB_ACC(fld)

References PgStat_EntryRef::pending, pgstat_lock_entry(), pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and SUB_ACC.

◆ pgstat_subscription_reset_timestamp_cb()

void pgstat_subscription_reset_timestamp_cb ( PgStatShared_Common header,
TimestampTz  ts 
)

Definition at line 107 of file pgstat_subscription.c.

108 {
109  ((PgStatShared_Subscription *) header)->stats.stat_reset_timestamp = ts;
110 }

References header().

◆ pgstat_unlock_entry()

◆ pgstat_update_dbstats()

void pgstat_update_dbstats ( TimestampTz  ts)

Definition at line 267 of file pgstat_database.c.

268 {
269  PgStat_StatDBEntry *dbentry;
270 
272 
273  /*
274  * Accumulate xact commit/rollback and I/O timings to stats entry of the
275  * current database.
276  */
277  dbentry->n_xact_commit += pgStatXactCommit;
281 
283  {
284  long secs;
285  int usecs;
286 
287  /*
288  * pgLastSessionReportTime is initialized to MyStartTimestamp by
289  * pgstat_report_connect().
290  */
291  TimestampDifference(pgLastSessionReportTime, ts, &secs, &usecs);
293  dbentry->total_session_time += (PgStat_Counter) secs * 1000000 + usecs;
296  }
297 
298  pgStatXactCommit = 0;
299  pgStatXactRollback = 0;
302  pgStatActiveTime = 0;
304 }
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1650
int64 PgStat_Counter
Definition: pgstat.h:88
PgStat_Counter pgStatActiveTime
PgStat_Counter pgStatBlockReadTime
PgStat_Counter pgStatBlockWriteTime
static PgStat_Counter pgLastSessionReportTime
PgStat_Counter pgStatTransactionIdleTime
PgStat_Counter total_session_time
Definition: pgstat.h:304
PgStat_Counter total_idle_in_xact_time
Definition: pgstat.h:306
PgStat_Counter n_xact_commit
Definition: pgstat.h:281
PgStat_Counter n_xact_rollback
Definition: pgstat.h:282
PgStat_Counter total_active_time
Definition: pgstat.h:305
PgStat_Counter n_block_read_time
Definition: pgstat.h:301
PgStat_Counter n_block_write_time
Definition: pgstat.h:302

References MyDatabaseId, PgStat_StatDBEntry::n_block_read_time, PgStat_StatDBEntry::n_block_write_time, PgStat_StatDBEntry::n_xact_commit, PgStat_StatDBEntry::n_xact_rollback, pgLastSessionReportTime, pgstat_prep_database_pending(), pgstat_should_report_connstat(), pgStatActiveTime, pgStatBlockReadTime, pgStatBlockWriteTime, pgStatTransactionIdleTime, pgStatXactCommit, pgStatXactRollback, TimestampDifference(), PgStat_StatDBEntry::total_active_time, PgStat_StatDBEntry::total_idle_in_xact_time, and PgStat_StatDBEntry::total_session_time.

Referenced by pgstat_report_stat().

◆ pgstat_wal_reset_all_cb()

void pgstat_wal_reset_all_cb ( TimestampTz  ts)

Definition at line 152 of file pgstat_wal.c.

153 {
154  PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal;
155 
156  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
157  memset(&stats_shmem->stats, 0, sizeof(stats_shmem->stats));
158  stats_shmem->stats.stat_reset_timestamp = ts;
159  LWLockRelease(&stats_shmem->lock);
160 }
PgStat_WalStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:395

References PgStatShared_Wal::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_WalStats::stat_reset_timestamp, PgStatShared_Wal::stats, and PgStat_ShmemControl::wal.

◆ pgstat_wal_snapshot_cb()

void pgstat_wal_snapshot_cb ( void  )

Definition at line 163 of file pgstat_wal.c.

164 {
165  PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal;
166 
167  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
168  memcpy(&pgStatLocal.snapshot.wal, &stats_shmem->stats,
169  sizeof(pgStatLocal.snapshot.wal));
170  LWLockRelease(&stats_shmem->lock);
171 }
PgStat_WalStats wal

References PgStatShared_Wal::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, PgStatShared_Wal::stats, PgStat_ShmemControl::wal, and PgStat_Snapshot::wal.

◆ PostPrepare_PgStat_Relations()

void PostPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)

Definition at line 674 of file pgstat_relation.c.

675 {
677 
678  for (trans = xact_state->first; trans != NULL; trans = trans->next)
679  {
680  PgStat_TableStatus *tabstat;
681 
682  tabstat = trans->parent;
683  tabstat->trans = NULL;
684  }
685 }

References PgStat_SubXactStatus::first, PgStat_TableStatus::trans, and trans.

Referenced by PostPrepare_PgStat().

Variable Documentation

◆ have_slrustats

PGDLLIMPORT bool have_slrustats
extern

Definition at line 35 of file pgstat_slru.c.

Referenced by get_slru_entry(), pgstat_report_stat(), and pgstat_slru_flush().

◆ pgStatLocal

◆ slru_names

const char* const slru_names[]
static
Initial value:
= {
"CommitTs",
"MultiXactMember",
"MultiXactOffset",
"Notify",
"Serial",
"Subtrans",
"Xact",
"other"
}

Definition at line 271 of file pgstat_internal.h.

Referenced by pgstat_get_slru_index(), and pgstat_get_slru_name().