PostgreSQL Source Code  git master
pgstat.c File Reference
#include "postgres.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "access/twophase_rmgr.h"
#include "access/xact.h"
#include "catalog/partition.h"
#include "catalog/pg_database.h"
#include "catalog/pg_proc.h"
#include "common/ip.h"
#include "executor/instrument.h"
#include "libpq/libpq.h"
#include "libpq/pqsignal.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "postmaster/fork_process.h"
#include "postmaster/interrupt.h"
#include "postmaster/postmaster.h"
#include "replication/slot.h"
#include "replication/walsender.h"
#include "storage/backendid.h"
#include "storage/dsm.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lmgr.h"
#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/timestamp.h"
Include dependency graph for pgstat.c:

Go to the source code of this file.

Data Structures

struct  TabStatusArray
 
struct  TabStatHashEntry
 
struct  PgStat_SubXactStatus
 
struct  TwoPhasePgStatRecord
 

Macros

#define PGSTAT_STAT_INTERVAL
 
#define PGSTAT_RETRY_DELAY
 
#define PGSTAT_MAX_WAIT_TIME
 
#define PGSTAT_INQ_INTERVAL
 
#define PGSTAT_RESTART_INTERVAL
 
#define PGSTAT_POLL_LOOP_COUNT   (PGSTAT_MAX_WAIT_TIME / PGSTAT_RETRY_DELAY)
 
#define PGSTAT_INQ_LOOP_COUNT   (PGSTAT_INQ_INTERVAL / PGSTAT_RETRY_DELAY)
 
#define PGSTAT_MIN_RCVBUF   (100 * 1024)
 
#define PGSTAT_DB_HASH_SIZE   16
 
#define PGSTAT_TAB_HASH_SIZE   512
 
#define PGSTAT_FUNCTION_HASH_SIZE   512
 
#define PGSTAT_REPLSLOT_HASH_SIZE   32
 
#define SLRU_NUM_ELEMENTS   lengthof(slru_names)
 
#define TABSTAT_QUANTUM   100 /* we alloc this many at a time */
 
#define TESTBYTEVAL   ((char) 199)
 

Typedefs

typedef struct TabStatusArray TabStatusArray
 
typedef struct TabStatHashEntry TabStatHashEntry
 
typedef struct PgStat_SubXactStatus PgStat_SubXactStatus
 
typedef struct TwoPhasePgStatRecord TwoPhasePgStatRecord
 

Functions

NON_EXEC_STATIC void PgstatCollectorMain (int argc, char *argv[]) pg_attribute_noreturn()
 
static PgStat_StatDBEntrypgstat_get_db_entry (Oid databaseid, bool create)
 
static PgStat_StatTabEntrypgstat_get_tab_entry (PgStat_StatDBEntry *dbentry, Oid tableoid, bool create)
 
static void pgstat_write_statsfiles (bool permanent, bool allDbs)
 
static void pgstat_write_db_statsfile (PgStat_StatDBEntry *dbentry, bool permanent)
 
static HTABpgstat_read_statsfiles (Oid onlydb, bool permanent, bool deep)
 
static void pgstat_read_db_statsfile (Oid databaseid, HTAB *tabhash, HTAB *funchash, bool permanent)
 
static void backend_read_statsfile (void)
 
static bool pgstat_write_statsfile_needed (void)
 
static bool pgstat_db_requested (Oid databaseid)
 
static PgStat_StatReplSlotEntrypgstat_get_replslot_entry (NameData name, bool create_it)
 
static void pgstat_reset_replslot (PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
 
static void pgstat_send_tabstat (PgStat_MsgTabstat *tsmsg)
 
static void pgstat_send_funcstats (void)
 
static void pgstat_send_slru (void)
 
static HTABpgstat_collect_oids (Oid catalogid, AttrNumber anum_oid)
 
static void pgstat_send_connstats (bool disconnect, TimestampTz last_report)
 
static PgStat_TableStatusget_tabstat_entry (Oid rel_id, bool isshared)
 
static void pgstat_setup_memcxt (void)
 
static void pgstat_setheader (PgStat_MsgHdr *hdr, StatMsgType mtype)
 
static void pgstat_send (void *msg, int len)
 
static void pgstat_recv_inquiry (PgStat_MsgInquiry *msg, int len)
 
static void pgstat_recv_tabstat (PgStat_MsgTabstat *msg, int len)
 
static void pgstat_recv_tabpurge (PgStat_MsgTabpurge *msg, int len)
 
static void pgstat_recv_dropdb (PgStat_MsgDropdb *msg, int len)
 
static void pgstat_recv_resetcounter (PgStat_MsgResetcounter *msg, int len)
 
static void pgstat_recv_resetsharedcounter (PgStat_MsgResetsharedcounter *msg, int len)
 
static void pgstat_recv_resetsinglecounter (PgStat_MsgResetsinglecounter *msg, int len)
 
static void pgstat_recv_resetslrucounter (PgStat_MsgResetslrucounter *msg, int len)
 
static void pgstat_recv_resetreplslotcounter (PgStat_MsgResetreplslotcounter *msg, int len)
 
static void pgstat_recv_autovac (PgStat_MsgAutovacStart *msg, int len)
 
static void pgstat_recv_vacuum (PgStat_MsgVacuum *msg, int len)
 
static void pgstat_recv_analyze (PgStat_MsgAnalyze *msg, int len)
 
static void pgstat_recv_anl_ancestors (PgStat_MsgAnlAncestors *msg, int len)
 
static void pgstat_recv_archiver (PgStat_MsgArchiver *msg, int len)
 
static void pgstat_recv_bgwriter (PgStat_MsgBgWriter *msg, int len)
 
static void pgstat_recv_wal (PgStat_MsgWal *msg, int len)
 
static void pgstat_recv_slru (PgStat_MsgSLRU *msg, int len)
 
static void pgstat_recv_funcstat (PgStat_MsgFuncstat *msg, int len)
 
static void pgstat_recv_funcpurge (PgStat_MsgFuncpurge *msg, int len)
 
static void pgstat_recv_recoveryconflict (PgStat_MsgRecoveryConflict *msg, int len)
 
static void pgstat_recv_deadlock (PgStat_MsgDeadlock *msg, int len)
 
static void pgstat_recv_checksum_failure (PgStat_MsgChecksumFailure *msg, int len)
 
static void pgstat_recv_connstat (PgStat_MsgConn *msg, int len)
 
static void pgstat_recv_replslot (PgStat_MsgReplSlot *msg, int len)
 
static void pgstat_recv_tempfile (PgStat_MsgTempFile *msg, int len)
 
void pgstat_init (void)
 
static void pgstat_reset_remove_files (const char *directory)
 
void pgstat_reset_all (void)
 
int pgstat_start (void)
 
void allow_immediate_pgstat_restart (void)
 
void pgstat_report_stat (bool disconnect)
 
void pgstat_vacuum_stat (void)
 
void pgstat_drop_database (Oid databaseid)
 
void pgstat_reset_counters (void)
 
void pgstat_reset_shared_counters (const char *target)
 
void pgstat_reset_single_counter (Oid objoid, PgStat_Single_Reset_Type type)
 
void pgstat_reset_slru_counter (const char *name)
 
void pgstat_reset_replslot_counter (const char *name)
 
void pgstat_report_autovac (Oid dboid)
 
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_report_anl_ancestors (Oid relid)
 
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_tempfile (size_t filesize)
 
void pgstat_report_replslot (const PgStat_StatReplSlotEntry *repSlotStat)
 
void pgstat_report_replslot_create (const char *slotname)
 
void pgstat_report_replslot_drop (const char *slotname)
 
void pgstat_ping (void)
 
static void pgstat_send_inquiry (TimestampTz clock_time, TimestampTz cutoff_time, Oid databaseid)
 
void pgstat_init_function_usage (FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
 
PgStat_BackendFunctionEntryfind_funcstat_entry (Oid func_id)
 
void pgstat_end_function_usage (PgStat_FunctionCallUsage *fcu, bool finalize)
 
void pgstat_initstats (Relation rel)
 
PgStat_TableStatusfind_tabstat_entry (Oid rel_id)
 
static PgStat_SubXactStatusget_tabstat_stack_level (int nest_level)
 
static void add_tabstat_xact_level (PgStat_TableStatus *pgstat_info, int nest_level)
 
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)
 
static void pgstat_truncate_save_counters (PgStat_TableXactStatus *trans)
 
static void pgstat_truncate_restore_counters (PgStat_TableXactStatus *trans)
 
void pgstat_count_truncate (Relation rel)
 
void pgstat_update_heap_dead_tuples (Relation rel, int delta)
 
void AtEOXact_PgStat (bool isCommit, bool parallel)
 
void AtEOSubXact_PgStat (bool isCommit, int nestDepth)
 
void AtPrepare_PgStat (void)
 
void PostPrepare_PgStat (void)
 
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_StatDBEntrypgstat_fetch_stat_dbentry (Oid dbid)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry (Oid relid)
 
PgStat_StatFuncEntrypgstat_fetch_stat_funcentry (Oid func_id)
 
PgStat_ArchiverStatspgstat_fetch_stat_archiver (void)
 
PgStat_GlobalStatspgstat_fetch_global (void)
 
PgStat_WalStatspgstat_fetch_stat_wal (void)
 
PgStat_SLRUStatspgstat_fetch_slru (void)
 
PgStat_StatReplSlotEntrypgstat_fetch_replslot (NameData slotname)
 
static void pgstat_shutdown_hook (int code, Datum arg)
 
void pgstat_initialize (void)
 
void pgstat_send_archiver (const char *xlog, bool failed)
 
void pgstat_send_bgwriter (void)
 
void pgstat_send_wal (bool force)
 
static void reset_dbentry_counters (PgStat_StatDBEntry *dbentry)
 
static void get_dbstat_filename (bool permanent, bool tempname, Oid databaseid, char *filename, int len)
 
static bool pgstat_read_db_statsfile_timestamp (Oid databaseid, bool permanent, TimestampTz *ts)
 
void pgstat_clear_snapshot (void)
 
int pgstat_slru_index (const char *name)
 
const char * pgstat_slru_name (int slru_idx)
 
static PgStat_MsgSLRUslru_entry (int slru_idx)
 
void pgstat_count_slru_page_zeroed (int slru_idx)
 
void pgstat_count_slru_page_hit (int slru_idx)
 
void pgstat_count_slru_page_exists (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_flush (int slru_idx)
 
void pgstat_count_slru_truncate (int slru_idx)
 

Variables

bool pgstat_track_counts = false
 
int pgstat_track_functions = TRACK_FUNC_OFF
 
char * pgstat_stat_directory = NULL
 
char * pgstat_stat_filename = NULL
 
char * pgstat_stat_tmpname = NULL
 
PgStat_MsgBgWriter BgWriterStats
 
PgStat_MsgWal WalStats
 
static WalUsage prevWalUsage
 
static const char *const slru_names []
 
static PgStat_MsgSLRU SLRUStats [SLRU_NUM_ELEMENTS]
 
NON_EXEC_STATIC pgsocket pgStatSock = PGINVALID_SOCKET
 
static struct sockaddr_storage pgStatAddr
 
static time_t last_pgstat_start_time
 
static bool pgStatRunningInCollector = false
 
static TabStatusArraypgStatTabList = NULL
 
static HTABpgStatTabHash = NULL
 
static HTABpgStatFunctions = NULL
 
static bool have_function_stats = false
 
static PgStat_SubXactStatuspgStatXactStack = NULL
 
static int pgStatXactCommit = 0
 
static int pgStatXactRollback = 0
 
PgStat_Counter pgStatBlockReadTime = 0
 
PgStat_Counter pgStatBlockWriteTime = 0
 
PgStat_Counter pgStatActiveTime = 0
 
PgStat_Counter pgStatTransactionIdleTime = 0
 
SessionEndType pgStatSessionEndCause = DISCONNECT_NORMAL
 
static MemoryContext pgStatLocalContext = NULL
 
static HTABpgStatDBHash = NULL
 
static PgStat_ArchiverStats archiverStats
 
static PgStat_GlobalStats globalStats
 
static PgStat_WalStats walStats
 
static PgStat_SLRUStats slruStats [SLRU_NUM_ELEMENTS]
 
static HTABreplSlotStatHash = NULL
 
static Listpending_write_requests = NIL
 
static instr_time total_func_time
 

Macro Definition Documentation

◆ PGSTAT_DB_HASH_SIZE

#define PGSTAT_DB_HASH_SIZE   16

Definition at line 105 of file pgstat.c.

Referenced by pgstat_read_statsfiles().

◆ PGSTAT_FUNCTION_HASH_SIZE

#define PGSTAT_FUNCTION_HASH_SIZE   512

◆ PGSTAT_INQ_INTERVAL

#define PGSTAT_INQ_INTERVAL
Value:
640 /* How often to ping the collector for a
* new file; in milliseconds. */

Definition at line 87 of file pgstat.c.

◆ PGSTAT_INQ_LOOP_COUNT

#define PGSTAT_INQ_LOOP_COUNT   (PGSTAT_INQ_INTERVAL / PGSTAT_RETRY_DELAY)

Definition at line 95 of file pgstat.c.

Referenced by backend_read_statsfile().

◆ PGSTAT_MAX_WAIT_TIME

#define PGSTAT_MAX_WAIT_TIME
Value:
10000 /* Maximum time to wait for a stats
* file update; in milliseconds. */

Definition at line 84 of file pgstat.c.

◆ PGSTAT_MIN_RCVBUF

#define PGSTAT_MIN_RCVBUF   (100 * 1024)

Definition at line 98 of file pgstat.c.

Referenced by pgstat_init().

◆ PGSTAT_POLL_LOOP_COUNT

#define PGSTAT_POLL_LOOP_COUNT   (PGSTAT_MAX_WAIT_TIME / PGSTAT_RETRY_DELAY)

Definition at line 94 of file pgstat.c.

Referenced by backend_read_statsfile().

◆ PGSTAT_REPLSLOT_HASH_SIZE

#define PGSTAT_REPLSLOT_HASH_SIZE   32

Definition at line 108 of file pgstat.c.

Referenced by pgstat_get_replslot_entry(), and pgstat_read_statsfiles().

◆ PGSTAT_RESTART_INTERVAL

#define PGSTAT_RESTART_INTERVAL
Value:
60 /* How often to attempt to restart a
* failed statistics collector; in
* seconds. */

Definition at line 90 of file pgstat.c.

Referenced by pgstat_start().

◆ PGSTAT_RETRY_DELAY

#define PGSTAT_RETRY_DELAY
Value:
10 /* How long to wait between checks for a
* new file; in milliseconds. */

Definition at line 81 of file pgstat.c.

Referenced by backend_read_statsfile().

◆ PGSTAT_STAT_INTERVAL

#define PGSTAT_STAT_INTERVAL
Value:
500 /* Minimum time between stats file
* updates; in milliseconds. */

Definition at line 78 of file pgstat.c.

Referenced by backend_read_statsfile(), pgstat_report_stat(), and pgstat_send_wal().

◆ PGSTAT_TAB_HASH_SIZE

#define PGSTAT_TAB_HASH_SIZE   512

Definition at line 106 of file pgstat.c.

Referenced by pgstat_collect_oids(), pgstat_read_statsfiles(), and reset_dbentry_counters().

◆ SLRU_NUM_ELEMENTS

◆ TABSTAT_QUANTUM

#define TABSTAT_QUANTUM   100 /* we alloc this many at a time */

Definition at line 191 of file pgstat.c.

Referenced by get_tabstat_entry().

◆ TESTBYTEVAL

#define TESTBYTEVAL   ((char) 199)

Referenced by pgstat_init().

Typedef Documentation

◆ PgStat_SubXactStatus

◆ TabStatHashEntry

◆ TabStatusArray

◆ TwoPhasePgStatRecord

Function Documentation

◆ add_tabstat_xact_level()

static void add_tabstat_xact_level ( PgStat_TableStatus pgstat_info,
int  nest_level 
)
static

Definition at line 2202 of file pgstat.c.

References PgStat_SubXactStatus::first, get_tabstat_stack_level(), MemoryContextAllocZero(), PgStat_TableXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, TopTransactionContext, PgStat_TableStatus::trans, trans, and PgStat_TableXactStatus::upper.

Referenced by pgstat_count_heap_delete(), pgstat_count_heap_insert(), pgstat_count_heap_update(), and pgstat_count_truncate().

2203 {
2204  PgStat_SubXactStatus *xact_state;
2206 
2207  /*
2208  * If this is the first rel to be modified at the current nest level, we
2209  * first have to push a transaction stack entry.
2210  */
2211  xact_state = get_tabstat_stack_level(nest_level);
2212 
2213  /* Now make a per-table stack entry */
2214  trans = (PgStat_TableXactStatus *)
2216  sizeof(PgStat_TableXactStatus));
2217  trans->nest_level = nest_level;
2218  trans->upper = pgstat_info->trans;
2219  trans->parent = pgstat_info;
2220  trans->next = xact_state->first;
2221  xact_state->first = trans;
2222  pgstat_info->trans = trans;
2223 }
MemoryContext TopTransactionContext
Definition: mcxt.c:53
struct PgStat_TableXactStatus * next
Definition: pgstat.h:197
static PgStat_SubXactStatus * get_tabstat_stack_level(int nest_level)
Definition: pgstat.c:2180
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:194
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:239
PgStat_TableStatus * parent
Definition: pgstat.h:195

◆ allow_immediate_pgstat_restart()

void allow_immediate_pgstat_restart ( void  )

Definition at line 817 of file pgstat.c.

References last_pgstat_start_time.

Referenced by HandleChildCrash().

818 {
820 }
static time_t last_pgstat_start_time
Definition: pgstat.c:176

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

Definition at line 2462 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, get_tabstat_stack_level(), PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pfree(), pgstat_truncate_restore_counters(), pgstat_truncate_save_counters(), pgStatXactStack, PgStat_SubXactStatus::prev, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncated, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

2463 {
2464  PgStat_SubXactStatus *xact_state;
2465 
2466  /*
2467  * Transfer transactional insert/update counts into the next higher
2468  * subtransaction state.
2469  */
2470  xact_state = pgStatXactStack;
2471  if (xact_state != NULL &&
2472  xact_state->nest_level >= nestDepth)
2473  {
2475  PgStat_TableXactStatus *next_trans;
2476 
2477  /* delink xact_state from stack immediately to simplify reuse case */
2478  pgStatXactStack = xact_state->prev;
2479 
2480  for (trans = xact_state->first; trans != NULL; trans = next_trans)
2481  {
2482  PgStat_TableStatus *tabstat;
2483 
2484  next_trans = trans->next;
2485  Assert(trans->nest_level == nestDepth);
2486  tabstat = trans->parent;
2487  Assert(tabstat->trans == trans);
2488  if (isCommit)
2489  {
2490  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
2491  {
2492  if (trans->truncated)
2493  {
2494  /* propagate the truncate status one level up */
2496  /* replace upper xact stats with ours */
2497  trans->upper->tuples_inserted = trans->tuples_inserted;
2498  trans->upper->tuples_updated = trans->tuples_updated;
2499  trans->upper->tuples_deleted = trans->tuples_deleted;
2500  }
2501  else
2502  {
2503  trans->upper->tuples_inserted += trans->tuples_inserted;
2504  trans->upper->tuples_updated += trans->tuples_updated;
2505  trans->upper->tuples_deleted += trans->tuples_deleted;
2506  }
2507  tabstat->trans = trans->upper;
2508  pfree(trans);
2509  }
2510  else
2511  {
2512  /*
2513  * When there isn't an immediate parent state, we can just
2514  * reuse the record instead of going through a
2515  * palloc/pfree pushup (this works since it's all in
2516  * TopTransactionContext anyway). We have to re-link it
2517  * into the parent level, though, and that might mean
2518  * pushing a new entry into the pgStatXactStack.
2519  */
2520  PgStat_SubXactStatus *upper_xact_state;
2521 
2522  upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
2523  trans->next = upper_xact_state->first;
2524  upper_xact_state->first = trans;
2525  trans->nest_level = nestDepth - 1;
2526  }
2527  }
2528  else
2529  {
2530  /*
2531  * On abort, update top-level tabstat counts, then forget the
2532  * subtransaction
2533  */
2534 
2535  /* first restore values obliterated by truncate */
2537  /* count attempted actions regardless of commit/abort */
2538  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2539  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2540  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2541  /* inserted tuples are dead, deleted tuples are unaffected */
2542  tabstat->t_counts.t_delta_dead_tuples +=
2543  trans->tuples_inserted + trans->tuples_updated;
2544  tabstat->trans = trans->upper;
2545  pfree(trans);
2546  }
2547  }
2548  pfree(xact_state);
2549  }
2550 }
PgStat_Counter tuples_updated
Definition: pgstat.h:186
struct PgStat_TableXactStatus * next
Definition: pgstat.h:197
PgStat_TableCounts t_counts
Definition: pgstat.h:176
static PgStat_SubXactStatus * get_tabstat_stack_level(int nest_level)
Definition: pgstat.c:2180
void pfree(void *pointer)
Definition: mcxt.c:1169
PgStat_Counter t_tuples_updated
Definition: pgstat.h:122
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2316
PgStat_Counter tuples_inserted
Definition: pgstat.h:185
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:128
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:194
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:123
PgStat_Counter tuples_deleted
Definition: pgstat.h:187
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:238
#define Assert(condition)
Definition: c.h:804
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:242
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:239
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2301
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:121
PgStat_TableStatus * parent
Definition: pgstat.h:195

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)

