PostgreSQL Source Code  git master
pgstat.h File Reference
Include dependency graph for pgstat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PgStat_FunctionCounts
 
struct  PgStat_BackendFunctionEntry
 
struct  PgStat_FunctionCallUsage
 
struct  PgStat_BackendSubEntry
 
struct  PgStat_TableCounts
 
struct  PgStat_TableStatus
 
struct  PgStat_TableXactStatus
 
struct  PgStat_ArchiverStats
 
struct  PgStat_BgWriterStats
 
struct  PgStat_CheckpointerStats
 
struct  PgStat_StatDBEntry
 
struct  PgStat_StatFuncEntry
 
struct  PgStat_StatReplSlotEntry
 
struct  PgStat_SLRUStats
 
struct  PgStat_StatSubEntry
 
struct  PgStat_StatTabEntry
 
struct  PgStat_WalStats
 

Macros

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"
 
#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/pgstat.stat"
 
#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/pgstat.tmp"
 
#define PG_STAT_TMP_DIR   "pg_stat_tmp"
 
#define PGSTAT_KIND_FIRST_VALID   PGSTAT_KIND_DATABASE
 
#define PGSTAT_KIND_LAST   PGSTAT_KIND_WAL
 
#define PGSTAT_NUM_KINDS   (PGSTAT_KIND_LAST + 1)
 
#define PGSTAT_FILE_FORMAT_ID   0x01A5BCA7
 
#define pgstat_count_buffer_read_time(n)    (pgStatBlockReadTime += (n))
 
#define pgstat_count_buffer_write_time(n)    (pgStatBlockWriteTime += (n))
 
#define pgstat_count_conn_active_time(n)    (pgStatActiveTime += (n))
 
#define pgstat_count_conn_txn_idle_time(n)    (pgStatTransactionIdleTime += (n))
 
#define pgstat_should_count_relation(rel)
 
#define pgstat_count_heap_scan(rel)
 
#define pgstat_count_heap_getnext(rel)
 
#define pgstat_count_heap_fetch(rel)
 
#define pgstat_count_index_scan(rel)
 
#define pgstat_count_index_tuples(rel, n)
 
#define pgstat_count_buffer_read(rel)
 
#define pgstat_count_buffer_hit(rel)
 

Typedefs

typedef enum PgStat_Kind PgStat_Kind
 
typedef enum TrackFunctionsLevel TrackFunctionsLevel
 
typedef enum PgStat_FetchConsistency PgStat_FetchConsistency
 
typedef enum SessionEndType SessionEndType
 
typedef int64 PgStat_Counter
 
typedef struct PgStat_FunctionCounts PgStat_FunctionCounts
 
typedef struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
 
typedef struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
 
typedef struct PgStat_BackendSubEntry PgStat_BackendSubEntry
 
typedef struct PgStat_TableCounts PgStat_TableCounts
 
typedef struct PgStat_TableStatus PgStat_TableStatus
 
typedef struct PgStat_TableXactStatus PgStat_TableXactStatus
 
typedef struct PgStat_ArchiverStats PgStat_ArchiverStats
 
typedef struct PgStat_BgWriterStats PgStat_BgWriterStats
 
typedef struct PgStat_CheckpointerStats PgStat_CheckpointerStats
 
typedef struct PgStat_StatDBEntry PgStat_StatDBEntry
 
typedef struct PgStat_StatFuncEntry PgStat_StatFuncEntry
 
typedef struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
 
typedef struct PgStat_SLRUStats PgStat_SLRUStats
 
typedef struct PgStat_StatSubEntry PgStat_StatSubEntry
 
typedef struct PgStat_StatTabEntry PgStat_StatTabEntry
 
typedef struct PgStat_WalStats PgStat_WalStats
 

Enumerations

enum  PgStat_Kind {
  PGSTAT_KIND_INVALID = 0 , PGSTAT_KIND_DATABASE , PGSTAT_KIND_RELATION , PGSTAT_KIND_FUNCTION ,
  PGSTAT_KIND_REPLSLOT , PGSTAT_KIND_SUBSCRIPTION , PGSTAT_KIND_ARCHIVER , PGSTAT_KIND_BGWRITER ,
  PGSTAT_KIND_CHECKPOINTER , PGSTAT_KIND_SLRU , PGSTAT_KIND_WAL
}
 
enum  TrackFunctionsLevel { TRACK_FUNC_OFF , TRACK_FUNC_PL , TRACK_FUNC_ALL }
 
enum  PgStat_FetchConsistency { PGSTAT_FETCH_CONSISTENCY_NONE , PGSTAT_FETCH_CONSISTENCY_CACHE , PGSTAT_FETCH_CONSISTENCY_SNAPSHOT }
 
enum  SessionEndType {
  DISCONNECT_NOT_YET , DISCONNECT_NORMAL , DISCONNECT_CLIENT_EOF , DISCONNECT_FATAL ,
  DISCONNECT_KILLED
}
 

Functions

Size StatsShmemSize (void)
 
void StatsShmemInit (void)
 
void pgstat_restore_stats (void)
 
void pgstat_discard_stats (void)
 
void pgstat_before_server_shutdown (int code, Datum arg)
 
void pgstat_initialize (void)
 
long pgstat_report_stat (bool force)
 
void pgstat_force_next_flush (void)
 
void pgstat_reset_counters (void)
 
void pgstat_reset (PgStat_Kind kind, Oid dboid, Oid objectid)
 
void pgstat_reset_of_kind (PgStat_Kind kind)
 
void pgstat_clear_snapshot (void)
 
TimestampTz pgstat_get_stat_snapshot_timestamp (bool *have_snapshot)
 
PgStat_Kind pgstat_get_kind_from_str (char *kind_str)
 
bool pgstat_have_entry (PgStat_Kind kind, Oid dboid, Oid objoid)
 
void pgstat_report_archiver (const char *xlog, bool failed)
 
PgStat_ArchiverStatspgstat_fetch_stat_archiver (void)
 
void pgstat_report_bgwriter (void)
 
PgStat_BgWriterStatspgstat_fetch_stat_bgwriter (void)
 
void pgstat_report_checkpointer (void)
 
PgStat_CheckpointerStatspgstat_fetch_stat_checkpointer (void)
 
void pgstat_drop_database (Oid databaseid)
 
void pgstat_report_autovac (Oid dboid)
 
void pgstat_report_recovery_conflict (int reason)
 
void pgstat_report_deadlock (void)
 
void pgstat_report_checksum_failures_in_db (Oid dboid, int failurecount)
 
void pgstat_report_checksum_failure (void)
 
void pgstat_report_connect (Oid dboid)
 
PgStat_StatDBEntrypgstat_fetch_stat_dbentry (Oid dbid)
 
void pgstat_create_function (Oid proid)
 
void pgstat_drop_function (Oid proid)
 
