PostgreSQL Source Code git master
pgstat_internal.h File Reference
#include "common/hashfn_unstable.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_IO
 
struct  PgStatShared_SLRU
 
struct  PgStatShared_Wal
 
struct  PgStatShared_Database
 
struct  PgStatShared_Relation
 
struct  PgStatShared_Function
 
struct  PgStatShared_Subscription
 
struct  PgStatShared_ReplSlot
 
struct  PgStatShared_Backend
 
struct  PgStat_ShmemControl
 
struct  PgStat_Snapshot
 
struct  PgStat_LocalState
 

Macros

#define SLRU_NUM_ELEMENTS   lengthof(slru_names)
 
#define pgstat_assert_is_up()   ((void)true)
 
#define PGSTAT_BACKEND_FLUSH_IO   (1 << 0) /* Flush I/O statistics */
 
#define PGSTAT_BACKEND_FLUSH_WAL   (1 << 1) /* Flush WAL statistics */
 
#define PGSTAT_BACKEND_FLUSH_ALL   (PGSTAT_BACKEND_FLUSH_IO | PGSTAT_BACKEND_FLUSH_WAL)
 

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_IO PgStatShared_IO
 
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 PgStatShared_Backend PgStatShared_Backend
 
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)
 
static void * pgstat_get_custom_shmem_data (PgStat_Kind kind)
 
static void * pgstat_get_custom_snapshot_data (PgStat_Kind kind)
 
const PgStat_KindInfopgstat_get_kind_info (PgStat_Kind kind)
 
void pgstat_register_kind (PgStat_Kind kind, const PgStat_KindInfo *kind_info)
 
void pgstat_delete_pending_entry (PgStat_EntryRef *entry_ref)
 
PgStat_EntryRefpgstat_prep_pending_entry (PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
 
PgStat_EntryRefpgstat_fetch_pending_entry (PgStat_Kind kind, Oid dboid, uint64 objid)
 
void * pgstat_fetch_entry (PgStat_Kind kind, Oid dboid, uint64 objid)
 
void pgstat_snapshot_fixed (PgStat_Kind kind)
 
void pgstat_archiver_init_shmem_cb (void *stats)
 
void pgstat_archiver_reset_all_cb (TimestampTz ts)
 
void pgstat_archiver_snapshot_cb (void)
 
bool pgstat_flush_backend (bool nowait, bits32 flags)
 
bool pgstat_backend_flush_cb (bool nowait)
 
bool pgstat_backend_have_pending_cb (void)
 
void pgstat_backend_reset_timestamp_cb (PgStatShared_Common *header, TimestampTz ts)
 
void pgstat_bgwriter_init_shmem_cb (void *stats)
 
void pgstat_bgwriter_reset_all_cb (TimestampTz ts)
 
void pgstat_bgwriter_snapshot_cb (void)
 
void pgstat_checkpointer_init_shmem_cb (void *stats)
 
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 pgstat_flush_io (bool nowait)
 
bool pgstat_io_have_pending_cb (void)
 
bool pgstat_io_flush_cb (bool nowait)
 
void pgstat_io_init_shmem_cb (void *stats)
 
void pgstat_io_reset_all_cb (TimestampTz ts)
 
void pgstat_io_snapshot_cb (void)
 
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 PgStat_HashKey *key, const PgStatShared_Common *header, 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, uint64 objid, bool create, bool *created_entry)
 
bool pgstat_lock_entry (PgStat_EntryRef *entry_ref, bool nowait)
 
bool pgstat_lock_entry_shared (PgStat_EntryRef *entry_ref, bool nowait)
 
void pgstat_unlock_entry (PgStat_EntryRef *entry_ref)
 
bool pgstat_drop_entry (PgStat_Kind kind, Oid dboid, uint64 objid)
 
void pgstat_drop_all_entries (void)
 
void pgstat_drop_matching_entries (bool(*do_drop)(PgStatShared_HashEntry *, Datum), Datum match_data)
 
PgStat_EntryRefpgstat_get_entry_ref_locked (PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
 
void pgstat_reset_entry (PgStat_Kind kind, Oid dboid, uint64 objid, 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_have_pending_cb (void)
 
bool pgstat_slru_flush_cb (bool nowait)
 
void pgstat_slru_init_shmem_cb (void *stats)
 
void pgstat_slru_reset_all_cb (TimestampTz ts)
 
void pgstat_slru_snapshot_cb (void)
 
void pgstat_wal_init_backend_cb (void)
 
bool pgstat_wal_have_pending_cb (void)
 
bool pgstat_wal_flush_cb (bool nowait)
 
void pgstat_wal_init_shmem_cb (void *stats)
 
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, uint64 objid)
 
void pgstat_create_transactional (PgStat_Kind kind, Oid dboid, uint64 objid)
 

Variables

static const char *const slru_names []
 
PGDLLIMPORT PgStat_LocalState pgStatLocal
 

Macro Definition Documentation

◆ pgstat_assert_is_up

#define pgstat_assert_is_up ( )    ((void)true)

Definition at line 597 of file pgstat_internal.h.

◆ PGSTAT_BACKEND_FLUSH_ALL

#define PGSTAT_BACKEND_FLUSH_ALL   (PGSTAT_BACKEND_FLUSH_IO | PGSTAT_BACKEND_FLUSH_WAL)

Definition at line 626 of file pgstat_internal.h.

◆ PGSTAT_BACKEND_FLUSH_IO

#define PGSTAT_BACKEND_FLUSH_IO   (1 << 0) /* Flush I/O statistics */

Definition at line 624 of file pgstat_internal.h.

◆ PGSTAT_BACKEND_FLUSH_WAL

#define PGSTAT_BACKEND_FLUSH_WAL   (1 << 1) /* Flush WAL statistics */

Definition at line 625 of file pgstat_internal.h.

◆ SLRU_NUM_ELEMENTS

#define SLRU_NUM_ELEMENTS   lengthof(slru_names)

Definition at line 345 of file pgstat_internal.h.

Typedef Documentation

◆ PgStat_EntryRef

◆ PgStat_HashKey

◆ PgStat_KindInfo

◆ PgStat_LocalState

◆ PgStat_ShmemControl

◆ PgStat_Snapshot

◆ PgStat_SubXactStatus

◆ PgStatShared_Archiver

◆ PgStatShared_Backend

◆ PgStatShared_BgWriter

◆ PgStatShared_Checkpointer

◆ PgStatShared_Common

◆ PgStatShared_Database

◆ PgStatShared_Function

◆ PgStatShared_HashEntry

◆ PgStatShared_IO

◆ 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 609 of file pgstat_relation.c.

610{
612 PgStat_TableXactStatus *next_trans;
613
614 for (trans = xact_state->first; trans != NULL; trans = next_trans)
615 {
616 PgStat_TableStatus *tabstat;
617
618 next_trans = trans->next;
619 Assert(trans->nest_level == nestDepth);
620 tabstat = trans->parent;
621 Assert(tabstat->trans == trans);
622
623 if (isCommit)
624 {
625 if (trans->upper && trans->upper->nest_level == nestDepth - 1)
626 {
627 if (trans->truncdropped)
628 {
629 /* propagate the truncate/drop status one level up */
630 save_truncdrop_counters(trans->upper, false);
631 /* replace upper xact stats with ours */
632 trans->upper->tuples_inserted = trans->tuples_inserted;
633 trans->upper->tuples_updated = trans->tuples_updated;
634 trans->upper->tuples_deleted = trans->tuples_deleted;
635 }
636 else
637 {
638 trans->upper->tuples_inserted += trans->tuples_inserted;
639 trans->upper->tuples_updated += trans->tuples_updated;
640 trans->upper->tuples_deleted += trans->tuples_deleted;
641 }
642 tabstat->trans = trans->upper;
643 pfree(trans);
644 }
645 else
646 {
647 /*
648 * When there isn't an immediate parent state, we can just
649 * reuse the record instead of going through a palloc/pfree
650 * pushup (this works since it's all in TopTransactionContext
651 * anyway). We have to re-link it into the parent level,
652 * though, and that might mean pushing a new entry into the
653 * pgStatXactStack.
654 */
655 PgStat_SubXactStatus *upper_xact_state;
656
657 upper_xact_state = pgstat_get_xact_stack_level(nestDepth - 1);
658 trans->next = upper_xact_state->first;
659 upper_xact_state->first = trans;
660 trans->nest_level = nestDepth - 1;
661 }
662 }
663 else
664 {
665 /*
666 * On abort, update top-level tabstat counts, then forget the
667 * subtransaction
668 */
669
670 /* first restore values obliterated by truncate/drop */
672 /* count attempted actions regardless of commit/abort */
673 tabstat->counts.tuples_inserted += trans->tuples_inserted;
674 tabstat->counts.tuples_updated += trans->tuples_updated;
675 tabstat->counts.tuples_deleted += trans->tuples_deleted;
676 /* inserted tuples are dead, deleted tuples are unaffected */
677 tabstat->counts.delta_dead_tuples +=
678 trans->tuples_inserted + trans->tuples_updated;
679 tabstat->trans = trans->upper;
680 pfree(trans);
681 }
682 }
683}
Assert(PointerIsAligned(start, uint64))
void pfree(void *pointer)
Definition: mcxt.c:1524
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:238
PgStat_TableXactStatus * first
PgStat_Counter tuples_inserted
Definition: pgstat.h:143
PgStat_Counter tuples_updated
Definition: pgstat.h:144
PgStat_Counter delta_dead_tuples
Definition: pgstat.h:151
PgStat_Counter tuples_deleted
Definition: pgstat.h:145
PgStat_TableCounts counts
Definition: pgstat.h:178
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:177
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:402

References Assert(), PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_SubXactStatus::first, pfree(), pgstat_get_xact_stack_level(), restore_truncdrop_counters(), save_truncdrop_counters(), PgStat_TableStatus::trans, trans, PgStat_TableCounts::tuples_deleted, PgStat_TableCounts::tuples_inserted, and PgStat_TableCounts::tuples_updated.

Referenced by AtEOSubXact_PgStat().

◆ AtEOXact_PgStat_Database()

void AtEOXact_PgStat_Database ( bool  isCommit,
bool  parallel 
)

Definition at line 249 of file pgstat_database.c.

250{
251 /* Don't count parallel worker transaction stats */
252 if (!parallel)
253 {
254 /*
255 * Count transaction commit or abort. (We use counters, not just
256 * bools, in case the reporting message isn't sent right away.)
257 */
258 if (isCommit)
260 else
262 }
263}
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 551 of file pgstat_relation.c.

552{
554
555 for (trans = xact_state->first; trans != NULL; trans = trans->next)
556 {
557 PgStat_TableStatus *tabstat;
558
559 Assert(trans->nest_level == 1);
560 Assert(trans->upper == NULL);
561 tabstat = trans->parent;
562 Assert(tabstat->trans == trans);
563 /* restore pre-truncate/drop stats (if any) in case of aborted xact */
564 if (!isCommit)
566 /* count attempted actions regardless of commit/abort */
567 tabstat->counts.tuples_inserted += trans->tuples_inserted;
568 tabstat->counts.tuples_updated += trans->tuples_updated;
569 tabstat->counts.tuples_deleted += trans->tuples_deleted;
570 if (isCommit)
571 {
572 tabstat->counts.truncdropped = trans->truncdropped;
573 if (trans->truncdropped)
574 {
575 /* forget live/dead stats seen by backend thus far */
576 tabstat->counts.delta_live_tuples = 0;
577 tabstat->counts.delta_dead_tuples = 0;
578 }
579 /* insert adds a live tuple, delete removes one */
580 tabstat->counts.delta_live_tuples +=
581 trans->tuples_inserted - trans->tuples_deleted;
582 /* update and delete each create a dead tuple */
583 tabstat->counts.delta_dead_tuples +=
584 trans->tuples_updated + trans->tuples_deleted;
585 /* insert, update, delete each count as one change event */
586 tabstat->counts.changed_tuples +=
587 trans->tuples_inserted + trans->tuples_updated +
588 trans->tuples_deleted;
589 }
590 else
591 {
592 /* inserted tuples are dead, deleted tuples are unaffected */
593 tabstat->counts.delta_dead_tuples +=
594 trans->tuples_inserted + trans->tuples_updated;
595 /* an aborted xact generates no changed_tuple events */
596 }
597 tabstat->trans = NULL;
598 }
599}
PgStat_Counter delta_live_tuples
Definition: pgstat.h:150
PgStat_Counter changed_tuples
Definition: pgstat.h:152

References Assert(), PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, PgStat_SubXactStatus::first, restore_truncdrop_counters(), PgStat_TableStatus::trans, trans, PgStat_TableCounts::truncdropped, PgStat_TableCounts::tuples_deleted, PgStat_TableCounts::tuples_inserted, and PgStat_TableCounts::tuples_updated.

Referenced by AtEOXact_PgStat().

◆ AtPrepare_PgStat_Relations()

void AtPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)