Definition at line 2375 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pgstat_clear_snapshot(), pgstat_truncate_restore_counters(), pgStatXactCommit, pgStatXactRollback, pgStatXactStack, PgStat_SubXactStatus::prev, PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, PgStat_TableCounts::t_truncated, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncated, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

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

2376 {
2377  PgStat_SubXactStatus *xact_state;
2378 
2379  /* Don't count parallel worker transaction stats */
2380  if (!parallel)
2381  {
2382  /*
2383  * Count transaction commit or abort. (We use counters, not just
2384  * bools, in case the reporting message isn't sent right away.)
2385  */
2386  if (isCommit)
2387  pgStatXactCommit++;
2388  else
2390  }
2391 
2392  /*
2393  * Transfer transactional insert/update counts into the base tabstat
2394  * entries. We don't bother to free any of the transactional state, since
2395  * it's all in TopTransactionContext and will go away anyway.
2396  */
2397  xact_state = pgStatXactStack;
2398  if (xact_state != NULL)
2399  {
2401 
2402  Assert(xact_state->nest_level == 1);
2403  Assert(xact_state->prev == NULL);
2404  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2405  {
2406  PgStat_TableStatus *tabstat;
2407 
2408  Assert(trans->nest_level == 1);
2409  Assert(trans->upper == NULL);
2410  tabstat = trans->parent;
2411  Assert(tabstat->trans == trans);
2412  /* restore pre-truncate stats (if any) in case of aborted xact */
2413  if (!isCommit)
2415  /* count attempted actions regardless of commit/abort */
2416  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2417  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2418  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2419  if (isCommit)
2420  {
2421  tabstat->t_counts.t_truncated = trans->truncated;
2422  if (trans->truncated)
2423  {
2424  /* forget live/dead stats seen by backend thus far */
2425  tabstat->t_counts.t_delta_live_tuples = 0;
2426  tabstat->t_counts.t_delta_dead_tuples = 0;
2427  }
2428  /* insert adds a live tuple, delete removes one */
2429  tabstat->t_counts.t_delta_live_tuples +=
2430  trans->tuples_inserted - trans->tuples_deleted;
2431  /* update and delete each create a dead tuple */
2432  tabstat->t_counts.t_delta_dead_tuples +=
2433  trans->tuples_updated + trans->tuples_deleted;
2434  /* insert, update, delete each count as one change event */
2435  tabstat->t_counts.t_changed_tuples +=
2436  trans->tuples_inserted + trans->tuples_updated +
2437  trans->tuples_deleted;
2438  }
2439  else
2440  {
2441  /* inserted tuples are dead, deleted tuples are unaffected */
2442  tabstat->t_counts.t_delta_dead_tuples +=
2443  trans->tuples_inserted + trans->tuples_updated;
2444  /* an aborted xact generates no changed_tuple events */
2445  }
2446  tabstat->trans = NULL;
2447  }
2448  }
2449  pgStatXactStack = NULL;
2450 
2451  /* Make sure any stats snapshot is thrown away */
2453 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:127
PgStat_Counter tuples_updated
Definition: pgstat.h:186
static int pgStatXactCommit
Definition: pgstat.c:244
struct PgStat_TableXactStatus * next
Definition: pgstat.h:197
PgStat_TableCounts t_counts
Definition: pgstat.h:176
PgStat_Counter t_tuples_updated
Definition: pgstat.h:122
static void pgstat_truncate_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2316
static int pgStatXactRollback
Definition: pgstat.c:245
PgStat_Counter tuples_inserted
Definition: pgstat.h:185
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:128
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:194
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:123
PgStat_Counter tuples_deleted
Definition: pgstat.h:187
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:238
PgStat_Counter t_changed_tuples
Definition: pgstat.h:129
#define Assert(condition)
Definition: c.h:804
void pgstat_clear_snapshot(void)
Definition: pgstat.c:4709
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:242
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:239
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:121
PgStat_TableStatus * parent
Definition: pgstat.h:195

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )

Definition at line 2561 of file pgstat.c.

References Assert, PgStat_TableXactStatus::deleted_pre_trunc, TwoPhasePgStatRecord::deleted_pre_trunc, PgStat_SubXactStatus::first, PgStat_TableXactStatus::inserted_pre_trunc, TwoPhasePgStatRecord::inserted_pre_trunc, PgStat_TableXactStatus::nest_level, PgStat_SubXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pgStatXactStack, PgStat_SubXactStatus::prev, RegisterTwoPhaseRecord(), PgStat_TableStatus::t_id, TwoPhasePgStatRecord::t_id, PgStat_TableStatus::t_shared, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncated, PgStat_TableXactStatus::tuples_deleted, TwoPhasePgStatRecord::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, TwoPhasePgStatRecord::tuples_inserted, PgStat_TableXactStatus::tuples_updated, TwoPhasePgStatRecord::tuples_updated, TWOPHASE_RM_PGSTAT_ID, PgStat_TableXactStatus::updated_pre_trunc, TwoPhasePgStatRecord::updated_pre_trunc, and PgStat_TableXactStatus::upper.

Referenced by PrepareTransaction().

2562 {
2563  PgStat_SubXactStatus *xact_state;
2564 
2565  xact_state = pgStatXactStack;
2566  if (xact_state != NULL)
2567  {
2569 
2570  Assert(xact_state->nest_level == 1);
2571  Assert(xact_state->prev == NULL);
2572  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2573  {
2574  PgStat_TableStatus *tabstat;
2575  TwoPhasePgStatRecord record;
2576 
2577  Assert(trans->nest_level == 1);
2578  Assert(trans->upper == NULL);
2579  tabstat = trans->parent;
2580  Assert(tabstat->trans == trans);
2581 
2582  record.tuples_inserted = trans->tuples_inserted;
2583  record.tuples_updated = trans->tuples_updated;
2584  record.tuples_deleted = trans->tuples_deleted;
2585  record.inserted_pre_trunc = trans->inserted_pre_trunc;
2586  record.updated_pre_trunc = trans->updated_pre_trunc;
2587  record.deleted_pre_trunc = trans->deleted_pre_trunc;
2588  record.t_id = tabstat->t_id;
2589  record.t_shared = tabstat->t_shared;
2590  record.t_truncated = trans->truncated;
2591 
2593  &record, sizeof(TwoPhasePgStatRecord));
2594  }
2595  }
2596 }
PgStat_Counter tuples_updated
Definition: pgstat.h:186
struct PgStat_TableXactStatus * next
Definition: pgstat.h:197
PgStat_Counter deleted_pre_trunc
Definition: pgstat.h:191
PgStat_Counter deleted_pre_trunc
Definition: pgstat.c:260
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1182
PgStat_Counter tuples_inserted
Definition: pgstat.h:185
PgStat_Counter updated_pre_trunc
Definition: pgstat.c:259
PgStat_Counter inserted_pre_trunc
Definition: pgstat.c:258
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:194
PgStat_Counter tuples_updated
Definition: pgstat.c:256
PgStat_Counter tuples_deleted
Definition: pgstat.h:187
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:238
#define Assert(condition)
Definition: c.h:804
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:189
PgStat_Counter tuples_inserted
Definition: pgstat.c:255
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:242
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175
PgStat_Counter tuples_deleted
Definition: pgstat.c:257
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:190
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:239
PgStat_TableStatus * parent
Definition: pgstat.h:195

◆ backend_read_statsfile()

static void backend_read_statsfile ( void  )
static

Definition at line 4554 of file pgstat.c.

References Assert, CHECK_FOR_INTERRUPTS, ereport, errmsg(), GetCurrentTimestamp(), InvalidOid, IsAutoVacuumLauncherProcess(), IsAutoVacuumWorkerProcess(), LOG, MyDatabaseId, pfree(), pg_usleep(), PGSTAT_INQ_LOOP_COUNT, PGSTAT_POLL_LOOP_COUNT, pgstat_read_db_statsfile_timestamp(), pgstat_read_statsfiles(), PGSTAT_RETRY_DELAY, pgstat_send_inquiry(), PGSTAT_STAT_INTERVAL, pgStatRunningInCollector, pstrdup(), timestamptz_to_str(), and TimestampTzPlusMilliseconds.

Referenced by pgstat_fetch_global(), pgstat_fetch_replslot(), pgstat_fetch_slru(), pgstat_fetch_stat_archiver(), pgstat_fetch_stat_dbentry(), pgstat_fetch_stat_funcentry(), pgstat_fetch_stat_tabentry(), pgstat_fetch_stat_wal(), and pgstat_vacuum_stat().

4555 {
4556  TimestampTz min_ts = 0;
4557  TimestampTz ref_ts = 0;
4558  Oid inquiry_db;
4559  int count;
4560 
4561  /* already read it? */
4562  if (pgStatDBHash)
4563  return;
4565 
4566  /*
4567  * In a normal backend, we check staleness of the data for our own DB, and
4568  * so we send MyDatabaseId in inquiry messages. In the autovac launcher,
4569  * check staleness of the shared-catalog data, and send InvalidOid in
4570  * inquiry messages so as not to force writing unnecessary data.
4571  */
4573  inquiry_db = InvalidOid;
4574  else
4575  inquiry_db = MyDatabaseId;
4576 
4577  /*
4578  * Loop until fresh enough stats file is available or we ran out of time.
4579  * The stats inquiry message is sent repeatedly in case collector drops
4580  * it; but not every single time, as that just swamps the collector.
4581  */
4582  for (count = 0; count < PGSTAT_POLL_LOOP_COUNT; count++)
4583  {
4584  bool ok;
4585  TimestampTz file_ts = 0;
4586  TimestampTz cur_ts;
4587 
4589 
4590  ok = pgstat_read_db_statsfile_timestamp(inquiry_db, false, &file_ts);
4591 
4592  cur_ts = GetCurrentTimestamp();
4593  /* Calculate min acceptable timestamp, if we didn't already */
4594  if (count == 0 || cur_ts < ref_ts)
4595  {
4596  /*
4597  * We set the minimum acceptable timestamp to PGSTAT_STAT_INTERVAL
4598  * msec before now. This indirectly ensures that the collector
4599  * needn't write the file more often than PGSTAT_STAT_INTERVAL. In
4600  * an autovacuum worker, however, we want a lower delay to avoid
4601  * using stale data, so we use PGSTAT_RETRY_DELAY (since the
4602  * number of workers is low, this shouldn't be a problem).
4603  *
4604  * We don't recompute min_ts after sleeping, except in the
4605  * unlikely case that cur_ts went backwards. So we might end up
4606  * accepting a file a bit older than PGSTAT_STAT_INTERVAL. In
4607  * practice that shouldn't happen, though, as long as the sleep
4608  * time is less than PGSTAT_STAT_INTERVAL; and we don't want to
4609  * tell the collector that our cutoff time is less than what we'd
4610  * actually accept.
4611  */
4612  ref_ts = cur_ts;
4614  min_ts = TimestampTzPlusMilliseconds(ref_ts,
4616  else
4617  min_ts = TimestampTzPlusMilliseconds(ref_ts,
4619  }
4620 
4621  /*
4622  * If the file timestamp is actually newer than cur_ts, we must have
4623  * had a clock glitch (system time went backwards) or there is clock
4624  * skew between our processor and the stats collector's processor.
4625  * Accept the file, but send an inquiry message anyway to make
4626  * pgstat_recv_inquiry do a sanity check on the collector's time.
4627  */
4628  if (ok && file_ts > cur_ts)
4629  {
4630  /*
4631  * A small amount of clock skew between processors isn't terribly
4632  * surprising, but a large difference is worth logging. We
4633  * arbitrarily define "large" as 1000 msec.
4634  */
4635  if (file_ts >= TimestampTzPlusMilliseconds(cur_ts, 1000))
4636  {
4637  char *filetime;
4638  char *mytime;
4639 
4640  /* Copy because timestamptz_to_str returns a static buffer */
4641  filetime = pstrdup(timestamptz_to_str(file_ts));
4642  mytime = pstrdup(timestamptz_to_str(cur_ts));
4643  ereport(LOG,
4644  (errmsg("statistics collector's time %s is later than backend local time %s",
4645  filetime, mytime)));
4646  pfree(filetime);
4647  pfree(mytime);
4648  }
4649 
4650  pgstat_send_inquiry(cur_ts, min_ts, inquiry_db);
4651  break;
4652  }
4653 
4654  /* Normal acceptance case: file is not older than cutoff time */
4655  if (ok && file_ts >= min_ts)
4656  break;
4657 
4658  /* Not there or too old, so kick the collector and wait a bit */
4659  if ((count % PGSTAT_INQ_LOOP_COUNT) == 0)
4660  pgstat_send_inquiry(cur_ts, min_ts, inquiry_db);
4661 
4662  pg_usleep(PGSTAT_RETRY_DELAY * 1000L);
4663  }
4664 
4665  if (count >= PGSTAT_POLL_LOOP_COUNT)
4666  ereport(LOG,
4667  (errmsg("using stale statistics instead of current ones "
4668  "because stats collector is not responding")));
4669 
4670  /*
4671  * Autovacuum launcher wants stats about all databases, but a shallow read
4672  * is sufficient. Regular backends want a deep read for just the tables
4673  * they can see (MyDatabaseId + shared catalogs).
4674  */
4677  else
4679 }
#define PGSTAT_RETRY_DELAY
Definition: pgstat.c:81
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
#define PGSTAT_INQ_LOOP_COUNT
Definition: pgstat.c:95
char * pstrdup(const char *in)
Definition: mcxt.c:1299
static bool pgStatRunningInCollector
Definition: pgstat.c:178
#define LOG
Definition: elog.h:26
unsigned int Oid
Definition: postgres_ext.h:31
#define PGSTAT_POLL_LOOP_COUNT
Definition: pgstat.c:94
void pg_usleep(long microsec)
Definition: signal.c:53
void pfree(void *pointer)
Definition: mcxt.c:1169
static void pgstat_send_inquiry(TimestampTz clock_time, TimestampTz cutoff_time, Oid databaseid)
Definition: pgstat.c:1891
#define PGSTAT_STAT_INTERVAL
Definition: pgstat.c:78
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3454
static HTAB * pgstat_read_statsfiles(Oid onlydb, bool permanent, bool deep)
Definition: pgstat.c:3926
Oid MyDatabaseId
Definition: globals.c:88
#define InvalidOid
Definition: postgres_ext.h:36
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:56
#define ereport(elevel,...)
Definition: elog.h:157
static bool pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent, TimestampTz *ts)
Definition: pgstat.c:4390
bool IsAutoVacuumLauncherProcess(void)
Definition: autovacuum.c:3448
#define Assert(condition)
Definition: c.h:804
static HTAB * pgStatDBHash
Definition: pgstat.c:270
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
const char * timestamptz_to_str(TimestampTz t)
Definition: timestamp.c:1774

◆ find_funcstat_entry()

PgStat_BackendFunctionEntry* find_funcstat_entry ( Oid  func_id)

Definition at line 1959 of file pgstat.c.

References HASH_FIND, and hash_search().

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

1960 {
1961  if (pgStatFunctions == NULL)
1962  return NULL;
1963 
1965  (void *) &func_id,
1966  HASH_FIND, NULL);
1967 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * pgStatFunctions
Definition: pgstat.c:220

◆ find_tabstat_entry()

PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

Definition at line 2160 of file pgstat.c.

References HASH_FIND, hash_search(), and TabStatHashEntry::tsa_entry.

Referenced by pg_stat_get_xact_blocks_fetched(), pg_stat_get_xact_blocks_hit(), pg_stat_get_xact_numscans(), pg_stat_get_xact_tuples_deleted(), pg_stat_get_xact_tuples_fetched(), pg_stat_get_xact_tuples_hot_updated(), pg_stat_get_xact_tuples_inserted(), pg_stat_get_xact_tuples_returned(), and pg_stat_get_xact_tuples_updated().

2161 {
2162  TabStatHashEntry *hash_entry;
2163 
2164  /* If hashtable doesn't exist, there are no entries at all */
2165  if (!pgStatTabHash)
2166  return NULL;
2167 
2168  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_FIND, NULL);
2169  if (!hash_entry)
2170  return NULL;
2171 
2172  /* Note that this step could also return NULL, but that's correct */
2173  return hash_entry->tsa_entry;
2174 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * pgStatTabHash
Definition: pgstat.c:214
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:208

◆ get_dbstat_filename()

static void get_dbstat_filename ( bool  permanent,
bool  tempname,
Oid  databaseid,
char *  filename,
int  len 
)
static

Definition at line 3777 of file pgstat.c.

References elog, ERROR, pgstat_stat_directory, PGSTAT_STAT_PERMANENT_DIRECTORY, and snprintf.

Referenced by pgstat_read_db_statsfile(), pgstat_recv_dropdb(), and pgstat_write_db_statsfile().

3779 {
3780  int printed;
3781 
3782  /* NB -- pgstat_reset_remove_files knows about the pattern this uses */
3783  printed = snprintf(filename, len, "%s/db_%u.%s",
3784  permanent ? PGSTAT_STAT_PERMANENT_DIRECTORY :
3786  databaseid,
3787  tempname ? "tmp" : "stat");
3788  if (printed >= len)
3789  elog(ERROR, "overlength pgstat path");
3790 }
#define PGSTAT_STAT_PERMANENT_DIRECTORY
Definition: pgstat.h:28
#define ERROR
Definition: elog.h:46
char * pgstat_stat_directory
Definition: pgstat.c:122
static char * filename
Definition: pg_dumpall.c:92
#define elog(elevel,...)
Definition: elog.h:232
#define snprintf
Definition: port.h:216

◆ get_tabstat_entry()

static PgStat_TableStatus * get_tabstat_entry ( Oid  rel_id,
bool  isshared 
)
static

Definition at line 2072 of file pgstat.c.

References HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASHCTL::keysize, MemoryContextAllocZero(), pgStatTabList, PgStat_TableStatus::t_id, PgStat_TableStatus::t_shared, TABSTAT_QUANTUM, TopMemoryContext, TabStatusArray::tsa_entries, TabStatHashEntry::tsa_entry, TabStatusArray::tsa_next, and TabStatusArray::tsa_used.

Referenced by pgstat_initstats(), pgstat_twophase_postabort(), and pgstat_twophase_postcommit().

2073 {
2074  TabStatHashEntry *hash_entry;
2075  PgStat_TableStatus *entry;
2076  TabStatusArray *tsa;
2077  bool found;
2078 
2079  /*
2080  * Create hash table if we don't have it already.
2081  */
2082  if (pgStatTabHash == NULL)
2083  {
2084  HASHCTL ctl;
2085 
2086  ctl.keysize = sizeof(Oid);
2087  ctl.entrysize = sizeof(TabStatHashEntry);
2088 
2089  pgStatTabHash = hash_create("pgstat TabStatusArray lookup hash table",
2091  &ctl,
2092  HASH_ELEM | HASH_BLOBS);
2093  }
2094 
2095  /*
2096  * Find an entry or create a new one.
2097  */
2098  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_ENTER, &found);
2099  if (!found)
2100  {
2101  /* initialize new entry with null pointer */
2102  hash_entry->tsa_entry = NULL;
2103  }
2104 
2105  /*
2106  * If entry is already valid, we're done.
2107  */
2108  if (hash_entry->tsa_entry)
2109  return hash_entry->tsa_entry;
2110 
2111  /*
2112  * Locate the first pgStatTabList entry with free space, making a new list
2113  * entry if needed. Note that we could get an OOM failure here, but if so
2114  * we have left the hashtable and the list in a consistent state.
2115  */
2116  if (pgStatTabList == NULL)
2117  {
2118  /* Set up first pgStatTabList entry */
2121  sizeof(TabStatusArray));
2122  }
2123 
2124  tsa = pgStatTabList;
2125  while (tsa->tsa_used >= TABSTAT_QUANTUM)
2126  {
2127  if (tsa->tsa_next == NULL)
2128  tsa->tsa_next = (TabStatusArray *)
2130  sizeof(TabStatusArray));
2131  tsa = tsa->tsa_next;
2132  }
2133 
2134  /*
2135  * Allocate a PgStat_TableStatus entry within this list entry. We assume
2136  * the entry was already zeroed, either at creation or after last use.
2137  */
2138  entry = &tsa->tsa_entries[tsa->tsa_used++];
2139  entry->t_id = rel_id;
2140  entry->t_shared = isshared;
2141 
2142  /*
2143  * Now we can fill the entry in pgStatTabHash.
2144  */
2145  hash_entry->tsa_entry = entry;
2146 
2147  return entry;
2148 }
int tsa_used
Definition: pgstat.c:196
#define HASH_ELEM
Definition: hsearch.h:95
Size entrysize
Definition: hsearch.h:76
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
struct TabStatusArray * tsa_next
Definition: pgstat.c:195
unsigned int Oid
Definition: postgres_ext.h:31
struct TabStatHashEntry TabStatHashEntry
static HTAB * pgStatTabHash
Definition: pgstat.c:214
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
PgStat_TableStatus tsa_entries[TABSTAT_QUANTUM]
Definition: pgstat.c:197
MemoryContext TopMemoryContext
Definition: mcxt.c:48
#define HASH_BLOBS
Definition: hsearch.h:97
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:208
Size keysize
Definition: hsearch.h:75
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
static TabStatusArray * pgStatTabList
Definition: pgstat.c:200
#define TABSTAT_QUANTUM
Definition: pgstat.c:191