void pgstat_init_function_usage (struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
 
void pgstat_end_function_usage (PgStat_FunctionCallUsage *fcu, bool finalize)
 
PgStat_StatFuncEntrypgstat_fetch_stat_funcentry (Oid funcid)
 
PgStat_BackendFunctionEntryfind_funcstat_entry (Oid func_id)
 
void pgstat_create_relation (Relation rel)
 
void pgstat_drop_relation (Relation rel)
 
void pgstat_copy_relation_stats (Relation dstrel, Relation srcrel)
 
void pgstat_init_relation (Relation rel)
 
void pgstat_assoc_relation (Relation rel)
 
void pgstat_unlink_relation (Relation rel)
 
void pgstat_report_vacuum (Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
 
void pgstat_report_analyze (Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
 
void pgstat_count_heap_insert (Relation rel, PgStat_Counter n)
 
void pgstat_count_heap_update (Relation rel, bool hot)
 
void pgstat_count_heap_delete (Relation rel)
 
void pgstat_count_truncate (Relation rel)
 
void pgstat_update_heap_dead_tuples (Relation rel, int delta)
 
void pgstat_twophase_postcommit (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
void pgstat_twophase_postabort (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry (Oid relid)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry_ext (bool shared, Oid relid)
 
PgStat_TableStatusfind_tabstat_entry (Oid rel_id)
 
void pgstat_reset_replslot (const char *name)
 
void pgstat_report_replslot (struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
 
void pgstat_create_replslot (struct ReplicationSlot *slot)
 
void pgstat_acquire_replslot (struct ReplicationSlot *slot)
 
void pgstat_drop_replslot (struct ReplicationSlot *slot)
 
PgStat_StatReplSlotEntrypgstat_fetch_replslot (NameData slotname)
 
void pgstat_reset_slru (const char *)
 
void pgstat_count_slru_page_zeroed (int slru_idx)
 
void pgstat_count_slru_page_hit (int slru_idx)
 
void pgstat_count_slru_page_read (int slru_idx)
 
void pgstat_count_slru_page_written (int slru_idx)
 
void pgstat_count_slru_page_exists (int slru_idx)
 
void pgstat_count_slru_flush (int slru_idx)
 
void pgstat_count_slru_truncate (int slru_idx)
 
const char * pgstat_get_slru_name (int slru_idx)
 
int pgstat_get_slru_index (const char *name)
 
PgStat_SLRUStatspgstat_fetch_slru (void)
 
void pgstat_report_subscription_error (Oid subid, bool is_apply_error)
 
void pgstat_create_subscription (Oid subid)
 
void pgstat_drop_subscription (Oid subid)
 
PgStat_StatSubEntrypgstat_fetch_stat_subscription (Oid subid)
 
void AtEOXact_PgStat (bool isCommit, bool parallel)
 
void AtEOSubXact_PgStat (bool isCommit, int nestDepth)
 
void AtPrepare_PgStat (void)
 
void PostPrepare_PgStat (void)
 
int pgstat_get_transactional_drops (bool isCommit, struct xl_xact_stats_item **items)
 
void pgstat_execute_transactional_drops (int ndrops, struct xl_xact_stats_item *items, bool is_redo)
 
void pgstat_report_wal (bool force)
 
PgStat_WalStatspgstat_fetch_stat_wal (void)
 

Variables

PGDLLIMPORT bool pgstat_track_counts
 
PGDLLIMPORT int pgstat_track_functions
 
PGDLLIMPORT int pgstat_fetch_consistency
 
PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
 
PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
 
PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
 
PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
 
PGDLLIMPORT PgStat_Counter pgStatActiveTime
 
PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
 
PGDLLIMPORT SessionEndType pgStatSessionEndCause
 
PGDLLIMPORT PgStat_WalStats PendingWalStats
 

Macro Definition Documentation

◆ PG_STAT_TMP_DIR

#define PG_STAT_TMP_DIR   "pg_stat_tmp"

Definition at line 32 of file pgstat.h.

◆ pgstat_count_buffer_hit

#define pgstat_count_buffer_hit (   rel)
Value:
do { \
(rel)->pgstat_info->t_counts.t_blocks_hit++; \
} while (0)
#define pgstat_should_count_relation(rel)
Definition: pgstat.h:519

Definition at line 555 of file pgstat.h.

◆ pgstat_count_buffer_read

#define pgstat_count_buffer_read (   rel)
Value:
do { \
(rel)->pgstat_info->t_counts.t_blocks_fetched++; \
} while (0)

Definition at line 550 of file pgstat.h.

◆ pgstat_count_buffer_read_time

#define pgstat_count_buffer_read_time (   n)     (pgStatBlockReadTime += (n))

Definition at line 468 of file pgstat.h.

◆ pgstat_count_buffer_write_time

#define pgstat_count_buffer_write_time (   n)     (pgStatBlockWriteTime += (n))

Definition at line 470 of file pgstat.h.

◆ pgstat_count_conn_active_time

#define pgstat_count_conn_active_time (   n)     (pgStatActiveTime += (n))

Definition at line 472 of file pgstat.h.

◆ pgstat_count_conn_txn_idle_time

#define pgstat_count_conn_txn_idle_time (   n)     (pgStatTransactionIdleTime += (n))

Definition at line 474 of file pgstat.h.

◆ pgstat_count_heap_fetch

#define pgstat_count_heap_fetch (   rel)
Value:
do { \
(rel)->pgstat_info->t_counts.t_tuples_fetched++; \
} while (0)

Definition at line 535 of file pgstat.h.

◆ pgstat_count_heap_getnext

#define pgstat_count_heap_getnext (   rel)
Value:
do { \
(rel)->pgstat_info->t_counts.t_tuples_returned++; \
} while (0)

Definition at line 530 of file pgstat.h.

◆ pgstat_count_heap_scan

#define pgstat_count_heap_scan (   rel)
Value:
do { \
(rel)->pgstat_info->t_counts.t_numscans++; \
} while (0)

Definition at line 525 of file pgstat.h.

◆ pgstat_count_index_scan

#define pgstat_count_index_scan (   rel)
Value:
do { \
(rel)->pgstat_info->t_counts.t_numscans++; \
} while (0)

Definition at line 540 of file pgstat.h.

◆ pgstat_count_index_tuples

#define pgstat_count_index_tuples (   rel,
 
)
Value:
do { \
(rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
} while (0)

Definition at line 545 of file pgstat.h.

◆ PGSTAT_FILE_FORMAT_ID

#define PGSTAT_FILE_FORMAT_ID   0x01A5BCA7

Definition at line 245 of file pgstat.h.

◆ PGSTAT_KIND_FIRST_VALID

#define PGSTAT_KIND_FIRST_VALID   PGSTAT_KIND_DATABASE

Definition at line 55 of file pgstat.h.

◆ PGSTAT_KIND_LAST

#define PGSTAT_KIND_LAST   PGSTAT_KIND_WAL

Definition at line 56 of file pgstat.h.

◆ PGSTAT_NUM_KINDS

#define PGSTAT_NUM_KINDS   (PGSTAT_KIND_LAST + 1)

Definition at line 57 of file pgstat.h.

◆ pgstat_should_count_relation

#define pgstat_should_count_relation (   rel)
Value:
(likely((rel)->pgstat_info != NULL) ? true : \
((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
#define likely(x)
Definition: c.h:272
return true
Definition: isn.c:126
void pgstat_assoc_relation(Relation rel)

Definition at line 519 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_DIRECTORY

#define PGSTAT_STAT_PERMANENT_DIRECTORY   "pg_stat"

Definition at line 27 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_FILENAME

#define PGSTAT_STAT_PERMANENT_FILENAME   "pg_stat/pgstat.stat"

Definition at line 28 of file pgstat.h.

◆ PGSTAT_STAT_PERMANENT_TMPFILE

#define PGSTAT_STAT_PERMANENT_TMPFILE   "pg_stat/pgstat.tmp"

Definition at line 29 of file pgstat.h.

Typedef Documentation

◆ PgStat_ArchiverStats

◆ PgStat_BackendFunctionEntry

◆ PgStat_BackendSubEntry

◆ PgStat_BgWriterStats

◆ PgStat_CheckpointerStats

◆ PgStat_Counter

typedef int64 PgStat_Counter

Definition at line 88 of file pgstat.h.

◆ PgStat_FetchConsistency

◆ PgStat_FunctionCallUsage

◆ PgStat_FunctionCounts

◆ PgStat_Kind

typedef enum PgStat_Kind PgStat_Kind

◆ PgStat_SLRUStats

◆ PgStat_StatDBEntry

◆ PgStat_StatFuncEntry

◆ PgStat_StatReplSlotEntry

◆ PgStat_StatSubEntry

◆ PgStat_StatTabEntry

◆ PgStat_TableCounts

◆ PgStat_TableStatus

◆ PgStat_TableXactStatus

◆ PgStat_WalStats

◆ SessionEndType

◆ TrackFunctionsLevel

Enumeration Type Documentation

◆ PgStat_FetchConsistency

Enumerator
PGSTAT_FETCH_CONSISTENCY_NONE 
PGSTAT_FETCH_CONSISTENCY_CACHE 
PGSTAT_FETCH_CONSISTENCY_SNAPSHOT 

Definition at line 67 of file pgstat.h.

68 {
PgStat_FetchConsistency
Definition: pgstat.h:68
@ PGSTAT_FETCH_CONSISTENCY_NONE
Definition: pgstat.h:69
@ PGSTAT_FETCH_CONSISTENCY_CACHE
Definition: pgstat.h:70
@ PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
Definition: pgstat.h:71

◆ PgStat_Kind

Enumerator
PGSTAT_KIND_INVALID 
PGSTAT_KIND_DATABASE 
PGSTAT_KIND_RELATION 
PGSTAT_KIND_FUNCTION 
PGSTAT_KIND_REPLSLOT 
PGSTAT_KIND_SUBSCRIPTION 
PGSTAT_KIND_ARCHIVER 
PGSTAT_KIND_BGWRITER 
PGSTAT_KIND_CHECKPOINTER 
PGSTAT_KIND_SLRU 
PGSTAT_KIND_WAL 

Definition at line 35 of file pgstat.h.

36 {
37  /* use 0 for INVALID, to catch zero-initialized data */
39 
40  /* stats for variable-numbered objects */
41  PGSTAT_KIND_DATABASE, /* database-wide statistics */
42  PGSTAT_KIND_RELATION, /* per-table statistics */
43  PGSTAT_KIND_FUNCTION, /* per-function statistics */
44  PGSTAT_KIND_REPLSLOT, /* per-slot statistics */
45  PGSTAT_KIND_SUBSCRIPTION, /* per-subscription statistics */
46 
47  /* stats for fixed-numbered objects */
53 } PgStat_Kind;
PgStat_Kind
Definition: pgstat.h:36
@ PGSTAT_KIND_DATABASE
Definition: pgstat.h:41
@ PGSTAT_KIND_REPLSLOT
Definition: pgstat.h:44
@ PGSTAT_KIND_ARCHIVER
Definition: pgstat.h:48
@ PGSTAT_KIND_SLRU
Definition: pgstat.h:51
@ PGSTAT_KIND_BGWRITER
Definition: pgstat.h:49
@ PGSTAT_KIND_INVALID
Definition: pgstat.h:38
@ PGSTAT_KIND_SUBSCRIPTION
Definition: pgstat.h:45
@ PGSTAT_KIND_CHECKPOINTER
Definition: pgstat.h:50
@ PGSTAT_KIND_FUNCTION
Definition: pgstat.h:43
@ PGSTAT_KIND_WAL
Definition: pgstat.h:52
@ PGSTAT_KIND_RELATION
Definition: pgstat.h:42

◆ SessionEndType

Enumerator
DISCONNECT_NOT_YET 
DISCONNECT_NORMAL 
DISCONNECT_CLIENT_EOF 
DISCONNECT_FATAL 
DISCONNECT_KILLED 

Definition at line 75 of file pgstat.h.

76 {
77  DISCONNECT_NOT_YET, /* still active */
SessionEndType
Definition: pgstat.h:76
@ DISCONNECT_NOT_YET
Definition: pgstat.h:77
@ DISCONNECT_FATAL
Definition: pgstat.h:80
@ DISCONNECT_KILLED
Definition: pgstat.h:81
@ DISCONNECT_CLIENT_EOF
Definition: pgstat.h:79
@ DISCONNECT_NORMAL
Definition: pgstat.h:78

◆ TrackFunctionsLevel

Enumerator
TRACK_FUNC_OFF 
TRACK_FUNC_PL 
TRACK_FUNC_ALL 

Definition at line 60 of file pgstat.h.

61 {
TrackFunctionsLevel
Definition: pgstat.h:61
@ TRACK_FUNC_PL
Definition: pgstat.h:63
@ TRACK_FUNC_ALL
Definition: pgstat.h:64
@ TRACK_FUNC_OFF
Definition: pgstat.h:62

Function Documentation

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

Definition at line 117 of file pgstat_xact.c.

118 {
119  PgStat_SubXactStatus *xact_state;
120 
121  /* merge the sub-transaction's transactional stats into the parent */
122  xact_state = pgStatXactStack;
123  if (xact_state != NULL &&
124  xact_state->nest_level >= nestDepth)
125  {
126  /* delink xact_state from stack immediately to simplify reuse case */
127  pgStatXactStack = xact_state->prev;
128 
129  AtEOSubXact_PgStat_Relations(xact_state, isCommit, nestDepth);
130  AtEOSubXact_PgStat_DroppedStats(xact_state, isCommit, nestDepth);
131 
132  pfree(xact_state);
133  }
134 }
void pfree(void *pointer)
Definition: mcxt.c:1175
void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat_xact.c:34
static void AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
Definition: pgstat_xact.c:140
struct PgStat_SubXactStatus * prev

References AtEOSubXact_PgStat_DroppedStats(), AtEOSubXact_PgStat_Relations(), PgStat_SubXactStatus::nest_level, pfree(), pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)

Definition at line 41 of file pgstat_xact.c.

42 {
43  PgStat_SubXactStatus *xact_state;
44 
45  AtEOXact_PgStat_Database(isCommit, parallel);
46 
47  /* handle transactional stats information */
48  xact_state = pgStatXactStack;
49  if (xact_state != NULL)
50  {
51  Assert(xact_state->nest_level == 1);
52  Assert(xact_state->prev == NULL);
53 
54  AtEOXact_PgStat_Relations(xact_state, isCommit);
55  AtEOXact_PgStat_DroppedStats(xact_state, isCommit);
56  }
57  pgStatXactStack = NULL;
58 
59  /* Make sure any stats snapshot is thrown away */
61 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void pgstat_clear_snapshot(void)
Definition: pgstat.c:752
void AtEOXact_PgStat_Database(bool isCommit, bool parallel)
void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit)
static void AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit)
Definition: pgstat_xact.c:68

References Assert(), AtEOXact_PgStat_Database(), AtEOXact_PgStat_DroppedStats(), AtEOXact_PgStat_Relations(), PgStat_SubXactStatus::nest_level, pgstat_clear_snapshot(), pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by AbortTransaction(), CommitTransaction(), and FinishPreparedTransaction().

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )

Definition at line 196 of file pgstat_xact.c.

197 {
198  PgStat_SubXactStatus *xact_state;
199 
200  xact_state = pgStatXactStack;
201  if (xact_state != NULL)
202  {
203  Assert(xact_state->nest_level == 1);
204  Assert(xact_state->prev == NULL);
205 
206  AtPrepare_PgStat_Relations(xact_state);
207  }
208 }
void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)

References Assert(), AtPrepare_PgStat_Relations(), PgStat_SubXactStatus::nest_level, pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by PrepareTransaction().

◆ find_funcstat_entry()

PgStat_BackendFunctionEntry* find_funcstat_entry ( Oid  func_id)

Definition at line 223 of file pgstat_function.c.

224 {
225  PgStat_EntryRef *entry_ref;
226 
228 
229  if (entry_ref)
230  return entry_ref->pending;
231  return NULL;
232 }
Oid MyDatabaseId
Definition: globals.c:89
PgStat_EntryRef * pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:1091

References MyDatabaseId, PgStat_EntryRef::pending, pgstat_fetch_pending_entry(), and PGSTAT_KIND_FUNCTION.

Referenced by pg_stat_get_xact_function_calls(), pg_stat_get_xact_function_self_time(), and pg_stat_get_xact_function_total_time().

◆ find_tabstat_entry()

◆ pgstat_acquire_replslot()

void pgstat_acquire_replslot ( struct ReplicationSlot slot)

Definition at line 136 of file pgstat_replslot.c.

137 {
138  PgStat_EntryRef *entry_ref;
139  PgStatShared_ReplSlot *shstatent;
140  PgStat_StatReplSlotEntry *statent;
141 
143  ReplicationSlotIndex(slot), false);
144  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
145  statent = &shstatent->stats;
146 
147  /*
148  * NB: need to accept that there might be stats from an older slot, e.g.
149  * if we previously crashed after dropping a slot.
150  */
151  if (NameStr(statent->slotname)[0] == 0 ||
152  namestrcmp(&statent->slotname, NameStr(slot->data.name)) != 0)
153  {
154  memset(statent, 0, sizeof(*statent));
155  namestrcpy(&statent->slotname, NameStr(slot->data.name));
156  }
157 
158  pgstat_unlock_entry(entry_ref);
159 }
#define NameStr(name)
Definition: c.h:681
int namestrcmp(Name name, const char *str)
Definition: name.c:247
void namestrcpy(Name name, const char *str)
Definition: name.c:233
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:583
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
Definition: pgstat_shmem.c:592
int ReplicationSlotIndex(ReplicationSlot *slot)
Definition: slot.c:410
PgStat_StatReplSlotEntry stats
PgStatShared_Common * shared_stats
ReplicationSlotPersistentData data
Definition: slot.h:147

References ReplicationSlot::data, if(), InvalidOid, ReplicationSlotPersistentData::name, NameStr, namestrcmp(), namestrcpy(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), PgStat_EntryRef::shared_stats, PgStat_StatReplSlotEntry::slotname, and PgStatShared_ReplSlot::stats.

Referenced by ReplicationSlotAcquire().

◆ pgstat_assoc_relation()

void pgstat_assoc_relation ( Relation  rel)

Definition at line 132 of file pgstat_relation.c.

133 {
134  Assert(rel->pgstat_enabled);
135  Assert(rel->pgstat_info == NULL);
136 
137  /* Else find or make the PgStat_TableStatus entry, and update link */
139  rel->rd_rel->relisshared);
140 
141  /* don't allow link a stats to multiple relcache entries */
142  Assert(rel->pgstat_info->relation == NULL);
143 
144  /* mark this relation as the owner */
145  rel->pgstat_info->relation = rel;
146 }
static PgStat_TableStatus * pgstat_prep_relation_pending(Oid rel_id, bool isshared)
#define RelationGetRelid(relation)
Definition: rel.h:488
Relation relation
Definition: pgstat.h:210
bool pgstat_enabled
Definition: rel.h:248
Form_pg_class rd_rel
Definition: rel.h:109
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:250

References Assert(), RelationData::pgstat_enabled, RelationData::pgstat_info, pgstat_prep_relation_pending(), RelationData::rd_rel, PgStat_TableStatus::relation, and RelationGetRelid.

◆ pgstat_before_server_shutdown()

void pgstat_before_server_shutdown ( int  code,
Datum  arg 
)

Definition at line 448 of file pgstat.c.

449 {
450  Assert(pgStatLocal.shmem != NULL);
452 
453  /*
454  * Stats should only be reported after pgstat_initialize() and before
455  * pgstat_shutdown(). This is a convenient point to catch most violations
456  * of this rule.
457  */
458  Assert(pgstat_is_initialized && !pgstat_is_shutdown);
459 
460  /* flush out our own pending changes before writing out */
461  pgstat_report_stat(true);
462 
463  /*
464  * Only write out file during normal shutdown. Don't even signal that
465  * we've shutdown during irregular shutdowns, because the shutdown
466  * sequence isn't coordinated to ensure this backend shuts down last.
467  */
468  if (code == 0)
469  {
470  pgStatLocal.shmem->is_shutdown = true;
472  }
473 }
static void pgstat_write_statsfile(void)
Definition: pgstat.c:1256
long pgstat_report_stat(bool force)
Definition: pgstat.c:565
PgStat_LocalState pgStatLocal
Definition: pgstat.c:195
PgStat_ShmemControl * shmem

References Assert(), PgStat_ShmemControl::is_shutdown, pgstat_report_stat(), pgstat_write_statsfile(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by CheckpointerMain(), and InitPostgres().

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 752 of file pgstat.c.

753 {
755 
756  memset(&pgStatLocal.snapshot.fixed_valid, 0,
758  pgStatLocal.snapshot.stats = NULL;
760 
761  /* Release memory, if any was allocated */
763  {
765 
766  /* Reset variables */
768  }
769 
770  /*
771  * Historically the backend_status.c facilities lived in this file, and
772  * were reset with the same function. For now keep it that way, and
773  * forward the reset request.
774  */
776 }
void pgstat_clear_backend_activity_snapshot(void)
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
#define pgstat_assert_is_up()
PgStat_Snapshot snapshot
MemoryContext context
bool fixed_valid[PGSTAT_NUM_KINDS]
PgStat_FetchConsistency mode
struct pgstat_snapshot_hash * stats

References PgStat_Snapshot::context, PgStat_Snapshot::fixed_valid, MemoryContextDelete(), PgStat_Snapshot::mode, pgstat_assert_is_up, pgstat_clear_backend_activity_snapshot(), PGSTAT_FETCH_CONSISTENCY_NONE, pgStatLocal, PgStat_LocalState::snapshot, and PgStat_Snapshot::stats.

Referenced by AtEOXact_PgStat(), pg_stat_clear_snapshot(), and PostPrepare_PgStat().

◆ pgstat_copy_relation_stats()

void pgstat_copy_relation_stats ( Relation  dstrel,
Relation  srcrel 
)

Definition at line 58 of file pgstat_relation.c.

59 {
60  PgStat_StatTabEntry *srcstats;
61  PgStatShared_Relation *dstshstats;
62  PgStat_EntryRef *dst_ref;
63 
64  srcstats = pgstat_fetch_stat_tabentry_ext(src->rd_rel->relisshared,
65  RelationGetRelid(src));
66  if (!srcstats)
67  return;
68 
70  dst->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
71  RelationGetRelid(dst),
72  false);
73 
74  dstshstats = (PgStatShared_Relation *) dst_ref->shared_stats;
75  dstshstats->stats = *srcstats;
76 
77  pgstat_unlock_entry(dst_ref);
78 }
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
PgStat_StatTabEntry stats

References InvalidOid, MyDatabaseId, pgstat_fetch_stat_tabentry_ext(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, PgStat_EntryRef::shared_stats, and PgStatShared_Relation::stats.

Referenced by index_concurrently_swap().

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

Definition at line 383 of file pgstat_relation.c.

384 {
386  {
387  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
388 
389  ensure_tabstat_xact_level(pgstat_info);
390  pgstat_info->trans->tuples_deleted++;
391  }
392 }
static void ensure_tabstat_xact_level(PgStat_TableStatus *pgstat_info)
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:208
PgStat_Counter tuples_deleted
Definition: pgstat.h:221

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_deleted.

Referenced by heap_abort_speculative(), and heap_delete().

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 349 of file pgstat_relation.c.

350 {
352  {
353  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
354 
355  ensure_tabstat_xact_level(pgstat_info);
356  pgstat_info->trans->tuples_inserted += n;
357  }
358 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:219

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_inserted.

Referenced by ExecRefreshMatView(), heap_insert(), and heap_multi_insert().

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

Definition at line 364 of file pgstat_relation.c.

365 {
367  {
368  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
369 
370  ensure_tabstat_xact_level(pgstat_info);
371  pgstat_info->trans->tuples_updated++;
372 
373  /* t_tuples_hot_updated is nontransactional, so just advance it */
374  if (hot)
375  pgstat_info->t_counts.t_tuples_hot_updated++;
376  }
377 }
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:178
PgStat_TableCounts t_counts
Definition: pgstat.h:209
PgStat_Counter tuples_updated
Definition: pgstat.h:220

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_tuples_hot_updated, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_update().

◆ pgstat_count_slru_flush()

void pgstat_count_slru_flush ( int  slru_idx)

Definition at line 89 of file pgstat_slru.c.

90 {
91  get_slru_entry(slru_idx)->flush += 1;
92 }
static PgStat_SLRUStats * get_slru_entry(int slru_idx)
Definition: pgstat_slru.c:222
PgStat_Counter flush
Definition: pgstat.h:343

References PgStat_SLRUStats::flush, and get_slru_entry().

Referenced by SimpleLruWriteAll().

◆ pgstat_count_slru_page_exists()

void pgstat_count_slru_page_exists ( int  slru_idx)

Definition at line 71 of file pgstat_slru.c.

72 {
73  get_slru_entry(slru_idx)->blocks_exists += 1;
74 }
PgStat_Counter blocks_exists
Definition: pgstat.h:342

References PgStat_SLRUStats::blocks_exists, and get_slru_entry().

Referenced by SimpleLruDoesPhysicalPageExist().

◆ pgstat_count_slru_page_hit()

void pgstat_count_slru_page_hit ( int  slru_idx)

Definition at line 65 of file pgstat_slru.c.

66 {
67  get_slru_entry(slru_idx)->blocks_hit += 1;
68 }
PgStat_Counter blocks_hit
Definition: pgstat.h:339

References PgStat_SLRUStats::blocks_hit, and get_slru_entry().

Referenced by SimpleLruReadPage(), and SimpleLruReadPage_ReadOnly().

◆ pgstat_count_slru_page_read()

void pgstat_count_slru_page_read ( int  slru_idx)

Definition at line 77 of file pgstat_slru.c.

78 {
79  get_slru_entry(slru_idx)->blocks_read += 1;
80 }
PgStat_Counter blocks_read
Definition: pgstat.h:340

References PgStat_SLRUStats::blocks_read, and get_slru_entry().

Referenced by SimpleLruReadPage().

◆ pgstat_count_slru_page_written()

void pgstat_count_slru_page_written ( int  slru_idx)

Definition at line 83 of file pgstat_slru.c.

84 {
85  get_slru_entry(slru_idx)->blocks_written += 1;
86 }
PgStat_Counter blocks_written
Definition: pgstat.h:341

References PgStat_SLRUStats::blocks_written, and get_slru_entry().

Referenced by SlruPhysicalWritePage().

◆ pgstat_count_slru_page_zeroed()

void pgstat_count_slru_page_zeroed ( int  slru_idx)

Definition at line 59 of file pgstat_slru.c.

60 {
61  get_slru_entry(slru_idx)->blocks_zeroed += 1;
62 }
PgStat_Counter blocks_zeroed
Definition: pgstat.h:338

References PgStat_SLRUStats::blocks_zeroed, and get_slru_entry().

Referenced by SimpleLruZeroPage().

◆ pgstat_count_slru_truncate()

void pgstat_count_slru_truncate ( int  slru_idx)

Definition at line 95 of file pgstat_slru.c.

96 {
97  get_slru_entry(slru_idx)->truncate += 1;
98 }
PgStat_Counter truncate
Definition: pgstat.h:344

References get_slru_entry(), and PgStat_SLRUStats::truncate.

Referenced by SimpleLruTruncate().

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

Definition at line 398 of file pgstat_relation.c.

399 {
401  {
402  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
403 
404  ensure_tabstat_xact_level(pgstat_info);
405  save_truncdrop_counters(pgstat_info->trans, false);
406  pgstat_info->trans->tuples_inserted = 0;
407  pgstat_info->trans->tuples_updated = 0;
408  pgstat_info->trans->tuples_deleted = 0;
409  }
410 }
static void save_truncdrop_counters(PgStat_TableXactStatus *trans, bool is_drop)

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, save_truncdrop_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by ExecRefreshMatView(), and ExecuteTruncateGuts().

◆ pgstat_create_function()

void pgstat_create_function ( Oid  proid)

Definition at line 45 of file pgstat_function.c.

46 {
49  proid);
50 }
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_xact.c:366

References MyDatabaseId, pgstat_create_transactional(), and PGSTAT_KIND_FUNCTION.

Referenced by ProcedureCreate().

◆ pgstat_create_relation()

void pgstat_create_relation ( Relation  rel)

◆ pgstat_create_replslot()

void pgstat_create_replslot ( struct ReplicationSlot slot)

Definition at line 113 of file pgstat_replslot.c.

114 {
115  PgStat_EntryRef *entry_ref;
116  PgStatShared_ReplSlot *shstatent;
117 
119  ReplicationSlotIndex(slot), false);
120  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
121 
122  /*
123  * NB: need to accept that there might be stats from an older slot, e.g.
124  * if we previously crashed after dropping a slot.
125  */
126  memset(&shstatent->stats, 0, sizeof(shstatent->stats));
127  namestrcpy(&shstatent->stats.slotname, NameStr(slot->data.name));
128 
129  pgstat_unlock_entry(entry_ref);
130 }

References ReplicationSlot::data, InvalidOid, ReplicationSlotPersistentData::name, NameStr, namestrcpy(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), PgStat_EntryRef::shared_stats, PgStat_StatReplSlotEntry::slotname, and PgStatShared_ReplSlot::stats.

Referenced by ReplicationSlotCreate().

◆ pgstat_create_subscription()

void pgstat_create_subscription ( Oid  subid)

◆ pgstat_discard_stats()

void pgstat_discard_stats ( void  )

Definition at line 405 of file pgstat.c.

406 {
407  int ret;
408 
409  /* NB: this needs to be done even in single user mode */
410 
411  ret = unlink(PGSTAT_STAT_PERMANENT_FILENAME);
412  if (ret != 0)
413  {
414  if (errno == ENOENT)
415  elog(DEBUG2,
416  "didn't need to unlink permanent stats file \"%s\" - didn't exist",
418  else
419  ereport(LOG,
421  errmsg("could not unlink permanent statistics file \"%s\": %m",
423  }
424  else
425  {
426  ereport(DEBUG2,
428  errmsg("unlinked permanent statistics file \"%s\"",
430  }
431 
432  /*
433  * Reset stats contents. This will set reset timestamps of fixed-numbered
434  * stats to the current time (no variable stats exist).
435  */
437 }
int errcode_for_file_access(void)
Definition: elog.c:716
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define LOG
Definition: elog.h:25
#define DEBUG2
Definition: elog.h:23
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
static void pgstat_reset_after_failure(void)
Definition: pgstat.c:1620
#define PGSTAT_STAT_PERMANENT_FILENAME
Definition: pgstat.h:28

References DEBUG2, elog, ereport, errcode_for_file_access(), errmsg(), LOG, pgstat_reset_after_failure(), and PGSTAT_STAT_PERMANENT_FILENAME.

Referenced by StartupXLOG().

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)

Definition at line 44 of file pgstat_database.c.

45 {
47 }
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_xact.c:388

References InvalidOid, pgstat_drop_transactional(), and PGSTAT_KIND_DATABASE.

Referenced by dropdb().

◆ pgstat_drop_function()

void pgstat_drop_function ( Oid  proid)

Definition at line 60 of file pgstat_function.c.

61 {
64  proid);
65 }

References MyDatabaseId, pgstat_drop_transactional(), and PGSTAT_KIND_FUNCTION.

Referenced by RemoveFunctionById().

◆ pgstat_drop_relation()

void pgstat_drop_relation ( Relation  rel)

Definition at line 180 of file pgstat_relation.c.

181 {
182  int nest_level = GetCurrentTransactionNestLevel();
183  PgStat_TableStatus *pgstat_info;
184 
186  rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
187  RelationGetRelid(rel));
188 
190  return;
191 
192  /*
193  * Transactionally set counters to 0. That ensures that accesses to
194  * pg_stat_xact_all_tables inside the transaction show 0.
195  */
196  pgstat_info = rel->pgstat_info;
197  if (pgstat_info->trans &&
198  pgstat_info->trans->nest_level == nest_level)
199  {
200  save_truncdrop_counters(pgstat_info->trans, true);
201  pgstat_info->trans->tuples_inserted = 0;
202  pgstat_info->trans->tuples_updated = 0;
203  pgstat_info->trans->tuples_deleted = 0;
204  }
205 }
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:910

References GetCurrentTransactionNestLevel(), InvalidOid, MyDatabaseId, PgStat_TableXactStatus::nest_level, pgstat_drop_transactional(), RelationData::pgstat_info, PGSTAT_KIND_RELATION, pgstat_should_count_relation, RelationData::rd_rel, RelationGetRelid, save_truncdrop_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_drop_with_catalog().

◆ pgstat_drop_replslot()

void pgstat_drop_replslot ( struct ReplicationSlot slot)

Definition at line 165 of file pgstat_replslot.c.

166 {
168  ReplicationSlotIndex(slot));
169 }
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_shmem.c:838

References InvalidOid, pgstat_drop_entry(), PGSTAT_KIND_REPLSLOT, and ReplicationSlotIndex().

Referenced by ReplicationSlotDropPtr().

◆ pgstat_drop_subscription()

void pgstat_drop_subscription ( Oid  subid)

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 146 of file pgstat_function.c.

147 {
148  PgStat_FunctionCounts *fs = fcu->fs;
149  instr_time f_total;
150  instr_time f_others;
151  instr_time f_self;
152 
153  /* stats not wanted? */
154  if (fs == NULL)
155  return;
156 
157  /* total elapsed time in this function call */
158  INSTR_TIME_SET_CURRENT(f_total);
159  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
160 
161  /* self usage: elapsed minus anything already charged to other calls */
162  f_others = total_func_time;
163  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
164  f_self = f_total;
165  INSTR_TIME_SUBTRACT(f_self, f_others);
166 
167  /* update backend-wide total time */
169 
170  /*
171  * Compute the new f_total_time as the total elapsed time added to the
172  * pre-call value of f_total_time. This is necessary to avoid
173  * double-counting any time taken by recursive calls of myself. (We do
174  * not need any similar kluge for self time, since that already excludes
175  * any recursive calls.)
176  */
177  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
178 
179  /* update counters in function stats table */
180  if (finalize)
181  fs->f_numcalls++;
182  fs->f_total_time = f_total;
183  INSTR_TIME_ADD(fs->f_self_time, f_self);
184 }
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:158
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:170
struct timeval instr_time
Definition: instr_time.h:150
static instr_time total_func_time
instr_time save_total
Definition: pgstat.h:133
PgStat_FunctionCounts * fs
Definition: pgstat.h:129
instr_time f_start
Definition: pgstat.h:135
instr_time save_f_total_time
Definition: pgstat.h:131
instr_time f_total_time
Definition: pgstat.h:109
PgStat_Counter f_numcalls
Definition: pgstat.h:108
instr_time f_self_time
Definition: pgstat.h:110

References PgStat_FunctionCounts::f_numcalls, PgStat_FunctionCounts::f_self_time, PgStat_FunctionCallUsage::f_start, PgStat_FunctionCounts::f_total_time, PgStat_FunctionCallUsage::fs, INSTR_TIME_ADD, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, PgStat_FunctionCallUsage::save_f_total_time, PgStat_FunctionCallUsage::save_total, and total_func_time.

Referenced by call_pltcl_start_proc(), EventTriggerInvoke(), ExecCallTriggerFunc(), ExecEvalFuncExprFusage(), ExecEvalFuncExprStrictFusage(), ExecMakeFunctionResultSet(), ExecMakeTableFunctionResult(), ExecuteCallStmt(), and fmgr_security_definer().

◆ pgstat_execute_transactional_drops()

void pgstat_execute_transactional_drops ( int  ndrops,
struct xl_xact_stats_item items,
bool  is_redo 
)

Definition at line 320 of file pgstat_xact.c.

321 {
322  int not_freed_count = 0;
323 
324  if (ndrops == 0)
325  return;
326 
327  for (int i = 0; i < ndrops; i++)
328  {
329  xl_xact_stats_item *it = &items[i];
330 
331  if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid))
332  not_freed_count++;
333  }
334 
335  if (not_freed_count > 0)
337 }
int i
Definition: isn.c:73
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:608

References xl_xact_stats_item::dboid, i, xl_xact_stats_item::kind, xl_xact_stats_item::objoid, pgstat_drop_entry(), and pgstat_request_entry_refs_gc().

Referenced by FinishPreparedTransaction(), xact_redo_abort(), and xact_redo_commit().

◆ pgstat_fetch_replslot()

PgStat_StatReplSlotEntry* pgstat_fetch_replslot ( NameData  slotname)

Definition at line 176 of file pgstat_replslot.c.

177 {
178  int idx = get_replslot_index(NameStr(slotname));
179 
180  if (idx == -1)
181  return NULL;
182 
183  return (PgStat_StatReplSlotEntry *)
185 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:779
static int get_replslot_index(const char *name)

References get_replslot_index(), idx(), InvalidOid, NameStr, pgstat_fetch_entry(), and PGSTAT_KIND_REPLSLOT.

Referenced by pg_stat_get_replication_slot().

◆ pgstat_fetch_slru()

PgStat_SLRUStats* pgstat_fetch_slru ( void  )

Definition at line 105 of file pgstat_slru.c.

106 {
108 
109  return pgStatLocal.snapshot.slru;
110 }
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:899
PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]

References PGSTAT_KIND_SLRU, pgstat_snapshot_fixed(), pgStatLocal, PgStat_Snapshot::slru, and PgStat_LocalState::snapshot.

Referenced by pg_stat_get_slru().

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

◆ pgstat_fetch_stat_bgwriter()

◆ pgstat_fetch_stat_checkpointer()

◆ pgstat_fetch_stat_dbentry()

◆ pgstat_fetch_stat_funcentry()

◆ pgstat_fetch_stat_subscription()

PgStat_StatSubEntry* pgstat_fetch_stat_subscription ( Oid  subid)

◆ pgstat_fetch_stat_tabentry()

◆ pgstat_fetch_stat_tabentry_ext()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry_ext ( bool  shared,
Oid  relid 
)

Definition at line 458 of file pgstat_relation.c.

459 {
460  Oid dboid = (shared ? InvalidOid : MyDatabaseId);
461 
462  return (PgStat_StatTabEntry *)
464 }
unsigned int Oid
Definition: postgres_ext.h:31

References InvalidOid, MyDatabaseId, pgstat_fetch_entry(), and PGSTAT_KIND_RELATION.

Referenced by do_autovacuum(), pgstat_copy_relation_stats(), pgstat_fetch_stat_tabentry(), and recheck_relation_needs_vacanalyze().

◆ pgstat_fetch_stat_wal()

PgStat_WalStats* pgstat_fetch_stat_wal ( void  )

◆ pgstat_force_next_flush()

void pgstat_force_next_flush ( void  )

Definition at line 665 of file pgstat.c.

666 {
667  pgStatForceNextFlush = true;
668 }
static bool pgStatForceNextFlush
Definition: pgstat.c:227

References pgStatForceNextFlush.

Referenced by pg_stat_force_next_flush().

◆ pgstat_get_kind_from_str()

PgStat_Kind pgstat_get_kind_from_str ( char *  kind_str)

Definition at line 1190 of file pgstat.c.

1191 {
1192  for (int kind = PGSTAT_KIND_FIRST_VALID; kind <= PGSTAT_KIND_LAST; kind++)
1193  {
1194  if (pg_strcasecmp(kind_str, pgstat_kind_infos[kind].name) == 0)
1195  return kind;
1196  }
1197 
1198  ereport(ERROR,
1199  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1200  errmsg("invalid statistics kind: \"%s\"", kind_str)));
1201  return PGSTAT_KIND_DATABASE; /* avoid compiler warnings */
1202 }
int errcode(int sqlerrcode)
Definition: elog.c:693
#define ERROR
Definition: elog.h:33
const char * name
Definition: encode.c:561
static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS]
Definition: pgstat.c:252
#define PGSTAT_KIND_LAST
Definition: pgstat.h:56
#define PGSTAT_KIND_FIRST_VALID
Definition: pgstat.h:55
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36

References ereport, errcode(), errmsg(), ERROR, name, pg_strcasecmp(), PGSTAT_KIND_DATABASE, PGSTAT_KIND_FIRST_VALID, pgstat_kind_infos, and PGSTAT_KIND_LAST.

Referenced by pg_stat_have_stats().

◆ pgstat_get_slru_index()

int pgstat_get_slru_index ( const char *  name)

Definition at line 132 of file pgstat_slru.c.

133 {
134  int i;
135 
136  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
137  {
138  if (strcmp(slru_names[i], name) == 0)
139  return i;
140  }
141 
142  /* return index of the last entry (which is the "other" one) */
143  return (SLRU_NUM_ELEMENTS - 1);
144 }
static const char *const slru_names[]
#define SLRU_NUM_ELEMENTS

References i, name, slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pgstat_reset_slru(), and SimpleLruInit().

◆ pgstat_get_slru_name()

const char* pgstat_get_slru_name ( int  slru_idx)

Definition at line 118 of file pgstat_slru.c.

119 {
120  if (slru_idx < 0 || slru_idx >= SLRU_NUM_ELEMENTS)
121  return NULL;
122 
123  return slru_names[slru_idx];
124 }

References slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pg_stat_get_slru().

◆ pgstat_get_stat_snapshot_timestamp()

TimestampTz pgstat_get_stat_snapshot_timestamp ( bool have_snapshot)

Definition at line 869 of file pgstat.c.

870 {
872  {
873  *have_snapshot = true;
875  }
876 
877  *have_snapshot = false;
878 
879  return 0;
880 }
TimestampTz snapshot_timestamp

References PgStat_Snapshot::mode, PGSTAT_FETCH_CONSISTENCY_SNAPSHOT, pgStatLocal, PgStat_LocalState::snapshot, and PgStat_Snapshot::snapshot_timestamp.

Referenced by pg_stat_get_snapshot_timestamp().

◆ pgstat_get_transactional_drops()

int pgstat_get_transactional_drops ( bool  isCommit,
struct xl_xact_stats_item **  items 
)

Definition at line 278 of file pgstat_xact.c.

279 {
281  int nitems = 0;
282  dlist_iter iter;
283 
284  if (xact_state == NULL)
285  return 0;
286 
287  /*
288  * We expect to be called for subtransaction abort (which logs a WAL
289  * record), but not for subtransaction commit (which doesn't).
290  */
291  Assert(!isCommit || xact_state->nest_level == 1);
292  Assert(!isCommit || xact_state->prev == NULL);
293 
294  *items = palloc(xact_state->pending_drops_count
295  * sizeof(xl_xact_stats_item));
296 
297  dlist_foreach(iter, &xact_state->pending_drops)
298  {
301 
302  if (isCommit && pending->is_create)
303  continue;
304  if (!isCommit && !pending->is_create)
305  continue;
306 
307  Assert(nitems < xact_state->pending_drops_count);
308  (*items)[nitems++] = pending->item;
309  }
310 
311  return nitems;
312 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:526
#define dlist_container(type, membername, ptr)
Definition: ilist.h:496
void * palloc(Size size)
Definition: mcxt.c:1068
xl_xact_stats_item item
Definition: pgstat_xact.c:24
dlist_node * cur
Definition: ilist.h:161

References Assert(), dlist_iter::cur, dlist_container, dlist_foreach, PgStat_PendingDroppedStatsItem::is_create, PgStat_PendingDroppedStatsItem::item, PgStat_SubXactStatus::nest_level, palloc(), PgStat_SubXactStatus::pending_drops, PgStat_SubXactStatus::pending_drops_count, pgStatXactStack, and PgStat_SubXactStatus::prev.

Referenced by RecordTransactionAbort(), RecordTransactionCommit(), and StartPrepare().

◆ pgstat_have_entry()

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

Definition at line 883 of file pgstat.c.

884 {
885  /* fixed-numbered stats always exist */
886  if (pgstat_get_kind_info(kind)->fixed_amount)
887  return true;
888 
889  return pgstat_get_entry_ref(kind, dboid, objoid, false, NULL) != NULL;
890 }
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
Definition: pgstat.c:1211
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:393

References pgstat_get_entry_ref(), and pgstat_get_kind_info().

Referenced by pg_stat_have_stats().

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( struct FunctionCallInfoBaseData fcinfo,
PgStat_FunctionCallUsage fcu 
)

◆ pgstat_init_relation()

void pgstat_init_relation ( Relation  rel)

Definition at line 92 of file pgstat_relation.c.

93 {
94  char relkind = rel->rd_rel->relkind;
95 
96  /*
97  * We only count stats for relations with storage and partitioned tables
98  */
99  if (!RELKIND_HAS_STORAGE(relkind) && relkind != RELKIND_PARTITIONED_TABLE)
100  {
101  rel->pgstat_enabled = false;
102  rel->pgstat_info = NULL;
103  return;
104  }
105 
106  if (!pgstat_track_counts)
107  {
108  if (rel->pgstat_info)
110 
111  /* We're not counting at all */
112  rel->pgstat_enabled = false;
113  rel->pgstat_info = NULL;
114  return;
115  }
116 
117  rel->pgstat_enabled = true;
118 }
bool pgstat_track_counts
Definition: pgstat.c:186
void pgstat_unlink_relation(Relation rel)

References RelationData::pgstat_enabled, RelationData::pgstat_info, pgstat_track_counts, pgstat_unlink_relation(), and RelationData::rd_rel.

Referenced by relation_open(), and try_relation_open().

◆ pgstat_initialize()

void pgstat_initialize ( void  )

Definition at line 523 of file pgstat.c.

524 {
525  Assert(!pgstat_is_initialized);
526 
528 
529  pgstat_init_wal();
530 
531  /* Set up a process-exit hook to clean up */
533 
534 #ifdef USE_ASSERT_CHECKING
535  pgstat_is_initialized = true;
536 #endif
537 }
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
static void pgstat_shutdown_hook(int code, Datum arg)
Definition: pgstat.c:489
void pgstat_attach_shmem(void)
Definition: pgstat_shmem.c:213
void pgstat_init_wal(void)
Definition: pgstat_wal.c:126

References Assert(), before_shmem_exit(), pgstat_attach_shmem(), pgstat_init_wal(), and pgstat_shutdown_hook().

Referenced by BaseInit().

◆ pgstat_report_analyze()

void pgstat_report_analyze ( Relation  rel,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples,
bool  resetcounter 
)

Definition at line 269 of file pgstat_relation.c.

272 {
273  PgStat_EntryRef *entry_ref;
274  PgStatShared_Relation *shtabentry;
275  PgStat_StatTabEntry *tabentry;
276  Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
277 
278  if (!pgstat_track_counts)
279  return;
280 
281  /*
282  * Unlike VACUUM, ANALYZE might be running inside a transaction that has
283  * already inserted and/or deleted rows in the target table. ANALYZE will
284  * have counted such rows as live or dead respectively. Because we will
285  * report our counts of such rows at transaction end, we should subtract
286  * off these counts from the update we're making now, else they'll be
287  * double-counted after commit. (This approach also ensures that the
288  * shared stats entry ends up with the right numbers if we abort instead
289  * of committing.)
290  *
291  * Waste no time on partitioned tables, though.
292  */
293  if (pgstat_should_count_relation(rel) &&
294  rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
295  {
297 
298  for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
299  {
300  livetuples -= trans->tuples_inserted - trans->tuples_deleted;
301  deadtuples -= trans->tuples_updated + trans->tuples_deleted;
302  }
303  /* count stuff inserted by already-aborted subxacts, too */
304  deadtuples -= rel->pgstat_info->t_counts.t_delta_dead_tuples;
305  /* Since ANALYZE's counts are estimates, we could have underflowed */
306  livetuples = Max(livetuples, 0);
307  deadtuples = Max(deadtuples, 0);
308  }
309 
310  /* block acquiring lock for the same reason as pgstat_report_autovac() */
312  RelationGetRelid(rel),
313  false);
314  /* can't get dropped while accessed */
315  Assert(entry_ref != NULL && entry_ref->shared_stats != NULL);
316 
317  shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
318  tabentry = &shtabentry->stats;
319 
320  tabentry->n_live_tuples = livetuples;
321  tabentry->n_dead_tuples = deadtuples;
322 
323  /*
324  * If commanded, reset changes_since_analyze to zero. This forgets any
325  * changes that were committed while the ANALYZE was in progress, but we
326  * have no good way to estimate how many of those there were.
327  */
328  if (resetcounter)
329  tabentry->changes_since_analyze = 0;
330 
332  {
334  tabentry->autovac_analyze_count++;
335  }
336  else
337  {
339  tabentry->analyze_count++;
340  }
341 
342  pgstat_unlock_entry(entry_ref);
343 }
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3309
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1574
#define Max(x, y)
Definition: c.h:980
PgStat_Counter analyze_count
Definition: pgstat.h:380
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:381
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:382
PgStat_Counter changes_since_analyze
Definition: pgstat.h:369
TimestampTz analyze_timestamp
Definition: pgstat.h:379
PgStat_Counter n_live_tuples
Definition: pgstat.h:367
PgStat_Counter n_dead_tuples
Definition: pgstat.h:368
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:182
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400

References PgStat_StatTabEntry::analyze_count, PgStat_StatTabEntry::analyze_timestamp, Assert(), PgStat_StatTabEntry::autovac_analyze_count, PgStat_StatTabEntry::autovac_analyze_timestamp, PgStat_StatTabEntry::changes_since_analyze, GetCurrentTimestamp(), if(), InvalidOid, IsAutoVacuumWorkerProcess(), Max, MyDatabaseId, PgStat_StatTabEntry::n_dead_tuples, PgStat_StatTabEntry::n_live_tuples, pgstat_get_entry_ref_locked(), RelationData::pgstat_info, PGSTAT_KIND_RELATION, pgstat_should_count_relation, pgstat_track_counts, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableStatus::trans, and trans.

Referenced by do_analyze_rel().

◆ pgstat_report_archiver()

void pgstat_report_archiver ( const char *  xlog,
bool  failed 
)

Definition at line 28 of file pgstat_archiver.c.

29 {
32 
34 
35  if (failed)
36  {
37  ++stats_shmem->stats.failed_count;
38  memcpy(&stats_shmem->stats.last_failed_wal, xlog,
39  sizeof(stats_shmem->stats.last_failed_wal));
40  stats_shmem->stats.last_failed_timestamp = now;
41  }
42  else
43  {
44  ++stats_shmem->stats.archived_count;
45  memcpy(&stats_shmem->stats.last_archived_wal, xlog,
46  sizeof(stats_shmem->stats.last_archived_wal));
47  stats_shmem->stats.last_archived_timestamp = now;
48  }
49 
51 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1538
int64 TimestampTz
Definition: timestamp.h:39
static void pgstat_end_changecount_write(uint32 *cc)
static void pgstat_begin_changecount_write(uint32 *cc)
PgStat_ArchiverStats stats
TimestampTz last_failed_timestamp
Definition: pgstat.h:256
TimestampTz last_archived_timestamp
Definition: pgstat.h:252
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:254
PgStat_Counter failed_count
Definition: pgstat.h:253
PgStat_Counter archived_count
Definition: pgstat.h:249
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:250
PgStatShared_Archiver archiver

References PgStat_ArchiverStats::archived_count, PgStat_ShmemControl::archiver, PgStatShared_Archiver::changecount, PgStat_ArchiverStats::failed_count, GetCurrentTimestamp(), PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, now(), pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgStatLocal, PgStat_LocalState::shmem, and PgStatShared_Archiver::stats.

Referenced by pgarch_ArchiverCopyLoop().

◆ pgstat_report_autovac()

void pgstat_report_autovac ( Oid  dboid)

Definition at line 55 of file pgstat_database.c.

56 {
57  PgStat_EntryRef *entry_ref;
58  PgStatShared_Database *dbentry;
59 
60  /* can't get here in single user mode */
62 
63  /*
64  * End-of-vacuum is reported instantly. Report the start the same way for
65  * consistency. Vacuum doesn't run frequently and is a long-lasting
66  * operation so it doesn't matter if we get blocked here a little.
67  */
69  dboid, InvalidOid, false);
70 
71  dbentry = (PgStatShared_Database *) entry_ref->shared_stats;
73 
74  pgstat_unlock_entry(entry_ref);
75 }
bool IsUnderPostmaster
Definition: globals.c:113
PgStat_StatDBEntry stats
TimestampTz last_autovac_time
Definition: pgstat.h:290

References Assert(), GetCurrentTimestamp(), InvalidOid, IsUnderPostmaster, PgStat_StatDBEntry::last_autovac_time, pgstat_get_entry_ref_locked(), PGSTAT_KIND_DATABASE, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_Database::stats.

Referenced by AutoVacWorkerMain().

◆ pgstat_report_bgwriter()

void pgstat_report_bgwriter ( void  )

Definition at line 30 of file pgstat_bgwriter.c.

31 {
33  static const PgStat_BgWriterStats all_zeroes;
34 
37 
38  /*
39  * This function can be called even if nothing at all has happened. In
40  * this case, avoid unnecessarily modifying the stats entry.
41  */
42  if (memcmp(&PendingBgWriterStats, &all_zeroes, sizeof(all_zeroes)) == 0)
43  return;
44 
46 
47 #define BGWRITER_ACC(fld) stats_shmem->stats.fld += PendingBgWriterStats.fld
48  BGWRITER_ACC(buf_written_clean);
49  BGWRITER_ACC(maxwritten_clean);
50  BGWRITER_ACC(buf_alloc);
51 #undef BGWRITER_ACC
52 
54 
55  /*
56  * Clear out the statistics buffer, so it can be re-used.
57  */
59 }
#define MemSet(start, val, len)
Definition: c.h:1008
#define BGWRITER_ACC(fld)
PgStat_BgWriterStats PendingBgWriterStats
PgStatShared_BgWriter bgwriter

References Assert(), PgStat_ShmemControl::bgwriter, BGWRITER_ACC, PgStatShared_BgWriter::changecount, PgStat_ShmemControl::is_shutdown, MemSet, PendingBgWriterStats, pgstat_assert_is_up, pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by BackgroundWriterMain().

◆ pgstat_report_checkpointer()

void pgstat_report_checkpointer ( void  )

Definition at line 30 of file pgstat_checkpointer.c.

31 {
32  /* We assume this initializes to zeroes */
33  static const PgStat_CheckpointerStats all_zeroes;
35 
38 
39  /*
40  * This function can be called even if nothing at all has happened. In
41  * this case, avoid unnecessarily modifying the stats entry.
42  */
43  if (memcmp(&PendingCheckpointerStats, &all_zeroes,
44  sizeof(all_zeroes)) == 0)
45  return;
46 
48 
49 #define CHECKPOINTER_ACC(fld) stats_shmem->stats.fld += PendingCheckpointerStats.fld
50  CHECKPOINTER_ACC(timed_checkpoints);
51  CHECKPOINTER_ACC(requested_checkpoints);
52  CHECKPOINTER_ACC(checkpoint_write_time);
53  CHECKPOINTER_ACC(checkpoint_sync_time);
54  CHECKPOINTER_ACC(buf_written_checkpoints);
55  CHECKPOINTER_ACC(buf_written_backend);
56  CHECKPOINTER_ACC(buf_fsync_backend);
57 #undef CHECKPOINTER_ACC
58 
60 
61  /*
62  * Clear out the statistics buffer, so it can be re-used.
63  */
65 }
PgStat_CheckpointerStats PendingCheckpointerStats
#define CHECKPOINTER_ACC(fld)
PgStatShared_Checkpointer checkpointer

References Assert(), PgStatShared_Checkpointer::changecount, PgStat_ShmemControl::checkpointer, CHECKPOINTER_ACC, PgStat_ShmemControl::is_shutdown, MemSet, PendingCheckpointerStats, pgstat_assert_is_up, pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by CheckpointerMain(), CheckpointWriteDelay(), and HandleCheckpointerInterrupts().

◆ pgstat_report_checksum_failure()

void pgstat_report_checksum_failure ( void  )

Definition at line 163 of file pgstat_database.c.

164 {
166 }
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)

References MyDatabaseId, and pgstat_report_checksum_failures_in_db().

Referenced by PageIsVerifiedExtended().

◆ pgstat_report_checksum_failures_in_db()

void pgstat_report_checksum_failures_in_db ( Oid  dboid,
int  failurecount 
)

Definition at line 137 of file pgstat_database.c.

138 {
139  PgStat_EntryRef *entry_ref;
140  PgStatShared_Database *sharedent;
141 
142  if (!pgstat_track_counts)
143  return;
144 
145  /*
146  * Update the shared stats directly - checksum failures should never be
147  * common enough for that to be a problem.
148  */
149  entry_ref =
151 
152  sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
153  sharedent->stats.n_checksum_failures += failurecount;
155 
156  pgstat_unlock_entry(entry_ref);
157 }
TimestampTz last_checksum_failure
Definition: pgstat.h:300
PgStat_Counter n_checksum_failures
Definition: pgstat.h:299

References GetCurrentTimestamp(), InvalidOid, PgStat_StatDBEntry::last_checksum_failure, PgStat_StatDBEntry::n_checksum_failures, pgstat_get_entry_ref_locked(), PGSTAT_KIND_DATABASE, pgstat_track_counts, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_Database::stats.

Referenced by pgstat_report_checksum_failure(), and sendFile().

◆ pgstat_report_connect()

void pgstat_report_connect ( Oid  dboid)

Definition at line 188 of file pgstat_database.c.

189 {
190  PgStat_StatDBEntry *dbentry;
191 
193  return;
194 
196 
198  dbentry->n_sessions++;
199 }
TimestampTz MyStartTimestamp
Definition: globals.c:46
static bool pgstat_should_report_connstat(void)
static PgStat_Counter pgLastSessionReportTime
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
PgStat_Counter n_sessions
Definition: pgstat.h:303

References MyDatabaseId, MyStartTimestamp, PgStat_StatDBEntry::n_sessions, pgLastSessionReportTime, pgstat_prep_database_pending(), and pgstat_should_report_connstat().

Referenced by PostgresMain().

◆ pgstat_report_deadlock()

void pgstat_report_deadlock ( void  )

Definition at line 122 of file pgstat_database.c.

123 {
124  PgStat_StatDBEntry *dbent;
125 
126  if (!pgstat_track_counts)
127  return;
128 
130  dbent->n_deadlocks++;
131 }
PgStat_Counter n_deadlocks
Definition: pgstat.h:298

References MyDatabaseId, PgStat_StatDBEntry::n_deadlocks, pgstat_prep_database_pending(), and pgstat_track_counts.

Referenced by DeadLockReport().

◆ pgstat_report_recovery_conflict()

void pgstat_report_recovery_conflict ( int  reason)

Definition at line 81 of file pgstat_database.c.

82 {
83  PgStat_StatDBEntry *dbentry;
84 
87  return;
88 
90 
91  switch (reason)
92  {
94 
95  /*
96  * Since we drop the information about the database as soon as it
97  * replicates, there is no point in counting these conflicts.
98  */
99  break;
101  dbentry->n_conflict_tablespace++;
102  break;
104  dbentry->n_conflict_lock++;
105  break;
107  dbentry->n_conflict_snapshot++;
108  break;
110  dbentry->n_conflict_bufferpin++;
111  break;
113  dbentry->n_conflict_startup_deadlock++;
114  break;
115  }
116 }
@ PROCSIG_RECOVERY_CONFLICT_BUFFERPIN
Definition: procsignal.h:44
@ PROCSIG_RECOVERY_CONFLICT_LOCK
Definition: procsignal.h:42
@ PROCSIG_RECOVERY_CONFLICT_DATABASE
Definition: procsignal.h:40
@ PROCSIG_RECOVERY_CONFLICT_SNAPSHOT
Definition: procsignal.h:43
@ PROCSIG_RECOVERY_CONFLICT_TABLESPACE
Definition: procsignal.h:41
@ PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK
Definition: procsignal.h:45
PgStat_Counter n_conflict_lock
Definition: pgstat.h:292
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:291
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:294
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:295
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:293

References Assert(), IsUnderPostmaster, MyDatabaseId, PgStat_StatDBEntry::n_conflict_bufferpin, PgStat_StatDBEntry::n_conflict_lock, PgStat_StatDBEntry::n_conflict_snapshot, PgStat_StatDBEntry::n_conflict_startup_deadlock, PgStat_StatDBEntry::n_conflict_tablespace, pgstat_prep_database_pending(), pgstat_track_counts, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, and PROCSIG_RECOVERY_CONFLICT_TABLESPACE.

Referenced by ProcessInterrupts().

◆ pgstat_report_replslot()

void pgstat_report_replslot ( struct ReplicationSlot slot,
const PgStat_StatReplSlotEntry repSlotStat 
)

Definition at line 74 of file pgstat_replslot.c.

75 {
76  PgStat_EntryRef *entry_ref;
77  PgStatShared_ReplSlot *shstatent;
78  PgStat_StatReplSlotEntry *statent;
79 
81  ReplicationSlotIndex(slot), false);
82  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
83  statent = &shstatent->stats;
84 
85  /*
86  * Any mismatch should have been fixed in pgstat_create_replslot() or
87  * pgstat_acquire_replslot().
88  */
89  Assert(namestrcmp(&statent->slotname, NameStr(slot->data.name)) == 0);
90 
91  /* Update the replication slot statistics */
92 #define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
93  REPLSLOT_ACC(spill_txns);
94  REPLSLOT_ACC(spill_count);
95  REPLSLOT_ACC(spill_bytes);
96  REPLSLOT_ACC(stream_txns);
97  REPLSLOT_ACC(stream_count);
98  REPLSLOT_ACC(stream_bytes);
99  REPLSLOT_ACC(total_txns);
100  REPLSLOT_ACC(total_bytes);
101 #undef REPLSLOT_ACC
102 
103  pgstat_unlock_entry(entry_ref);
104 }
#define REPLSLOT_ACC(fld)

References Assert(), ReplicationSlot::data, InvalidOid, ReplicationSlotPersistentData::name, NameStr, namestrcmp(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), REPLSLOT_ACC, PgStat_EntryRef::shared_stats, PgStat_StatReplSlotEntry::slotname, and PgStatShared_ReplSlot::stats.

Referenced by UpdateDecodingStats().

◆ pgstat_report_stat()

long pgstat_report_stat ( bool  force)

Definition at line 565 of file pgstat.c.

566 {
567  static TimestampTz pending_since = 0;
568  static TimestampTz last_flush = 0;
569  bool partial_flush;
571  bool nowait;
572 
575 
576  /* "absorb" the forced flush even if there's nothing to flush */
578  {
579  force = true;
580  pgStatForceNextFlush = false;
581  }
582 
583  /* Don't expend a clock check if nothing to do */
585  !have_slrustats &&
587  {
588  Assert(pending_since == 0);
589  return 0;
590  }
591 
592  /*
593  * There should never be stats to report once stats are shut down. Can't
594  * assert that before the checks above, as there is an unconditional
595  * pgstat_report_stat() call in pgstat_shutdown_hook() - which at least
596  * the process that ran pgstat_before_server_shutdown() will still call.
597  */
599 
601 
602  if (!force)
603  {
604  if (pending_since > 0 &&
606  {
607  /* don't keep pending updates longer than PGSTAT_MAX_INTERVAL */
608  force = true;
609  }
610  else if (last_flush > 0 &&
612  {
613  /* don't flush too frequently */
614  if (pending_since == 0)
615  pending_since = now;
616 
617  return PGSTAT_IDLE_INTERVAL;
618  }
619  }
620 
622 
623  /* don't wait for lock acquisition when !force */
624  nowait = !force;
625 
626  partial_flush = false;
627 
628  /* flush database / relation / function / ... stats */
629  partial_flush |= pgstat_flush_pending_entries(nowait);
630 
631  /* flush wal stats */
632  partial_flush |= pgstat_flush_wal(nowait);
633 
634  /* flush SLRU stats */
635  partial_flush |= pgstat_slru_flush(nowait);
636 
637  last_flush = now;
638 
639  /*
640  * If some of the pending stats could not be flushed due to lock
641  * contention, let the caller know when to retry.
642  */
643  if (partial_flush)
644  {
645  /* force should have prevented us from getting here */
646  Assert(!force);
647 
648  /* remember since when stats have been pending */
649  if (pending_since == 0)
650  pending_since = now;
651 
652  return PGSTAT_IDLE_INTERVAL;
653  }
654 
655  pending_since = 0;
656 
657  return 0;
658 }
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1705
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
#define PGSTAT_MIN_INTERVAL
Definition: pgstat.c:119
static bool pgstat_flush_pending_entries(bool nowait)
Definition: pgstat.c:1128
static dlist_head pgStatPending
Definition: pgstat.c:220
#define PGSTAT_MAX_INTERVAL
Definition: pgstat.c:121
#define PGSTAT_IDLE_INTERVAL
Definition: pgstat.c:123
void pgstat_update_dbstats(TimestampTz ts)
bool have_slrustats
Definition: pgstat_slru.c:35
bool pgstat_slru_flush(bool nowait)
Definition: pgstat_slru.c:158
bool pgstat_have_pending_wal(void)
Definition: pgstat_wal.c:144
bool pgstat_flush_wal(bool nowait)
Definition: pgstat_wal.c:68
bool IsTransactionBlock(void)
Definition: xact.c:4766
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition: xact.c:872

References Assert(), dlist_is_empty(), GetCurrentTransactionStopTimestamp(), have_slrustats, PgStat_ShmemControl::is_shutdown, IsTransactionBlock(), now(), pgstat_assert_is_up, pgstat_flush_pending_entries(), pgstat_flush_wal(), pgstat_have_pending_wal(), PGSTAT_IDLE_INTERVAL, PGSTAT_MAX_INTERVAL, PGSTAT_MIN_INTERVAL, pgstat_slru_flush(), pgstat_update_dbstats(), pgStatForceNextFlush, pgStatLocal, pgStatPending, PgStat_LocalState::shmem, and TimestampDifferenceExceeds().

Referenced by AllTablesyncsReady(), apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_rollback_prepared(), apply_handle_stream_prepare(), LogicalRepApplyLoop(), LogicalRepSyncTableStart(), pg_attribute_noreturn(), pgstat_before_server_shutdown(), pgstat_shutdown_hook(), PostgresMain(), process_syncing_tables_for_apply(), and ProcessInterrupts().

◆ pgstat_report_subscription_error()

void pgstat_report_subscription_error ( Oid  subid,
bool  is_apply_error 
)

Definition at line 27 of file pgstat_subscription.c.

28 {
29  PgStat_EntryRef *entry_ref;
30  PgStat_BackendSubEntry *pending;
31 
33  InvalidOid, subid, NULL);
34  pending = entry_ref->pending;
35 
36  if (is_apply_error)
37  pending->apply_error_count++;
38  else
39  pending->sync_error_count++;
40 }
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry)
Definition: pgstat.c:1053
PgStat_Counter apply_error_count
Definition: pgstat.h:144
PgStat_Counter sync_error_count
Definition: pgstat.h:145

References PgStat_BackendSubEntry::apply_error_count, InvalidOid, PgStat_EntryRef::pending, PGSTAT_KIND_SUBSCRIPTION, pgstat_prep_pending_entry(), and PgStat_BackendSubEntry::sync_error_count.

Referenced by DisableSubscriptionAndExit(), start_apply(), and start_table_sync().

◆ pgstat_report_vacuum()

void pgstat_report_vacuum ( Oid  tableoid,
bool  shared,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples 
)

Definition at line 211 of file pgstat_relation.c.

213 {
214  PgStat_EntryRef *entry_ref;
215  PgStatShared_Relation *shtabentry;
216  PgStat_StatTabEntry *tabentry;
217  Oid dboid = (shared ? InvalidOid : MyDatabaseId);
218  TimestampTz ts;
219 
220  if (!pgstat_track_counts)
221  return;
222 
223  /* Store the data in the table's hash table entry. */
224  ts = GetCurrentTimestamp();
225 
226  /* block acquiring lock for the same reason as pgstat_report_autovac() */
228  dboid, tableoid, false);
229 
230  shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
231  tabentry = &shtabentry->stats;
232 
233  tabentry->n_live_tuples = livetuples;
234  tabentry->n_dead_tuples = deadtuples;
235 
236  /*
237  * It is quite possible that a non-aggressive VACUUM ended up skipping
238  * various pages, however, we'll zero the insert counter here regardless.
239  * It's currently used only to track when we need to perform an "insert"
240  * autovacuum, which are mainly intended to freeze newly inserted tuples.
241  * Zeroing this may just mean we'll not try to vacuum the table again
242  * until enough tuples have been inserted to trigger another insert
243  * autovacuum. An anti-wraparound autovacuum will catch any persistent
244  * stragglers.
245  */
246  tabentry->inserts_since_vacuum = 0;
247 
249  {
250  tabentry->autovac_vacuum_timestamp = ts;
251  tabentry->autovac_vacuum_count++;
252  }
253  else
254  {
255  tabentry->vacuum_timestamp = ts;
256  tabentry->vacuum_count++;
257  }
258 
259  pgstat_unlock_entry(entry_ref);
260 }
PgStat_Counter vacuum_count
Definition: pgstat.h:376
TimestampTz vacuum_timestamp
Definition: pgstat.h:375
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:370
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:378
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:377

References PgStat_StatTabEntry::autovac_vacuum_count, PgStat_StatTabEntry::autovac_vacuum_timestamp, GetCurrentTimestamp(), if(), PgStat_StatTabEntry::inserts_since_vacuum, InvalidOid, IsAutoVacuumWorkerProcess(), MyDatabaseId, PgStat_StatTabEntry::n_dead_tuples, PgStat_StatTabEntry::n_live_tuples, pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_track_counts, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, PgStat_StatTabEntry::vacuum_count, and PgStat_StatTabEntry::vacuum_timestamp.

Referenced by heap_vacuum_rel().

◆ pgstat_report_wal()

void pgstat_report_wal ( bool  force)

Definition at line 43 of file pgstat_wal.c.

44 {
45  pgstat_flush_wal(force);
46 }

References pgstat_flush_wal().

Referenced by CheckpointerMain(), HandleCheckpointerInterrupts(), HandleWalWriterInterrupts(), and WalWriterMain().

◆ pgstat_reset()

void pgstat_reset ( PgStat_Kind  kind,
Oid  dboid,
Oid  objectid 
)

Definition at line 705 of file pgstat.c.

706 {
707  const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
709 
710  /* not needed atm, and doesn't make sense with the current signature */
711  Assert(!pgstat_get_kind_info(kind)->fixed_amount);
712 
713  /* reset the "single counter" */
714  pgstat_reset_entry(kind, dboid, objoid, ts);
715 
716  if (!kind_info->accessed_across_databases)
718 }
void pgstat_reset_database_timestamp(Oid dboid, TimestampTz ts)
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts)
Definition: pgstat_shmem.c:913
bool accessed_across_databases

References PgStat_KindInfo::accessed_across_databases, Assert(), GetCurrentTimestamp(), pgstat_get_kind_info(), pgstat_reset_database_timestamp(), and pgstat_reset_entry().

Referenced by pg_stat_reset_single_function_counters(), pg_stat_reset_single_table_counters(), pg_stat_reset_subscription_stats(), pgstat_create_transactional(), and pgstat_reset_replslot().

◆ pgstat_reset_counters()

void pgstat_reset_counters ( void  )

Definition at line 686 of file pgstat.c.

687 {
689 
692  ts);
693 }
static bool match_db_entries(PgStatShared_HashEntry *entry, Datum match_data)
Definition: pgstat.c:674
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
Definition: pgstat_shmem.c:933
#define ObjectIdGetDatum(X)
Definition: postgres.h:551