Definition at line 690 of file pgstat_relation.c.

691{
693
694 for (trans = xact_state->first; trans != NULL; trans = trans->next)
695 {
698
699 Assert(trans->nest_level == 1);
700 Assert(trans->upper == NULL);
701 tabstat = trans->parent;
702 Assert(tabstat->trans == trans);
703
704 record.tuples_inserted = trans->tuples_inserted;
705 record.tuples_updated = trans->tuples_updated;
706 record.tuples_deleted = trans->tuples_deleted;
707 record.inserted_pre_truncdrop = trans->inserted_pre_truncdrop;
708 record.updated_pre_truncdrop = trans->updated_pre_truncdrop;
709 record.deleted_pre_truncdrop = trans->deleted_pre_truncdrop;
710 record.id = tabstat->id;
711 record.shared = tabstat->shared;
712 record.truncdropped = trans->truncdropped;
713
715 &record, sizeof(TwoPhasePgStatRecord));
716 }
717}
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:224
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:1264
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26

References Assert(), TwoPhasePgStatRecord::deleted_pre_truncdrop, PgStat_SubXactStatus::first, TwoPhasePgStatRecord::id, TwoPhasePgStatRecord::inserted_pre_truncdrop, PG_USED_FOR_ASSERTS_ONLY, RegisterTwoPhaseRecord(), TwoPhasePgStatRecord::shared, trans, TwoPhasePgStatRecord::truncdropped, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, TWOPHASE_RM_PGSTAT_ID, and TwoPhasePgStatRecord::updated_pre_truncdrop.

Referenced by AtPrepare_PgStat().

◆ pgstat_archiver_init_shmem_cb()

void pgstat_archiver_init_shmem_cb ( void *  stats)

Definition at line 66 of file pgstat_archiver.c.

67{
68 PgStatShared_Archiver *stats_shmem = (PgStatShared_Archiver *) stats;
69
71}
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:718
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:208

References PgStatShared_Archiver::lock, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_archiver_reset_all_cb()

void pgstat_archiver_reset_all_cb ( TimestampTz  ts)

Definition at line 74 of file pgstat_archiver.c.

75{
77
78 /* see explanation above PgStatShared_Archiver 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}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1179
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1899
@ LW_EXCLUSIVE
Definition: lwlock.h:114
PgStat_LocalState pgStatLocal
Definition: pgstat.c:212
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:226
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 89 of file pgstat_archiver.c.

90{
93 PgStat_ArchiverStats *reset_offset = &stats_shmem->reset_offset;
95
97 &stats_shmem->stats,
98 sizeof(stats_shmem->stats),
99 &stats_shmem->changecount);
100
101 LWLockAcquire(&stats_shmem->lock, LW_SHARED);
102 memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
103 LWLockRelease(&stats_shmem->lock);
104
105 /* compensate by reset offsets */
106 if (stat_snap->archived_count == reset.archived_count)
107 {
108 stat_snap->last_archived_wal[0] = 0;
109 stat_snap->last_archived_timestamp = 0;
110 }
111 stat_snap->archived_count -= reset.archived_count;
112
113 if (stat_snap->failed_count == reset.failed_count)
114 {
115 stat_snap->last_failed_wal[0] = 0;
116 stat_snap->last_failed_timestamp = 0;
117 }
118 stat_snap->failed_count -= reset.failed_count;
119}
@ LW_SHARED
Definition: lwlock.h:115
void reset(void)
Definition: sql-declare.c:600
TimestampTz last_failed_timestamp
Definition: pgstat.h:225
TimestampTz last_archived_timestamp
Definition: pgstat.h:221
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:223
PgStat_Counter failed_count
Definition: pgstat.h:222
PgStat_Counter archived_count
Definition: pgstat.h:218
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:219
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 244 of file pgstat_shmem.c.

245{
246 MemoryContext oldcontext;
247
248 Assert(pgStatLocal.dsa == NULL);
249
250 /* stats shared memory persists for the backend lifetime */
252
254 NULL);
256
259
260 MemoryContextSwitchTo(oldcontext);
261}
dsa_area * dsa_attach_in_place(void *place, dsm_segment *segment)
Definition: dsa.c:545
void dsa_pin_mapping(dsa_area *area)
Definition: dsa.c:635
dshash_table * dshash_attach(dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg)
Definition: dshash.c:270
MemoryContext TopMemoryContext
Definition: mcxt.c:149
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
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_backend_flush_cb()

bool pgstat_backend_flush_cb ( bool  nowait)

Definition at line 314 of file pgstat_backend.c.

315{
317}
bool pgstat_flush_backend(bool nowait, bits32 flags)
#define PGSTAT_BACKEND_FLUSH_ALL

References PGSTAT_BACKEND_FLUSH_ALL, and pgstat_flush_backend().

◆ pgstat_backend_have_pending_cb()

bool pgstat_backend_have_pending_cb ( void  )

Definition at line 300 of file pgstat_backend.c.

301{
303 return false;
304
306}
BackendType MyBackendType
Definition: miscinit.c:64
bool pgstat_tracks_backend_bktype(BackendType bktype)
static bool pgstat_backend_wal_have_pending(void)
static bool backend_has_iostats

References backend_has_iostats, MyBackendType, pgstat_backend_wal_have_pending(), and pgstat_tracks_backend_bktype().

◆ pgstat_backend_reset_timestamp_cb()

void pgstat_backend_reset_timestamp_cb ( PgStatShared_Common header,
TimestampTz  ts 
)

Definition at line 401 of file pgstat_backend.c.

402{
403 ((PgStatShared_Backend *) header)->stats.stat_reset_timestamp = ts;
404}

◆ pgstat_begin_changecount_read()

static uint32 pgstat_begin_changecount_read ( uint32 cc)
inlinestatic

Definition at line 816 of file pgstat_internal.h.

817{
818 uint32 before_cc = *cc;
819
821
823
824 return before_cc;
825}
#define pg_read_barrier()
Definition: atomics.h:156
uint32_t uint32
Definition: c.h:502
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122

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 794 of file pgstat_internal.h.

795{
796 Assert((*cc & 1) == 0);
797
799 (*cc)++;
801}
#define pg_write_barrier()
Definition: atomics.h:157
#define START_CRIT_SECTION()
Definition: miscadmin.h:149

References Assert(), pg_write_barrier, and START_CRIT_SECTION.

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

◆ pgstat_bgwriter_init_shmem_cb()

void pgstat_bgwriter_init_shmem_cb ( void *  stats)

◆ pgstat_bgwriter_reset_all_cb()

void pgstat_bgwriter_reset_all_cb ( TimestampTz  ts)

Definition at line 88 of file pgstat_bgwriter.c.

89{
91
92 /* see explanation above PgStatShared_BgWriter for the reset protocol */
93 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
95 &stats_shmem->stats,
96 sizeof(stats_shmem->stats),
97 &stats_shmem->changecount);
98 stats_shmem->stats.stat_reset_timestamp = ts;
99 LWLockRelease(&stats_shmem->lock);
100}
PgStat_BgWriterStats reset_offset
PgStat_BgWriterStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:242
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 103 of file pgstat_bgwriter.c.

104{
106 PgStat_BgWriterStats *reset_offset = &stats_shmem->reset_offset;
108
110 &stats_shmem->stats,
111 sizeof(stats_shmem->stats),
112 &stats_shmem->changecount);
113
114 LWLockAcquire(&stats_shmem->lock, LW_SHARED);
115 memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
116 LWLockRelease(&stats_shmem->lock);
117
118 /* compensate by reset offsets */
119#define BGWRITER_COMP(fld) pgStatLocal.snapshot.bgwriter.fld -= reset.fld;
120 BGWRITER_COMP(buf_written_clean);
121 BGWRITER_COMP(maxwritten_clean);
122 BGWRITER_COMP(buf_alloc);
123#undef BGWRITER_COMP
124}
#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_init_shmem_cb()

void pgstat_checkpointer_init_shmem_cb ( void *  stats)

◆ pgstat_checkpointer_reset_all_cb()

void pgstat_checkpointer_reset_all_cb ( TimestampTz  ts)

Definition at line 97 of file pgstat_checkpointer.c.

98{
100
101 /* see explanation above PgStatShared_Checkpointer for the reset protocol */
102 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
104 &stats_shmem->stats,
105 sizeof(stats_shmem->stats),
106 &stats_shmem->changecount);
107 stats_shmem->stats.stat_reset_timestamp = ts;
108 LWLockRelease(&stats_shmem->lock);
109}
PgStat_CheckpointerStats reset_offset
PgStat_CheckpointerStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:265
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, PgStat_CheckpointerStats::stat_reset_timestamp, and PgStatShared_Checkpointer::stats.

◆ pgstat_checkpointer_snapshot_cb()

void pgstat_checkpointer_snapshot_cb ( void  )

Definition at line 112 of file pgstat_checkpointer.c.

113{
115 PgStat_CheckpointerStats *reset_offset = &stats_shmem->reset_offset;
117
119 &stats_shmem->stats,
120 sizeof(stats_shmem->stats),
121 &stats_shmem->changecount);
122
123 LWLockAcquire(&stats_shmem->lock, LW_SHARED);
124 memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
125 LWLockRelease(&stats_shmem->lock);
126
127 /* compensate by reset offsets */
128#define CHECKPOINTER_COMP(fld) pgStatLocal.snapshot.checkpointer.fld -= reset.fld;
129 CHECKPOINTER_COMP(num_timed);
130 CHECKPOINTER_COMP(num_requested);
131 CHECKPOINTER_COMP(num_performed);
132 CHECKPOINTER_COMP(restartpoints_timed);
133 CHECKPOINTER_COMP(restartpoints_requested);
134 CHECKPOINTER_COMP(restartpoints_performed);
135 CHECKPOINTER_COMP(write_time);
136 CHECKPOINTER_COMP(sync_time);
137 CHECKPOINTER_COMP(buffers_written);
138 CHECKPOINTER_COMP(slru_written);
139#undef CHECKPOINTER_COMP
140}
#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 871 of file pgstat_internal.h.

872{
873 Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
874 return memcmp(a, b, sizeof(PgStat_HashKey));
875}
int b
Definition: isn.c:71
int a
Definition: isn.c:70
void * arg

References a, arg, Assert(), 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 855 of file pgstat_internal.h.

857{
858 uint32 cc_before;
859
860 do
861 {
862 cc_before = pgstat_begin_changecount_read(cc);
863
864 memcpy(dst, src, len);
865 }
866 while (!pgstat_end_changecount_read(cc, cc_before));
867}
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 injection_stats_fixed_reset_all_cb(), injection_stats_fixed_snapshot_cb(), 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,
uint64  objid 
)

Definition at line 361 of file pgstat_xact.c.