◆ get_tabstat_stack_level()

static PgStat_SubXactStatus* get_tabstat_stack_level ( int  nest_level)
static

Definition at line 2180 of file pgstat.c.

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

Referenced by add_tabstat_xact_level(), and AtEOSubXact_PgStat().

2181 {
2182  PgStat_SubXactStatus *xact_state;
2183 
2184  xact_state = pgStatXactStack;
2185  if (xact_state == NULL || xact_state->nest_level != nest_level)
2186  {
2187  xact_state = (PgStat_SubXactStatus *)
2189  sizeof(PgStat_SubXactStatus));
2190  xact_state->nest_level = nest_level;
2191  xact_state->prev = pgStatXactStack;
2192  xact_state->first = NULL;
2193  pgStatXactStack = xact_state;
2194  }
2195  return xact_state;
2196 }
MemoryContext TopTransactionContext
Definition: mcxt.c:53
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:238
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:242
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
PgStat_TableXactStatus * first
Definition: pgstat.c:239

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 4709 of file pgstat.c.

References MemoryContextDelete(), and pgstat_clear_backend_activity_snapshot().

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

4710 {
4711  /* Release memory, if any was allocated */
4712  if (pgStatLocalContext)
4714 
4715  /* Reset variables */
4716  pgStatLocalContext = NULL;
4717  pgStatDBHash = NULL;
4718  replSlotStatHash = NULL;
4719 
4720  /*
4721  * Historically the backend_status.c facilities lived in this file, and
4722  * were reset with the same function. For now keep it that way, and
4723  * forward the reset request.
4724  */
4726 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
static HTAB * pgStatDBHash
Definition: pgstat.c:270
static HTAB * replSlotStatHash
Definition: pgstat.c:281
static MemoryContext pgStatLocalContext
Definition: pgstat.c:269
void pgstat_clear_backend_activity_snapshot(void)

◆ pgstat_collect_oids()

static HTAB * pgstat_collect_oids ( Oid  catalogid,
AttrNumber  anum_oid 
)
static

Definition at line 1274 of file pgstat.c.

References AccessShareLock, Assert, CHECK_FOR_INTERRUPTS, CurrentMemoryContext, HASHCTL::entrysize, ForwardScanDirection, GetLatestSnapshot(), HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASHCTL::hcxt, heap_getattr, heap_getnext(), HASHCTL::keysize, PGSTAT_TAB_HASH_SIZE, RegisterSnapshot(), RelationGetDescr, table_beginscan(), table_close(), table_endscan(), table_open(), and UnregisterSnapshot().

Referenced by pgstat_vacuum_stat().

1275 {
1276  HTAB *htab;
1277  HASHCTL hash_ctl;
1278  Relation rel;
1279  TableScanDesc scan;
1280  HeapTuple tup;
1281  Snapshot snapshot;
1282 
1283  hash_ctl.keysize = sizeof(Oid);
1284  hash_ctl.entrysize = sizeof(Oid);
1285  hash_ctl.hcxt = CurrentMemoryContext;
1286  htab = hash_create("Temporary table of OIDs",
1288  &hash_ctl,
1290 
1291  rel = table_open(catalogid, AccessShareLock);
1292  snapshot = RegisterSnapshot(GetLatestSnapshot());
1293  scan = table_beginscan(rel, snapshot, 0, NULL);
1294  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
1295  {
1296  Oid thisoid;
1297  bool isnull;
1298 
1299  thisoid = heap_getattr(tup, anum_oid, RelationGetDescr(rel), &isnull);
1300  Assert(!isnull);
1301 
1303 
1304  (void) hash_search(htab, (void *) &thisoid, HASH_ENTER, NULL);
1305  }
1306  table_endscan(scan);
1307  UnregisterSnapshot(snapshot);
1309 
1310  return htab;
1311 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
MemoryContext hcxt
Definition: hsearch.h:86
#define RelationGetDescr(relation)
Definition: rel.h:503
#define PGSTAT_TAB_HASH_SIZE
Definition: pgstat.c:106
#define AccessShareLock
Definition: lockdefs.h:36
Size entrysize
Definition: hsearch.h:76
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
Definition: dynahash.c:219
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:883
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1340
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:852
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:761
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
#define Assert(condition)
Definition: c.h:804
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:325
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:991
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

Definition at line 2275 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_deleted.

Referenced by heap_abort_speculative(), and heap_delete().

2276 {
2277  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2278 
2279  if (pgstat_info != NULL)
2280  {
2281  /* We have to log the effect at the proper transactional level */
2282  int nest_level = GetCurrentTransactionNestLevel();
2283 
2284  if (pgstat_info->trans == NULL ||
2285  pgstat_info->trans->nest_level != nest_level)
2286  add_tabstat_xact_level(pgstat_info, nest_level);
2287 
2288  pgstat_info->trans->tuples_deleted++;
2289  }
2290 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:187
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:249
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2202
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 2229 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_inserted.

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

2230 {
2231  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2232 
2233  if (pgstat_info != NULL)
2234  {
2235  /* We have to log the effect at the proper transactional level */
2236  int nest_level = GetCurrentTransactionNestLevel();
2237 
2238  if (pgstat_info->trans == NULL ||
2239  pgstat_info->trans->nest_level != nest_level)
2240  add_tabstat_xact_level(pgstat_info, nest_level);
2241 
2242  pgstat_info->trans->tuples_inserted += n;
2243  }
2244 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:185
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:249
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2202
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

Definition at line 2250 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_tuples_hot_updated, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_update().

2251 {
2252  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2253 
2254  if (pgstat_info != NULL)
2255  {
2256  /* We have to log the effect at the proper transactional level */
2257  int nest_level = GetCurrentTransactionNestLevel();
2258 
2259  if (pgstat_info->trans == NULL ||
2260  pgstat_info->trans->nest_level != nest_level)
2261  add_tabstat_xact_level(pgstat_info, nest_level);
2262 
2263  pgstat_info->trans->tuples_updated++;
2264 
2265  /* t_tuples_hot_updated is nontransactional, so just advance it */
2266  if (hot)
2267  pgstat_info->t_counts.t_tuples_hot_updated++;
2268  }
2269 }
PgStat_Counter tuples_updated
Definition: pgstat.h:186
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:124
PgStat_TableCounts t_counts
Definition: pgstat.h:176
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:249
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2202
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175

◆ pgstat_count_slru_flush()

void pgstat_count_slru_flush ( int  slru_idx)

Definition at line 5864 of file pgstat.c.

References PgStat_MsgSLRU::m_flush, and slru_entry().

Referenced by SimpleLruWriteAll().

5865 {
5866  slru_entry(slru_idx)->m_flush += 1;
5867 }
PgStat_Counter m_flush
Definition: pgstat.h:517
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816

◆ pgstat_count_slru_page_exists()

void pgstat_count_slru_page_exists ( int  slru_idx)

Definition at line 5846 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_exists, and slru_entry().

Referenced by SimpleLruDoesPhysicalPageExist().

5847 {
5848  slru_entry(slru_idx)->m_blocks_exists += 1;
5849 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816
PgStat_Counter m_blocks_exists
Definition: pgstat.h:516

◆ pgstat_count_slru_page_hit()

void pgstat_count_slru_page_hit ( int  slru_idx)

Definition at line 5840 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_hit, and slru_entry().

Referenced by SimpleLruReadPage(), and SimpleLruReadPage_ReadOnly().

5841 {
5842  slru_entry(slru_idx)->m_blocks_hit += 1;
5843 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816
PgStat_Counter m_blocks_hit
Definition: pgstat.h:513

◆ pgstat_count_slru_page_read()

void pgstat_count_slru_page_read ( int  slru_idx)

Definition at line 5852 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_read, and slru_entry().

Referenced by SimpleLruReadPage().

5853 {
5854  slru_entry(slru_idx)->m_blocks_read += 1;
5855 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816
PgStat_Counter m_blocks_read
Definition: pgstat.h:514

◆ pgstat_count_slru_page_written()

void pgstat_count_slru_page_written ( int  slru_idx)

Definition at line 5858 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_written, and slru_entry().

Referenced by SlruPhysicalWritePage().

5859 {
5860  slru_entry(slru_idx)->m_blocks_written += 1;
5861 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816
PgStat_Counter m_blocks_written
Definition: pgstat.h:515

◆ pgstat_count_slru_page_zeroed()

void pgstat_count_slru_page_zeroed ( int  slru_idx)

Definition at line 5834 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_zeroed, and slru_entry().

Referenced by SimpleLruZeroPage().

5835 {
5836  slru_entry(slru_idx)->m_blocks_zeroed += 1;
5837 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:512

◆ pgstat_count_slru_truncate()

void pgstat_count_slru_truncate ( int  slru_idx)

Definition at line 5870 of file pgstat.c.

References PgStat_MsgSLRU::m_truncate, and slru_entry().

Referenced by SimpleLruTruncate().

5871 {
5872  slru_entry(slru_idx)->m_truncate += 1;
5873 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5816
PgStat_Counter m_truncate
Definition: pgstat.h:518

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

Definition at line 2330 of file pgstat.c.

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, RelationData::pgstat_info, pgstat_truncate_save_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by ExecRefreshMatView(), and ExecuteTruncateGuts().

2331 {
2332  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2333 
2334  if (pgstat_info != NULL)
2335  {
2336  /* We have to log the effect at the proper transactional level */
2337  int nest_level = GetCurrentTransactionNestLevel();
2338 
2339  if (pgstat_info->trans == NULL ||
2340  pgstat_info->trans->nest_level != nest_level)
2341  add_tabstat_xact_level(pgstat_info, nest_level);
2342 
2343  pgstat_truncate_save_counters(pgstat_info->trans);
2344  pgstat_info->trans->tuples_inserted = 0;
2345  pgstat_info->trans->tuples_updated = 0;
2346  pgstat_info->trans->tuples_deleted = 0;
2347  }
2348 }
PgStat_Counter tuples_updated
Definition: pgstat.h:186
PgStat_Counter tuples_inserted
Definition: pgstat.h:185
PgStat_Counter tuples_deleted
Definition: pgstat.h:187
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:249
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
Definition: pgstat.c:2202
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175
static void pgstat_truncate_save_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2301

◆ pgstat_db_requested()

static bool pgstat_db_requested ( Oid  databaseid)
static

Definition at line 5676 of file pgstat.c.

References InvalidOid, list_member_oid(), and NIL.

Referenced by pgstat_write_statsfiles().

5677 {
5678  /*
5679  * If any requests are outstanding at all, we should write the stats for
5680  * shared catalogs (the "database" with OID 0). This ensures that
5681  * backends will see up-to-date stats for shared catalogs, even though
5682  * they send inquiry messages mentioning only their own DB.
5683  */
5684  if (databaseid == InvalidOid && pending_write_requests != NIL)
5685  return true;
5686 
5687  /* Search to see if there's an open request to write this database. */
5688  if (list_member_oid(pending_write_requests, databaseid))
5689  return true;
5690 
5691  return false;
5692 }
#define NIL
Definition: pg_list.h:65
static List * pending_write_requests
Definition: pgstat.c:288
#define InvalidOid
Definition: postgres_ext.h:36
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689

◆ pgstat_drop_database()

void pgstat_drop_database ( Oid  databaseid)

Definition at line 1323 of file pgstat.c.

References PgStat_MsgTabpurge::m_databaseid, PgStat_MsgDropdb::m_databaseid, PgStat_MsgTabpurge::m_hdr, PgStat_MsgDropdb::m_hdr, PgStat_MsgTabpurge::m_nentries, PgStat_MsgTabpurge::m_tableid, MyDatabaseId, offsetof, PGINVALID_SOCKET, PGSTAT_MTYPE_DROPDB, PGSTAT_MTYPE_TABPURGE, pgstat_send(), pgstat_setheader(), and pgStatSock.

Referenced by dropdb(), and pgstat_vacuum_stat().

1324 {
1325  PgStat_MsgDropdb msg;
1326 
1328  return;
1329 
1331  msg.m_databaseid = databaseid;
1332  pgstat_send(&msg, sizeof(msg));
1333 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:2967
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:172
Oid m_databaseid
Definition: pgstat.h:324
PgStat_MsgHdr m_hdr
Definition: pgstat.h:323
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:2954

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 1979 of file pgstat.c.

References PgStat_FunctionCounts::f_numcalls, PgStat_FunctionCounts::f_self_time, PgStat_FunctionCallUsage::f_start, PgStat_FunctionCounts::f_total_time, PgStat_FunctionCallUsage::fs, have_function_stats, 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().

1980 {
1981  PgStat_FunctionCounts *fs = fcu->fs;
1982  instr_time f_total;
1983  instr_time f_others;
1984  instr_time f_self;
1985 
1986  /* stats not wanted? */
1987  if (fs == NULL)
1988  return;
1989 
1990  /* total elapsed time in this function call */
1991  INSTR_TIME_SET_CURRENT(f_total);
1992  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
1993 
1994  /* self usage: elapsed minus anything already charged to other calls */
1995  f_others = total_func_time;
1996  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
1997  f_self = f_total;
1998  INSTR_TIME_SUBTRACT(f_self, f_others);
1999 
2000  /* update backend-wide total time */
2002 
2003  /*
2004  * Compute the new f_total_time as the total elapsed time added to the
2005  * pre-call value of f_total_time. This is necessary to avoid
2006  * double-counting any time taken by recursive calls of myself. (We do
2007  * not need any similar kluge for self time, since that already excludes
2008  * any recursive calls.)
2009  */
2010  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
2011 
2012  /* update counters in function stats table */
2013  if (finalize)
2014  fs->f_numcalls++;
2015  fs->f_total_time = f_total;
2016  INSTR_TIME_ADD(fs->f_self_time, f_self);
2017 
2018  /* indicate that we have something to send */
2019  have_function_stats = true;
2020 }
instr_time f_self_time
Definition: pgstat.h:581
instr_time f_start
Definition: pgstat.h:925
instr_time save_total
Definition: pgstat.h:923
struct timeval instr_time
Definition: instr_time.h:150
instr_time f_total_time
Definition: pgstat.h:580
PgStat_FunctionCounts * fs
Definition: pgstat.h:919
PgStat_Counter f_numcalls
Definition: pgstat.h:579
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:170
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:158
static instr_time total_func_time
Definition: pgstat.c:295
static bool have_function_stats
Definition: pgstat.c:226
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:921

◆ pgstat_fetch_global()

◆ pgstat_fetch_replslot()

PgStat_StatReplSlotEntry* pgstat_fetch_replslot ( NameData  slotname)

Definition at line 2891 of file pgstat.c.

References backend_read_statsfile(), and pgstat_get_replslot_entry().

Referenced by pg_stat_get_replication_slot().

2892 {
2894 
2895  return pgstat_get_replslot_entry(slotname, false);
2896 }
static void backend_read_statsfile(void)
Definition: pgstat.c:4554
static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry(NameData name, bool create_it)
Definition: pgstat.c:5704

◆ pgstat_fetch_slru()

PgStat_SLRUStats* pgstat_fetch_slru ( void  )

Definition at line 2875 of file pgstat.c.

References backend_read_statsfile(), and slruStats.

Referenced by pg_stat_get_slru().

2876 {
2878 
2879  return slruStats;
2880 }
static void backend_read_statsfile(void)
Definition: pgstat.c:4554
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:280

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 2826 of file pgstat.c.

References archiverStats, and backend_read_statsfile().

Referenced by pg_stat_get_archiver().

2827 {
2829 
2830  return &archiverStats;
2831 }
static void backend_read_statsfile(void)
Definition: pgstat.c:4554
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:277

◆ pgstat_fetch_stat_dbentry()

PgStat_StatDBEntry* pgstat_fetch_stat_dbentry ( Oid  dbid)

Definition at line 2713 of file pgstat.c.

References backend_read_statsfile(), HASH_FIND, and hash_search().

Referenced by do_autovacuum(), do_start_worker(), pg_stat_get_db_active_time(), pg_stat_get_db_blk_read_time(), pg_stat_get_db_blk_write_time(), pg_stat_get_db_blocks_fetched(), pg_stat_get_db_blocks_hit(), pg_stat_get_db_checksum_failures(), pg_stat_get_db_checksum_last_failure(), pg_stat_get_db_conflict_all(), pg_stat_get_db_conflict_bufferpin(), pg_stat_get_db_conflict_lock(), pg_stat_get_db_conflict_snapshot(), pg_stat_get_db_conflict_startup_deadlock(), pg_stat_get_db_conflict_tablespace(), pg_stat_get_db_deadlocks(), pg_stat_get_db_idle_in_transaction_time(), pg_stat_get_db_session_time(), pg_stat_get_db_sessions(), pg_stat_get_db_sessions_abandoned(), pg_stat_get_db_sessions_fatal(), pg_stat_get_db_sessions_killed(), pg_stat_get_db_stat_reset_time(), pg_stat_get_db_temp_bytes(), pg_stat_get_db_temp_files(), pg_stat_get_db_tuples_deleted(), pg_stat_get_db_tuples_fetched(), pg_stat_get_db_tuples_inserted(), pg_stat_get_db_tuples_returned(), pg_stat_get_db_tuples_updated(), pg_stat_get_db_xact_commit(), pg_stat_get_db_xact_rollback(), pgstat_fetch_stat_funcentry(), rebuild_database_list(), and recheck_relation_needs_vacanalyze().

2714 {
2715  /*
2716  * If not done for this transaction, read the statistics collector stats
2717  * file into some hash tables.
2718  */
2720 
2721  /*
2722  * Lookup the requested database; return NULL if not found
2723  */
2725  (void *) &dbid,
2726  HASH_FIND, NULL);
2727 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static void backend_read_statsfile(void)
Definition: pgstat.c:4554
static HTAB * pgStatDBHash
Definition: pgstat.c:270

◆ pgstat_fetch_stat_funcentry()

PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  func_id)

Definition at line 2796 of file pgstat.c.

References backend_read_statsfile(), PgStat_StatDBEntry::functions, HASH_FIND, hash_search(), MyDatabaseId, and pgstat_fetch_stat_dbentry().

Referenced by pg_stat_get_function_calls(), pg_stat_get_function_self_time(), and pg_stat_get_function_total_time().

2797 {
2798  PgStat_StatDBEntry *dbentry;
2799  PgStat_StatFuncEntry *funcentry = NULL;
2800 
2801  /* load the stats file if needed */
2803 
2804  /* Lookup our database, then find the requested function. */
2806  if (dbentry != NULL && dbentry->functions != NULL)
2807  {
2808  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
2809  (void *) &func_id,
2810  HASH_FIND, NULL);
2811  }
2812 
2813  return funcentry;
2814 }
HTAB * functions
Definition: pgstat.h:771
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2713
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static void backend_read_statsfile(void)
Definition: pgstat.c:4554
Oid MyDatabaseId
Definition: globals.c:88

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 2740 of file pgstat.c.

References backend_read_statsfile(), HASH_FIND, hash_search(), InvalidOid, MyDatabaseId, and PgStat_StatDBEntry::tables.

Referenced by do_autovacuum(), index_concurrently_swap(), pg_stat_get_analyze_count(), pg_stat_get_autoanalyze_count(), pg_stat_get_autovacuum_count(), pg_stat_get_blocks_fetched(), pg_stat_get_blocks_hit(), pg_stat_get_dead_tuples(), pg_stat_get_ins_since_vacuum(), pg_stat_get_last_analyze_time(), pg_stat_get_last_autoanalyze_time(), pg_stat_get_last_autovacuum_time(), pg_stat_get_last_vacuum_time(), pg_stat_get_live_tuples(), pg_stat_get_mod_since_analyze(), pg_stat_get_numscans(), pg_stat_get_tuples_deleted(), pg_stat_get_tuples_fetched(), pg_stat_get_tuples_hot_updated(), pg_stat_get_tuples_inserted(), pg_stat_get_tuples_returned(), pg_stat_get_tuples_updated(), and pg_stat_get_vacuum_count().

2741 {
2742  Oid dbid;
2743  PgStat_StatDBEntry *dbentry;
2744  PgStat_StatTabEntry *tabentry;
2745 
2746  /*
2747  * If not done for this transaction, read the statistics collector stats
2748  * file into some hash tables.
2749  */
2751 
2752  /*
2753  * Lookup our database, then look in its table hash table.
2754  */
2755  dbid = MyDatabaseId;
2757  (void *) &dbid,
2758  HASH_FIND, NULL);
2759  if (dbentry != NULL && dbentry->tables != NULL)
2760  {
2761  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2762  (void *) &relid,
2763  HASH_FIND, NULL);
2764  if (tabentry)
2765  return tabentry;
2766  }
2767 
2768  /*
2769  * If we didn't find it, maybe it's a shared table.
2770  */
2771  dbid = InvalidOid;
2773  (void *) &dbid,
2774  HASH_FIND, NULL);
2775  if (dbentry != NULL && dbentry->tables != NULL)
2776  {
2777  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2778  (void *) &relid,
2779  HASH_FIND, NULL);
2780  if (tabentry)
2781  return tabentry;
2782  }
2783 
2784  return NULL;
2785 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
static void backend_read_statsfile(void)
Definition: pgstat.c:4554
Oid MyDatabaseId
Definition: globals.c:88
#define InvalidOid
Definition: postgres_ext.h:36
static HTAB * pgStatDBHash
Definition: pgstat.c:270

◆ pgstat_fetch_stat_wal()

PgStat_WalStats* pgstat_fetch_stat_wal ( void  )

Definition at line 2859 of file pgstat.c.

References backend_read_statsfile(), and walStats.

Referenced by pg_stat_get_wal().

2860 {
2862 
2863  return &walStats;
2864 }
static PgStat_WalStats walStats
Definition: pgstat.c:279
static void backend_read_statsfile(void)
Definition: pgstat.c:4554

◆ pgstat_get_db_entry()

static PgStat_StatDBEntry * pgstat_get_db_entry ( Oid  databaseid,
bool  create 
)
static

Definition at line 3533 of file pgstat.c.

References generate_unaccent_rules::action, HASH_ENTER, HASH_FIND, hash_search(), and reset_dbentry_counters().

Referenced by pgstat_recv_analyze(), pgstat_recv_anl_ancestors(), pgstat_recv_autovac(), pgstat_recv_checksum_failure(), pgstat_recv_connstat(), pgstat_recv_deadlock(), pgstat_recv_dropdb(), pgstat_recv_funcpurge(), pgstat_recv_funcstat(), pgstat_recv_inquiry(), pgstat_recv_recoveryconflict(), pgstat_recv_resetcounter(), pgstat_recv_resetsinglecounter(), pgstat_recv_tabpurge(), pgstat_recv_tabstat(), pgstat_recv_tempfile(), and pgstat_recv_vacuum().

3534 {
3535  PgStat_StatDBEntry *result;
3536  bool found;
3537  HASHACTION action = (create ? HASH_ENTER : HASH_FIND);
3538 
3539  /* Lookup or create the hash table entry for this database */
3541  &databaseid,
3542  action, &found);
3543 
3544  if (!create && !found)
3545  return NULL;
3546 
3547  /*
3548  * If not found, initialize the new one. This creates empty hash tables
3549  * for tables and functions, too.
3550  */
3551  if (!found)
3552  reset_dbentry_counters(result);
3553 
3554  return result;
3555 }
static void reset_dbentry_counters(PgStat_StatDBEntry *dbentry)
Definition: pgstat.c:3475
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * pgStatDBHash
Definition: pgstat.c:270
HASHACTION
Definition: hsearch.h:111

◆ pgstat_get_replslot_entry()

static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry ( NameData  name,
bool  create_it 
)
static

Definition at line 5704 of file pgstat.c.

References Assert, HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, HASH_FIND, hash_search(), HASHCTL::keysize, name, NameStr, namestrcpy(), PGSTAT_REPLSLOT_HASH_SIZE, pgstat_reset_replslot(), and PgStat_StatReplSlotEntry::slotname.

Referenced by pgstat_fetch_replslot(), pgstat_recv_replslot(), and pgstat_recv_resetreplslotcounter().

5705 {
5706  PgStat_StatReplSlotEntry *slotent;
5707  bool found;
5708 
5709  if (replSlotStatHash == NULL)
5710  {
5711  HASHCTL hash_ctl;
5712 
5713  /*
5714  * Quick return NULL if the hash table is empty and the caller didn't
5715  * request to create the entry.
5716  */
5717  if (!create)
5718  return NULL;
5719 
5720  hash_ctl.keysize = sizeof(NameData);
5721  hash_ctl.entrysize = sizeof(PgStat_StatReplSlotEntry);
5722  replSlotStatHash = hash_create("Replication slots hash",
5724  &hash_ctl,
5725  HASH_ELEM | HASH_BLOBS);
5726  }
5727 
5729  (void *) &name,
5730  create ? HASH_ENTER : HASH_FIND,
5731  &found);
5732 
5733  if (!slotent)
5734  {
5735  /* not found */
5736  Assert(!create && !found);
5737  return NULL;
5738  }
5739 
5740  /* initialize the entry */
5741  if (create && !found)
5742  {
5743  namestrcpy(&(slotent->slotname), NameStr(name));
5744  pgstat_reset_replslot(slotent, 0);
5745  }
5746 
5747  return slotent;
5748 }
static void pgstat_reset_replslot(PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
Definition: pgstat.c:5757
#define HASH_ELEM
Definition: hsearch.h:95
void namestrcpy(Name name, const char *str)
Definition: name.c:233
struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
Size entrysize
Definition: hsearch.h:76
#define PGSTAT_REPLSLOT_HASH_SIZE
Definition: pgstat.c:108
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
#define Assert(condition)
Definition: c.h:804
const char * name
Definition: encode.c:515
static HTAB * replSlotStatHash
Definition: pgstat.c:281
#define NameStr(name)
Definition: c.h:681
struct nameData NameData

◆ pgstat_get_tab_entry()

static PgStat_StatTabEntry * pgstat_get_tab_entry ( PgStat_StatDBEntry dbentry,
Oid  tableoid,
bool  create 
)
static

Definition at line 3564 of file pgstat.c.

References generate_unaccent_rules::action, PgStat_StatTabEntry::analyze_count, PgStat_StatTabEntry::analyze_timestamp, PgStat_StatTabEntry::autovac_analyze_count, PgStat_StatTabEntry::autovac_analyze_timestamp, PgStat_StatTabEntry::autovac_vacuum_count, PgStat_StatTabEntry::autovac_vacuum_timestamp, PgStat_StatTabEntry::blocks_fetched, PgStat_StatTabEntry::blocks_hit, PgStat_StatTabEntry::changes_since_analyze, PgStat_StatTabEntry::changes_since_analyze_reported, HASH_ENTER, HASH_FIND, hash_search(), PgStat_StatTabEntry::inserts_since_vacuum, PgStat_StatTabEntry::n_dead_tuples, PgStat_StatTabEntry::n_live_tuples, PgStat_StatTabEntry::numscans, PgStat_StatDBEntry::tables, PgStat_StatTabEntry::tuples_deleted, PgStat_StatTabEntry::tuples_fetched, PgStat_StatTabEntry::tuples_hot_updated, PgStat_StatTabEntry::tuples_inserted, PgStat_StatTabEntry::tuples_returned, PgStat_StatTabEntry::tuples_updated, PgStat_StatTabEntry::vacuum_count, and PgStat_StatTabEntry::vacuum_timestamp.

Referenced by pgstat_recv_analyze(), pgstat_recv_anl_ancestors(), and pgstat_recv_vacuum().

3565 {
3566  PgStat_StatTabEntry *result;
3567  bool found;
3568  HASHACTION action = (create ? HASH_ENTER : HASH_FIND);
3569 
3570  /* Lookup or create the hash table entry for this table */
3571  result = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
3572  &tableoid,
3573  action, &found);
3574 
3575  if (!create && !found)
3576  return NULL;
3577 
3578  /* If not found, initialize the new one. */
3579  if (!found)
3580  {
3581  result->numscans = 0;
3582  result->tuples_returned = 0;
3583  result->tuples_fetched = 0;
3584  result->tuples_inserted = 0;
3585  result->tuples_updated = 0;
3586  result->tuples_deleted = 0;
3587  result->tuples_hot_updated = 0;
3588  result->n_live_tuples = 0;
3589  result->n_dead_tuples = 0;
3590  result->changes_since_analyze = 0;
3591  result->changes_since_analyze_reported = 0;
3592  result->inserts_since_vacuum = 0;
3593  result->blocks_fetched = 0;
3594  result->blocks_hit = 0;
3595  result->vacuum_timestamp = 0;
3596  result->vacuum_count = 0;
3597  result->autovac_vacuum_timestamp = 0;
3598  result->autovac_vacuum_count = 0;
3599  result->analyze_timestamp = 0;
3600  result->analyze_count = 0;
3601  result->autovac_analyze_timestamp = 0;
3602  result->autovac_analyze_count = 0;
3603  }
3604 
3605  return result;
3606 }
PgStat_Counter analyze_count
Definition: pgstat.h:807
PgStat_Counter tuples_returned
Definition: pgstat.h:785
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:808
PgStat_Counter vacuum_count
Definition: pgstat.h:803
PgStat_Counter numscans
Definition: pgstat.h:783
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:791
PgStat_Counter tuples_inserted
Definition: pgstat.h:788
PgStat_Counter n_live_tuples
Definition: pgstat.h:793
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:797
TimestampTz vacuum_timestamp
Definition: pgstat.h:802
PgStat_Counter n_dead_tuples
Definition: pgstat.h:794
PgStat_Counter tuples_fetched
Definition: pgstat.h:786
PgStat_Counter blocks_hit
Definition: pgstat.h:800
TimestampTz analyze_timestamp
Definition: pgstat.h:806
PgStat_Counter changes_since_analyze
Definition: pgstat.h:795
PgStat_Counter tuples_deleted
Definition: pgstat.h:790
PgStat_Counter tuples_updated
Definition: pgstat.h:789
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:804
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:809
PgStat_Counter changes_since_analyze_reported
Definition: pgstat.h:796
PgStat_Counter blocks_fetched
Definition: pgstat.h:799
HASHACTION
Definition: hsearch.h:111
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:805

◆ pgstat_init()

void pgstat_init ( void  )

Definition at line 377 of file pgstat.c.

References addrinfo::ai_next, AI_PASSIVE, bind, closesocket, connect, EINTR, ereport, errcode(), errcode_for_socket_access(), errmsg(), gai_strerror, LOG, pg_freeaddrinfo_all(), pg_getaddrinfo_all(), pg_set_noblock(), PGC_INTERNAL, PGC_S_OVERRIDE, PGINVALID_SOCKET, PGSTAT_MAX_MSG_SIZE, PGSTAT_MIN_RCVBUF, pgStatAddr, pgStatSock, recv, ReserveExternalFD(), select, send, SetConfigOption(), socket, StaticAssertStmt, and TESTBYTEVAL.

Referenced by PostmasterMain().

378 {
379  ACCEPT_TYPE_ARG3 alen;
380  struct addrinfo *addrs = NULL,
381  *addr,
382  hints;
383  int ret;
384  fd_set rset;
385  struct timeval tv;
386  char test_byte;
387  int sel_res;
388  int tries = 0;
389 
390 #define TESTBYTEVAL ((char) 199)
391 
392  /*
393  * This static assertion verifies that we didn't mess up the calculations
394  * involved in selecting maximum payload sizes for our UDP messages.
395  * Because the only consequence of overrunning PGSTAT_MAX_MSG_SIZE would
396  * be silent performance loss from fragmentation, it seems worth having a
397  * compile-time cross-check that we didn't.
398  */
400  "maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE");
401 
402  /*
403  * Create the UDP socket for sending and receiving statistic messages
404  */
405  hints.ai_flags = AI_PASSIVE;
406  hints.ai_family = AF_UNSPEC;
407  hints.ai_socktype = SOCK_DGRAM;
408  hints.ai_protocol = 0;
409  hints.ai_addrlen = 0;
410  hints.ai_addr = NULL;
411  hints.ai_canonname = NULL;
412  hints.ai_next = NULL;
413  ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
414  if (ret || !addrs)
415  {
416  ereport(LOG,
417  (errmsg("could not resolve \"localhost\": %s",
418  gai_strerror(ret))));
419  goto startup_failed;
420  }
421 
422  /*
423  * On some platforms, pg_getaddrinfo_all() may return multiple addresses
424  * only one of which will actually work (eg, both IPv6 and IPv4 addresses
425  * when kernel will reject IPv6). Worse, the failure may occur at the
426  * bind() or perhaps even connect() stage. So we must loop through the
427  * results till we find a working combination. We will generate LOG
428  * messages, but no error, for bogus combinations.
429  */
430  for (addr = addrs; addr; addr = addr->ai_next)
431  {
432 #ifdef HAVE_UNIX_SOCKETS
433  /* Ignore AF_UNIX sockets, if any are returned. */
434  if (addr->ai_family == AF_UNIX)
435  continue;
436 #endif
437 
438  if (++tries > 1)
439  ereport(LOG,
440  (errmsg("trying another address for the statistics collector")));
441 
442  /*
443  * Create the socket.
444  */
445  if ((pgStatSock = socket(addr->ai_family, SOCK_DGRAM, 0)) == PGINVALID_SOCKET)
446  {
447  ereport(LOG,
449  errmsg("could not create socket for statistics collector: %m")));
450  continue;
451  }
452 
453  /*
454  * Bind it to a kernel assigned port on localhost and get the assigned
455  * port via getsockname().
456  */
457  if (bind(pgStatSock, addr->ai_addr, addr->ai_addrlen) < 0)
458  {
459  ereport(LOG,
461  errmsg("could not bind socket for statistics collector: %m")));
464  continue;
465  }
466 
467  alen = sizeof(pgStatAddr);
468  if (getsockname(pgStatSock, (struct sockaddr *) &pgStatAddr, &alen) < 0)
469  {
470  ereport(LOG,
472  errmsg("could not get address of socket for statistics collector: %m")));
475  continue;
476  }
477 
478  /*
479  * Connect the socket to its own address. This saves a few cycles by
480  * not having to respecify the target address on every send. This also
481  * provides a kernel-level check that only packets from this same
482  * address will be received.
483  */
484  if (connect(pgStatSock, (struct sockaddr *) &pgStatAddr, alen) < 0)
485  {
486  ereport(LOG,
488  errmsg("could not connect socket for statistics collector: %m")));
491  continue;
492  }
493 
494  /*
495  * Try to send and receive a one-byte test message on the socket. This
496  * is to catch situations where the socket can be created but will not
497  * actually pass data (for instance, because kernel packet filtering
498  * rules prevent it).
499  */
500  test_byte = TESTBYTEVAL;
501 
502 retry1:
503  if (send(pgStatSock, &test_byte, 1, 0) != 1)
504  {
505  if (errno == EINTR)
506  goto retry1; /* if interrupted, just retry */
507  ereport(LOG,
509  errmsg("could not send test message on socket for statistics collector: %m")));
512  continue;
513  }
514 
515  /*
516  * There could possibly be a little delay before the message can be
517  * received. We arbitrarily allow up to half a second before deciding
518  * it's broken.
519  */
520  for (;;) /* need a loop to handle EINTR */
521  {
522  FD_ZERO(&rset);
523  FD_SET(pgStatSock, &rset);
524 
525  tv.tv_sec = 0;
526  tv.tv_usec = 500000;
527  sel_res = select(pgStatSock + 1, &rset, NULL, NULL, &tv);
528  if (sel_res >= 0 || errno != EINTR)
529  break;
530  }
531  if (sel_res < 0)
532  {
533  ereport(LOG,
535  errmsg("select() failed in statistics collector: %m")));
538  continue;
539  }
540  if (sel_res == 0 || !FD_ISSET(pgStatSock, &rset))
541  {
542  /*
543  * This is the case we actually think is likely, so take pains to
544  * give a specific message for it.
545  *
546  * errno will not be set meaningfully here, so don't use it.
547  */
548  ereport(LOG,
549  (errcode(ERRCODE_CONNECTION_FAILURE),
550  errmsg("test message did not get through on socket for statistics collector")));
553  continue;
554  }
555 
556  test_byte++; /* just make sure variable is changed */
557 
558 retry2:
559  if (recv(pgStatSock, &test_byte, 1, 0) != 1)
560  {
561  if (errno == EINTR)
562  goto retry2; /* if interrupted, just retry */
563  ereport(LOG,
565  errmsg("could not receive test message on socket for statistics collector: %m")));
568  continue;
569  }
570 
571  if (test_byte != TESTBYTEVAL) /* strictly paranoia ... */
572  {
573  ereport(LOG,
574  (errcode(ERRCODE_INTERNAL_ERROR),
575  errmsg("incorrect test message transmission on socket for statistics collector")));
578  continue;
579  }
580 
581  /* If we get here, we have a working socket */
582  break;
583  }
584 
585  /* Did we find a working address? */
586  if (!addr || pgStatSock == PGINVALID_SOCKET)
587  goto startup_failed;
588 
589  /*
590  * Set the socket to non-blocking IO. This ensures that if the collector
591  * falls behind, statistics messages will be discarded; backends won't
592  * block waiting to send messages to the collector.
593  */
595  {
596  ereport(LOG,
598  errmsg("could not set statistics collector socket to nonblocking mode: %m")));
599  goto startup_failed;
600  }
601 
602  /*
603  * Try to ensure that the socket's receive buffer is at least
604  * PGSTAT_MIN_RCVBUF bytes, so that it won't easily overflow and lose
605  * data. Use of UDP protocol means that we are willing to lose data under
606  * heavy load, but we don't want it to happen just because of ridiculously
607  * small default buffer sizes (such as 8KB on older Windows versions).
608  */
609  {
610  int old_rcvbuf;
611  int new_rcvbuf;
612  ACCEPT_TYPE_ARG3 rcvbufsize = sizeof(old_rcvbuf);
613 
614  if (getsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
615  (char *) &old_rcvbuf, &rcvbufsize) < 0)
616  {
617  ereport(LOG,
618  (errmsg("%s(%s) failed: %m", "getsockopt", "SO_RCVBUF")));
619  /* if we can't get existing size, always try to set it */
620  old_rcvbuf = 0;
621  }
622 
623  new_rcvbuf = PGSTAT_MIN_RCVBUF;
624  if (old_rcvbuf < new_rcvbuf)
625  {
626  if (setsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
627  (char *) &new_rcvbuf, sizeof(new_rcvbuf)) < 0)
628  ereport(LOG,
629  (errmsg("%s(%s) failed: %m", "setsockopt", "SO_RCVBUF")));
630  }
631  }
632 
633  pg_freeaddrinfo_all(hints.ai_family, addrs);
634 
635  /* Now that we have a long-lived socket, tell fd.c about it. */
637 
638  return;
639 
640 startup_failed:
641  ereport(LOG,
642  (errmsg("disabling statistics collector for lack of working socket")));
643 
644  if (addrs)
645  pg_freeaddrinfo_all(hints.ai_family, addrs);
646 
650 
651  /*
652  * Adjust GUC variables to suppress useless activity, and for debugging
653  * purposes (seeing track_counts off is a clue that we failed here). We
654  * use PGC_S_OVERRIDE because there is no point in trying to turn it back
655  * on from postgresql.conf without a restart.
656  */
657  SetConfigOption("track_counts", "off", PGC_INTERNAL, PGC_S_OVERRIDE);
658 }
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
Definition: ip.c:88
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:172
#define closesocket
Definition: port.h:332
int errcode(int sqlerrcode)
Definition: elog.c:698
#define connect(s, name, namelen)
Definition: win32_port.h:463
#define LOG
Definition: elog.h:26
#define bind(s, addr, addrlen)
Definition: win32_port.h:460
#define recv(s, buf, len, flags)
Definition: win32_port.h:465
#define gai_strerror
Definition: getaddrinfo.h:146
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
Definition: ip.c:57
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:918
#define PGSTAT_MIN_RCVBUF
Definition: pgstat.c:98
#define TESTBYTEVAL
void ReserveExternalFD(void)
Definition: fd.c:1174
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8086
#define AI_PASSIVE
Definition: getaddrinfo.h:62
#define select(n, r, w, e, timeout)
Definition: win32_port.h:464
int errcode_for_socket_access(void)
Definition: elog.c:792
#define socket(af, type, protocol)
Definition: win32_port.h:459
#define PGSTAT_MAX_MSG_SIZE
Definition: pgstat.h:224
#define PGINVALID_SOCKET
Definition: port.h:33
#define ereport(elevel,...)
Definition: elog.h:157
static struct sockaddr_storage pgStatAddr
Definition: pgstat.c:174
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:25
struct addrinfo * ai_next
Definition: getaddrinfo.h:107
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define EINTR
Definition: win32_port.h:343
#define send(s, buf, len, flags)
Definition: win32_port.h:466

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( FunctionCallInfo  fcinfo,
PgStat_FunctionCallUsage fcu 
)