References GetCurrentTimestamp(), match_db_entries(), MyDatabaseId, ObjectIdGetDatum, and pgstat_reset_matching_entries().

Referenced by pg_stat_reset().

◆ pgstat_reset_of_kind()

void pgstat_reset_of_kind ( PgStat_Kind  kind)

Definition at line 727 of file pgstat.c.

728 {
729  const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
731 
732  if (kind_info->fixed_amount)
733  kind_info->reset_all_cb(ts);
734  else
736 }
void pgstat_reset_entries_of_kind(PgStat_Kind kind, TimestampTz ts)
Definition: pgstat_shmem.c:969
void(* reset_all_cb)(TimestampTz ts)

References PgStat_KindInfo::fixed_amount, GetCurrentTimestamp(), pgstat_get_kind_info(), pgstat_reset_entries_of_kind(), and PgStat_KindInfo::reset_all_cb.

Referenced by pg_stat_reset_replication_slot(), pg_stat_reset_shared(), pg_stat_reset_slru(), and pg_stat_reset_subscription_stats().

◆ pgstat_reset_replslot()

void pgstat_reset_replslot ( const char *  name)

Definition at line 43 of file pgstat_replslot.c.

44 {
45  ReplicationSlot *slot;
46 
47  AssertArg(name != NULL);
48 
49  /* Check if the slot exits with the given name. */
50  slot = SearchNamedReplicationSlot(name, true);
51 
52  if (!slot)
53  ereport(ERROR,
54  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
55  errmsg("replication slot \"%s\" does not exist",
56  name)));
57 
58  /*
59  * Nothing to do for physical slots as we collect stats only for logical
60  * slots.
61  */
62  if (SlotIsPhysical(slot))
63  return;
64 
65  /* reset this one entry */
67  ReplicationSlotIndex(slot));
68 }
#define AssertArg(condition)
Definition: c.h:806
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:705
ReplicationSlot * SearchNamedReplicationSlot(const char *name, bool need_lock)
Definition: slot.c:377
#define SlotIsPhysical(slot)
Definition: slot.h:168