362{
363 if (pgstat_get_entry_ref(kind, dboid, objid, false, NULL))
364 {
366 errmsg("resetting existing statistics for kind %s, db=%u, oid=%llu",
367 (pgstat_get_kind_info(kind))->name, dboid,
368 (unsigned long long) objid));
369
370 pgstat_reset(kind, dboid, objid);
371 }
372
373 create_drop_transactional_internal(kind, dboid, objid, /* create */ true);
374}
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:149
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:869
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1453
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:444
static void create_drop_transactional_internal(PgStat_Kind kind, Oid dboid, uint64 objid, bool is_create)
Definition: pgstat_xact.c:335
const char * name

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 392 of file pgstat_database.c.

393{
394 PgStatShared_Database *sharedent;
395 PgStat_StatDBEntry *pendingent;
396
397 pendingent = (PgStat_StatDBEntry *) entry_ref->pending;
398 sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
399
400 if (!pgstat_lock_entry(entry_ref, nowait))
401 return false;
402
403#define PGSTAT_ACCUM_DBCOUNT(item) \
404 (sharedent)->stats.item += (pendingent)->item
405
406 PGSTAT_ACCUM_DBCOUNT(xact_commit);
407 PGSTAT_ACCUM_DBCOUNT(xact_rollback);
408 PGSTAT_ACCUM_DBCOUNT(blocks_fetched);
409 PGSTAT_ACCUM_DBCOUNT(blocks_hit);
410
411 PGSTAT_ACCUM_DBCOUNT(tuples_returned);
412 PGSTAT_ACCUM_DBCOUNT(tuples_fetched);
413 PGSTAT_ACCUM_DBCOUNT(tuples_inserted);
414 PGSTAT_ACCUM_DBCOUNT(tuples_updated);
415 PGSTAT_ACCUM_DBCOUNT(tuples_deleted);
416
417 /* last_autovac_time is reported immediately */
418 Assert(pendingent->last_autovac_time == 0);
419
420 PGSTAT_ACCUM_DBCOUNT(conflict_tablespace);
421 PGSTAT_ACCUM_DBCOUNT(conflict_lock);
422 PGSTAT_ACCUM_DBCOUNT(conflict_snapshot);
423 PGSTAT_ACCUM_DBCOUNT(conflict_logicalslot);
424 PGSTAT_ACCUM_DBCOUNT(conflict_bufferpin);
425 PGSTAT_ACCUM_DBCOUNT(conflict_startup_deadlock);
426
427 PGSTAT_ACCUM_DBCOUNT(temp_bytes);
428 PGSTAT_ACCUM_DBCOUNT(temp_files);
429 PGSTAT_ACCUM_DBCOUNT(deadlocks);
430
431 /* checksum failures are reported immediately */
432 Assert(pendingent->checksum_failures == 0);
433 Assert(pendingent->last_checksum_failure == 0);
434
435 PGSTAT_ACCUM_DBCOUNT(blk_read_time);
436 PGSTAT_ACCUM_DBCOUNT(blk_write_time);
437
438 PGSTAT_ACCUM_DBCOUNT(sessions);
439 PGSTAT_ACCUM_DBCOUNT(session_time);
440 PGSTAT_ACCUM_DBCOUNT(active_time);
441 PGSTAT_ACCUM_DBCOUNT(idle_in_transaction_time);
442 PGSTAT_ACCUM_DBCOUNT(sessions_abandoned);
443 PGSTAT_ACCUM_DBCOUNT(sessions_fatal);
444 PGSTAT_ACCUM_DBCOUNT(sessions_killed);
445 PGSTAT_ACCUM_DBCOUNT(parallel_workers_to_launch);
446 PGSTAT_ACCUM_DBCOUNT(parallel_workers_launched);
447#undef PGSTAT_ACCUM_DBCOUNT
448
449 pgstat_unlock_entry(entry_ref);
450
451 memset(pendingent, 0, sizeof(*pendingent));
452
453 return true;
454}
#define PGSTAT_ACCUM_DBCOUNT(item)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:675
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:647
PgStatShared_Common * shared_stats
TimestampTz last_checksum_failure
Definition: pgstat.h:364
TimestampTz last_autovac_time
Definition: pgstat.h:353
PgStat_Counter checksum_failures
Definition: pgstat.h:363

References Assert(), PgStat_StatDBEntry::checksum_failures, PgStat_StatDBEntry::last_autovac_time, PgStat_StatDBEntry::last_checksum_failure, 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 457 of file pgstat_database.c.

458{
459 ((PgStatShared_Database *) header)->stats.stat_reset_timestamp = ts;
460}

◆ pgstat_delete_pending_entry()

void pgstat_delete_pending_entry ( PgStat_EntryRef entry_ref)

Definition at line 1334 of file pgstat.c.

1336{
1337 PgStat_Kind kind = entry_ref->shared_entry->key.kind;
1338 const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
1339 void *pending_data = entry_ref->pending;
1340
1341 Assert(pending_data != NULL);
1342 /* !fixed_amount stats should be handled explicitly */
1343 Assert(!pgstat_get_kind_info(kind)->fixed_amount);
1344
1345 if (kind_info->delete_pending_cb)
1346 kind_info->delete_pending_cb(entry_ref);
1347
1348 pfree(pending_data);
1349 entry_ref->pending = NULL;
1350
1351 dlist_delete(&entry_ref->pending_node);
static void dlist_delete(dlist_node *node)
Definition: ilist.h:405
#define PgStat_Kind
Definition: pgstat_kind.h:17
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(), PgStat_Kind, 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 264 of file pgstat_shmem.c.

265{
267
268 /* we shouldn't leave references to shared stats */
270
273
275
276 /*
277 * dsa_detach() does not decrement the DSA reference count as no segment
278 * was provided to dsa_attach_in_place(), causing no cleanup callbacks to
279 * be registered. Hence, release it manually now.
280 */
282
283 pgStatLocal.dsa = NULL;
284}
void dsa_release_in_place(void *place)
Definition: dsa.c:605
void dsa_detach(dsa_area *area)
Definition: dsa.c:1952
void dshash_detach(dshash_table *hash_table)
Definition: dshash.c:307
static void pgstat_release_all_entry_refs(bool discard_pending)
Definition: pgstat_shmem.c:793

References Assert(), PgStat_LocalState::dsa, dsa_detach(), dsa_release_in_place(), dshash_detach(), pgstat_release_all_entry_refs(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shared_hash, and PgStat_LocalState::shmem.

Referenced by pgstat_shutdown_hook().

◆ pgstat_drop_all_entries()

void pgstat_drop_all_entries ( void  )

Definition at line 1042 of file pgstat_shmem.c.

1043{
1045}
void pgstat_drop_matching_entries(bool(*do_drop)(PgStatShared_HashEntry *, Datum), Datum match_data)

References pgstat_drop_matching_entries().

Referenced by pgstat_reset_after_failure().

◆ pgstat_drop_entry()

bool pgstat_drop_entry ( PgStat_Kind  kind,
Oid  dboid,
uint64  objid 
)

Definition at line 953 of file pgstat_shmem.c.

954{
957 bool freed = true;
958
959 /* clear padding */
960 memset(&key, 0, sizeof(struct PgStat_HashKey));
961
962 key.kind = kind;
963 key.dboid = dboid;
964 key.objid = objid;
965
966 /* delete local reference */
968 {
969 PgStat_EntryRefHashEntry *lohashent =
970 pgstat_entry_ref_hash_lookup(pgStatEntryRefHash, key);
971
972 if (lohashent)
973 pgstat_release_entry_ref(lohashent->key, lohashent->entry_ref,
974 true);
975 }
976
977 /* mark entry in shared hashtable as deleted, drop if possible */
978 shent = dshash_find(pgStatLocal.shared_hash, &key, true);
979 if (shent)
980 {
981 freed = pgstat_drop_entry_internal(shent, NULL);
982
983 /*
984 * Database stats contain other stats. Drop those as well when
985 * dropping the database. XXX: Perhaps this should be done in a
986 * slightly more principled way? But not obvious what that'd look
987 * like, and so far this is the only case...
988 */
989 if (key.kind == PGSTAT_KIND_DATABASE)
991 }
992
993 return freed;
994}
void * dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
Definition: dshash.c:390
#define PGSTAT_KIND_DATABASE
Definition: pgstat_kind.h:27
static void pgstat_release_entry_ref(PgStat_HashKey key, PgStat_EntryRef *entry_ref, bool discard_pending)
Definition: pgstat_shmem.c:576
static void pgstat_drop_database_and_contents(Oid dboid)
Definition: pgstat_shmem.c:892
static pgstat_entry_ref_hash_hash * pgStatEntryRefHash
Definition: pgstat_shmem.c:82
static bool pgstat_drop_entry_internal(PgStatShared_HashEntry *shent, dshash_seq_status *hstat)
Definition: pgstat_shmem.c:852
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_inj(), pgstat_drop_replslot(), pgstat_execute_transactional_drops(), pgstat_init_function_usage(), and pgstat_shutdown_hook().

◆ pgstat_drop_matching_entries()

void pgstat_drop_matching_entries ( bool(*)(PgStatShared_HashEntry *, Datum do_drop,
Datum  match_data 
)

Definition at line 1001 of file pgstat_shmem.c.

1003{
1004 dshash_seq_status hstat;
1006 uint64 not_freed_count = 0;
1007
1008 /* entries are removed, take an exclusive lock */
1010 while ((ps = dshash_seq_next(&hstat)) != NULL)
1011 {
1012 if (ps->dropped)
1013 continue;
1014
1015 if (do_drop != NULL && !do_drop(ps, match_data))
1016 continue;
1017
1018 /* delete local reference */
1020 {
1021 PgStat_EntryRefHashEntry *lohashent =
1022 pgstat_entry_ref_hash_lookup(pgStatEntryRefHash, ps->key);
1023
1024 if (lohashent)
1025 pgstat_release_entry_ref(lohashent->key, lohashent->entry_ref,
1026 true);
1027 }
1028
1029 if (!pgstat_drop_entry_internal(ps, &hstat))
1030 not_freed_count++;
1031 }
1032 dshash_seq_term(&hstat);
1033
1034 if (not_freed_count > 0)
1036}
uint64_t uint64
Definition: c.h:503
void dshash_seq_init(dshash_seq_status *status, dshash_table *hash_table, bool exclusive)
Definition: dshash.c:638
void dshash_seq_term(dshash_seq_status *status)
Definition: dshash.c:747
void * dshash_seq_next(dshash_seq_status *status)
Definition: dshash.c:657
struct parser_state ps
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:700

References dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), PgStat_EntryRefHashEntry::entry_ref, PgStat_EntryRefHashEntry::key, pgstat_drop_entry_internal(), pgstat_release_entry_ref(), pgstat_request_entry_refs_gc(), pgStatEntryRefHash, pgStatLocal, ps, and PgStat_LocalState::shared_hash.

Referenced by injection_points_stats_drop(), and pgstat_drop_all_entries().

◆ pgstat_drop_transactional()

void pgstat_drop_transactional ( PgStat_Kind  kind,
Oid  dboid,
uint64  objid 
)

Definition at line 384 of file pgstat_xact.c.

385{
386 create_drop_transactional_internal(kind, dboid, objid, /* create */ false);
387}

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 831 of file pgstat_internal.h.

832{
833 uint32 after_cc;
834
836
837 after_cc = *cc;
838
839 /* was a write in progress when we started? */
840 if (before_cc & 1)
841 return false;
842
843 /* did writes start and complete while we read? */
844 return before_cc == after_cc;
845}

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 804 of file pgstat_internal.h.

805{
806 Assert((*cc & 1) == 1);
807
809
810 (*cc)++;
811
813}
#define END_CRIT_SECTION()
Definition: miscadmin.h:151

References Assert(), END_CRIT_SECTION, and pg_write_barrier.

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

◆ pgstat_fetch_entry()

void * pgstat_fetch_entry ( PgStat_Kind  kind,
Oid  dboid,
uint64  objid 
)

Definition at line 949 of file pgstat.c.

951{
953 PgStat_EntryRef *entry_ref;
954 void *stats_data;
955 const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
956
957 /* should be called from backends */
959 Assert(!kind_info->fixed_amount);
960
962
963 /* clear padding */
964 memset(&key, 0, sizeof(struct PgStat_HashKey));
965
966 key.kind = kind;
967 key.dboid = dboid;
968 key.objid = objid;
969
970 /* if we need to build a full snapshot, do so */
973
974 /* if caching is desired, look up in cache */
976 {
977 PgStat_SnapshotEntry *entry = NULL;
978
979 entry = pgstat_snapshot_lookup(pgStatLocal.snapshot.stats, key);
980
981 if (entry)
982 return entry->data;
983
984 /*
985 * If we built a full snapshot and the key is not in
986 * pgStatLocal.snapshot.stats, there are no matching stats.
987 */
989 return NULL;
990 }
991
993
994 entry_ref = pgstat_get_entry_ref(kind, dboid, objid, false, NULL);
995
996 if (entry_ref == NULL || entry_ref->shared_entry->dropped)
997 {
998 /* create empty entry when using PGSTAT_FETCH_CONSISTENCY_CACHE */
1000 {
1001 PgStat_SnapshotEntry *entry = NULL;
1002 bool found;
1003
1004 entry = pgstat_snapshot_insert(pgStatLocal.snapshot.stats, key, &found);
1005 Assert(!found);
1006 entry->data = NULL;
1007 }
1008 return NULL;
1009 }
1010
1011 /*
1012 * Allocate in caller's context for PGSTAT_FETCH_CONSISTENCY_NONE,
1013 * otherwise we could quickly end up with a fair bit of memory used due to
1014 * repeated accesses.
1015 */
1017 stats_data = palloc(kind_info->shared_data_len);
1018 else
1020 kind_info->shared_data_len);
1021
1022 pgstat_lock_entry_shared(entry_ref, false);
1023 memcpy(stats_data,
1024 pgstat_get_entry_data(kind, entry_ref->shared_stats),
1025 kind_info->shared_data_len);
1026 pgstat_unlock_entry(entry_ref);
1027
1029 {
1030 PgStat_SnapshotEntry *entry = NULL;
1031 bool found;
1032
1033 entry = pgstat_snapshot_insert(pgStatLocal.snapshot.stats, key, &found);
1034 entry->data = stats_data;
1035 }
1036
1037 return stats_data;
bool IsUnderPostmaster
Definition: globals.c:119
bool IsPostmasterEnvironment
Definition: globals.c:118
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
void * palloc(Size size)
Definition: mcxt.c:1317
int pgstat_fetch_consistency
Definition: pgstat.c:204
static void pgstat_prep_snapshot(void)
Definition: pgstat.c:1117
static void pgstat_build_snapshot(void)
Definition: pgstat.c:1138
@ PGSTAT_FETCH_CONSISTENCY_NONE
Definition: pgstat.h:46
@ PGSTAT_FETCH_CONSISTENCY_CACHE
Definition: pgstat.h:47
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
Definition: pgstat.h:48
static void * pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry)
bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:663
MemoryContext context
PgStat_FetchConsistency mode
struct pgstat_snapshot_hash * stats

References Assert(), 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_lock_entry_shared(), pgstat_prep_snapshot(), pgstat_unlock_entry(), 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_backend(), pgstat_fetch_stat_dbentry(), pgstat_fetch_stat_funcentry(), pgstat_fetch_stat_injentry(), 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,
uint64  objid 
)