Definition at line 1908 of file pgstat.c.

References HASHCTL::entrysize, PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCallUsage::f_start, PgStat_FunctionCounts::f_total_time, FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_oid, PgStat_FunctionCallUsage::fs, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), INSTR_TIME_SET_CURRENT, HASHCTL::keysize, MemSet, PGSTAT_FUNCTION_HASH_SIZE, 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().

1910 {
1911  PgStat_BackendFunctionEntry *htabent;
1912  bool found;
1913 
1914  if (pgstat_track_functions <= fcinfo->flinfo->fn_stats)
1915  {
1916  /* stats not wanted */
1917  fcu->fs = NULL;
1918  return;
1919  }
1920 
1921  if (!pgStatFunctions)
1922  {
1923  /* First time through - initialize function stat table */
1924  HASHCTL hash_ctl;
1925 
1926  hash_ctl.keysize = sizeof(Oid);
1927  hash_ctl.entrysize = sizeof(PgStat_BackendFunctionEntry);
1928  pgStatFunctions = hash_create("Function stat entries",
1930  &hash_ctl,
1931  HASH_ELEM | HASH_BLOBS);
1932  }
1933 
1934  /* Get the stats entry for this function, create if necessary */
1935  htabent = hash_search(pgStatFunctions, &fcinfo->flinfo->fn_oid,
1936  HASH_ENTER, &found);
1937  if (!found)
1938  MemSet(&htabent->f_counts, 0, sizeof(PgStat_FunctionCounts));
1939 
1940  fcu->fs = &htabent->f_counts;
1941 
1942  /* save stats for this function, later used to compensate for recursion */
1943  fcu->save_f_total_time = htabent->f_counts.f_total_time;
1944 
1945  /* save current backend-wide total time */
1946  fcu->save_total = total_func_time;
1947 
1948  /* get clock time as of function start */
1950 }
instr_time f_start
Definition: pgstat.h:925
#define HASH_ELEM
Definition: hsearch.h:95
instr_time save_total
Definition: pgstat.h:923
Size entrysize
Definition: hsearch.h:76
#define MemSet(start, val, len)
Definition: c.h:1008
instr_time f_total_time
Definition: pgstat.h:580
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts * fs
Definition: pgstat.h:919
PgStat_FunctionCounts f_counts
Definition: pgstat.h:591
#define PGSTAT_FUNCTION_HASH_SIZE
Definition: pgstat.c:107
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
#define HASH_BLOBS
Definition: hsearch.h:97
FmgrInfo * flinfo
Definition: fmgr.h:87
Size keysize
Definition: hsearch.h:75
Oid fn_oid
Definition: fmgr.h:59
static instr_time total_func_time
Definition: pgstat.c:295
static HTAB * pgStatFunctions
Definition: pgstat.c:220
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:921
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry

◆ pgstat_initialize()

void pgstat_initialize ( void  )

Definition at line 2928 of file pgstat.c.

References on_shmem_exit(), pgstat_shutdown_hook(), and pgWalUsage.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

2929 {
2930  /*
2931  * Initialize prevWalUsage with pgWalUsage so that pgstat_send_wal() can
2932  * calculate how much pgWalUsage counters are increased by subtracting
2933  * prevWalUsage from pgWalUsage.
2934  */
2936 
2937  /* Set up a process-exit hook to clean up */
2939 }
static void pgstat_shutdown_hook(int code, Datum arg)
Definition: pgstat.c:2906
WalUsage pgWalUsage
Definition: instrument.c:22
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
static WalUsage prevWalUsage
Definition: pgstat.c:140

◆ pgstat_initstats()

void pgstat_initstats ( Relation  rel)

Definition at line 2036 of file pgstat.c.

References get_tabstat_entry(), PGINVALID_SOCKET, RelationData::pgstat_info, pgstat_track_counts, pgStatSock, RelationData::rd_id, RelationData::rd_rel, and PgStat_TableStatus::t_id.

Referenced by relation_open(), and try_relation_open().

2037 {
2038  Oid rel_id = rel->rd_id;
2039  char relkind = rel->rd_rel->relkind;
2040 
2041  /* We only count stats for things that have storage */
2042  if (!RELKIND_HAS_STORAGE(relkind) &&
2043  relkind != RELKIND_PARTITIONED_TABLE)
2044  {
2045  rel->pgstat_info = NULL;
2046  return;
2047  }
2048 
2050  {
2051  /* We're not counting at all */
2052  rel->pgstat_info = NULL;
2053  return;
2054  }
2055 
2056  /*
2057  * If we already set up this relation in the current transaction, nothing
2058  * to do.
2059  */
2060  if (rel->pgstat_info != NULL &&
2061  rel->pgstat_info->t_id == rel_id)
2062  return;
2063 
2064  /* Else find or make the PgStat_TableStatus entry, and update link */
2065  rel->pgstat_info = get_tabstat_entry(rel_id, rel->rd_rel->relisshared);
2066 }
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:172
Form_pg_class rd_rel
Definition: rel.h:109
unsigned int Oid
Definition: postgres_ext.h:31
bool pgstat_track_counts
Definition: pgstat.c:115
Oid rd_id
Definition: rel.h:111
static PgStat_TableStatus * get_tabstat_entry(Oid rel_id, bool isshared)
Definition: pgstat.c:2072
#define PGINVALID_SOCKET
Definition: port.h:33
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:249

◆ pgstat_ping()

void pgstat_ping ( void  )

Definition at line 1873 of file pgstat.c.

References PgStat_MsgDummy::m_hdr, PGINVALID_SOCKET, PGSTAT_MTYPE_DUMMY, pgstat_send(), pgstat_setheader(), and pgStatSock.

1874 {
1875  PgStat_MsgDummy msg;
1876 
1878  return;
1879 
1881  pgstat_send(&msg, sizeof(msg));
1882 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:2967
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:172
#define PGINVALID_SOCKET
Definition: port.h:33
PgStat_MsgHdr m_hdr
Definition: pgstat.h:234
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:2954

◆ pgstat_read_db_statsfile()

static void pgstat_read_db_statsfile ( Oid  databaseid,
HTAB tabhash,
HTAB funchash,
bool  permanent 
)
static

Definition at line 4227 of file pgstat.c.

References AllocateFile(), DEBUG2, elog, ereport, errcode_for_file_access(), errmsg(), FreeFile(), PgStat_StatFuncEntry::functionid, get_dbstat_filename(), HASH_ENTER, hash_search(), LOG, MAXPGPATH, PG_BINARY_R, PGSTAT_FILE_FORMAT_ID, pgStatRunningInCollector, PgStat_StatTabEntry::tableid, and WARNING.

Referenced by pgstat_read_statsfiles().

4229 {
4230  PgStat_StatTabEntry *tabentry;
4231  PgStat_StatTabEntry tabbuf;
4232  PgStat_StatFuncEntry funcbuf;
4233  PgStat_StatFuncEntry *funcentry;
4234  FILE *fpin;
4235  int32 format_id;
4236  bool found;
4237  char statfile[MAXPGPATH];
4238 
4239  get_dbstat_filename(permanent, false, databaseid, statfile, MAXPGPATH);
4240 
4241  /*
4242  * Try to open the stats file. If it doesn't exist, the backends simply
4243  * return zero for anything and the collector simply starts from scratch
4244  * with empty counters.
4245  *
4246  * ENOENT is a possibility if the stats collector is not running or has
4247  * not yet written the stats file the first time. Any other failure
4248  * condition is suspicious.
4249  */
4250  if ((fpin = AllocateFile(statfile, PG_BINARY_R)) == NULL)
4251  {
4252  if (errno != ENOENT)
4255  errmsg("could not open statistics file \"%s\": %m",
4256  statfile)));
4257  return;
4258  }
4259 
4260  /*
4261  * Verify it's of the expected format.
4262  */
4263  if (fread(&format_id, 1, sizeof(format_id), fpin) != sizeof(format_id) ||
4264  format_id != PGSTAT_FILE_FORMAT_ID)
4265  {
4266  ereport(pgStatRunningInCollector ? LOG : WARNING,
4267  (errmsg("corrupted statistics file \"%s\"", statfile)));
4268  goto done;
4269  }
4270 
4271  /*
4272  * We found an existing collector stats file. Read it and put all the
4273  * hashtable entries into place.
4274  */
4275  for (;;)
4276  {
4277  switch (fgetc(fpin))
4278  {
4279  /*
4280  * 'T' A PgStat_StatTabEntry follows.
4281  */
4282  case 'T':
4283  if (fread(&tabbuf, 1, sizeof(PgStat_StatTabEntry),
4284  fpin) != sizeof(PgStat_StatTabEntry))
4285  {
4286  ereport(pgStatRunningInCollector ? LOG : WARNING,
4287  (errmsg("corrupted statistics file \"%s\"",
4288  statfile)));
4289  goto done;
4290  }
4291 
4292  /*
4293  * Skip if table data not wanted.
4294  */
4295  if (tabhash == NULL)
4296  break;
4297 
4298  tabentry = (PgStat_StatTabEntry *) hash_search(tabhash,
4299  (void *) &tabbuf.tableid,
4300  HASH_ENTER, &found);
4301 
4302  if (found)
4303  {
4304  ereport(pgStatRunningInCollector ? LOG : WARNING,
4305  (errmsg("corrupted statistics file \"%s\"",
4306  statfile)));
4307  goto done;
4308  }
4309 
4310  memcpy(tabentry, &tabbuf, sizeof(tabbuf));
4311  break;
4312 
4313  /*
4314  * 'F' A PgStat_StatFuncEntry follows.
4315  */
4316  case 'F':
4317  if (fread(&funcbuf, 1, sizeof(PgStat_StatFuncEntry),
4318  fpin) != sizeof(PgStat_StatFuncEntry))
4319  {
4320  ereport(pgStatRunningInCollector ? LOG : WARNING,
4321  (errmsg("corrupted statistics file \"%s\"",
4322  statfile)));
4323  goto done;
4324  }
4325 
4326  /*
4327  * Skip if function data not wanted.
4328  */
4329  if (funchash == NULL)
4330  break;
4331 
4332  funcentry = (PgStat_StatFuncEntry *) hash_search(funchash,
4333  (void *) &funcbuf.functionid,
4334  HASH_ENTER, &found);
4335 
4336  if (found)
4337  {
4338  ereport(pgStatRunningInCollector ? LOG : WARNING,
4339  (errmsg("corrupted statistics file \"%s\"",
4340  statfile)));
4341  goto done;
4342  }
4343 
4344  memcpy(funcentry, &funcbuf, sizeof(funcbuf));
4345  break;
4346 
4347  /*
4348  * 'E' The EOF marker of a complete stats file.
4349  */
4350  case 'E':
4351  goto done;
4352 
4353  default:
4354  ereport(pgStatRunningInCollector ? LOG : WARNING,
4355  (errmsg("corrupted statistics file \"%s\"",
4356  statfile)));
4357  goto done;
4358  }
4359  }
4360 
4361 done:
4362  FreeFile(fpin);
4363 
4364  if (permanent)
4365  {
4366  elog(DEBUG2, "removing permanent stats file \"%s\"", statfile);
4367  unlink(statfile);
4368  }
4369 }
static bool pgStatRunningInCollector
Definition: pgstat.c:178
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
#define LOG
Definition: elog.h:26
#define PG_BINARY_R
Definition: c.h:1273
signed int int32
Definition: c.h:429
#define MAXPGPATH
#define DEBUG2
Definition: elog.h:24
int errcode_for_file_access(void)
Definition: elog.c:721
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2417
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
int FreeFile(FILE *file)
Definition: fd.c:2616
#define PGSTAT_FILE_FORMAT_ID
Definition: pgstat.h:724
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
static void get_dbstat_filename(bool permanent, bool tempname, Oid databaseid, char *filename, int len)
Definition: pgstat.c:3777

◆ pgstat_read_db_statsfile_timestamp()

static bool pgstat_read_db_statsfile_timestamp ( Oid  databaseid,
bool  permanent,
TimestampTz ts 
)
static

Definition at line 4390 of file pgstat.c.

References AllocateFile(), PgStat_StatDBEntry::databaseid, ereport, errcode_for_file_access(), errmsg(), FreeFile(), LOG, offsetof, PG_BINARY_R, PGSTAT_FILE_FORMAT_ID, pgstat_stat_filename, PGSTAT_STAT_PERMANENT_FILENAME, pgStatRunningInCollector, SLRU_NUM_ELEMENTS, PgStat_StatDBEntry::stats_timestamp, PgStat_GlobalStats::stats_timestamp, and WARNING.

Referenced by backend_read_statsfile().

4392 {
4393  PgStat_StatDBEntry dbentry;
4394  PgStat_GlobalStats myGlobalStats;
4395  PgStat_ArchiverStats myArchiverStats;
4396  PgStat_WalStats myWalStats;
4397  PgStat_SLRUStats mySLRUStats[SLRU_NUM_ELEMENTS];
4398  PgStat_StatReplSlotEntry myReplSlotStats;
4399  FILE *fpin;
4400  int32 format_id;
4401  const char *statfile = permanent ? PGSTAT_STAT_PERMANENT_FILENAME : pgstat_stat_filename;
4402 
4403  /*
4404  * Try to open the stats file. As above, anything but ENOENT is worthy of
4405  * complaining about.
4406  */
4407  if ((fpin = AllocateFile(statfile, PG_BINARY_R)) == NULL)
4408  {
4409  if (errno != ENOENT)
4412  errmsg("could not open statistics file \"%s\": %m",
4413  statfile)));
4414  return false;
4415  }
4416 
4417  /*
4418  * Verify it's of the expected format.
4419  */
4420  if (fread(&format_id, 1, sizeof(format_id), fpin) != sizeof(format_id) ||
4421  format_id != PGSTAT_FILE_FORMAT_ID)
4422  {
4423  ereport(pgStatRunningInCollector ? LOG : WARNING,
4424  (errmsg("corrupted statistics file \"%s\"", statfile)));
4425  FreeFile(fpin);
4426  return false;
4427  }
4428 
4429  /*
4430  * Read global stats struct
4431  */
4432  if (fread(&myGlobalStats, 1, sizeof(myGlobalStats),
4433  fpin) != sizeof(myGlobalStats))
4434  {
4435  ereport(pgStatRunningInCollector ? LOG : WARNING,
4436  (errmsg("corrupted statistics file \"%s\"", statfile)));
4437  FreeFile(fpin);
4438  return false;
4439  }
4440 
4441  /*
4442  * Read archiver stats struct
4443  */
4444  if (fread(&myArchiverStats, 1, sizeof(myArchiverStats),
4445  fpin) != sizeof(myArchiverStats))
4446  {
4447  ereport(pgStatRunningInCollector ? LOG : WARNING,
4448  (errmsg("corrupted statistics file \"%s\"", statfile)));
4449  FreeFile(fpin);
4450  return false;
4451  }
4452 
4453  /*
4454  * Read WAL stats struct
4455  */
4456  if (fread(&myWalStats, 1, sizeof(myWalStats), fpin) != sizeof(myWalStats))
4457  {
4458  ereport(pgStatRunningInCollector ? LOG : WARNING,
4459  (errmsg("corrupted statistics file \"%s\"", statfile)));
4460  FreeFile(fpin);
4461  return false;
4462  }
4463 
4464  /*
4465  * Read SLRU stats struct
4466  */
4467  if (fread(mySLRUStats, 1, sizeof(mySLRUStats), fpin) != sizeof(mySLRUStats))
4468  {
4469  ereport(pgStatRunningInCollector ? LOG : WARNING,
4470  (errmsg("corrupted statistics file \"%s\"", statfile)));
4471  FreeFile(fpin);
4472  return false;
4473  }
4474 
4475  /* By default, we're going to return the timestamp of the global file. */
4476  *ts = myGlobalStats.stats_timestamp;
4477 
4478  /*
4479  * We found an existing collector stats file. Read it and look for a
4480  * record for the requested database. If found, use its timestamp.
4481  */
4482  for (;;)
4483  {
4484  switch (fgetc(fpin))
4485  {
4486  /*
4487  * 'D' A PgStat_StatDBEntry struct describing a database
4488  * follows.
4489  */
4490  case 'D':
4491  if (fread(&dbentry, 1, offsetof(PgStat_StatDBEntry, tables),
4492  fpin) != offsetof(PgStat_StatDBEntry, tables))
4493  {
4494  ereport(pgStatRunningInCollector ? LOG : WARNING,
4495  (errmsg("corrupted statistics file \"%s\"",
4496  statfile)));
4497  FreeFile(fpin);
4498  return false;
4499  }
4500 
4501  /*
4502  * If this is the DB we're looking for, save its timestamp and
4503  * we're done.
4504  */
4505  if (dbentry.databaseid == databaseid)
4506  {
4507  *ts = dbentry.stats_timestamp;
4508  goto done;
4509  }
4510 
4511  break;
4512 
4513  /*
4514  * 'R' A PgStat_StatReplSlotEntry struct describing a
4515  * replication slot follows.
4516  */
4517  case 'R':
4518  if (fread(&myReplSlotStats, 1, sizeof(PgStat_StatReplSlotEntry), fpin)
4519  != sizeof(PgStat_StatReplSlotEntry))
4520  {
4521  ereport(pgStatRunningInCollector ? LOG : WARNING,
4522  (errmsg("corrupted statistics file \"%s\"",
4523  statfile)));
4524  FreeFile(fpin);
4525  return false;
4526  }
4527  break;
4528 
4529  case 'E':
4530  goto done;
4531 
4532  default:
4533  {
4534  ereport(pgStatRunningInCollector ? LOG : WARNING,
4535  (errmsg("corrupted statistics file \"%s\"",
4536  statfile)));
4537  FreeFile(fpin);
4538  return false;
4539  }
4540  }
4541  }
4542 
4543 done:
4544  FreeFile(fpin);
4545  return true;
4546 }
TimestampTz stats_timestamp
Definition: pgstat.h:764
#define SLRU_NUM_ELEMENTS
Definition: pgstat.c:158
static bool pgStatRunningInCollector
Definition: pgstat.c:178
TimestampTz stats_timestamp
Definition: pgstat.h:849
#define PGSTAT_STAT_PERMANENT_FILENAME
Definition: pgstat.h:29
#define LOG
Definition: elog.h:26
#define PG_BINARY_R
Definition: c.h:1273
signed int int32
Definition: c.h:429
char * pgstat_stat_filename
Definition: pgstat.c:123
int errcode_for_file_access(void)
Definition: elog.c:721
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2417
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
int FreeFile(FILE *file)
Definition: fd.c:2616
#define PGSTAT_FILE_FORMAT_ID
Definition: pgstat.h:724
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define offsetof(type, field)
Definition: c.h:727

◆ pgstat_read_statsfiles()

static HTAB * pgstat_read_statsfiles ( Oid  onlydb,
bool  permanent,
bool  deep 
)
static

Definition at line 3926 of file pgstat.c.

References AllocateFile(), PgStat_StatDBEntry::databaseid, DEBUG2, elog, HASHCTL::entrysize, ereport, errcode_for_file_access(), errmsg(), FreeFile(), PgStat_StatDBEntry::functions, GetCurrentTimestamp(), HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASHCTL::hcxt, i, InvalidOid, HASHCTL::keysize, LOG, offsetof, PG_BINARY_R, PGSTAT_DB_HASH_SIZE, PGSTAT_FILE_FORMAT_ID, PGSTAT_FUNCTION_HASH_SIZE, pgstat_read_db_statsfile(), PGSTAT_REPLSLOT_HASH_SIZE, pgstat_setup_memcxt(), pgstat_stat_filename, PGSTAT_STAT_PERMANENT_FILENAME, PGSTAT_TAB_HASH_SIZE, pgStatLocalContext, pgStatRunningInCollector, PgStat_StatReplSlotEntry::slotname, SLRU_NUM_ELEMENTS, PgStat_ArchiverStats::stat_reset_timestamp, PgStat_GlobalStats::stat_reset_timestamp, PgStat_WalStats::stat_reset_timestamp, PgStat_StatDBEntry::stats_timestamp, PgStat_GlobalStats::stats_timestamp, PgStat_StatDBEntry::tables, and WARNING.