References AssertArg, ereport, errcode(), errmsg(), ERROR, InvalidOid, name, PGSTAT_KIND_REPLSLOT, pgstat_reset(), ReplicationSlotIndex(), SearchNamedReplicationSlot(), and SlotIsPhysical.

Referenced by pg_stat_reset_replication_slot().

◆ pgstat_reset_slru()

void pgstat_reset_slru ( const char *  name)

Definition at line 45 of file pgstat_slru.c.

46 {
48 
49  AssertArg(name != NULL);
50 
52 }
int pgstat_get_slru_index(const char *name)
Definition: pgstat_slru.c:132
static void pgstat_reset_slru_counter_internal(int index, TimestampTz ts)
Definition: pgstat_slru.c:240

References AssertArg, GetCurrentTimestamp(), name, pgstat_get_slru_index(), and pgstat_reset_slru_counter_internal().

Referenced by pg_stat_reset_slru().

◆ pgstat_restore_stats()

void pgstat_restore_stats ( void  )

Definition at line 393 of file pgstat.c.

394 {
396 }
static void pgstat_read_statsfile(void)
Definition: pgstat.c:1425

References pgstat_read_statsfile().

Referenced by StartupXLOG().

◆ pgstat_twophase_postabort()

void pgstat_twophase_postabort ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 729 of file pgstat_relation.c.