Definition at line 1321 of file pgstat.c.

1323{
1324 PgStat_EntryRef *entry_ref;
1325
1326 entry_ref = pgstat_get_entry_ref(kind, dboid, objid, false, NULL);
1327
1328 if (entry_ref == NULL || entry_ref->pending == NULL)
1329 return NULL;
1330
1331 return entry_ref;

References PgStat_EntryRef::pending, and pgstat_get_entry_ref().

Referenced by find_funcstat_entry(), and find_tabstat_entry().

◆ pgstat_flush_backend()

bool pgstat_flush_backend ( bool  nowait,
bits32  flags 
)

Definition at line 259 of file pgstat_backend.c.

260{
261 PgStat_EntryRef *entry_ref;
262 bool has_pending_data = false;
263
265 return false;
266
267 /* Some IO data pending? */
269 has_pending_data = true;
270
271 /* Some WAL data pending? */
272 if ((flags & PGSTAT_BACKEND_FLUSH_WAL) &&
274 has_pending_data = true;
275
276 if (!has_pending_data)
277 return false;
278
280 MyProcNumber, nowait);
281 if (!entry_ref)
282 return true;
283
284 /* Flush requested statistics */
285 if (flags & PGSTAT_BACKEND_FLUSH_IO)
287
288 if (flags & PGSTAT_BACKEND_FLUSH_WAL)
290
291 pgstat_unlock_entry(entry_ref);
292
293 return false;
294}
ProcNumber MyProcNumber
Definition: globals.c:89
static void pgstat_flush_backend_entry_wal(PgStat_EntryRef *entry_ref)
static void pgstat_flush_backend_entry_io(PgStat_EntryRef *entry_ref)
#define PGSTAT_BACKEND_FLUSH_IO
#define PGSTAT_BACKEND_FLUSH_WAL
#define PGSTAT_KIND_BACKEND
Definition: pgstat_kind.h:32
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
Definition: pgstat_shmem.c:684
#define InvalidOid
Definition: postgres_ext.h:37

References backend_has_iostats, InvalidOid, MyBackendType, MyProcNumber, PGSTAT_BACKEND_FLUSH_IO, PGSTAT_BACKEND_FLUSH_WAL, pgstat_backend_wal_have_pending(), pgstat_flush_backend_entry_io(), pgstat_flush_backend_entry_wal(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_BACKEND, pgstat_tracks_backend_bktype(), and pgstat_unlock_entry().

Referenced by pgstat_backend_flush_cb(), pgstat_report_analyze(), pgstat_report_vacuum(), and pgstat_report_wal().

◆ pgstat_flush_io()

void pgstat_flush_io ( bool  nowait)

Definition at line 183 of file pgstat_io.c.

184{
185 (void) pgstat_io_flush_cb(nowait);
186}
bool pgstat_io_flush_cb(bool nowait)
Definition: pgstat_io.c:197

References pgstat_io_flush_cb().

Referenced by pgstat_report_analyze(), pgstat_report_bgwriter(), pgstat_report_checkpointer(), pgstat_report_vacuum(), 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_FunctionCounts *localent;
196 PgStatShared_Function *shfuncent;
197
198 localent = (PgStat_FunctionCounts *) 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.numcalls += localent->numcalls;
207 shfuncent->stats.total_time +=
209 shfuncent->stats.self_time +=
211
212 pgstat_unlock_entry(entry_ref);
213
214 return true;
215}
#define INSTR_TIME_GET_MICROSEC(t)
Definition: instr_time.h:194
PgStat_StatFuncEntry stats
PgStat_Counter numcalls
Definition: pgstat.h:82
instr_time total_time
Definition: pgstat.h:83
instr_time self_time
Definition: pgstat.h:84
PgStat_Counter self_time
Definition: pgstat.h:385
PgStat_Counter numcalls
Definition: pgstat.h:382
PgStat_Counter total_time
Definition: pgstat.h:384

References INSTR_TIME_GET_MICROSEC, PgStat_FunctionCounts::numcalls, PgStat_StatFuncEntry::numcalls, PgStat_EntryRef::pending, pgstat_lock_entry(), pgstat_unlock_entry(), PgStat_FunctionCounts::self_time, PgStat_StatFuncEntry::self_time, PgStat_EntryRef::shared_stats, PgStatShared_Function::stats, PgStat_FunctionCounts::total_time, and PgStat_StatFuncEntry::total_time.

◆ pgstat_get_custom_shmem_data()

static void * pgstat_get_custom_shmem_data ( PgStat_Kind  kind)
inlinestatic

Definition at line 914 of file pgstat_internal.h.

915{
916 int idx = kind - PGSTAT_KIND_CUSTOM_MIN;
917
919 Assert(pgstat_get_kind_info(kind)->fixed_amount);
920
922}
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1453
PGDLLIMPORT PgStat_LocalState pgStatLocal
Definition: pgstat.c:212
static bool pgstat_is_kind_custom(PgStat_Kind kind)
Definition: pgstat_kind.h:67
#define PGSTAT_KIND_CUSTOM_MIN
Definition: pgstat_kind.h:49
void * custom_data[PGSTAT_KIND_CUSTOM_SIZE]

References Assert(), PgStat_ShmemControl::custom_data, idx(), pgstat_get_kind_info(), pgstat_is_kind_custom(), PGSTAT_KIND_CUSTOM_MIN, pgStatLocal, and PgStat_LocalState::shmem.

Referenced by injection_stats_fixed_reset_all_cb(), injection_stats_fixed_snapshot_cb(), and pgstat_report_inj_fixed().

◆ pgstat_get_custom_snapshot_data()

static void * pgstat_get_custom_snapshot_data ( PgStat_Kind  kind)
inlinestatic

◆ pgstat_get_entry_data()

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

Definition at line 900 of file pgstat_internal.h.

901{
902 size_t off = pgstat_get_kind_info(kind)->shared_data_off;
903
904 Assert(off != 0 && off < PG_UINT32_MAX);
905
906 return ((char *) (entry)) + off;
907}
#define PG_UINT32_MAX
Definition: c.h:561

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,
uint64  objid,
bool  create,
bool *  created_entry 
)

Definition at line 444 of file pgstat_shmem.c.

446{
448 PgStatShared_HashEntry *shhashent;
449 PgStatShared_Common *shheader = NULL;
450 PgStat_EntryRef *entry_ref;
451
452 /* clear padding */
453 memset(&key, 0, sizeof(struct PgStat_HashKey));
454
455 key.kind = kind;
456 key.dboid = dboid;
457 key.objid = objid;
458
459 /*
460 * passing in created_entry only makes sense if we possibly could create
461 * entry.
462 */
463 Assert(create || created_entry == NULL);
467
470
471 if (created_entry != NULL)
472 *created_entry = false;
473
474 /*
475 * Check if other backends dropped stats that could not be deleted because
476 * somebody held references to it. If so, check this backend's references.
477 * This is not expected to happen often. The location of the check is a
478 * bit random, but this is a relatively frequently called path, so better
479 * than most.
480 */
483
484 /*
485 * First check the lookup cache hashtable in local memory. If we find a
486 * match here we can avoid taking locks / causing contention.
487 */
488 if (pgstat_get_entry_ref_cached(key, &entry_ref))
489 return entry_ref;
490
491 Assert(entry_ref != NULL);
492
493 /*
494 * Do a lookup in the hash table first - it's quite likely that the entry
495 * already exists, and that way we only need a shared lock.
496 */
497 shhashent = dshash_find(pgStatLocal.shared_hash, &key, false);
498
499 if (create && !shhashent)
500 {
501 bool shfound;
502
503 /*
504 * It's possible that somebody created the entry since the above
505 * lookup. If so, fall through to the same path as if we'd have if it
506 * already had been created before the dshash_find() calls.
507 */
508 shhashent = dshash_find_or_insert(pgStatLocal.shared_hash, &key, &shfound);
509 if (!shfound)
510 {
511 shheader = pgstat_init_entry(kind, shhashent);
512 pgstat_acquire_entry_ref(entry_ref, shhashent, shheader);
513
514 if (created_entry != NULL)
515 *created_entry = true;
516
517 return entry_ref;
518 }
519 }
520
521 if (!shhashent)
522 {
523 /*
524 * If we're not creating, delete the reference again. In all
525 * likelihood it's just a stats lookup - no point wasting memory for a
526 * shared ref to nothing...
527 */
528 pgstat_release_entry_ref(key, entry_ref, false);
529
530 return NULL;
531 }
532 else
533 {
534 /*
535 * Can get here either because dshash_find() found a match, or if
536 * dshash_find_or_insert() found a concurrently inserted entry.
537 */
538
539 if (shhashent->dropped && create)
540 {
541 /*
542 * There are legitimate cases where the old stats entry might not
543 * yet have been dropped by the time it's reused. The most obvious
544 * case are replication slot stats, where a new slot can be
545 * created with the same index just after dropping. But oid
546 * wraparound can lead to other cases as well. We just reset the
547 * stats to their plain state, while incrementing its "generation"
548 * in the shared entry for any remaining local references.
549 */
550 shheader = pgstat_reinit_entry(kind, shhashent);
551 pgstat_acquire_entry_ref(entry_ref, shhashent, shheader);
552
553 if (created_entry != NULL)
554 *created_entry = true;
555
556 return entry_ref;
557 }
558 else if (shhashent->dropped)
559 {
561 pgstat_release_entry_ref(key, entry_ref, false);
562
563 return NULL;
564 }
565 else
566 {
567 shheader = dsa_get_address(pgStatLocal.dsa, shhashent->body);
568 pgstat_acquire_entry_ref(entry_ref, shhashent, shheader);
569
570 return entry_ref;
571 }
572 }
573}
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition: dsa.c:942
void dshash_release_lock(dshash_table *hash_table, void *entry)
Definition: dshash.c:558
void * dshash_find_or_insert(dshash_table *hash_table, const void *key, bool *found)
Definition: dshash.c:433
#define pgstat_assert_is_up()
static void pgstat_setup_memcxt(void)
static void pgstat_setup_shared_refs(void)
Definition: pgstat_shmem.c:352
static PgStatShared_Common * pgstat_reinit_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
Definition: pgstat_shmem.c:327
static void pgstat_acquire_entry_ref(PgStat_EntryRef *entry_ref, PgStatShared_HashEntry *shhashent, PgStatShared_Common *shheader)
Definition: pgstat_shmem.c:368
PgStatShared_Common * pgstat_init_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
Definition: pgstat_shmem.c:293
static bool pgstat_get_entry_ref_cached(PgStat_HashKey key, PgStat_EntryRef **entry_ref_p)
Definition: pgstat_shmem.c:388
static void pgstat_gc_entry_refs(void)
Definition: pgstat_shmem.c:722
static bool pgstat_need_entry_refs_gc(void)
Definition: pgstat_shmem.c:706