Referenced by backend_read_statsfile(), and PgstatCollectorMain().

3927 {
3928  PgStat_StatDBEntry *dbentry;
3929  PgStat_StatDBEntry dbbuf;
3930  HASHCTL hash_ctl;
3931  HTAB *dbhash;
3932  FILE *fpin;
3933  int32 format_id;
3934  bool found;
3935  const char *statfile = permanent ? PGSTAT_STAT_PERMANENT_FILENAME : pgstat_stat_filename;
3936  int i;
3937 
3938  /*
3939  * The tables will live in pgStatLocalContext.
3940  */
3942 
3943  /*
3944  * Create the DB hashtable
3945  */
3946  hash_ctl.keysize = sizeof(Oid);
3947  hash_ctl.entrysize = sizeof(PgStat_StatDBEntry);
3948  hash_ctl.hcxt = pgStatLocalContext;
3949  dbhash = hash_create("Databases hash", PGSTAT_DB_HASH_SIZE, &hash_ctl,
3951 
3952  /*
3953  * Clear out global, archiver, WAL and SLRU statistics so they start from
3954  * zero in case we can't load an existing statsfile.
3955  */
3956  memset(&globalStats, 0, sizeof(globalStats));
3957  memset(&archiverStats, 0, sizeof(archiverStats));
3958  memset(&walStats, 0, sizeof(walStats));
3959  memset(&slruStats, 0, sizeof(slruStats));
3960 
3961  /*
3962  * Set the current timestamp (will be kept only in case we can't load an
3963  * existing statsfile).
3964  */
3968 
3969  /*
3970  * Set the same reset timestamp for all SLRU items too.
3971  */
3972  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
3973  slruStats[i].stat_reset_timestamp = globalStats.stat_reset_timestamp;
3974 
3975  /*
3976  * Try to open the stats file. If it doesn't exist, the backends simply
3977  * return zero for anything and the collector simply starts from scratch
3978  * with empty counters.
3979  *
3980  * ENOENT is a possibility if the stats collector is not running or has
3981  * not yet written the stats file the first time. Any other failure
3982  * condition is suspicious.
3983  */
3984  if ((fpin = AllocateFile(statfile, PG_BINARY_R)) == NULL)
3985  {
3986  if (errno != ENOENT)
3989  errmsg("could not open statistics file \"%s\": %m",
3990  statfile)));
3991  return dbhash;
3992  }
3993 
3994  /*
3995  * Verify it's of the expected format.
3996  */
3997  if (fread(&format_id, 1, sizeof(format_id), fpin) != sizeof(format_id) ||
3998  format_id != PGSTAT_FILE_FORMAT_ID)
3999  {
4000  ereport(pgStatRunningInCollector ? LOG : WARNING,
4001  (errmsg("corrupted statistics file \"%s\"", statfile)));
4002  goto done;
4003  }
4004 
4005  /*
4006  * Read global stats struct
4007  */
4008  if (fread(&globalStats, 1, sizeof(globalStats), fpin) != sizeof(globalStats))
4009  {
4010  ereport(pgStatRunningInCollector ? LOG : WARNING,
4011  (errmsg("corrupted statistics file \"%s\"", statfile)));
4012  memset(&globalStats, 0, sizeof(globalStats));
4013  goto done;
4014  }
4015 
4016  /*
4017  * In the collector, disregard the timestamp we read from the permanent
4018  * stats file; we should be willing to write a temp stats file immediately
4019  * upon the first request from any backend. This only matters if the old
4020  * file's timestamp is less than PGSTAT_STAT_INTERVAL ago, but that's not
4021  * an unusual scenario.
4022  */
4025 
4026  /*
4027  * Read archiver stats struct
4028  */
4029  if (fread(&archiverStats, 1, sizeof(archiverStats), fpin) != sizeof(archiverStats))
4030  {
4031  ereport(pgStatRunningInCollector ? LOG : WARNING,
4032  (errmsg("corrupted statistics file \"%s\"", statfile)));
4033  memset(&archiverStats, 0, sizeof(archiverStats));
4034  goto done;
4035  }
4036 
4037  /*
4038  * Read WAL stats struct
4039  */
4040  if (fread(&walStats, 1, sizeof(walStats), fpin) != sizeof(walStats))
4041  {
4042  ereport(pgStatRunningInCollector ? LOG : WARNING,
4043  (errmsg("corrupted statistics file \"%s\"", statfile)));
4044  memset(&walStats, 0, sizeof(walStats));
4045  goto done;
4046  }
4047 
4048  /*
4049  * Read SLRU stats struct
4050  */
4051  if (fread(slruStats, 1, sizeof(slruStats), fpin) != sizeof(slruStats))
4052  {
4053  ereport(pgStatRunningInCollector ? LOG : WARNING,
4054  (errmsg("corrupted statistics file \"%s\"", statfile)));
4055  memset(&slruStats, 0, sizeof(slruStats));
4056  goto done;
4057  }
4058 
4059  /*
4060  * We found an existing collector stats file. Read it and put all the
4061  * hashtable entries into place.
4062  */
4063  for (;;)
4064  {
4065  switch (fgetc(fpin))
4066  {
4067  /*
4068  * 'D' A PgStat_StatDBEntry struct describing a database
4069  * follows.
4070  */
4071  case 'D':
4072  if (fread(&dbbuf, 1, offsetof(PgStat_StatDBEntry, tables),
4073  fpin) != offsetof(PgStat_StatDBEntry, tables))
4074  {
4075  ereport(pgStatRunningInCollector ? LOG : WARNING,
4076  (errmsg("corrupted statistics file \"%s\"",
4077  statfile)));
4078  goto done;
4079  }
4080 
4081  /*
4082  * Add to the DB hash
4083  */
4084  dbentry = (PgStat_StatDBEntry *) hash_search(dbhash,
4085  (void *) &dbbuf.databaseid,
4086  HASH_ENTER,
4087  &found);
4088  if (found)
4089  {
4090  ereport(pgStatRunningInCollector ? LOG : WARNING,
4091  (errmsg("corrupted statistics file \"%s\"",
4092  statfile)));
4093  goto done;
4094  }
4095 
4096  memcpy(dbentry, &dbbuf, sizeof(PgStat_StatDBEntry));
4097  dbentry->tables = NULL;
4098  dbentry->functions = NULL;
4099 
4100  /*
4101  * In the collector, disregard the timestamp we read from the
4102  * permanent stats file; we should be willing to write a temp
4103  * stats file immediately upon the first request from any
4104  * backend.
4105  */
4107  dbentry->stats_timestamp = 0;
4108 
4109  /*
4110  * Don't create tables/functions hashtables for uninteresting
4111  * databases.
4112  */
4113  if (onlydb != InvalidOid)
4114  {
4115  if (dbbuf.databaseid != onlydb &&
4116  dbbuf.databaseid != InvalidOid)
4117  break;
4118  }
4119 
4120  hash_ctl.keysize = sizeof(Oid);
4121  hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
4122  hash_ctl.hcxt = pgStatLocalContext;
4123  dbentry->tables = hash_create("Per-database table",
4125  &hash_ctl,
4127 
4128  hash_ctl.keysize = sizeof(Oid);
4129  hash_ctl.entrysize = sizeof(PgStat_StatFuncEntry);
4130  hash_ctl.hcxt = pgStatLocalContext;
4131  dbentry->functions = hash_create("Per-database function",
4133  &hash_ctl,
4135 
4136  /*
4137  * If requested, read the data from the database-specific
4138  * file. Otherwise we just leave the hashtables empty.
4139  */
4140  if (deep)
4142  dbentry->tables,
4143  dbentry->functions,
4144  permanent);
4145 
4146  break;
4147 
4148  /*
4149  * 'R' A PgStat_StatReplSlotEntry struct describing a
4150  * replication slot follows.
4151  */
4152  case 'R':
4153  {
4154  PgStat_StatReplSlotEntry slotbuf;
4155  PgStat_StatReplSlotEntry *slotent;
4156 
4157  if (fread(&slotbuf, 1, sizeof(PgStat_StatReplSlotEntry), fpin)
4158  != sizeof(PgStat_StatReplSlotEntry))
4159  {
4160  ereport(pgStatRunningInCollector ? LOG : WARNING,
4161  (errmsg("corrupted statistics file \"%s\"",
4162  statfile)));
4163  goto done;
4164  }
4165 
4166  /* Create hash table if we don't have it already. */
4167  if (replSlotStatHash == NULL)
4168  {
4169  HASHCTL hash_ctl;
4170 
4171  hash_ctl.keysize = sizeof(NameData);
4172  hash_ctl.entrysize = sizeof(PgStat_StatReplSlotEntry);
4173  hash_ctl.hcxt = pgStatLocalContext;
4174  replSlotStatHash = hash_create("Replication slots hash",
4176  &hash_ctl,
4178  }
4179 
4181  (void *) &slotbuf.slotname,
4182  HASH_ENTER, NULL);
4183  memcpy(slotent, &slotbuf, sizeof(PgStat_StatReplSlotEntry));
4184  break;
4185  }
4186 
4187  case 'E':
4188  goto done;
4189 
4190  default:
4191  ereport(pgStatRunningInCollector ? LOG : WARNING,
4192  (errmsg("corrupted statistics file \"%s\"",
4193  statfile)));
4194  goto done;
4195  }
4196  }
4197 
4198 done:
4199  FreeFile(fpin);
4200 
4201  /* If requested to read the permanent file, also get rid of it. */
4202  if (permanent)
4203  {
4204  elog(DEBUG2, "removing permanent stats file \"%s\"", statfile);
4205  unlink(statfile);
4206  }
4207 
4208  return dbhash;
4209 }
#define PGSTAT_DB_HASH_SIZE
Definition: pgstat.c:105
TimestampTz stat_reset_timestamp
Definition: pgstat.h:876
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
TimestampTz stats_timestamp
Definition: pgstat.h:764
MemoryContext hcxt
Definition: hsearch.h:86
static PgStat_GlobalStats globalStats
Definition: pgstat.c:278
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
#define SLRU_NUM_ELEMENTS
Definition: pgstat.c:158
struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
static PgStat_WalStats walStats
Definition: pgstat.c:279
#define PGSTAT_TAB_HASH_SIZE
Definition: pgstat.c:106
static bool pgStatRunningInCollector
Definition: pgstat.c:178
HTAB * functions
Definition: pgstat.h:771
Size entrysize
Definition: hsearch.h:76
#define PGSTAT_REPLSLOT_HASH_SIZE
Definition: pgstat.c:108
TimestampTz stats_timestamp
Definition: pgstat.h:849
#define PGSTAT_STAT_PERMANENT_FILENAME
Definition: pgstat.h:29
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
#define LOG
Definition: elog.h:26
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_BINARY_R
Definition: c.h:1273
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
signed int int32
Definition: c.h:429
Definition: dynahash.c:219
char * pgstat_stat_filename
Definition: pgstat.c:123
#define DEBUG2
Definition: elog.h:24
#define PGSTAT_FUNCTION_HASH_SIZE
Definition: pgstat.c:107
int errcode_for_file_access(void)
Definition: elog.c:721
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2417
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
static void pgstat_setup_memcxt(void)
Definition: pgstat.c:4689
static void pgstat_read_db_statsfile(Oid databaseid, HTAB *tabhash, HTAB *funchash, bool permanent)
Definition: pgstat.c:4227
#define WARNING
Definition: elog.h:40
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:157
struct PgStat_StatTabEntry PgStat_StatTabEntry
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:277
TimestampTz stat_reset_timestamp
Definition: pgstat.h:860
struct PgStat_StatDBEntry PgStat_StatDBEntry
int FreeFile(FILE *file)
Definition: fd.c:2616
#define PGSTAT_FILE_FORMAT_ID
Definition: pgstat.h:724
TimestampTz stat_reset_timestamp
Definition: pgstat.h:841
int errmsg(const char *fmt,...)
Definition: elog.c:909
static HTAB * replSlotStatHash
Definition: pgstat.c:281
#define elog(elevel,...)
Definition: elog.h:232
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:280
int i
static MemoryContext pgStatLocalContext
Definition: pgstat.c:269
struct nameData NameData
#define offsetof(type, field)
Definition: c.h:727

◆ pgstat_recv_analyze()

static void pgstat_recv_analyze ( PgStat_MsgAnalyze msg,
int  len 
)
static

Definition at line 5250 of file pgstat.c.

References PgStat_StatTabEntry::analyze_count, PgStat_StatTabEntry::analyze_timestamp, PgStat_StatTabEntry::autovac_analyze_count, PgStat_StatTabEntry::autovac_analyze_timestamp, PgStat_StatTabEntry::changes_since_analyze, PgStat_StatTabEntry::changes_since_analyze_reported, PgStat_MsgAnalyze::m_analyzetime, PgStat_MsgAnalyze::m_autovacuum, PgStat_MsgAnalyze::m_databaseid, PgStat_MsgAnalyze::m_dead_tuples, PgStat_MsgAnalyze::m_live_tuples, PgStat_MsgAnalyze::m_resetcounter, PgStat_MsgAnalyze::m_tableoid, PgStat_StatTabEntry::n_dead_tuples, PgStat_StatTabEntry::n_live_tuples, pgstat_get_db_entry(), and pgstat_get_tab_entry().

Referenced by PgstatCollectorMain().

5251 {
5252  PgStat_StatDBEntry *dbentry;
5253  PgStat_StatTabEntry *tabentry;
5254 
5255  /*
5256  * Store the data in the table's hashtable entry.
5257  */
5258  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5259 
5260  tabentry = pgstat_get_tab_entry(dbentry, msg->m_tableoid, true);
5261 
5262  tabentry->n_live_tuples = msg->m_live_tuples;
5263  tabentry->n_dead_tuples = msg->m_dead_tuples;
5264 
5265  /*
5266  * If commanded, reset changes_since_analyze to zero. This forgets any
5267  * changes that were committed while the ANALYZE was in progress, but we
5268  * have no good way to estimate how many of those there were.
5269  */
5270  if (msg->m_resetcounter)
5271  {
5272  tabentry->changes_since_analyze = 0;
5273  tabentry->changes_since_analyze_reported = 0;
5274  }
5275 
5276  if (msg->m_autovacuum)
5277  {
5278  tabentry->autovac_analyze_timestamp = msg->m_analyzetime;
5279  tabentry->autovac_analyze_count++;
5280  }
5281  else
5282  {
5283  tabentry->analyze_timestamp = msg->m_analyzetime;
5284  tabentry->analyze_count++;
5285  }
5286 }
PgStat_Counter analyze_count
Definition: pgstat.h:807
static PgStat_StatTabEntry * pgstat_get_tab_entry(PgStat_StatDBEntry *dbentry, Oid tableoid, bool create)
Definition: pgstat.c:3564
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:808
TimestampTz m_analyzetime
Definition: pgstat.h:428
bool m_resetcounter
Definition: pgstat.h:427
PgStat_Counter n_live_tuples
Definition: pgstat.h:793
PgStat_Counter n_dead_tuples
Definition: pgstat.h:794
PgStat_Counter m_live_tuples
Definition: pgstat.h:429
bool m_autovacuum
Definition: pgstat.h:426
TimestampTz analyze_timestamp
Definition: pgstat.h:806
PgStat_Counter changes_since_analyze
Definition: pgstat.h:795
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:809
PgStat_Counter changes_since_analyze_reported
Definition: pgstat.h:796
PgStat_Counter m_dead_tuples
Definition: pgstat.h:430

◆ pgstat_recv_anl_ancestors()

static void pgstat_recv_anl_ancestors ( PgStat_MsgAnlAncestors msg,
int  len 
)
static

Definition at line 5289 of file pgstat.c.

References PgStat_StatTabEntry::changes_since_analyze, PgStat_StatTabEntry::changes_since_analyze_reported, i, PgStat_MsgAnlAncestors::m_ancestors, PgStat_MsgAnlAncestors::m_databaseid, PgStat_MsgAnlAncestors::m_nancestors, PgStat_MsgAnlAncestors::m_tableoid, pgstat_get_db_entry(), and pgstat_get_tab_entry().

Referenced by PgstatCollectorMain().

5290 {
5291  PgStat_StatDBEntry *dbentry;
5292  PgStat_StatTabEntry *tabentry;
5293 
5294  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5295 
5296  tabentry = pgstat_get_tab_entry(dbentry, msg->m_tableoid, true);
5297 
5298  for (int i = 0; i < msg->m_nancestors; i++)
5299  {
5300  Oid ancestor_relid = msg->m_ancestors[i];
5301  PgStat_StatTabEntry *ancestor;
5302 
5303  ancestor = pgstat_get_tab_entry(dbentry, ancestor_relid, true);
5304  ancestor->changes_since_analyze +=
5306  }
5307 
5309 
5310 }
static PgStat_StatTabEntry * pgstat_get_tab_entry(PgStat_StatDBEntry *dbentry, Oid tableoid, bool create)
Definition: pgstat.c:3564
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter changes_since_analyze
Definition: pgstat.h:795
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
Oid m_ancestors[PGSTAT_NUM_ANCESTORENTRIES]
Definition: pgstat.h:450
PgStat_Counter changes_since_analyze_reported
Definition: pgstat.h:796
int i

◆ pgstat_recv_archiver()

static void pgstat_recv_archiver ( PgStat_MsgArchiver msg,
int  len 
)
static

Definition at line 5319 of file pgstat.c.

References PgStat_ArchiverStats::archived_count, PgStat_ArchiverStats::failed_count, PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, PgStat_MsgArchiver::m_failed, PgStat_MsgArchiver::m_timestamp, and PgStat_MsgArchiver::m_xlog.

Referenced by PgstatCollectorMain().