731 {
732  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
733  PgStat_TableStatus *pgstat_info;
734 
735  /* Find or create a tabstat entry for the rel */
736  pgstat_info = pgstat_prep_relation_pending(rec->t_id, rec->t_shared);
737 
738  /* Same math as in AtEOXact_PgStat, abort case */
739  if (rec->t_truncdropped)
740  {
744  }
745  pgstat_info->t_counts.t_tuples_inserted += rec->tuples_inserted;
746  pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
747  pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
748  pgstat_info->t_counts.t_delta_dead_tuples +=
749  rec->tuples_inserted + rec->tuples_updated;
750 }
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:175
PgStat_Counter t_tuples_updated
Definition: pgstat.h:176
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:177
PgStat_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

References TwoPhasePgStatRecord::deleted_pre_truncdrop, TwoPhasePgStatRecord::inserted_pre_truncdrop, pgstat_prep_relation_pending(), PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, TwoPhasePgStatRecord::t_id, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncdropped, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, and TwoPhasePgStatRecord::updated_pre_truncdrop.

◆ pgstat_twophase_postcommit()

void pgstat_twophase_postcommit ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 693 of file pgstat_relation.c.

695 {
696  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
697  PgStat_TableStatus *pgstat_info;
698 
699  /* Find or create a tabstat entry for the rel */
700  pgstat_info = pgstat_prep_relation_pending(rec->t_id, rec->t_shared);
701 
702  /* Same math as in AtEOXact_PgStat, commit case */
703  pgstat_info->t_counts.t_tuples_inserted += rec->tuples_inserted;
704  pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
705  pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
706  pgstat_info->t_counts.t_truncdropped = rec->t_truncdropped;
707  if (rec->t_truncdropped)
708  {
709  /* forget live/dead stats seen by backend thus far */
710  pgstat_info->t_counts.t_delta_live_tuples = 0;
711  pgstat_info->t_counts.t_delta_dead_tuples = 0;
712  }
713  pgstat_info->t_counts.t_delta_live_tuples +=
714  rec->tuples_inserted - rec->tuples_deleted;
715  pgstat_info->t_counts.t_delta_dead_tuples +=
716  rec->tuples_updated + rec->tuples_deleted;
717  pgstat_info->t_counts.t_changed_tuples +=
718  rec->tuples_inserted + rec->tuples_updated +
719  rec->tuples_deleted;
720 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:181
bool t_truncdropped
Definition: pgstat.h:179
PgStat_Counter t_changed_tuples
Definition: pgstat.h:183

References pgstat_prep_relation_pending(), PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, TwoPhasePgStatRecord::t_id, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncdropped, PgStat_TableCounts::t_truncdropped, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, and TwoPhasePgStatRecord::tuples_updated.

◆ pgstat_unlink_relation()

void pgstat_unlink_relation ( Relation  rel)

Definition at line 153 of file pgstat_relation.c.

154 {
155  /* remove the link to stats info if any */
156  if (rel->pgstat_info == NULL)
157  return;
158 
159  /* link sanity check */
160  Assert(rel->pgstat_info->relation == rel);
161  rel->pgstat_info->relation = NULL;
162  rel->pgstat_info = NULL;
163 }

References Assert(), RelationData::pgstat_info, and PgStat_TableStatus::relation.

Referenced by pgstat_init_relation(), pgstat_relation_delete_pending_cb(), and RelationDestroyRelation().

◆ pgstat_update_heap_dead_tuples()

void pgstat_update_heap_dead_tuples ( Relation  rel,
int  delta 
)

Definition at line 421 of file pgstat_relation.c.

422 {
424  {
425  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
426 
427  pgstat_info->t_counts.t_delta_dead_tuples -= delta;
428  }
429 }

References RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::t_counts, and PgStat_TableCounts::t_delta_dead_tuples.

Referenced by heap_page_prune_opt().

◆ PostPrepare_PgStat()

void PostPrepare_PgStat ( void  )

Definition at line 216 of file pgstat_xact.c.

217 {
218  PgStat_SubXactStatus *xact_state;
219 
220  /*
221  * We don't bother to free any of the transactional state, since it's all
222  * in TopTransactionContext and will go away anyway.
223  */
224  xact_state = pgStatXactStack;
225  if (xact_state != NULL)
226  {
227  Assert(xact_state->nest_level == 1);
228  Assert(xact_state->prev == NULL);
229 
230  PostPrepare_PgStat_Relations(xact_state);
231  }
232  pgStatXactStack = NULL;
233 
234  /* Make sure any stats snapshot is thrown away */
236 }
void PostPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)