References Assert(), 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_acquire_replslot(), pgstat_create_subscription(), 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,
uint64  objid,
bool  nowait 
)

Definition at line 684 of file pgstat_shmem.c.

686{
687 PgStat_EntryRef *entry_ref;
688
689 /* find shared table stats entry corresponding to the local entry */
690 entry_ref = pgstat_get_entry_ref(kind, dboid, objid, true, NULL);
691
692 /* lock the shared entry to protect the content, skip if failed */
693 if (!pgstat_lock_entry(entry_ref, nowait))
694 return NULL;
695
696 return entry_ref;
697}

References pgstat_get_entry_ref(), and pgstat_lock_entry().

Referenced by pgstat_copy_relation_stats(), pgstat_create_backend(), pgstat_create_replslot(), pgstat_flush_backend(), 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()

const PgStat_KindInfo * pgstat_get_kind_info ( PgStat_Kind  kind)

Definition at line 1453 of file pgstat.c.

1455{
1456 if (pgstat_is_kind_builtin(kind))
1457 return &pgstat_kind_builtin_infos[kind];
1458
1459 if (pgstat_is_kind_custom(kind))
1460 {
1462
1463 if (pgstat_kind_custom_infos == NULL ||
1465 return NULL;
1467 }
1468
1469 return NULL;
static const PgStat_KindInfo ** pgstat_kind_custom_infos
Definition: pgstat.c:491
static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
Definition: pgstat.c:276
static bool pgstat_is_kind_builtin(PgStat_Kind kind)
Definition: pgstat_kind.h:61

References idx(), pgstat_is_kind_builtin(), pgstat_is_kind_custom(), pgstat_kind_builtin_infos, pgstat_kind_custom_infos, and PGSTAT_KIND_CUSTOM_MIN.

Referenced by pgstat_build_snapshot(), pgstat_build_snapshot_fixed(), pgstat_create_transactional(), pgstat_delete_pending_entry(), pgstat_drop_entry_internal(), pgstat_fetch_entry(), pgstat_flush_pending_entries(), pgstat_get_custom_shmem_data(), pgstat_get_custom_snapshot_data(), pgstat_get_entry_data(), pgstat_get_entry_len(), pgstat_have_entry(), pgstat_init_entry(), pgstat_init_snapshot_fixed(), pgstat_initialize(), pgstat_prep_pending_entry(), pgstat_read_statsfile(), pgstat_report_stat(), pgstat_reset(), pgstat_reset_after_failure(), pgstat_reset_entry(), pgstat_reset_of_kind(), pgstat_snapshot_fixed(), pgstat_write_statsfile(), shared_stat_reset_contents(), StatsShmemInit(), and StatsShmemSize().

◆ pgstat_get_xact_stack_level()

PgStat_SubXactStatus * pgstat_get_xact_stack_level ( int  nest_level)

Definition at line 238 of file pgstat_xact.c.

239{
240 PgStat_SubXactStatus *xact_state;
241
242 xact_state = pgStatXactStack;
243 if (xact_state == NULL || xact_state->nest_level != nest_level)
244 {
245 xact_state = (PgStat_SubXactStatus *)
247 sizeof(PgStat_SubXactStatus));
248 dclist_init(&xact_state->pending_drops);
249 xact_state->nest_level = nest_level;
250 xact_state->prev = pgStatXactStack;
251 xact_state->first = NULL;
252 pgStatXactStack = xact_state;
253 }
254 return xact_state;
255}
static void dclist_init(dclist_head *head)
Definition: ilist.h:671
MemoryContext TopTransactionContext
Definition: mcxt.c:154
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat_xact.c:33
struct PgStat_SubXactStatus * prev

References dclist_init(), PgStat_SubXactStatus::first, MemoryContextAlloc(), PgStat_SubXactStatus::nest_level, PgStat_SubXactStatus::pending_drops, 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 878 of file pgstat_internal.h.

879{
880 const char *key = (const char *) d;
881
882 Assert(size == sizeof(PgStat_HashKey) && arg == NULL);
883 return fasthash32(key, size, 0);
884}
static uint32 fasthash32(const char *k, size_t len, uint64 seed)

References arg, Assert(), fasthash32(), and sort-test::key.

◆ pgstat_init_entry()

PgStatShared_Common * pgstat_init_entry ( PgStat_Kind  kind,
PgStatShared_HashEntry shhashent 
)

Definition at line 293 of file pgstat_shmem.c.

295{
296 /* Create new stats entry. */
297 dsa_pointer chunk;
298 PgStatShared_Common *shheader;
299
300 /*
301 * Initialize refcount to 1, marking it as valid / not dropped. The entry
302 * can't be freed before the initialization because it can't be found as
303 * long as we hold the dshash partition lock. Caller needs to increase
304 * further if a longer lived reference is needed.
305 */
306 pg_atomic_init_u32(&shhashent->refcount, 1);
307
308 /*
309 * Initialize "generation" to 0, as freshly created.
310 */
311 pg_atomic_init_u32(&shhashent->generation, 0);
312 shhashent->dropped = false;
313
314 chunk = dsa_allocate0(pgStatLocal.dsa, pgstat_get_kind_info(kind)->shared_size);
315 shheader = dsa_get_address(pgStatLocal.dsa, chunk);
316 shheader->magic = 0xdeadbeef;
317
318 /* Link the new entry from the hash entry. */
319 shhashent->body = chunk;
320
322
323 return shheader;
324}
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:221
#define dsa_allocate0(area, size)
Definition: dsa.h:113
uint64 dsa_pointer
Definition: dsa.h:62
pg_atomic_uint32 refcount
pg_atomic_uint32 generation

References PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_allocate0, dsa_get_address(), PgStatShared_HashEntry::generation, 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_io_flush_cb()

bool pgstat_io_flush_cb ( bool  nowait)

Definition at line 197 of file pgstat_io.c.

198{
199 LWLock *bktype_lock;
200 PgStat_BktypeIO *bktype_shstats;
201
202 if (!have_iostats)
203 return false;
204
205 bktype_lock = &pgStatLocal.shmem->io.locks[MyBackendType];
206 bktype_shstats =
208
209 if (!nowait)
210 LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
211 else if (!LWLockConditionalAcquire(bktype_lock, LW_EXCLUSIVE))
212 return true;
213
214 for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
215 {
216 for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
217 {
218 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
219 {
220 instr_time time;
221
222 bktype_shstats->counts[io_object][io_context][io_op] +=
223 PendingIOStats.counts[io_object][io_context][io_op];
224
225 bktype_shstats->bytes[io_object][io_context][io_op] +=
226 PendingIOStats.bytes[io_object][io_context][io_op];
227
228 time = PendingIOStats.pending_times[io_object][io_context][io_op];
229
230 bktype_shstats->times[io_object][io_context][io_op] +=
232 }
233 }
234 }
235
237
238 LWLockRelease(bktype_lock);
239
240 memset(&PendingIOStats, 0, sizeof(PendingIOStats));
241
242 have_iostats = false;
243
244 return false;
245}
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1350
#define IOOP_NUM_TYPES
Definition: pgstat.h:316
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:290
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:279
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
Definition: pgstat_io.c:37
static PgStat_PendingIO PendingIOStats
Definition: pgstat_io.c:23
static bool have_iostats
Definition: pgstat_io.c:24
Definition: lwlock.h:42
LWLock locks[BACKEND_NUM_TYPES]
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:326
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:324
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:325
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:339
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:332
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:331
instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:333
PgStatShared_IO io

References Assert(), PgStat_BktypeIO::bytes, PgStat_PendingIO::bytes, PgStat_BktypeIO::counts, PgStat_PendingIO::counts, have_iostats, INSTR_TIME_GET_MICROSEC, PgStat_ShmemControl::io, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, PgStatShared_IO::locks, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockRelease(), MyBackendType, PgStat_PendingIO::pending_times, PendingIOStats, pgstat_bktype_io_stats_valid(), pgStatLocal, PgStat_LocalState::shmem, PgStat_IO::stats, PgStatShared_IO::stats, and PgStat_BktypeIO::times.

Referenced by pgstat_flush_io().

◆ pgstat_io_have_pending_cb()

bool pgstat_io_have_pending_cb ( void  )

Definition at line 174 of file pgstat_io.c.

175{
176 return have_iostats;
177}

References have_iostats.

◆ pgstat_io_init_shmem_cb()

void pgstat_io_init_shmem_cb ( void *  stats)

Definition at line 286 of file pgstat_io.c.

287{
288 PgStatShared_IO *stat_shmem = (PgStatShared_IO *) stats;
289
290 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
292}
int i
Definition: isn.c:74
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:376

References BACKEND_NUM_TYPES, i, PgStatShared_IO::locks, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_io_reset_all_cb()

void pgstat_io_reset_all_cb ( TimestampTz  ts)

Definition at line 295 of file pgstat_io.c.

296{
297 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
298 {
299 LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
300 PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
301
302 LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
303
304 /*
305 * Use the lock in the first BackendType's PgStat_BktypeIO to protect
306 * the reset timestamp as well.
307 */
308 if (i == 0)
310
311 memset(bktype_shstats, 0, sizeof(*bktype_shstats));
312 LWLockRelease(bktype_lock);
313 }
314}
TimestampTz stat_reset_timestamp
Definition: pgstat.h:338

References BACKEND_NUM_TYPES, i, PgStat_ShmemControl::io, PgStatShared_IO::locks, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_IO::stat_reset_timestamp, PgStat_IO::stats, and PgStatShared_IO::stats.

◆ pgstat_io_snapshot_cb()

void pgstat_io_snapshot_cb ( void  )

Definition at line 317 of file pgstat_io.c.

318{
319 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
320 {
321 LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
322 PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
323 PgStat_BktypeIO *bktype_snap = &pgStatLocal.snapshot.io.stats[i];
324
325 LWLockAcquire(bktype_lock, LW_SHARED);
326
327 /*
328 * Use the lock in the first BackendType's PgStat_BktypeIO to protect
329 * the reset timestamp as well.
330 */
331 if (i == 0)
334
335 /* using struct assignment due to better type safety */
336 *bktype_snap = *bktype_shstats;
337 LWLockRelease(bktype_lock);
338 }
339}

References BACKEND_NUM_TYPES, i, PgStat_ShmemControl::io, PgStat_Snapshot::io, PgStatShared_IO::locks, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, PgStat_IO::stat_reset_timestamp, PgStat_IO::stats, and PgStatShared_IO::stats.

◆ pgstat_lock_entry()

◆ pgstat_lock_entry_shared()

bool pgstat_lock_entry_shared ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 663 of file pgstat_shmem.c.

664{
665 LWLock *lock = &entry_ref->shared_stats->lock;
666
667 if (nowait)
669
671 return true;
672}

References PgStatShared_Common::lock, LW_SHARED, LWLockAcquire(), LWLockConditionalAcquire(), and PgStat_EntryRef::shared_stats.

Referenced by pgstat_fetch_entry().

◆ pgstat_prep_database_pending()

PgStat_StatDBEntry * pgstat_prep_database_pending ( Oid  dboid)

Definition at line 350 of file pgstat_database.c.

351{
352 PgStat_EntryRef *entry_ref;
353
354 /*
355 * This should not report stats on database objects before having
356 * connected to a database.
357 */
359
361 NULL);
362
363 return entry_ref->pending;
364}
#define OidIsValid(objectId)
Definition: c.h:746
Oid MyDatabaseId
Definition: globals.c:93
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition: pgstat.c:1283