5320 {
5321  if (msg->m_failed)
5322  {
5323  /* Failed archival attempt */
5325  memcpy(archiverStats.last_failed_wal, msg->m_xlog,
5326  sizeof(archiverStats.last_failed_wal));
5328  }
5329  else
5330  {
5331  /* Successful archival operation */
5333  memcpy(archiverStats.last_archived_wal, msg->m_xlog,
5336  }
5337 }
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:838
char m_xlog[MAX_XFN_CHARS+1]
Definition: pgstat.h:461
PgStat_Counter archived_count
Definition: pgstat.h:833
TimestampTz m_timestamp
Definition: pgstat.h:462
TimestampTz last_failed_timestamp
Definition: pgstat.h:840
PgStat_Counter failed_count
Definition: pgstat.h:837
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:277
TimestampTz last_archived_timestamp
Definition: pgstat.h:836
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:834

◆ pgstat_recv_autovac()

static void pgstat_recv_autovac ( PgStat_MsgAutovacStart msg,
int  len 
)
static

Definition at line 5185 of file pgstat.c.

References PgStat_StatDBEntry::last_autovac_time, PgStat_MsgAutovacStart::m_databaseid, PgStat_MsgAutovacStart::m_start_time, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5186 {
5187  PgStat_StatDBEntry *dbentry;
5188 
5189  /*
5190  * Store the last autovacuum time in the database's hashtable entry.
5191  */
5192  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5193 
5194  dbentry->last_autovac_time = msg->m_start_time;
5195 }
TimestampTz last_autovac_time
Definition: pgstat.h:742
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
TimestampTz m_start_time
Definition: pgstat.h:395

◆ pgstat_recv_bgwriter()

static void pgstat_recv_bgwriter ( PgStat_MsgBgWriter msg,
int  len 
)
static

Definition at line 5346 of file pgstat.c.

References PgStat_GlobalStats::buf_alloc, PgStat_GlobalStats::buf_fsync_backend, PgStat_GlobalStats::buf_written_backend, PgStat_GlobalStats::buf_written_checkpoints, PgStat_GlobalStats::buf_written_clean, PgStat_GlobalStats::checkpoint_sync_time, PgStat_GlobalStats::checkpoint_write_time, PgStat_MsgBgWriter::m_buf_alloc, PgStat_MsgBgWriter::m_buf_fsync_backend, PgStat_MsgBgWriter::m_buf_written_backend, PgStat_MsgBgWriter::m_buf_written_checkpoints, PgStat_MsgBgWriter::m_buf_written_clean, PgStat_MsgBgWriter::m_checkpoint_sync_time, PgStat_MsgBgWriter::m_checkpoint_write_time, PgStat_MsgBgWriter::m_maxwritten_clean, PgStat_MsgBgWriter::m_requested_checkpoints, PgStat_MsgBgWriter::m_timed_checkpoints, PgStat_GlobalStats::maxwritten_clean, PgStat_GlobalStats::requested_checkpoints, and PgStat_GlobalStats::timed_checkpoints.

Referenced by PgstatCollectorMain().

5347 {
5358 }
PgStat_Counter m_buf_fsync_backend
Definition: pgstat.h:479
PgStat_Counter buf_alloc
Definition: pgstat.h:859
PgStat_Counter m_buf_written_checkpoints
Definition: pgstat.h:475
PgStat_Counter m_buf_alloc
Definition: pgstat.h:480
PgStat_Counter m_checkpoint_write_time
Definition: pgstat.h:481
static PgStat_GlobalStats globalStats
Definition: pgstat.c:278
PgStat_Counter m_timed_checkpoints
Definition: pgstat.h:473
PgStat_Counter m_maxwritten_clean
Definition: pgstat.h:477
PgStat_Counter timed_checkpoints
Definition: pgstat.h:850
PgStat_Counter m_buf_written_clean
Definition: pgstat.h:476
PgStat_Counter buf_fsync_backend
Definition: pgstat.h:858
PgStat_Counter m_requested_checkpoints
Definition: pgstat.h:474
PgStat_Counter buf_written_backend
Definition: pgstat.h:857
PgStat_Counter checkpoint_write_time
Definition: pgstat.h:852
PgStat_Counter buf_written_checkpoints
Definition: pgstat.h:854
PgStat_Counter buf_written_clean
Definition: pgstat.h:855
PgStat_Counter m_checkpoint_sync_time
Definition: pgstat.h:482
PgStat_Counter m_buf_written_backend
Definition: pgstat.h:478
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:853
PgStat_Counter maxwritten_clean
Definition: pgstat.h:856
PgStat_Counter requested_checkpoints
Definition: pgstat.h:851

◆ pgstat_recv_checksum_failure()

static void pgstat_recv_checksum_failure ( PgStat_MsgChecksumFailure msg,
int  len 
)
static

Definition at line 5460 of file pgstat.c.

References PgStat_StatDBEntry::last_checksum_failure, PgStat_MsgChecksumFailure::m_databaseid, PgStat_MsgChecksumFailure::m_failure_time, PgStat_MsgChecksumFailure::m_failurecount, PgStat_StatDBEntry::n_checksum_failures, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5461 {
5462  PgStat_StatDBEntry *dbentry;
5463 
5464  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5465 
5466  dbentry->n_checksum_failures += msg->m_failurecount;
5467  dbentry->last_checksum_failure = msg->m_failure_time;
5468 }
PgStat_Counter n_checksum_failures
Definition: pgstat.h:751
TimestampTz last_checksum_failure
Definition: pgstat.h:752
TimestampTz m_failure_time
Definition: pgstat.h:661
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533

◆ pgstat_recv_connstat()

static void pgstat_recv_connstat ( PgStat_MsgConn msg,
int  len 
)
static

Definition at line 5528 of file pgstat.c.

References DISCONNECT_CLIENT_EOF, DISCONNECT_FATAL, DISCONNECT_KILLED, DISCONNECT_NORMAL, DISCONNECT_NOT_YET, PgStat_MsgConn::m_active_time, PgStat_MsgConn::m_count, PgStat_MsgConn::m_databaseid, PgStat_MsgConn::m_disconnect, PgStat_MsgConn::m_idle_in_xact_time, PgStat_MsgConn::m_session_time, PgStat_StatDBEntry::n_sessions, PgStat_StatDBEntry::n_sessions_abandoned, PgStat_StatDBEntry::n_sessions_fatal, PgStat_StatDBEntry::n_sessions_killed, pgstat_get_db_entry(), PgStat_StatDBEntry::total_active_time, PgStat_StatDBEntry::total_idle_in_xact_time, and PgStat_StatDBEntry::total_session_time.

Referenced by PgstatCollectorMain().

5529 {
5530  PgStat_StatDBEntry *dbentry;
5531 
5532  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5533 
5534  dbentry->n_sessions += msg->m_count;
5535  dbentry->total_session_time += msg->m_session_time;
5536  dbentry->total_active_time += msg->m_active_time;
5538  switch (msg->m_disconnect)
5539  {
5540  case DISCONNECT_NOT_YET:
5541  case DISCONNECT_NORMAL:
5542  /* we don't collect these */
5543  break;
5544  case DISCONNECT_CLIENT_EOF:
5545  dbentry->n_sessions_abandoned++;
5546  break;
5547  case DISCONNECT_FATAL:
5548  dbentry->n_sessions_fatal++;
5549  break;
5550  case DISCONNECT_KILLED:
5551  dbentry->n_sessions_killed++;
5552  break;
5553  }
5554 }
PgStat_Counter m_active_time
Definition: pgstat.h:674
PgStat_Counter n_sessions_killed
Definition: pgstat.h:761
Oid m_databaseid
Definition: pgstat.h:671
PgStat_Counter total_active_time
Definition: pgstat.h:757
PgStat_Counter n_sessions_abandoned
Definition: pgstat.h:759
PgStat_Counter n_sessions_fatal
Definition: pgstat.h:760
PgStat_Counter total_idle_in_xact_time
Definition: pgstat.h:758
PgStat_Counter total_session_time
Definition: pgstat.h:756
PgStat_Counter m_idle_in_xact_time
Definition: pgstat.h:675
PgStat_Counter n_sessions
Definition: pgstat.h:755
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
PgStat_Counter m_session_time
Definition: pgstat.h:673
PgStat_Counter m_count
Definition: pgstat.h:672
SessionEndType m_disconnect
Definition: pgstat.h:676

◆ pgstat_recv_deadlock()

static void pgstat_recv_deadlock ( PgStat_MsgDeadlock msg,
int  len 
)
static

Definition at line 5444 of file pgstat.c.

References PgStat_MsgDeadlock::m_databaseid, PgStat_StatDBEntry::n_deadlocks, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5445 {
5446  PgStat_StatDBEntry *dbentry;
5447 
5448  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5449 
5450  dbentry->n_deadlocks++;
5451 }
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
PgStat_Counter n_deadlocks
Definition: pgstat.h:750

◆ pgstat_recv_dropdb()

static void pgstat_recv_dropdb ( PgStat_MsgDropdb msg,
int  len 
)
static

Definition at line 4973 of file pgstat.c.

References DEBUG2, elog, ereport, errmsg(), ERROR, PgStat_StatDBEntry::functions, get_dbstat_filename(), hash_destroy(), HASH_REMOVE, hash_search(), PgStat_MsgDropdb::m_databaseid, MAXPGPATH, pgstat_get_db_entry(), and PgStat_StatDBEntry::tables.

Referenced by PgstatCollectorMain().

4974 {
4975  Oid dbid = msg->m_databaseid;
4976  PgStat_StatDBEntry *dbentry;
4977 
4978  /*
4979  * Lookup the database in the hashtable.
4980  */
4981  dbentry = pgstat_get_db_entry(dbid, false);
4982 
4983  /*
4984  * If found, remove it (along with the db statfile).
4985  */
4986  if (dbentry)
4987  {
4988  char statfile[MAXPGPATH];
4989 
4990  get_dbstat_filename(false, false, dbid, statfile, MAXPGPATH);
4991 
4992  elog(DEBUG2, "removing stats file \"%s\"", statfile);
4993  unlink(statfile);
4994 
4995  if (dbentry->tables != NULL)
4996  hash_destroy(dbentry->tables);
4997  if (dbentry->functions != NULL)
4998  hash_destroy(dbentry->functions);
4999 
5001  (void *) &dbid,
5002  HASH_REMOVE, NULL) == NULL)
5003  ereport(ERROR,
5004  (errmsg("database hash table corrupted during cleanup --- abort")));
5005  }
5006 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
HTAB * functions
Definition: pgstat.h:771
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:46
#define MAXPGPATH
#define DEBUG2
Definition: elog.h:24
Oid m_databaseid
Definition: pgstat.h:324
#define ereport(elevel,...)
Definition: elog.h:157
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
static HTAB * pgStatDBHash
Definition: pgstat.c:270
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
static void get_dbstat_filename(bool permanent, bool tempname, Oid databaseid, char *filename, int len)
Definition: pgstat.c:3777

◆ pgstat_recv_funcpurge()

static void pgstat_recv_funcpurge ( PgStat_MsgFuncpurge msg,
int  len 
)
static

Definition at line 5628 of file pgstat.c.

References PgStat_StatDBEntry::functions, HASH_REMOVE, hash_search(), i, PgStat_MsgFuncpurge::m_databaseid, PgStat_MsgFuncpurge::m_functionid, PgStat_MsgFuncpurge::m_nentries, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5629 {
5630  PgStat_StatDBEntry *dbentry;
5631  int i;
5632 
5633  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5634 
5635  /*
5636  * No need to purge if we don't even know the database.
5637  */
5638  if (!dbentry || !dbentry->functions)
5639  return;
5640 
5641  /*
5642  * Process all function entries in the message.
5643  */
5644  for (i = 0; i < msg->m_nentries; i++)
5645  {
5646  /* Remove from hashtable if present; we don't care if it's not. */
5647  (void) hash_search(dbentry->functions,
5648  (void *) &(msg->m_functionid[i]),
5649  HASH_REMOVE, NULL);
5650  }
5651 }
HTAB * functions
Definition: pgstat.h:771
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
int i
Oid m_functionid[PGSTAT_NUM_FUNCPURGE]
Definition: pgstat.h:637

◆ pgstat_recv_funcstat()

static void pgstat_recv_funcstat ( PgStat_MsgFuncstat msg,
int  len 
)
static

Definition at line 5580 of file pgstat.c.

References PgStat_FunctionEntry::f_id, PgStat_FunctionEntry::f_numcalls, PgStat_StatFuncEntry::f_numcalls, PgStat_FunctionEntry::f_self_time, PgStat_StatFuncEntry::f_self_time, PgStat_FunctionEntry::f_total_time, PgStat_StatFuncEntry::f_total_time, PgStat_StatDBEntry::functions, HASH_ENTER, hash_search(), i, PgStat_MsgFuncstat::m_databaseid, PgStat_MsgFuncstat::m_entry, PgStat_MsgFuncstat::m_nentries, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5581 {
5582  PgStat_FunctionEntry *funcmsg = &(msg->m_entry[0]);
5583  PgStat_StatDBEntry *dbentry;
5584  PgStat_StatFuncEntry *funcentry;
5585  int i;
5586  bool found;
5587 
5588  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5589 
5590  /*
5591  * Process all function entries in the message.
5592  */
5593  for (i = 0; i < msg->m_nentries; i++, funcmsg++)
5594  {
5595  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
5596  (void *) &(funcmsg->f_id),
5597  HASH_ENTER, &found);
5598 
5599  if (!found)
5600  {
5601  /*
5602  * If it's a new function entry, initialize counters to the values
5603  * we just got.
5604  */
5605  funcentry->f_numcalls = funcmsg->f_numcalls;
5606  funcentry->f_total_time = funcmsg->f_total_time;
5607  funcentry->f_self_time = funcmsg->f_self_time;
5608  }
5609  else
5610  {
5611  /*
5612  * Otherwise add the values to the existing entry.
5613  */
5614  funcentry->f_numcalls += funcmsg->f_numcalls;
5615  funcentry->f_total_time += funcmsg->f_total_time;
5616  funcentry->f_self_time += funcmsg->f_self_time;
5617  }
5618  }
5619 }
PgStat_Counter f_self_time
Definition: pgstat.h:603
HTAB * functions
Definition: pgstat.h:771
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter f_total_time
Definition: pgstat.h:823
PgStat_Counter f_numcalls
Definition: pgstat.h:821
PgStat_Counter f_total_time
Definition: pgstat.h:602
PgStat_FunctionEntry m_entry[PGSTAT_NUM_FUNCENTRIES]
Definition: pgstat.h:620
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
int i
PgStat_Counter f_numcalls
Definition: pgstat.h:601
PgStat_Counter f_self_time
Definition: pgstat.h:824

◆ pgstat_recv_inquiry()

static void pgstat_recv_inquiry ( PgStat_MsgInquiry msg,
int  len 
)
static

Definition at line 4736 of file pgstat.c.

References PgStat_MsgInquiry::clock_time, PgStat_MsgInquiry::cutoff_time, PgStat_MsgInquiry::databaseid, PgStat_StatDBEntry::databaseid, DEBUG2, elog, ereport, errmsg(), GetCurrentTimestamp(), lappend_oid(), list_member_oid(), LOG, pfree(), pgstat_get_db_entry(), pstrdup(), PgStat_StatDBEntry::stats_timestamp, and timestamptz_to_str().

Referenced by PgstatCollectorMain().

4737 {
4738  PgStat_StatDBEntry *dbentry;
4739 
4740  elog(DEBUG2, "received inquiry for database %u", msg->databaseid);
4741 
4742  /*
4743  * If there's already a write request for this DB, there's nothing to do.
4744  *
4745  * Note that if a request is found, we return early and skip the below
4746  * check for clock skew. This is okay, since the only way for a DB
4747  * request to be present in the list is that we have been here since the
4748  * last write round. It seems sufficient to check for clock skew once per
4749  * write round.
4750  */
4752  return;
4753 
4754  /*
4755  * Check to see if we last wrote this database at a time >= the requested
4756  * cutoff time. If so, this is a stale request that was generated before
4757  * we updated the DB file, and we don't need to do so again.
4758  *
4759  * If the requestor's local clock time is older than stats_timestamp, we
4760  * should suspect a clock glitch, ie system time going backwards; though
4761  * the more likely explanation is just delayed message receipt. It is
4762  * worth expending a GetCurrentTimestamp call to be sure, since a large
4763  * retreat in the system clock reading could otherwise cause us to neglect
4764  * to update the stats file for a long time.
4765  */
4766  dbentry = pgstat_get_db_entry(msg->databaseid, false);
4767  if (dbentry == NULL)
4768  {
4769  /*
4770  * We have no data for this DB. Enter a write request anyway so that
4771  * the global stats will get updated. This is needed to prevent
4772  * backend_read_statsfile from waiting for data that we cannot supply,
4773  * in the case of a new DB that nobody has yet reported any stats for.
4774  * See the behavior of pgstat_read_db_statsfile_timestamp.
4775  */
4776  }
4777  else if (msg->clock_time < dbentry->stats_timestamp)
4778  {
4779  TimestampTz cur_ts = GetCurrentTimestamp();
4780 
4781  if (cur_ts < dbentry->stats_timestamp)
4782  {
4783  /*
4784  * Sure enough, time went backwards. Force a new stats file write
4785  * to get back in sync; but first, log a complaint.
4786  */
4787  char *writetime;
4788  char *mytime;
4789 
4790  /* Copy because timestamptz_to_str returns a static buffer */
4791  writetime = pstrdup(timestamptz_to_str(dbentry->stats_timestamp));
4792  mytime = pstrdup(timestamptz_to_str(cur_ts));
4793  ereport(LOG,
4794  (errmsg("stats_timestamp %s is later than collector's time %s for database %u",
4795  writetime, mytime, dbentry->databaseid)));
4796  pfree(writetime);
4797  pfree(mytime);
4798  }
4799  else
4800  {
4801  /*
4802  * Nope, it's just an old request. Assuming msg's clock_time is
4803  * >= its cutoff_time, it must be stale, so we can ignore it.
4804  */
4805  return;
4806  }
4807  }
4808  else if (msg->cutoff_time <= dbentry->stats_timestamp)
4809  {
4810  /* Stale request, ignore it */
4811  return;
4812  }
4813 
4814  /*
4815  * We need to write this DB, so create a request.
4816  */
4818  msg->databaseid);
4819 }
TimestampTz stats_timestamp
Definition: pgstat.h:764
static List * pending_write_requests
Definition: pgstat.c:288
TimestampTz clock_time
Definition: pgstat.h:260
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
char * pstrdup(const char *in)
Definition: mcxt.c:1299
#define LOG
Definition: elog.h:26
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
void pfree(void *pointer)
Definition: mcxt.c:1169
#define DEBUG2
Definition: elog.h:24
#define ereport(elevel,...)
Definition: elog.h:157
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
TimestampTz cutoff_time
Definition: pgstat.h:261
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
const char * timestamptz_to_str(TimestampTz t)
Definition: timestamp.c:1774

◆ pgstat_recv_recoveryconflict()

static void pgstat_recv_recoveryconflict ( PgStat_MsgRecoveryConflict msg,
int  len 
)
static

Definition at line 5404 of file pgstat.c.

References PgStat_MsgRecoveryConflict::m_databaseid, PgStat_MsgRecoveryConflict::m_reason, 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_get_db_entry(), 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 PgstatCollectorMain().

5405 {
5406  PgStat_StatDBEntry *dbentry;
5407 
5408  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5409 
5410  switch (msg->m_reason)
5411  {
5413 
5414  /*
5415  * Since we drop the information about the database as soon as it
5416  * replicates, there is no point in counting these conflicts.
5417  */
5418  break;
5420  dbentry->n_conflict_tablespace++;
5421  break;
5423  dbentry->n_conflict_lock++;
5424  break;
5426  dbentry->n_conflict_snapshot++;
5427  break;
5429  dbentry->n_conflict_bufferpin++;
5430  break;
5432  dbentry->n_conflict_startup_deadlock++;
5433  break;
5434  }
5435 }
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:746
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:747
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:743
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:745
PgStat_Counter n_conflict_lock
Definition: pgstat.h:744
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533

◆ pgstat_recv_replslot()

static void pgstat_recv_replslot ( PgStat_MsgReplSlot msg,
int  len 
)
static

Definition at line 5477 of file pgstat.c.

References Assert, HASH_REMOVE, hash_search(), PgStat_MsgReplSlot::m_create, PgStat_MsgReplSlot::m_drop, PgStat_MsgReplSlot::m_slotname, PgStat_MsgReplSlot::m_spill_bytes, PgStat_MsgReplSlot::m_spill_count, PgStat_MsgReplSlot::m_spill_txns, PgStat_MsgReplSlot::m_stream_bytes, PgStat_MsgReplSlot::m_stream_count, PgStat_MsgReplSlot::m_stream_txns, PgStat_MsgReplSlot::m_total_bytes, PgStat_MsgReplSlot::m_total_txns, pgstat_get_replslot_entry(), pgstat_reset_replslot(), PgStat_StatReplSlotEntry::spill_bytes, PgStat_StatReplSlotEntry::spill_count, PgStat_StatReplSlotEntry::spill_txns, PgStat_StatReplSlotEntry::stream_bytes, PgStat_StatReplSlotEntry::stream_count, PgStat_StatReplSlotEntry::stream_txns, PgStat_StatReplSlotEntry::total_bytes, and PgStat_StatReplSlotEntry::total_txns.

Referenced by PgstatCollectorMain().