References Assert(), PgStat_SubXactStatus::nest_level, pgstat_clear_snapshot(), pgStatXactStack, PostPrepare_PgStat_Relations(), and PgStat_SubXactStatus::prev.

Referenced by PrepareTransaction().

◆ StatsShmemInit()

void StatsShmemInit ( void  )

Definition at line 140 of file pgstat_shmem.c.

141 {
142  bool found;
143  Size sz;
144 
145  sz = StatsShmemSize();
147  ShmemInitStruct("Shared Memory Stats", sz, &found);
148 
149  if (!IsUnderPostmaster)
150  {
151  dsa_area *dsa;
152  dshash_table *dsh;
154  char *p = (char *) ctl;
155 
156  Assert(!found);
157 
158  /* the allocation of pgStatLocal.shmem itself */
159  p += MAXALIGN(sizeof(PgStat_ShmemControl));
160 
161  /*
162  * Create a small dsa allocation in plain shared memory. This is
163  * required because postmaster cannot use dsm segments. It also
164  * provides a small efficiency win.
165  */
166  ctl->raw_dsa_area = p;
171  dsa_pin(dsa);
172 
173  /*
174  * To ensure dshash is created in "plain" shared memory, temporarily
175  * limit size of dsa to the initial size of the dsa.
176  */
178 
179  /*
180  * With the limit in place, create the dshash table. XXX: It'd be nice
181  * if there were dshash_create_in_place().
182  */
183  dsh = dshash_create(dsa, &dsh_params, 0);
185 
186  /* lift limit set above */
187  dsa_set_size_limit(dsa, -1);
188 
189  /*
190  * Postmaster will never access these again, thus free the local
191  * dsa/dshash references.
192  */
193  dshash_detach(dsh);
194  dsa_detach(dsa);
195 
197 
198 
199  /* initialize fixed-numbered stats */
205  }
206  else
207  {
208  Assert(found);
209  }
210 }
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:415
#define MAXALIGN(LEN)
Definition: c.h:757
size_t Size
Definition: c.h:540
dsa_area * dsa_create_in_place(void *place, size_t size, int tranche_id, dsm_segment *segment)
Definition: dsa.c:469
void dsa_set_size_limit(dsa_area *area, size_t limit)
Definition: dsa.c:1008
void dsa_detach(dsa_area *area)
Definition: dsa.c:1910
void dsa_pin(dsa_area *area)
Definition: dsa.c:965
void dshash_detach(dshash_table *hash_table)
Definition: dshash.c:310
dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table)
Definition: dshash.c:370
dshash_table * dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
Definition: dshash.c:204
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:734
@ LWTRANCHE_PGSTATS_DSA
Definition: lwlock.h:193
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:195
static Size pgstat_dsa_init_size(void)
Definition: pgstat_shmem.c:105
Size StatsShmemSize(void)
Definition: pgstat_shmem.c:126
static const dshash_parameters dsh_params
Definition: pgstat_shmem.c:62
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
dshash_table_handle hash_handle
PgStatShared_SLRU slru
pg_atomic_uint64 gc_request_count
PgStatShared_Wal wal
Definition: dsa.c:355