References Assert(), InvalidOid, MyDatabaseId, OidIsValid, 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(), pgstat_update_dbstats(), and pgstat_update_parallel_workers_stats().

◆ pgstat_prep_pending_entry()

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

Definition at line 1283 of file pgstat.c.

1285{
1286 PgStat_EntryRef *entry_ref;
1287
1288 /* need to be able to flush out */
1289 Assert(pgstat_get_kind_info(kind)->flush_pending_cb != NULL);
1290
1292 {
1295 "PgStat Pending",
1297 }
1298
1299 entry_ref = pgstat_get_entry_ref(kind, dboid, objid,
1300 true, created_entry);
1301
1302 if (entry_ref->pending == NULL)
1303 {
1304 size_t entrysize = pgstat_get_kind_info(kind)->pending_size;
1305
1306 Assert(entrysize != (size_t) -1);
1307
1308 entry_ref->pending = MemoryContextAllocZero(pgStatPendingContext, entrysize);
1310 }
1311
1312 return entry_ref;
#define unlikely(x)
Definition: c.h:347
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:364
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1215
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_SMALL_SIZES
Definition: memutils.h:170
static MemoryContext pgStatPendingContext
Definition: pgstat.c:229
static dlist_head pgStatPending
Definition: pgstat.c:237

References ALLOCSET_SMALL_SIZES, AllocSetContextCreate, Assert(), 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, TopMemoryContext, and unlikely.

Referenced by pgstat_create_inj(), pgstat_init_function_usage(), pgstat_prep_database_pending(), pgstat_prep_relation_pending(), pgstat_report_inj(), pgstat_report_subscription_conflict(), and pgstat_report_subscription_error().

◆ pgstat_register_kind()

void pgstat_register_kind ( PgStat_Kind  kind,
const PgStat_KindInfo kind_info 
)

Definition at line 1481 of file pgstat.c.

1483{
1485
1486 if (kind_info->name == NULL || strlen(kind_info->name) == 0)
1487 ereport(ERROR,
1488 (errmsg("custom cumulative statistics name is invalid"),
1489 errhint("Provide a non-empty name for the custom cumulative statistics.")));
1490
1491 if (!pgstat_is_kind_custom(kind))
1492 ereport(ERROR, (errmsg("custom cumulative statistics ID %u is out of range", kind),
1493 errhint("Provide a custom cumulative statistics ID between %u and %u.",
1495
1497 ereport(ERROR,
1498 (errmsg("failed to register custom cumulative statistics \"%s\" with ID %u", kind_info->name, kind),
1499 errdetail("Custom cumulative statistics must be registered while initializing modules in \"shared_preload_libraries\".")));
1500
1501 /*
1502 * Check some data for fixed-numbered stats.
1503 */
1504 if (kind_info->fixed_amount)
1505 {
1506 if (kind_info->shared_size == 0)
1507 ereport(ERROR,
1508 (errmsg("custom cumulative statistics property is invalid"),
1509 errhint("Custom cumulative statistics require a shared memory size for fixed-numbered objects.")));
1510 }
1511
1512 /*
1513 * If pgstat_kind_custom_infos is not available yet, allocate it.
1514 */
1515 if (pgstat_kind_custom_infos == NULL)
1516 {
1520 }
1521
1522 if (pgstat_kind_custom_infos[idx] != NULL &&
1524 ereport(ERROR,
1525 (errmsg("failed to register custom cumulative statistics \"%s\" with ID %u", kind_info->name, kind),
1526 errdetail("Custom cumulative statistics \"%s\" already registered with the same ID.",
1528
1529 /* check for existing custom stats with the same name */
1530 for (PgStat_Kind existing_kind = PGSTAT_KIND_CUSTOM_MIN; existing_kind <= PGSTAT_KIND_CUSTOM_MAX; existing_kind++)
1531 {
1532 uint32 existing_idx = existing_kind - PGSTAT_KIND_CUSTOM_MIN;
1533
1534 if (pgstat_kind_custom_infos[existing_idx] == NULL)
1535 continue;
1536 if (!pg_strcasecmp(pgstat_kind_custom_infos[existing_idx]->name, kind_info->name))
1537 ereport(ERROR,
1538 (errmsg("failed to register custom cumulative statistics \"%s\" with ID %u", kind_info->name, kind),
1539 errdetail("Existing cumulative statistics with ID %u has the same name.", existing_kind)));
1540 }
1541
1542 /* Register it */
1543 pgstat_kind_custom_infos[idx] = kind_info;
1544 ereport(LOG,
1545 (errmsg("registered custom cumulative statistics \"%s\" with ID %u",
1546 kind_info->name, kind)));
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errhint(const char *fmt,...)
Definition: elog.c:1317
#define LOG
Definition: elog.h:31
#define ERROR
Definition: elog.h:39
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1837
#define PGSTAT_KIND_CUSTOM_MAX
Definition: pgstat_kind.h:50
#define PGSTAT_KIND_CUSTOM_SIZE
Definition: pgstat_kind.h:51
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char *const name

References ereport, errdetail(), errhint(), errmsg(), ERROR, PgStat_KindInfo::fixed_amount, idx(), LOG, MemoryContextAllocZero(), name, PgStat_KindInfo::name, pg_strcasecmp(), pgstat_is_kind_custom(), PgStat_Kind, pgstat_kind_custom_infos, PGSTAT_KIND_CUSTOM_MAX, PGSTAT_KIND_CUSTOM_MIN, PGSTAT_KIND_CUSTOM_SIZE, process_shared_preload_libraries_in_progress, PgStat_KindInfo::shared_size, and TopMemoryContext.

Referenced by pgstat_register_inj(), and pgstat_register_inj_fixed().

◆ pgstat_relation_delete_pending_cb()

void pgstat_relation_delete_pending_cb ( PgStat_EntryRef entry_ref)

Definition at line 896 of file pgstat_relation.c.

897{
898 PgStat_TableStatus *pending = (PgStat_TableStatus *) entry_ref->pending;
899
900 if (pending->relation)
902}
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:78
void pgstat_unlink_relation(Relation rel)
Relation relation
Definition: pgstat.h:179

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 816 of file pgstat_relation.c.

817{
818 Oid dboid;
819 PgStat_TableStatus *lstats; /* pending stats entry */
820 PgStatShared_Relation *shtabstats;
821 PgStat_StatTabEntry *tabentry; /* table entry of shared stats */
822 PgStat_StatDBEntry *dbentry; /* pending database entry */
823
824 dboid = entry_ref->shared_entry->key.dboid;
825 lstats = (PgStat_TableStatus *) entry_ref->pending;
826 shtabstats = (PgStatShared_Relation *) entry_ref->shared_stats;
827
828 /*
829 * Ignore entries that didn't accumulate any actual counts, such as
830 * indexes that were opened by the planner but not used.
831 */
832 if (pg_memory_is_all_zeros(&lstats->counts,
833 sizeof(struct PgStat_TableCounts)))
834 return true;
835
836 if (!pgstat_lock_entry(entry_ref, nowait))
837 return false;
838
839 /* add the values to the shared entry. */
840 tabentry = &shtabstats->stats;
841
842 tabentry->numscans += lstats->counts.numscans;
843 if (lstats->counts.numscans)
844 {
846
847 if (t > tabentry->lastscan)
848 tabentry->lastscan = t;
849 }
850 tabentry->tuples_returned += lstats->counts.tuples_returned;
851 tabentry->tuples_fetched += lstats->counts.tuples_fetched;
852 tabentry->tuples_inserted += lstats->counts.tuples_inserted;
853 tabentry->tuples_updated += lstats->counts.tuples_updated;
854 tabentry->tuples_deleted += lstats->counts.tuples_deleted;
855 tabentry->tuples_hot_updated += lstats->counts.tuples_hot_updated;
857
858 /*
859 * If table was truncated/dropped, first reset the live/dead counters.
860 */
861 if (lstats->counts.truncdropped)
862 {
863 tabentry->live_tuples = 0;
864 tabentry->dead_tuples = 0;
865 tabentry->ins_since_vacuum = 0;
866 }
867
868 tabentry->live_tuples += lstats->counts.delta_live_tuples;
869 tabentry->dead_tuples += lstats->counts.delta_dead_tuples;
870 tabentry->mod_since_analyze += lstats->counts.changed_tuples;
871 tabentry->ins_since_vacuum += lstats->counts.tuples_inserted;
872 tabentry->blocks_fetched += lstats->counts.blocks_fetched;
873 tabentry->blocks_hit += lstats->counts.blocks_hit;
874
875 /* Clamp live_tuples in case of negative delta_live_tuples */
876 tabentry->live_tuples = Max(tabentry->live_tuples, 0);
877 /* Likewise for dead_tuples */
878 tabentry->dead_tuples = Max(tabentry->dead_tuples, 0);
879
880 pgstat_unlock_entry(entry_ref);
881
882 /* The entry was successfully flushed, add the same to database stats */
883 dbentry = pgstat_prep_database_pending(dboid);
884 dbentry->tuples_returned += lstats->counts.tuples_returned;
885 dbentry->tuples_fetched += lstats->counts.tuples_fetched;
886 dbentry->tuples_inserted += lstats->counts.tuples_inserted;
887 dbentry->tuples_updated += lstats->counts.tuples_updated;
888 dbentry->tuples_deleted += lstats->counts.tuples_deleted;
889 dbentry->blocks_fetched += lstats->counts.blocks_fetched;
890 dbentry->blocks_hit += lstats->counts.blocks_hit;
891
892 return true;
893}
#define Max(x, y)
Definition: c.h:969
int64 TimestampTz
Definition: timestamp.h:39
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
Definition: memutils.h:219
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
unsigned int Oid
Definition: postgres_ext.h:32
PgStat_StatTabEntry stats
PgStat_Counter tuples_updated
Definition: pgstat.h:351
PgStat_Counter tuples_inserted
Definition: pgstat.h:350
PgStat_Counter tuples_returned
Definition: pgstat.h:348
PgStat_Counter blocks_hit
Definition: pgstat.h:347
PgStat_Counter blocks_fetched
Definition: pgstat.h:346
PgStat_Counter tuples_deleted
Definition: pgstat.h:352
PgStat_Counter tuples_fetched
Definition: pgstat.h:349
PgStat_Counter tuples_fetched
Definition: pgstat.h:427
PgStat_Counter ins_since_vacuum
Definition: pgstat.h:438
PgStat_Counter blocks_hit
Definition: pgstat.h:441
PgStat_Counter mod_since_analyze
Definition: pgstat.h:437
PgStat_Counter tuples_deleted
Definition: pgstat.h:431
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:432
PgStat_Counter tuples_updated
Definition: pgstat.h:430
PgStat_Counter live_tuples
Definition: pgstat.h:435
PgStat_Counter numscans
Definition: pgstat.h:423
PgStat_Counter dead_tuples
Definition: pgstat.h:436
PgStat_Counter blocks_fetched
Definition: pgstat.h:440
PgStat_Counter tuples_returned
Definition: pgstat.h:426
TimestampTz lastscan
Definition: pgstat.h:424
PgStat_Counter tuples_inserted
Definition: pgstat.h:429
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:433
PgStat_Counter blocks_hit
Definition: pgstat.h:155
PgStat_Counter numscans
Definition: pgstat.h:138
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:146
PgStat_Counter tuples_returned
Definition: pgstat.h:140
PgStat_Counter blocks_fetched
Definition: pgstat.h:154
PgStat_Counter tuples_fetched
Definition: pgstat.h:141
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:147
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition: xact.c:891

References PgStat_TableCounts::blocks_fetched, PgStat_StatDBEntry::blocks_fetched, PgStat_StatTabEntry::blocks_fetched, PgStat_TableCounts::blocks_hit, PgStat_StatDBEntry::blocks_hit, PgStat_StatTabEntry::blocks_hit, PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_HashKey::dboid, PgStat_StatTabEntry::dead_tuples, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, GetCurrentTransactionStopTimestamp(), PgStat_StatTabEntry::ins_since_vacuum, PgStatShared_HashEntry::key, PgStat_StatTabEntry::lastscan, PgStat_StatTabEntry::live_tuples, Max, PgStat_StatTabEntry::mod_since_analyze, PgStat_TableCounts::numscans, PgStat_StatTabEntry::numscans, PgStat_EntryRef::pending, pg_memory_is_all_zeros(), pgstat_lock_entry(), pgstat_prep_database_pending(), pgstat_unlock_entry(), PgStat_EntryRef::shared_entry, PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, PgStat_TableCounts::truncdropped, PgStat_TableCounts::tuples_deleted, PgStat_StatDBEntry::tuples_deleted, PgStat_StatTabEntry::tuples_deleted, PgStat_TableCounts::tuples_fetched, PgStat_StatDBEntry::tuples_fetched, PgStat_StatTabEntry::tuples_fetched, PgStat_TableCounts::tuples_hot_updated, PgStat_StatTabEntry::tuples_hot_updated, PgStat_TableCounts::tuples_inserted, PgStat_StatDBEntry::tuples_inserted, PgStat_StatTabEntry::tuples_inserted, PgStat_TableCounts::tuples_newpage_updated, PgStat_StatTabEntry::tuples_newpage_updated, PgStat_TableCounts::tuples_returned, PgStat_StatDBEntry::tuples_returned, PgStat_StatTabEntry::tuples_returned, PgStat_TableCounts::tuples_updated, PgStat_StatDBEntry::tuples_updated, 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 202 of file pgstat_replslot.c.

203{
204 int idx = get_replslot_index(NameStr(*name), true);
205
206 /* slot might have been deleted */
207 if (idx == -1)
208 return false;
209
211 key->dboid = InvalidOid;
212 key->objid = idx;
213
214 return true;
215}
#define NameStr(name)
Definition: c.h:717
#define PGSTAT_KIND_REPLSLOT
Definition: pgstat_kind.h:30
static int get_replslot_index(const char *name, bool need_lock)

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 218 of file pgstat_replslot.c.

219{
220 ((PgStatShared_ReplSlot *) header)->stats.stat_reset_timestamp = ts;
221}

◆ pgstat_replslot_to_serialized_name_cb()

void pgstat_replslot_to_serialized_name_cb ( const PgStat_HashKey key,
const PgStatShared_Common header,
NameData name 
)

Definition at line 189 of file pgstat_replslot.c.

190{
191 /*
192 * This is only called late during shutdown. The set of existing slots
193 * isn't allowed to change at this point, we can assume that a slot exists
194 * at the offset.
195 */
196 if (!ReplicationSlotName(key->objid, name))
197 elog(ERROR, "could not find name for replication slot index %llu",
198 (unsigned long long) key->objid);
199}
#define elog(elevel,...)
Definition: elog.h:225
bool ReplicationSlotName(int index, Name name)
Definition: slot.c:528

References elog, ERROR, sort-test::key, name, and ReplicationSlotName().

◆ pgstat_report_disconnect()

void pgstat_report_disconnect ( Oid  dboid)

Definition at line 208 of file pgstat_database.c.

209{
210 PgStat_StatDBEntry *dbentry;
211
213 return;
214
216
217 switch (pgStatSessionEndCause)
218 {
221 /* we don't collect these */
222 break;
224 dbentry->sessions_abandoned++;
225 break;
226 case DISCONNECT_FATAL:
227 dbentry->sessions_fatal++;
228 break;
230 dbentry->sessions_killed++;
231 break;
232 }
233}
@ DISCONNECT_NOT_YET
Definition: pgstat.h:54
@ DISCONNECT_FATAL
Definition: pgstat.h:57
@ DISCONNECT_KILLED
Definition: pgstat.h:58
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:56
@ DISCONNECT_NORMAL
Definition: pgstat.h:55
static bool pgstat_should_report_connstat(void)
SessionEndType pgStatSessionEndCause
PgStat_Counter sessions_fatal
Definition: pgstat.h:372
PgStat_Counter sessions_abandoned
Definition: pgstat.h:371
PgStat_Counter sessions_killed
Definition: pgstat.h:373

References DISCONNECT_CLIENT_EOF, DISCONNECT_FATAL, DISCONNECT_KILLED, DISCONNECT_NORMAL, DISCONNECT_NOT_YET, MyDatabaseId, pgstat_prep_database_pending(), pgstat_should_report_connstat(), pgStatSessionEndCause, PgStat_StatDBEntry::sessions_abandoned, PgStat_StatDBEntry::sessions_fatal, and PgStat_StatDBEntry::sessions_killed.

Referenced by pgstat_shutdown_hook().

◆ pgstat_request_entry_refs_gc()

◆ pgstat_reset_database_timestamp()

void pgstat_reset_database_timestamp ( Oid  dboid,
TimestampTz  ts 
)

◆ pgstat_reset_entries_of_kind()

void pgstat_reset_entries_of_kind ( PgStat_Kind  kind,
TimestampTz  ts 
)

Definition at line 1120 of file pgstat_shmem.c.

1121{
1123}
static bool match_kind(PgStatShared_HashEntry *p, Datum match_data)
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217

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,
uint64  objid,
TimestampTz  ts 
)

Definition at line 1064 of file pgstat_shmem.c.

1065{
1066 PgStat_EntryRef *entry_ref;
1067
1068 Assert(!pgstat_get_kind_info(kind)->fixed_amount);
1069
1070 entry_ref = pgstat_get_entry_ref(kind, dboid, objid, false, NULL);
1071 if (!entry_ref || entry_ref->shared_entry->dropped)
1072 return;
1073
1074 (void) pgstat_lock_entry(entry_ref, false);
1075 shared_stat_reset_contents(kind, entry_ref->shared_stats, ts);
1076 pgstat_unlock_entry(entry_ref);
1077}
static void shared_stat_reset_contents(PgStat_Kind kind, PgStatShared_Common *header, TimestampTz ts)

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_create_subscription(), and 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 1084 of file pgstat_shmem.c.

1086{
1087 dshash_seq_status hstat;
1089
1090 /* dshash entry is not modified, take shared lock */
1091 dshash_seq_init(&hstat, pgStatLocal.shared_hash, false);
1092 while ((p = dshash_seq_next(&hstat)) != NULL)
1093 {
1094 PgStatShared_Common *header;
1095
1096 if (p->dropped)
1097 continue;
1098
1099 if (!do_reset(p, match_data))
1100 continue;
1101
1102 header = dsa_get_address(pgStatLocal.dsa, p->body);
1103
1104 LWLockAcquire(&header->lock, LW_EXCLUSIVE);
1105
1106 shared_stat_reset_contents(p->key.kind, header, ts);
1107
1108 LWLockRelease(&header->lock);
1109 }
1110 dshash_seq_term(&hstat);
1111}

References PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), PgStatShared_HashEntry::key, PgStat_HashKey::kind, PgStatShared_Common::lock, 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_cb()

bool pgstat_slru_flush_cb ( bool  nowait)

Definition at line 165 of file pgstat_slru.c.

166{
167 PgStatShared_SLRU *stats_shmem = &pgStatLocal.shmem->slru;
168 int i;
169
170 if (!have_slrustats)
171 return false;
172
173 if (!nowait)
174 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
175 else if (!LWLockConditionalAcquire(&stats_shmem->lock, LW_EXCLUSIVE))
176 return true;
177
178 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
179 {
180 PgStat_SLRUStats *sharedent = &stats_shmem->stats[i];
181 PgStat_SLRUStats *pendingent = &pending_SLRUStats[i];
182
183#define SLRU_ACC(fld) sharedent->fld += pendingent->fld
184 SLRU_ACC(blocks_zeroed);
185 SLRU_ACC(blocks_hit);
186 SLRU_ACC(blocks_read);
188 SLRU_ACC(blocks_exists);
189 SLRU_ACC(flush);
190 SLRU_ACC(truncate);
191#undef SLRU_ACC
192 }
193
194 /* done, clear the pending entry */
196
197 LWLockRelease(&stats_shmem->lock);
198
199 have_slrustats = false;
200
201 return false;
202}
#define MemSet(start, val, len)
Definition: c.h:991
static int64 blocks_written
Definition: pg_checksums.c:38
#define SLRU_NUM_ELEMENTS
static 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.

◆ pgstat_slru_have_pending_cb()

bool pgstat_slru_have_pending_cb ( void  )

Definition at line 150 of file pgstat_slru.c.

151{
152 return have_slrustats;
153}

References have_slrustats.

◆ pgstat_slru_init_shmem_cb()

void pgstat_slru_init_shmem_cb ( void *  stats)

Definition at line 205 of file pgstat_slru.c.

206{
207 PgStatShared_SLRU *stats_shmem = (PgStatShared_SLRU *) stats;
208
210}

References PgStatShared_SLRU::lock, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_slru_reset_all_cb()

void pgstat_slru_reset_all_cb ( TimestampTz  ts)

Definition at line 213 of file pgstat_slru.c.

214{
215 for (int i = 0; i < SLRU_NUM_ELEMENTS; i++)
217}
static void pgstat_reset_slru_counter_internal(int index, TimestampTz ts)
Definition: pgstat_slru.c:255

References i, pgstat_reset_slru_counter_internal(), and SLRU_NUM_ELEMENTS.

◆ pgstat_slru_snapshot_cb()

void pgstat_slru_snapshot_cb ( void  )

Definition at line 220 of file pgstat_slru.c.

221{
222 PgStatShared_SLRU *stats_shmem = &pgStatLocal.shmem->slru;
223
224 LWLockAcquire(&stats_shmem->lock, LW_SHARED);
225
226 memcpy(pgStatLocal.snapshot.slru, &stats_shmem->stats,
227 sizeof(stats_shmem->stats));
228
229 LWLockRelease(&stats_shmem->lock);
230}
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()

void pgstat_snapshot_fixed ( PgStat_Kind  kind)

Definition at line 1078 of file pgstat.c.

1080{
1082 Assert(pgstat_get_kind_info(kind)->fixed_amount);
1083
1086
1089 else
1091
1092 if (pgstat_is_kind_builtin(kind))
1094 else if (pgstat_is_kind_custom(kind))
static void pgstat_build_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1228
static bool pgstat_is_kind_valid(PgStat_Kind kind)
Definition: pgstat.c:1447
void pgstat_clear_snapshot(void)
Definition: pgstat.c:917
static bool force_stats_snapshot_clear
Definition: pgstat.c:250
bool custom_valid[PGSTAT_KIND_CUSTOM_SIZE]
bool fixed_valid[PGSTAT_KIND_BUILTIN_SIZE]

References Assert(), PgStat_Snapshot::custom_valid, PgStat_Snapshot::fixed_valid, force_stats_snapshot_clear, pgstat_build_snapshot(), pgstat_build_snapshot_fixed(), pgstat_clear_snapshot(), pgstat_fetch_consistency, PGSTAT_FETCH_CONSISTENCY_SNAPSHOT, pgstat_get_kind_info(), pgstat_is_kind_builtin(), pgstat_is_kind_custom(), pgstat_is_kind_valid(), PGSTAT_KIND_CUSTOM_MIN, pgStatLocal, and PgStat_LocalState::snapshot.

Referenced by injection_points_stats_fixed(), pgstat_fetch_slru(), pgstat_fetch_stat_archiver(), pgstat_fetch_stat_bgwriter(), pgstat_fetch_stat_checkpointer(), pgstat_fetch_stat_io(), and pgstat_fetch_stat_wal().

◆ pgstat_subscription_flush_cb()

bool pgstat_subscription_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 103 of file pgstat_subscription.c.

104{
105 PgStat_BackendSubEntry *localent;
107
108 localent = (PgStat_BackendSubEntry *) entry_ref->pending;
109 shsubent = (PgStatShared_Subscription *) entry_ref->shared_stats;
110
111 /* localent always has non-zero content */
112
113 if (!pgstat_lock_entry(entry_ref, nowait))
114 return false;
115
116#define SUB_ACC(fld) shsubent->stats.fld += localent->fld
117 SUB_ACC(apply_error_count);
118 SUB_ACC(sync_error_count);
119 for (int i = 0; i < CONFLICT_NUM_TYPES; i++)
120 SUB_ACC(conflict_count[i]);
121#undef SUB_ACC
122
123 pgstat_unlock_entry(entry_ref);
124 return true;
125}
#define CONFLICT_NUM_TYPES
Definition: conflict.h:51
#define SUB_ACC(fld)

References CONFLICT_NUM_TYPES, i, 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 128 of file pgstat_subscription.c.

129{
130 ((PgStatShared_Subscription *) header)->stats.stat_reset_timestamp = ts;
131}

◆ pgstat_unlock_entry()

◆ pgstat_update_dbstats()

void pgstat_update_dbstats ( TimestampTz  ts)

Definition at line 287 of file pgstat_database.c.

288{
289 PgStat_StatDBEntry *dbentry;
290
291 /*
292 * If not connected to a database yet, don't attribute time to "shared
293 * state" (InvalidOid is used to track stats for shared relations, etc.).
294 */
296 return;
297
299
300 /*
301 * Accumulate xact commit/rollback and I/O timings to stats entry of the
302 * current database.
303 */
304 dbentry->xact_commit += pgStatXactCommit;
308
310 {
311 long secs;
312 int usecs;
313
314 /*
315 * pgLastSessionReportTime is initialized to MyStartTimestamp by
316 * pgstat_report_connect().
317 */
320 dbentry->session_time += (PgStat_Counter) secs * 1000000 + usecs;
321 dbentry->active_time += pgStatActiveTime;
323 }
324
331}
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1720
int64 PgStat_Counter
Definition: pgstat.h:65
PgStat_Counter pgStatActiveTime
PgStat_Counter pgStatBlockReadTime
PgStat_Counter pgStatBlockWriteTime
static PgStat_Counter pgLastSessionReportTime
PgStat_Counter pgStatTransactionIdleTime
PgStat_Counter blk_write_time
Definition: pgstat.h:366
PgStat_Counter xact_rollback
Definition: pgstat.h:345
PgStat_Counter blk_read_time
Definition: pgstat.h:365
PgStat_Counter xact_commit
Definition: pgstat.h:344
PgStat_Counter session_time
Definition: pgstat.h:368
PgStat_Counter active_time
Definition: pgstat.h:369
PgStat_Counter idle_in_transaction_time
Definition: pgstat.h:370

References PgStat_StatDBEntry::active_time, PgStat_StatDBEntry::blk_read_time, PgStat_StatDBEntry::blk_write_time, PgStat_StatDBEntry::idle_in_transaction_time, MyDatabaseId, OidIsValid, pgLastSessionReportTime, pgstat_prep_database_pending(), pgstat_should_report_connstat(), pgStatActiveTime, pgStatBlockReadTime, pgStatBlockWriteTime, pgStatTransactionIdleTime, pgStatXactCommit, pgStatXactRollback, PgStat_StatDBEntry::session_time, TimestampDifference(), PgStat_StatDBEntry::xact_commit, and PgStat_StatDBEntry::xact_rollback.

Referenced by pgstat_report_stat().

◆ pgstat_wal_flush_cb()

bool pgstat_wal_flush_cb ( bool  nowait)

Definition at line 82 of file pgstat_wal.c.

83{
84 PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal;
85 WalUsage wal_usage_diff = {0};
86
88 Assert(pgStatLocal.shmem != NULL &&
90
91 /*
92 * This function can be called even if nothing at all has happened. Avoid
93 * taking lock for nothing in that case.
94 */
96 return false;
97
98 /*
99 * We don't update the WAL usage portion of the local WalStats elsewhere.
100 * Calculate how much WAL usage counters were increased by subtracting the
101 * previous counters from the current ones.
102 */
103 WalUsageAccumDiff(&wal_usage_diff, &pgWalUsage, &prevWalUsage);
104
105 if (!nowait)
106 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
107 else if (!LWLockConditionalAcquire(&stats_shmem->lock, LW_EXCLUSIVE))
108 return true;
109
110#define WALSTAT_ACC(fld, var_to_add) \
111 (stats_shmem->stats.wal_counters.fld += var_to_add.fld)
112 WALSTAT_ACC(wal_records, wal_usage_diff);
113 WALSTAT_ACC(wal_fpi, wal_usage_diff);
114 WALSTAT_ACC(wal_bytes, wal_usage_diff);
115 WALSTAT_ACC(wal_buffers_full, wal_usage_diff);
116#undef WALSTAT_ACC
117
118 LWLockRelease(&stats_shmem->lock);
119
120 /*
121 * Save the current counters for the subsequent calculation of WAL usage.
122 */
124
125 return false;
126}
WalUsage pgWalUsage
Definition: instrument.c:22
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
Definition: instrument.c:287
#define WALSTAT_ACC(fld, var_to_add)
static WalUsage prevWalUsage
Definition: pgstat_wal.c:30
bool pgstat_wal_have_pending_cb(void)
Definition: pgstat_wal.c:143
PgStatShared_Wal wal

References Assert(), PgStat_ShmemControl::is_shutdown, IsPostmasterEnvironment, IsUnderPostmaster, PgStatShared_Wal::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockRelease(), pgstat_wal_have_pending_cb(), pgStatLocal, pgWalUsage, prevWalUsage, PgStat_LocalState::shmem, PgStat_ShmemControl::wal, WALSTAT_ACC, and WalUsageAccumDiff().

Referenced by pgstat_report_wal().

◆ pgstat_wal_have_pending_cb()

bool pgstat_wal_have_pending_cb ( void  )

Definition at line 143 of file pgstat_wal.c.

144{
146}
int64 wal_records
Definition: instrument.h:53

References pgWalUsage, prevWalUsage, and WalUsage::wal_records.

Referenced by pgstat_wal_flush_cb().

◆ pgstat_wal_init_backend_cb()

void pgstat_wal_init_backend_cb ( void  )

Definition at line 129 of file pgstat_wal.c.

130{
131 /*
132 * Initialize prevWalUsage with pgWalUsage so that pgstat_wal_flush_cb()
133 * can calculate how much pgWalUsage counters are increased by subtracting
134 * prevWalUsage from pgWalUsage.
135 */
137}

References pgWalUsage, and prevWalUsage.

◆ pgstat_wal_init_shmem_cb()

void pgstat_wal_init_shmem_cb ( void *  stats)

Definition at line 149 of file pgstat_wal.c.

150{
151 PgStatShared_Wal *stats_shmem = (PgStatShared_Wal *) stats;
152
154}

References PgStatShared_Wal::lock, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_wal_reset_all_cb()

void pgstat_wal_reset_all_cb ( TimestampTz  ts)

Definition at line 157 of file pgstat_wal.c.

158{
159 PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal;
160
161 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
162 memset(&stats_shmem->stats, 0, sizeof(stats_shmem->stats));
163 stats_shmem->stats.stat_reset_timestamp = ts;
164 LWLockRelease(&stats_shmem->lock);
165}
PgStat_WalStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:481

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  )

◆ PostPrepare_PgStat_Relations()

void PostPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)

Definition at line 728 of file pgstat_relation.c.

729{
731
732 for (trans = xact_state->first; trans != NULL; trans = trans->next)
733 {
734 PgStat_TableStatus *tabstat;
735
736 tabstat = trans->parent;
737 tabstat->trans = NULL;
738 }
739}

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

Referenced by PostPrepare_PgStat().

Variable Documentation

◆ pgStatLocal

PGDLLIMPORT PgStat_LocalState pgStatLocal
extern

Definition at line 212 of file pgstat.c.

Referenced by pgstat_acquire_entry_ref(), pgstat_archiver_reset_all_cb(), pgstat_archiver_snapshot_cb(), pgstat_attach_shmem(), pgstat_before_server_shutdown(), pgstat_bgwriter_reset_all_cb(), pgstat_bgwriter_snapshot_cb(), pgstat_build_snapshot(), pgstat_build_snapshot_fixed(), pgstat_checkpointer_reset_all_cb(), pgstat_checkpointer_snapshot_cb(), pgstat_clear_snapshot(), pgstat_detach_shmem(), pgstat_drop_database_and_contents(), pgstat_drop_entry(), pgstat_drop_entry_internal(), pgstat_drop_matching_entries(), pgstat_fetch_entry(), pgstat_fetch_slru(), pgstat_fetch_stat_archiver(), pgstat_fetch_stat_bgwriter(), pgstat_fetch_stat_checkpointer(), pgstat_fetch_stat_io(), pgstat_fetch_stat_wal(), pgstat_free_entry(), pgstat_gc_entry_refs(), pgstat_get_custom_shmem_data(), pgstat_get_custom_snapshot_data(), pgstat_get_entry_ref(), pgstat_get_stat_snapshot_timestamp(), pgstat_init_entry(), pgstat_init_snapshot_fixed(), pgstat_io_flush_cb(), pgstat_io_reset_all_cb(), pgstat_io_snapshot_cb(), pgstat_need_entry_refs_gc(), pgstat_prep_snapshot(), pgstat_read_statsfile(), pgstat_reinit_entry(), pgstat_release_entry_ref(), pgstat_report_archiver(), pgstat_report_bgwriter(), pgstat_report_checkpointer(), pgstat_report_stat(), pgstat_request_entry_refs_gc(), pgstat_reset_matching_entries(), pgstat_reset_slru_counter_internal(), pgstat_setup_shared_refs(), pgstat_slru_flush_cb(), pgstat_slru_snapshot_cb(), pgstat_snapshot_fixed(), pgstat_wal_flush_cb(), pgstat_wal_reset_all_cb(), pgstat_wal_snapshot_cb(), pgstat_write_statsfile(), and StatsShmemInit().

◆ slru_names

const char* const slru_names[]
static
Initial value:
= {
"commit_timestamp",
"multixact_member",
"multixact_offset",
"notify",
"serializable",
"subtransaction",
"transaction",
"other"
}

Definition at line 334 of file pgstat_internal.h.

Referenced by pgstat_get_slru_index(), and pgstat_get_slru_name().