5478 {
5479  if (msg->m_drop)
5480  {
5481  Assert(!msg->m_create);
5482 
5483  /* Remove the replication slot statistics with the given name */
5484  if (replSlotStatHash != NULL)
5486  (void *) &(msg->m_slotname),
5487  HASH_REMOVE,
5488  NULL);
5489  }
5490  else
5491  {
5492  PgStat_StatReplSlotEntry *slotent;
5493 
5494  slotent = pgstat_get_replslot_entry(msg->m_slotname, true);
5495  Assert(slotent);
5496 
5497  if (msg->m_create)
5498  {
5499  /*
5500  * If the message for dropping the slot with the same name gets
5501  * lost, slotent has stats for the old slot. So we initialize all
5502  * counters at slot creation.
5503  */
5504  pgstat_reset_replslot(slotent, 0);
5505  }
5506  else
5507  {
5508  /* Update the replication slot statistics */
5509  slotent->spill_txns += msg->m_spill_txns;
5510  slotent->spill_count += msg->m_spill_count;
5511  slotent->spill_bytes += msg->m_spill_bytes;
5512  slotent->stream_txns += msg->m_stream_txns;
5513  slotent->stream_count += msg->m_stream_count;
5514  slotent->stream_bytes += msg->m_stream_bytes;
5515  slotent->total_txns += msg->m_total_txns;
5516  slotent->total_bytes += msg->m_total_bytes;
5517  }
5518  }
5519 }
static void pgstat_reset_replslot(PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
Definition: pgstat.c:5757
PgStat_Counter spill_bytes
Definition: pgstat.h:902
PgStat_Counter m_spill_bytes
Definition: pgstat.h:534
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter m_stream_bytes
Definition: pgstat.h:537
PgStat_Counter m_spill_txns
Definition: pgstat.h:532
PgStat_Counter total_bytes
Definition: pgstat.h:907
PgStat_Counter stream_bytes
Definition: pgstat.h:905
PgStat_Counter spill_txns
Definition: pgstat.h:900
PgStat_Counter m_stream_txns
Definition: pgstat.h:535
#define Assert(condition)
Definition: c.h:804
static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry(NameData name, bool create_it)
Definition: pgstat.c:5704
PgStat_Counter m_total_txns
Definition: pgstat.h:538
PgStat_Counter m_spill_count
Definition: pgstat.h:533
PgStat_Counter m_total_bytes
Definition: pgstat.h:539
PgStat_Counter spill_count
Definition: pgstat.h:901
static HTAB * replSlotStatHash
Definition: pgstat.c:281
PgStat_Counter stream_count
Definition: pgstat.h:904
PgStat_Counter total_txns
Definition: pgstat.h:906
PgStat_Counter m_stream_count
Definition: pgstat.h:536
NameData m_slotname
Definition: pgstat.h:529
PgStat_Counter stream_txns
Definition: pgstat.h:903

◆ pgstat_recv_resetcounter()

static void pgstat_recv_resetcounter ( PgStat_MsgResetcounter msg,
int  len 
)
static

Definition at line 5016 of file pgstat.c.

References PgStat_StatDBEntry::functions, hash_destroy(), PgStat_MsgResetcounter::m_databaseid, pgstat_get_db_entry(), reset_dbentry_counters(), and PgStat_StatDBEntry::tables.

Referenced by PgstatCollectorMain().

5017 {
5018  PgStat_StatDBEntry *dbentry;
5019 
5020  /*
5021  * Lookup the database in the hashtable. Nothing to do if not there.
5022  */
5023  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5024 
5025  if (!dbentry)
5026  return;
5027 
5028  /*
5029  * We simply throw away all the database's table entries by recreating a
5030  * new hash table for them.
5031  */
5032  if (dbentry->tables != NULL)
5033  hash_destroy(dbentry->tables);
5034  if (dbentry->functions != NULL)
5035  hash_destroy(dbentry->functions);
5036 
5037  dbentry->tables = NULL;
5038  dbentry->functions = NULL;
5039 
5040  /*
5041  * Reset database-level stats, too. This creates empty hash tables for
5042  * tables and functions.
5043  */
5044  reset_dbentry_counters(dbentry);
5045 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
HTAB * functions
Definition: pgstat.h:771
static void reset_dbentry_counters(PgStat_StatDBEntry *dbentry)
Definition: pgstat.c:3475
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533

◆ pgstat_recv_resetreplslotcounter()

static void pgstat_recv_resetreplslotcounter ( PgStat_MsgResetreplslotcounter msg,
int  len 
)
static

Definition at line 5139 of file pgstat.c.

References PgStat_MsgResetreplslotcounter::clearall, GetCurrentTimestamp(), hash_seq_init(), hash_seq_search(), PgStat_MsgResetreplslotcounter::m_slotname, pgstat_get_replslot_entry(), and pgstat_reset_replslot().

Referenced by PgstatCollectorMain().

5141 {
5142  PgStat_StatReplSlotEntry *slotent;
5143  TimestampTz ts;
5144 
5145  /* Return if we don't have replication slot statistics */
5146  if (replSlotStatHash == NULL)
5147  return;
5148 
5149  ts = GetCurrentTimestamp();
5150  if (msg->clearall)
5151  {
5152  HASH_SEQ_STATUS sstat;
5153 
5155  while ((slotent = (PgStat_StatReplSlotEntry *) hash_seq_search(&sstat)) != NULL)
5156  pgstat_reset_replslot(slotent, ts);
5157  }
5158  else
5159  {
5160  /* Get the slot statistics to reset */
5161  slotent = pgstat_get_replslot_entry(msg->m_slotname, false);
5162 
5163  /*
5164  * Nothing to do if the given slot entry is not found. This could
5165  * happen when the slot with the given name is removed and the
5166  * corresponding statistics entry is also removed before receiving the
5167  * reset message.
5168  */
5169  if (!slotent)
5170  return;
5171 
5172  /* Reset the stats for the requested replication slot */
5173  pgstat_reset_replslot(slotent, ts);
5174  }
5175 }
static void pgstat_reset_replslot(PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
Definition: pgstat.c:5757
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry(NameData name, bool create_it)
Definition: pgstat.c:5704
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
static HTAB * replSlotStatHash
Definition: pgstat.c:281

◆ pgstat_recv_resetsharedcounter()

static void pgstat_recv_resetsharedcounter ( PgStat_MsgResetsharedcounter msg,
int  len 
)
static

Definition at line 5054 of file pgstat.c.

References GetCurrentTimestamp(), PgStat_MsgResetsharedcounter::m_resettarget, RESET_ARCHIVER, RESET_BGWRITER, RESET_WAL, PgStat_ArchiverStats::stat_reset_timestamp, PgStat_GlobalStats::stat_reset_timestamp, and PgStat_WalStats::stat_reset_timestamp.

Referenced by PgstatCollectorMain().

5055 {
5056  if (msg->m_resettarget == RESET_BGWRITER)
5057  {
5058  /* Reset the global background writer statistics for the cluster. */
5059  memset(&globalStats, 0, sizeof(globalStats));
5061  }
5062  else if (msg->m_resettarget == RESET_ARCHIVER)
5063  {
5064  /* Reset the archiver statistics for the cluster. */
5065  memset(&archiverStats, 0, sizeof(archiverStats));
5067  }
5068  else if (msg->m_resettarget == RESET_WAL)
5069  {
5070  /* Reset the WAL statistics for the cluster. */
5071  memset(&walStats, 0, sizeof(walStats));
5073  }
5074 
5075  /*
5076  * Presumably the sender of this message validated the target, don't
5077  * complain here if it's not valid
5078  */
5079 }
TimestampTz stat_reset_timestamp
Definition: pgstat.h:876
static PgStat_GlobalStats globalStats
Definition: pgstat.c:278
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
static PgStat_WalStats walStats
Definition: pgstat.c:279
PgStat_Shared_Reset_Target m_resettarget
Definition: pgstat.h:347
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:277
TimestampTz stat_reset_timestamp
Definition: pgstat.h:860
TimestampTz stat_reset_timestamp
Definition: pgstat.h:841

◆ pgstat_recv_resetsinglecounter()

static void pgstat_recv_resetsinglecounter ( PgStat_MsgResetsinglecounter msg,
int  len 
)
static

Definition at line 5088 of file pgstat.c.

References PgStat_StatDBEntry::functions, GetCurrentTimestamp(), HASH_REMOVE, hash_search(), PgStat_MsgResetsinglecounter::m_databaseid, PgStat_MsgResetsinglecounter::m_objectid, PgStat_MsgResetsinglecounter::m_resettype, pgstat_get_db_entry(), RESET_FUNCTION, RESET_TABLE, PgStat_StatDBEntry::stat_reset_timestamp, and PgStat_StatDBEntry::tables.

Referenced by PgstatCollectorMain().

5089 {
5090  PgStat_StatDBEntry *dbentry;
5091 
5092  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5093 
5094  if (!dbentry)
5095  return;
5096 
5097  /* Set the reset timestamp for the whole database */
5099 
5100  /* Remove object if it exists, ignore it if not */
5101  if (msg->m_resettype == RESET_TABLE)
5102  (void) hash_search(dbentry->tables, (void *) &(msg->m_objectid),
5103  HASH_REMOVE, NULL);
5104  else if (msg->m_resettype == RESET_FUNCTION)
5105  (void) hash_search(dbentry->functions, (void *) &(msg->m_objectid),
5106  HASH_REMOVE, NULL);
5107 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
HTAB * functions
Definition: pgstat.h:771
TimestampTz stat_reset_timestamp
Definition: pgstat.h:763
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
PgStat_Single_Reset_Type m_resettype
Definition: pgstat.h:359

◆ pgstat_recv_resetslrucounter()

static void pgstat_recv_resetslrucounter ( PgStat_MsgResetslrucounter msg,
int  len 
)
static

Definition at line 5116 of file pgstat.c.

References GetCurrentTimestamp(), i, PgStat_MsgResetslrucounter::m_index, SLRU_NUM_ELEMENTS, and PgStat_SLRUStats::stat_reset_timestamp.

Referenced by PgstatCollectorMain().

5117 {
5118  int i;
5120 
5121  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
5122  {
5123  /* reset entry with the given index, or all entries (index is -1) */
5124  if ((msg->m_index == -1) || (msg->m_index == i))
5125  {
5126  memset(&slruStats[i], 0, sizeof(slruStats[i]));
5128  }
5129  }
5130 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
#define SLRU_NUM_ELEMENTS
Definition: pgstat.c:158
TimestampTz stat_reset_timestamp
Definition: pgstat.h:891
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:280
int i

◆ pgstat_recv_slru()

static void pgstat_recv_slru ( PgStat_MsgSLRU msg,
int  len 
)
static

Definition at line 5386 of file pgstat.c.

References PgStat_SLRUStats::blocks_exists, PgStat_SLRUStats::blocks_hit, PgStat_SLRUStats::blocks_read, PgStat_SLRUStats::blocks_written, PgStat_SLRUStats::blocks_zeroed, PgStat_SLRUStats::flush, PgStat_MsgSLRU::m_blocks_exists, PgStat_MsgSLRU::m_blocks_hit, PgStat_MsgSLRU::m_blocks_read, PgStat_MsgSLRU::m_blocks_written, PgStat_MsgSLRU::m_blocks_zeroed, PgStat_MsgSLRU::m_flush, PgStat_MsgSLRU::m_index, PgStat_MsgSLRU::m_truncate, and PgStat_SLRUStats::truncate.

Referenced by PgstatCollectorMain().

5387 {
5389  slruStats[msg->m_index].blocks_hit += msg->m_blocks_hit;
5393  slruStats[msg->m_index].flush += msg->m_flush;
5394  slruStats[msg->m_index].truncate += msg->m_truncate;
5395 }
PgStat_Counter m_flush
Definition: pgstat.h:517
PgStat_Counter blocks_exists
Definition: pgstat.h:888
PgStat_Counter m_blocks_exists
Definition: pgstat.h:516
PgStat_Counter m_index
Definition: pgstat.h:511
PgStat_Counter m_blocks_written
Definition: pgstat.h:515
PgStat_Counter blocks_read
Definition: pgstat.h:886
PgStat_Counter blocks_hit
Definition: pgstat.h:885
PgStat_Counter blocks_zeroed
Definition: pgstat.h:884
PgStat_Counter m_blocks_read
Definition: pgstat.h:514
PgStat_Counter flush
Definition: pgstat.h:889
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:280
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:512
PgStat_Counter m_truncate
Definition: pgstat.h:518
PgStat_Counter truncate
Definition: pgstat.h:890
PgStat_Counter blocks_written
Definition: pgstat.h:887
PgStat_Counter m_blocks_hit
Definition: pgstat.h:513

◆ pgstat_recv_tabpurge()

static void pgstat_recv_tabpurge ( PgStat_MsgTabpurge msg,
int  len 
)
static

Definition at line 4940 of file pgstat.c.

References HASH_REMOVE, hash_search(), i, PgStat_MsgTabpurge::m_databaseid, PgStat_MsgTabpurge::m_nentries, PgStat_MsgTabpurge::m_tableid, pgstat_get_db_entry(), and PgStat_StatDBEntry::tables.

Referenced by PgstatCollectorMain().

4941 {
4942  PgStat_StatDBEntry *dbentry;
4943  int i;
4944 
4945  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
4946 
4947  /*
4948  * No need to purge if we don't even know the database.
4949  */
4950  if (!dbentry || !dbentry->tables)
4951  return;
4952 
4953  /*
4954  * Process all table entries in the message.
4955  */
4956  for (i = 0; i < msg->m_nentries; i++)
4957  {
4958  /* Remove from hashtable if present; we don't care if it's not. */
4959  (void) hash_search(dbentry->tables,
4960  (void *) &(msg->m_tableid[i]),
4961  HASH_REMOVE, NULL);
4962  }
4963 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
Oid m_tableid[PGSTAT_NUM_TABPURGE]
Definition: pgstat.h:312
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3533
int i

◆ pgstat_recv_tabstat()

static void pgstat_recv_tabstat ( PgStat_MsgTabstat msg,
int  len 
)
static

Definition at line 4829 of file pgstat.c.

References PgStat_StatTabEntry::analyze_count, PgStat_StatTabEntry::analyze_timestamp, PgStat_StatTabEntry::autovac_analyze_count, PgStat_StatTabEntry::autovac_analyze_timestamp, PgStat_StatTabEntry::autovac_vacuum_count, PgStat_StatTabEntry::autovac_vacuum_timestamp, PgStat_StatTabEntry::blocks_fetched, PgStat_StatTabEntry::blocks_hit, PgStat_StatTabEntry::changes_since_analyze, PgStat_StatTabEntry::changes_since_analyze_reported, HASH_ENTER, hash_search(), i, PgStat_StatTabEntry::inserts_since_vacuum, PgStat_MsgTabstat::m_block_read_time, PgStat_MsgTabstat::m_block_write_time, PgStat_MsgTabstat::m_databaseid, PgStat_MsgTabstat::m_entry, PgStat_MsgTabstat::m_nentries, PgStat_MsgTabstat::m_xact_commit, PgStat_MsgTabstat::m_xact_rollback, Max, PgStat_StatDBEntry::n_block_read_time, PgStat_StatDBEntry::n_block_write_time, PgStat_StatDBEntry::n_blocks_fetched, PgStat_StatDBEntry::n_blocks_hit, PgStat_StatTabEntry::n_dead_tuples, PgStat_StatTabEntry::n_live_tuples, PgStat_StatDBEntry::n_tuples_deleted, PgStat_StatDBEntry::n_tuples_fetched, PgStat_StatDBEntry::n_tuples_inserted, PgStat_StatDBEntry::n_tuples_returned, PgStat_StatDBEntry::n_tuples_updated, PgStat_StatDBEntry::n_xact_commit, PgStat_StatDBEntry::n_xact_rollback, PgStat_StatTabEntry::numscans, pgstat_get_db_entry(), PgStat_TableCounts::t_blocks_fetched, PgStat_TableCounts::t_blocks_hit, PgStat_TableCounts::t_changed_tuples, PgStat_TableEntry::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, PgStat_TableEntry::t_id, PgStat_TableCounts::t_numscans, PgStat_TableCounts::t_truncated, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_fetched, PgStat_TableCounts::t_tuples_hot_updated, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_returned, PgStat_TableCounts::t_tuples_updated, PgStat_StatDBEntry::tables, PgStat_StatTabEntry::tuples_deleted, PgStat_StatTabEntry::tuples_fetched, PgStat_StatTabEntry::tuples_hot_updated, PgStat_StatTabEntry::tuples_inserted, PgStat_StatTabEntry::tuples_returned, PgStat_StatTabEntry::tuples_updated, PgStat_StatTabEntry::vacuum_count, and PgStat_StatTabEntry::vacuum_timestamp.

Referenced by PgstatCollectorMain().

4830 {
4831  PgStat_StatDBEntry *dbentry;
4832  PgStat_StatTabEntry *tabentry;
4833  int i;
4834  bool found;
4835 
4836  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
4837 
4838  /*
4839  * Update database-wide stats.
4840  */
4841  dbentry->n_xact_commit += (PgStat_Counter) (msg->m_xact_commit);
4842  dbentry->n_xact_rollback += (PgStat_Counter) (msg->m_xact_rollback);
4843  dbentry->n_block_read_time += msg->m_block_read_time;
4844  dbentry->n_block_write_time += msg->m_block_write_time;
4845 
4846  /*
4847  * Process all table entries in the message.
4848  */
4849  for (i = 0; i < msg->m_nentries; i++)
4850  {
4851  PgStat_TableEntry *tabmsg = &(msg->m_entry[i]);
4852 
4853  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
4854  (void *) &(tabmsg->t_id),
4855  HASH_ENTER, &found);
4856 
4857  if (!found)
4858  {
4859  /*
4860  * If it's a new table entry, initialize counters to the values we
4861  * just got.
4862  */
4863  tabentry->numscans = tabmsg->t_counts.t_numscans;
4864  tabentry->tuples_returned = tabmsg->t_counts.t_tuples_returned;
4865  tabentry->tuples_fetched = tabmsg->t_counts.t_tuples_fetched;
4866  tabentry->tuples_inserted = tabmsg->t_counts.t_tuples_inserted;
4867  tabentry->tuples_updated = tabmsg->t_counts.t_tuples_updated;
4868  tabentry->tuples_deleted = tabmsg->t_counts.t_tuples_deleted;
4869  tabentry->tuples_hot_updated = tabmsg->t_counts.t_tuples_hot_updated;
4870  tabentry->n_live_tuples = tabmsg->t_counts.t_delta_live_tuples;
4871  tabentry->n_dead_tuples = tabmsg->t_counts.t_delta_dead_tuples;
4872  tabentry->changes_since_analyze = tabmsg->t_counts.t_changed_tuples;
4873  tabentry->changes_since_analyze_reported = 0;
4874  tabentry->inserts_since_vacuum = tabmsg->t_counts.t_tuples_inserted;
4875  tabentry->blocks_fetched = tabmsg->t_counts.t_blocks_fetched;
4876  tabentry->blocks_hit = tabmsg->t_counts.t_blocks_hit;
4877 
4878  tabentry->vacuum_timestamp = 0;
4879  tabentry->vacuum_count = 0;
4880  tabentry->autovac_vacuum_timestamp = 0;
4881  tabentry->autovac_vacuum_count = 0;
4882  tabentry->analyze_timestamp = 0;
4883  tabentry->analyze_count = 0;
4884  tabentry->autovac_analyze_timestamp = 0;
4885  tabentry->autovac_analyze_count = 0;
4886  }
4887  else
4888  {
4889  /*
4890  * Otherwise add the values to the existing entry.
4891  */
4892  tabentry->numscans += tabmsg->t_counts.t_numscans;
4893  tabentry->tuples_returned += tabmsg->t_counts.t_tuples_returned;
4894  tabentry->tuples_fetched += tabmsg->t_counts.t_tuples_fetched;
4895  tabentry->tuples_inserted += tabmsg->t_counts.t_tuples_inserted;
4896  tabentry->tuples_updated += tabmsg->t_counts.t_tuples_updated;
4897  tabentry->tuples_deleted += tabmsg->t_counts.t_tuples_deleted;
4898  tabentry->tuples_hot_updated += tabmsg->t_counts.t_tuples_hot_updated;
4899  /* If table was truncated, first reset the live/dead counters */
4900  if (tabmsg->t_counts.t_truncated)
4901  {
4902  tabentry->n_live_tuples = 0;
4903  tabentry->n_dead_tuples = 0;
4904  tabentry->inserts_since_vacuum = 0;
4905  }
4906  tabentry->n_live_tuples += tabmsg->t_counts.t_delta_live_tuples;
4907  tabentry->n_dead_tuples += tabmsg->t_counts.t_delta_dead_tuples;
4908  tabentry->changes_since_analyze += tabmsg->t_counts.t_changed_tuples;
4909  tabentry->inserts_since_vacuum += tabmsg->t_counts.t_tuples_inserted;
4910  tabentry->blocks_fetched += tabmsg->t_counts.t_blocks_fetched;
4911  tabentry->blocks_hit += tabmsg->t_counts.t_blocks_hit;
4912  }
4913 
4914  /* Clamp n_live_tuples in case of negative delta_live_tuples */
4915  tabentry->n_live_tuples = Max(tabentry->n_live_tuples, 0);
4916  /* Likewise for n_dead_tuples */
4917  tabentry->n_dead_tuples = Max(tabentry->n_dead_tuples, 0);
4918 
4919  /*
4920  * Add per-table stats to the per-database entry, too.
4921  */
4922  dbentry->n_tuples_returned += tabmsg->t_counts.t_tuples_returned;
4923  dbentry->n_tuples_fetched += tabmsg->t_counts.t_tuples_fetched;
4924  dbentry->n_tuples_inserted += tabmsg->t_counts.t_tuples_inserted;
4925  dbentry->n_tuples_updated += tabmsg->t_counts.t_tuples_updated;
4926  dbentry->n_tuples_deleted += tabmsg->t_counts.t_tuples_deleted;
4927  dbentry->n_blocks_fetched += tabmsg->t_counts.t_blocks_fetched;
4928  dbentry->n_blocks_hit += tabmsg->t_counts.t_blocks_hit;
4929  }
4930 }
PgStat_Counter analyze_count
Definition: pgstat.h:807
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:127
int64 PgStat_Counter
Definition: pgstat.h:91
PgStat_Counter tuples_returned
Definition: pgstat.h:785
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:119
PgStat_Counter n_blocks_hit
Definition: pgstat.h:736
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:124
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:808
PgStat_Counter n_tuples_returned
Definition: pgstat.h:737
PgStat_Counter vacuum_count
Definition: pgstat.h:803
PgStat_Counter numscans
Definition: pgstat.h:783
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:791
PgStat_Counter t_tuples_returned
Definition: pgstat.h:118
PgStat_Counter tuples_inserted
Definition: pgstat.h:788
PgStat_Counter n_xact_commit
Definition: pgstat.h:733
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:735
PgStat_Counter n_live_tuples
Definition: pgstat.h:793
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:797