References PgStat_ShmemControl::archiver, Assert(), PgStat_ShmemControl::bgwriter, PgStat_ShmemControl::checkpointer, dsa_create_in_place(), dsa_detach(), dsa_pin(), dsa_set_size_limit(), dsh_params, dshash_create(), dshash_detach(), dshash_get_hash_table_handle(), PgStat_ShmemControl::gc_request_count, PgStat_ShmemControl::hash_handle, IsUnderPostmaster, PgStatShared_Archiver::lock, PgStatShared_BgWriter::lock, PgStatShared_Checkpointer::lock, PgStatShared_SLRU::lock, PgStatShared_Wal::lock, LWLockInitialize(), LWTRANCHE_PGSTATS_DATA, LWTRANCHE_PGSTATS_DSA, MAXALIGN, pg_atomic_init_u64(), pgstat_dsa_init_size(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shmem, ShmemInitStruct(), PgStat_ShmemControl::slru, StatsShmemSize(), and PgStat_ShmemControl::wal.

Referenced by CreateSharedMemoryAndSemaphores().

◆ StatsShmemSize()

Size StatsShmemSize ( void  )

Definition at line 126 of file pgstat_shmem.c.

127 {
128  Size sz;
129 
130  sz = MAXALIGN(sizeof(PgStat_ShmemControl));
131  sz = add_size(sz, pgstat_dsa_init_size());
132 
133  return sz;
134 }
Size add_size(Size s1, Size s2)
Definition: shmem.c:502

References add_size(), MAXALIGN, and pgstat_dsa_init_size().

Referenced by CalculateShmemSize(), and StatsShmemInit().

Variable Documentation

◆ PendingBgWriterStats

PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
extern

Definition at line 23 of file pgstat_bgwriter.c.

Referenced by BgBufferSync(), and pgstat_report_bgwriter().

◆ PendingCheckpointerStats

◆ PendingWalStats

◆ pgstat_fetch_consistency

◆ pgstat_track_counts

◆ pgstat_track_functions

PGDLLIMPORT int pgstat_track_functions
extern

Definition at line 30 of file pgstat_function.c.

◆ pgStatActiveTime

PGDLLIMPORT PgStat_Counter pgStatActiveTime
extern

Definition at line 30 of file pgstat_database.c.

Referenced by pgstat_update_dbstats().

◆ pgStatBlockReadTime

PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
extern

Definition at line 28 of file pgstat_database.c.

Referenced by do_analyze_rel(), heap_vacuum_rel(), and pgstat_update_dbstats().

◆ pgStatBlockWriteTime

PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
extern

Definition at line 29 of file pgstat_database.c.

Referenced by do_analyze_rel(), heap_vacuum_rel(), and pgstat_update_dbstats().

◆ pgStatSessionEndCause

PGDLLIMPORT SessionEndType pgStatSessionEndCause
extern

Definition at line 32 of file pgstat_database.c.

Referenced by die(), errfinish(), pgstat_report_disconnect(), and PostgresMain().

◆ pgStatTransactionIdleTime

PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
extern

Definition at line 31 of file pgstat_database.c.

Referenced by pgstat_update_dbstats().