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/catalog.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, TimestampTz now)
 
static void pgstat_send_funcstats (void)
 
static void pgstat_send_slru (void)
 
static HTABpgstat_collect_oids (Oid catalogid, AttrNumber anum_oid)
 
static bool pgstat_should_report_connstat (void)
 
static void pgstat_report_disconnect (Oid dboid)
 
static PgStat_TableStatusget_tabstat_entry (Oid rel_id, bool isshared)
 
static void pgstat_setup_memcxt (void)
 
static void pgstat_assert_is_up (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_archiver (PgStat_MsgArchiver *msg, int len)
 
static void pgstat_recv_bgwriter (PgStat_MsgBgWriter *msg, int len)
 
static void pgstat_recv_checkpointer (PgStat_MsgCheckpointer *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_connect (PgStat_MsgConnect *msg, int len)
 
static void pgstat_recv_disconnect (PgStat_MsgDisconnect *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_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_connect (Oid dboid)
 
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_truncdrop_save_counters (PgStat_TableXactStatus *trans, bool is_drop)
 
static void pgstat_truncdrop_restore_counters (PgStat_TableXactStatus *trans)
 
void pgstat_count_truncate (Relation rel)
 
void pgstat_update_heap_dead_tuples (Relation rel, int delta)
 
static void AtEOXact_PgStat_Relations (PgStat_SubXactStatus *xact_state, bool isCommit)
 
static void AtEOXact_PgStat_Database (bool isCommit, bool parallel)
 
void AtEOXact_PgStat (bool isCommit, bool parallel)
 
static void AtEOSubXact_PgStat_Relations (PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
 
void AtEOSubXact_PgStat (bool isCommit, int nestDepth)
 
static void AtPrepare_PgStat_Relations (PgStat_SubXactStatus *xact_state)
 
void AtPrepare_PgStat (void)
 
static void PostPrepare_PgStat_Relations (PgStat_SubXactStatus *xact_state)
 
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_BgWriterStatspgstat_fetch_stat_bgwriter (void)
 
PgStat_CheckpointerStatspgstat_fetch_stat_checkpointer (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_checkpointer (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 PendingBgWriterStats
 
PgStat_MsgCheckpointer PendingCheckpointerStats
 
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
 
static PgStat_Counter pgLastSessionReportTime = 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 192 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 2213 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().

2214 {
2215  PgStat_SubXactStatus *xact_state;
2217 
2218  /*
2219  * If this is the first rel to be modified at the current nest level, we
2220  * first have to push a transaction stack entry.
2221  */
2222  xact_state = get_tabstat_stack_level(nest_level);
2223 
2224  /* Now make a per-table stack entry */
2225  trans = (PgStat_TableXactStatus *)
2227  sizeof(PgStat_TableXactStatus));
2228  trans->nest_level = nest_level;
2229  trans->upper = pgstat_info->trans;
2230  trans->parent = pgstat_info;
2231  trans->next = xact_state->first;
2232  xact_state->first = trans;
2233  pgstat_info->trans = trans;
2234 }
MemoryContext TopTransactionContext
Definition: mcxt.c:53
struct PgStat_TableXactStatus * next
Definition: pgstat.h:200
static PgStat_SubXactStatus * get_tabstat_stack_level(int nest_level)
Definition: pgstat.c:2191
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:197
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:240
PgStat_TableStatus * parent
Definition: pgstat.h:198

◆ allow_immediate_pgstat_restart()

void allow_immediate_pgstat_restart ( void  )

Definition at line 832 of file pgstat.c.

References last_pgstat_start_time.

Referenced by HandleChildCrash().

833 {
835 }
static time_t last_pgstat_start_time
Definition: pgstat.c:177

◆ AtEOSubXact_PgStat()

void AtEOSubXact_PgStat ( bool  isCommit,
int  nestDepth 
)

Definition at line 2576 of file pgstat.c.

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

Referenced by AbortSubTransaction(), and CommitSubTransaction().

2577 {
2578  PgStat_SubXactStatus *xact_state;
2579 
2580  /* merge the sub-transaction's transactional stats into the parent */
2581  xact_state = pgStatXactStack;
2582  if (xact_state != NULL &&
2583  xact_state->nest_level >= nestDepth)
2584  {
2585  /* delink xact_state from stack immediately to simplify reuse case */
2586  pgStatXactStack = xact_state->prev;
2587 
2588  AtEOSubXact_PgStat_Relations(xact_state, isCommit, nestDepth);
2589 
2590  pfree(xact_state);
2591  }
2592 }
void pfree(void *pointer)
Definition: mcxt.c:1169
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:239
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:243
static void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
Definition: pgstat.c:2493

◆ AtEOSubXact_PgStat_Relations()

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

Definition at line 2493 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, get_tabstat_stack_level(), PgStat_TableXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pfree(), pgstat_truncdrop_restore_counters(), pgstat_truncdrop_save_counters(), PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncdropped, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

Referenced by AtEOSubXact_PgStat().

2494 {
2496  PgStat_TableXactStatus *next_trans;
2497 
2498  for (trans = xact_state->first; trans != NULL; trans = next_trans)
2499  {
2500  PgStat_TableStatus *tabstat;
2501 
2502  next_trans = trans->next;
2503  Assert(trans->nest_level == nestDepth);
2504  tabstat = trans->parent;
2505  Assert(tabstat->trans == trans);
2506 
2507  if (isCommit)
2508  {
2509  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
2510  {
2511  if (trans->truncdropped)
2512  {
2513  /* propagate the truncate/drop status one level up */
2514  pgstat_truncdrop_save_counters(trans->upper, false);
2515  /* replace upper xact stats with ours */
2516  trans->upper->tuples_inserted = trans->tuples_inserted;
2517  trans->upper->tuples_updated = trans->tuples_updated;
2518  trans->upper->tuples_deleted = trans->tuples_deleted;
2519  }
2520  else
2521  {
2522  trans->upper->tuples_inserted += trans->tuples_inserted;
2523  trans->upper->tuples_updated += trans->tuples_updated;
2524  trans->upper->tuples_deleted += trans->tuples_deleted;
2525  }
2526  tabstat->trans = trans->upper;
2527  pfree(trans);
2528  }
2529  else
2530  {
2531  /*
2532  * When there isn't an immediate parent state, we can just
2533  * reuse the record instead of going through a
2534  * palloc/pfree pushup (this works since it's all in
2535  * TopTransactionContext anyway). We have to re-link it
2536  * into the parent level, though, and that might mean
2537  * pushing a new entry into the pgStatXactStack.
2538  */
2539  PgStat_SubXactStatus *upper_xact_state;
2540 
2541  upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
2542  trans->next = upper_xact_state->first;
2543  upper_xact_state->first = trans;
2544  trans->nest_level = nestDepth - 1;
2545  }
2546  }
2547  else
2548  {
2549  /*
2550  * On abort, update top-level tabstat counts, then forget the
2551  * subtransaction
2552  */
2553 
2554  /* first restore values obliterated by truncate/drop */
2556  /* count attempted actions regardless of commit/abort */
2557  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2558  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2559  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2560  /* inserted tuples are dead, deleted tuples are unaffected */
2561  tabstat->t_counts.t_delta_dead_tuples +=
2562  trans->tuples_inserted + trans->tuples_updated;
2563  tabstat->trans = trans->upper;
2564  pfree(trans);
2565  }
2566  }
2567 }
PgStat_Counter tuples_updated
Definition: pgstat.h:187
struct PgStat_TableXactStatus * next
Definition: pgstat.h:200
static void pgstat_truncdrop_save_counters(PgStat_TableXactStatus *trans, bool is_drop)
Definition: pgstat.c:2315
PgStat_TableCounts t_counts
Definition: pgstat.h:177
static PgStat_SubXactStatus * get_tabstat_stack_level(int nest_level)
Definition: pgstat.c:2191
void pfree(void *pointer)
Definition: mcxt.c:1169
PgStat_Counter t_tuples_updated
Definition: pgstat.h:123
static void pgstat_truncdrop_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2330
PgStat_Counter tuples_inserted
Definition: pgstat.h:186
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:129
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:197
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:124
PgStat_Counter tuples_deleted
Definition: pgstat.h:188
#define Assert(condition)
Definition: c.h:804
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:240
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:122
PgStat_TableStatus * parent
Definition: pgstat.h:198

◆ AtEOXact_PgStat()

void AtEOXact_PgStat ( bool  isCommit,
bool  parallel 
)

Definition at line 2464 of file pgstat.c.

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

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

2465 {
2466  PgStat_SubXactStatus *xact_state;
2467 
2468  AtEOXact_PgStat_Database(isCommit, parallel);
2469 
2470  /* handle transactional stats information */
2471  xact_state = pgStatXactStack;
2472  if (xact_state != NULL)
2473  {
2474  Assert(xact_state->nest_level == 1);
2475  Assert(xact_state->prev == NULL);
2476 
2477  AtEOXact_PgStat_Relations(xact_state, isCommit);
2478  }
2479  pgStatXactStack = NULL;
2480 
2481  /* Make sure any stats snapshot is thrown away */
2483 }
static void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit)
Definition: pgstat.c:2390
static void AtEOXact_PgStat_Database(bool isCommit, bool parallel)
Definition: pgstat.c:2441
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:239
#define Assert(condition)
Definition: c.h:804
void pgstat_clear_snapshot(void)
Definition: pgstat.c:4867
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:243

◆ AtEOXact_PgStat_Database()

static void AtEOXact_PgStat_Database ( bool  isCommit,
bool  parallel 
)
static

Definition at line 2441 of file pgstat.c.

References pgStatXactCommit, and pgStatXactRollback.

Referenced by AtEOXact_PgStat().

2442 {
2443  /* Don't count parallel worker transaction stats */
2444  if (!parallel)
2445  {
2446  /*
2447  * Count transaction commit or abort. (We use counters, not just
2448  * bools, in case the reporting message isn't sent right away.)
2449  */
2450  if (isCommit)
2451  pgStatXactCommit++;
2452  else
2454  }
2455 }
static int pgStatXactCommit
Definition: pgstat.c:245
static int pgStatXactRollback
Definition: pgstat.c:246

◆ AtEOXact_PgStat_Relations()

static void AtEOXact_PgStat_Relations ( PgStat_SubXactStatus xact_state,
bool  isCommit 
)
static

Definition at line 2390 of file pgstat.c.

References Assert, PgStat_SubXactStatus::first, PgStat_TableXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, pgstat_truncdrop_restore_counters(), PgStat_TableCounts::t_changed_tuples, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_delta_dead_tuples, PgStat_TableCounts::t_delta_live_tuples, PgStat_TableCounts::t_truncdropped, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncdropped, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

Referenced by AtEOXact_PgStat().

2391 {
2393 
2394  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2395  {
2396  PgStat_TableStatus *tabstat;
2397 
2398  Assert(trans->nest_level == 1);
2399  Assert(trans->upper == NULL);
2400  tabstat = trans->parent;
2401  Assert(tabstat->trans == trans);
2402  /* restore pre-truncate/drop stats (if any) in case of aborted xact */
2403  if (!isCommit)
2405  /* count attempted actions regardless of commit/abort */
2406  tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
2407  tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
2408  tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
2409  if (isCommit)
2410  {
2411  tabstat->t_counts.t_truncdropped = trans->truncdropped;
2412  if (trans->truncdropped)
2413  {
2414  /* forget live/dead stats seen by backend thus far */
2415  tabstat->t_counts.t_delta_live_tuples = 0;
2416  tabstat->t_counts.t_delta_dead_tuples = 0;
2417  }
2418  /* insert adds a live tuple, delete removes one */
2419  tabstat->t_counts.t_delta_live_tuples +=
2420  trans->tuples_inserted - trans->tuples_deleted;
2421  /* update and delete each create a dead tuple */
2422  tabstat->t_counts.t_delta_dead_tuples +=
2423  trans->tuples_updated + trans->tuples_deleted;
2424  /* insert, update, delete each count as one change event */
2425  tabstat->t_counts.t_changed_tuples +=
2426  trans->tuples_inserted + trans->tuples_updated +
2427  trans->tuples_deleted;
2428  }
2429  else
2430  {
2431  /* inserted tuples are dead, deleted tuples are unaffected */
2432  tabstat->t_counts.t_delta_dead_tuples +=
2433  trans->tuples_inserted + trans->tuples_updated;
2434  /* an aborted xact generates no changed_tuple events */
2435  }
2436  tabstat->trans = NULL;
2437  }
2438 }
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:128
PgStat_Counter tuples_updated
Definition: pgstat.h:187
bool t_truncdropped
Definition: pgstat.h:126
struct PgStat_TableXactStatus * next
Definition: pgstat.h:200
PgStat_TableCounts t_counts
Definition: pgstat.h:177
PgStat_Counter t_tuples_updated
Definition: pgstat.h:123
static void pgstat_truncdrop_restore_counters(PgStat_TableXactStatus *trans)
Definition: pgstat.c:2330
PgStat_Counter tuples_inserted
Definition: pgstat.h:186
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:129
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:197
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:124
PgStat_Counter tuples_deleted
Definition: pgstat.h:188
PgStat_Counter t_changed_tuples
Definition: pgstat.h:130
#define Assert(condition)
Definition: c.h:804
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:240
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:122
PgStat_TableStatus * parent
Definition: pgstat.h:198

◆ AtPrepare_PgStat()

void AtPrepare_PgStat ( void  )

Definition at line 2633 of file pgstat.c.

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

Referenced by PrepareTransaction().

2634 {
2635  PgStat_SubXactStatus *xact_state;
2636 
2637  xact_state = pgStatXactStack;
2638  if (xact_state != NULL)
2639  {
2640  Assert(xact_state->nest_level == 1);
2641  Assert(xact_state->prev == NULL);
2642 
2643  AtPrepare_PgStat_Relations(xact_state);
2644  }
2645 }
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:239
#define Assert(condition)
Definition: c.h:804
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:243
static void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)
Definition: pgstat.c:2599

◆ AtPrepare_PgStat_Relations()

static void AtPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)
static

Definition at line 2599 of file pgstat.c.

References Assert, PgStat_TableXactStatus::deleted_pre_truncdrop, TwoPhasePgStatRecord::deleted_pre_truncdrop, PgStat_SubXactStatus::first, PgStat_TableXactStatus::inserted_pre_truncdrop, TwoPhasePgStatRecord::inserted_pre_truncdrop, PgStat_TableXactStatus::nest_level, PgStat_TableXactStatus::next, PgStat_TableXactStatus::parent, RegisterTwoPhaseRecord(), PgStat_TableStatus::t_id, TwoPhasePgStatRecord::t_id, PgStat_TableStatus::t_shared, TwoPhasePgStatRecord::t_shared, TwoPhasePgStatRecord::t_truncdropped, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::truncdropped, 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_truncdrop, TwoPhasePgStatRecord::updated_pre_truncdrop, and PgStat_TableXactStatus::upper.

Referenced by AtPrepare_PgStat().

2600 {
2602 
2603  for (trans = xact_state->first; trans != NULL; trans = trans->next)
2604  {
2605  PgStat_TableStatus *tabstat;
2606  TwoPhasePgStatRecord record;
2607 
2608  Assert(trans->nest_level == 1);
2609  Assert(trans->upper == NULL);
2610  tabstat = trans->parent;
2611  Assert(tabstat->trans == trans);
2612 
2613  record.tuples_inserted = trans->tuples_inserted;
2614  record.tuples_updated = trans->tuples_updated;
2615  record.tuples_deleted = trans->tuples_deleted;
2619  record.t_id = tabstat->t_id;
2620  record.t_shared = tabstat->t_shared;
2621  record.t_truncdropped = trans->truncdropped;
2622 
2624  &record, sizeof(TwoPhasePgStatRecord));
2625  }
2626 }
PgStat_Counter deleted_pre_truncdrop
Definition: pgstat.c:263
PgStat_Counter tuples_updated
Definition: pgstat.h:187
PgStat_Counter updated_pre_truncdrop
Definition: pgstat.c:262
struct PgStat_TableXactStatus * next
Definition: pgstat.h:200
PgStat_Counter updated_pre_truncdrop
Definition: pgstat.h:193
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1239
PgStat_Counter tuples_inserted
Definition: pgstat.h:186
PgStat_Counter inserted_pre_truncdrop
Definition: pgstat.h:192
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:197
PgStat_Counter tuples_updated
Definition: pgstat.c:258
PgStat_Counter tuples_deleted
Definition: pgstat.h:188
PgStat_Counter deleted_pre_truncdrop
Definition: pgstat.h:194
PgStat_Counter inserted_pre_truncdrop
Definition: pgstat.c:261
#define Assert(condition)
Definition: c.h:804
PgStat_Counter tuples_inserted
Definition: pgstat.c:257
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176
PgStat_Counter tuples_deleted
Definition: pgstat.c:259
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400
PgStat_TableXactStatus * first
Definition: pgstat.c:240
PgStat_TableStatus * parent
Definition: pgstat.h:198

◆ backend_read_statsfile()

static void backend_read_statsfile ( void  )
static

Definition at line 4699 of file pgstat.c.

References Assert, CHECK_FOR_INTERRUPTS, ereport, errmsg(), GetCurrentTimestamp(), InvalidOid, IsAutoVacuumLauncherProcess(), IsAutoVacuumWorkerProcess(), LOG, MyDatabaseId, pfree(), pg_usleep(), pgstat_assert_is_up(), 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_bgwriter(), pgstat_fetch_stat_checkpointer(), pgstat_fetch_stat_dbentry(), pgstat_fetch_stat_funcentry(), pgstat_fetch_stat_tabentry(), pgstat_fetch_stat_wal(), and pgstat_vacuum_stat().

4700 {
4701  TimestampTz min_ts = 0;
4702  TimestampTz ref_ts = 0;
4703  Oid inquiry_db;
4704  int count;
4705 
4707 
4708  /* already read it? */
4709  if (pgStatDBHash)
4710  return;
4712 
4713  /*
4714  * In a normal backend, we check staleness of the data for our own DB, and
4715  * so we send MyDatabaseId in inquiry messages. In the autovac launcher,
4716  * check staleness of the shared-catalog data, and send InvalidOid in
4717  * inquiry messages so as not to force writing unnecessary data.
4718  */
4720  inquiry_db = InvalidOid;
4721  else
4722  inquiry_db = MyDatabaseId;
4723 
4724  /*
4725  * Loop until fresh enough stats file is available or we ran out of time.
4726  * The stats inquiry message is sent repeatedly in case collector drops
4727  * it; but not every single time, as that just swamps the collector.
4728  */
4729  for (count = 0; count < PGSTAT_POLL_LOOP_COUNT; count++)
4730  {
4731  bool ok;
4732  TimestampTz file_ts = 0;
4733  TimestampTz cur_ts;
4734 
4736 
4737  ok = pgstat_read_db_statsfile_timestamp(inquiry_db, false, &file_ts);
4738 
4739  cur_ts = GetCurrentTimestamp();
4740  /* Calculate min acceptable timestamp, if we didn't already */
4741  if (count == 0 || cur_ts < ref_ts)
4742  {
4743  /*
4744  * We set the minimum acceptable timestamp to PGSTAT_STAT_INTERVAL
4745  * msec before now. This indirectly ensures that the collector
4746  * needn't write the file more often than PGSTAT_STAT_INTERVAL. In
4747  * an autovacuum worker, however, we want a lower delay to avoid
4748  * using stale data, so we use PGSTAT_RETRY_DELAY (since the
4749  * number of workers is low, this shouldn't be a problem).
4750  *
4751  * We don't recompute min_ts after sleeping, except in the
4752  * unlikely case that cur_ts went backwards. So we might end up
4753  * accepting a file a bit older than PGSTAT_STAT_INTERVAL. In
4754  * practice that shouldn't happen, though, as long as the sleep
4755  * time is less than PGSTAT_STAT_INTERVAL; and we don't want to
4756  * tell the collector that our cutoff time is less than what we'd
4757  * actually accept.
4758  */
4759  ref_ts = cur_ts;
4761  min_ts = TimestampTzPlusMilliseconds(ref_ts,
4763  else
4764  min_ts = TimestampTzPlusMilliseconds(ref_ts,
4766  }
4767 
4768  /*
4769  * If the file timestamp is actually newer than cur_ts, we must have
4770  * had a clock glitch (system time went backwards) or there is clock
4771  * skew between our processor and the stats collector's processor.
4772  * Accept the file, but send an inquiry message anyway to make
4773  * pgstat_recv_inquiry do a sanity check on the collector's time.
4774  */
4775  if (ok && file_ts > cur_ts)
4776  {
4777  /*
4778  * A small amount of clock skew between processors isn't terribly
4779  * surprising, but a large difference is worth logging. We
4780  * arbitrarily define "large" as 1000 msec.
4781  */
4782  if (file_ts >= TimestampTzPlusMilliseconds(cur_ts, 1000))
4783  {
4784  char *filetime;
4785  char *mytime;
4786 
4787  /* Copy because timestamptz_to_str returns a static buffer */
4788  filetime = pstrdup(timestamptz_to_str(file_ts));
4789  mytime = pstrdup(timestamptz_to_str(cur_ts));
4790  ereport(LOG,
4791  (errmsg("statistics collector's time %s is later than backend local time %s",
4792  filetime, mytime)));
4793  pfree(filetime);
4794  pfree(mytime);
4795  }
4796 
4797  pgstat_send_inquiry(cur_ts, min_ts, inquiry_db);
4798  break;
4799  }
4800 
4801  /* Normal acceptance case: file is not older than cutoff time */
4802  if (ok && file_ts >= min_ts)
4803  break;
4804 
4805  /* Not there or too old, so kick the collector and wait a bit */
4806  if ((count % PGSTAT_INQ_LOOP_COUNT) == 0)
4807  pgstat_send_inquiry(cur_ts, min_ts, inquiry_db);
4808 
4809  pg_usleep(PGSTAT_RETRY_DELAY * 1000L);
4810  }
4811 
4812  if (count >= PGSTAT_POLL_LOOP_COUNT)
4813  ereport(LOG,
4814  (errmsg("using stale statistics instead of current ones "
4815  "because stats collector is not responding")));
4816 
4817  /*
4818  * Autovacuum launcher wants stats about all databases, but a shallow read
4819  * is sufficient. Regular backends want a deep read for just the tables
4820  * they can see (MyDatabaseId + shared catalogs).
4821  */
4824  else
4826 }
#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:179
#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:1897
#define PGSTAT_STAT_INTERVAL
Definition: pgstat.c:78
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3410
static HTAB * pgstat_read_statsfiles(Oid onlydb, bool permanent, bool deep)
Definition: pgstat.c:4069
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:4535
bool IsAutoVacuumLauncherProcess(void)
Definition: autovacuum.c:3404
#define Assert(condition)
Definition: c.h:804
static HTAB * pgStatDBHash
Definition: pgstat.c:273
int errmsg(const char *fmt,...)
Definition: elog.c:909
static void pgstat_assert_is_up(void)
Definition: pgstat.c:4850
#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 1965 of file pgstat.c.

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

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

1966 {
1968 
1969  if (pgStatFunctions == NULL)
1970  return NULL;
1971 
1973  (void *) &func_id,
1974  HASH_FIND, NULL);
1975 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * pgStatFunctions
Definition: pgstat.c:221
static void pgstat_assert_is_up(void)
Definition: pgstat.c:4850

◆ find_tabstat_entry()

PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

Definition at line 2171 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().

2172 {
2173  TabStatHashEntry *hash_entry;
2174 
2175  /* If hashtable doesn't exist, there are no entries at all */
2176  if (!pgStatTabHash)
2177  return NULL;
2178 
2179  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_FIND, NULL);
2180  if (!hash_entry)
2181  return NULL;
2182 
2183  /* Note that this step could also return NULL, but that's correct */
2184  return hash_entry->tsa_entry;
2185 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * pgStatTabHash
Definition: pgstat.c:215
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:209

◆ get_dbstat_filename()

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

Definition at line 3920 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().

3922 {
3923  int printed;
3924 
3925  /* NB -- pgstat_reset_remove_files knows about the pattern this uses */
3926  printed = snprintf(filename, len, "%s/db_%u.%s",
3927  permanent ? PGSTAT_STAT_PERMANENT_DIRECTORY :
3929  databaseid,
3930  tempname ? "tmp" : "stat");
3931  if (printed >= len)
3932  elog(ERROR, "overlength pgstat path");
3933 }
#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:217

◆ get_tabstat_entry()

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

Definition at line 2081 of file pgstat.c.

References HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASHCTL::keysize, MemoryContextAllocZero(), pgstat_assert_is_up(), 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().

2082 {
2083  TabStatHashEntry *hash_entry;
2084  PgStat_TableStatus *entry;
2085  TabStatusArray *tsa;
2086  bool found;
2087 
2089 
2090  /*
2091  * Create hash table if we don't have it already.
2092  */
2093  if (pgStatTabHash == NULL)
2094  {
2095  HASHCTL ctl;
2096 
2097  ctl.keysize = sizeof(Oid);
2098  ctl.entrysize = sizeof(TabStatHashEntry);
2099 
2100  pgStatTabHash = hash_create("pgstat TabStatusArray lookup hash table",
2102  &ctl,
2103  HASH_ELEM | HASH_BLOBS);
2104  }
2105 
2106  /*
2107  * Find an entry or create a new one.
2108  */
2109  hash_entry = hash_search(pgStatTabHash, &rel_id, HASH_ENTER, &found);
2110  if (!found)
2111  {
2112  /* initialize new entry with null pointer */
2113  hash_entry->tsa_entry = NULL;
2114  }
2115 
2116  /*
2117  * If entry is already valid, we're done.
2118  */
2119  if (hash_entry->tsa_entry)
2120  return hash_entry->tsa_entry;
2121 
2122  /*
2123  * Locate the first pgStatTabList entry with free space, making a new list
2124  * entry if needed. Note that we could get an OOM failure here, but if so
2125  * we have left the hashtable and the list in a consistent state.
2126  */
2127  if (pgStatTabList == NULL)
2128  {
2129  /* Set up first pgStatTabList entry */
2132  sizeof(TabStatusArray));
2133  }
2134 
2135  tsa = pgStatTabList;
2136  while (tsa->tsa_used >= TABSTAT_QUANTUM)
2137  {
2138  if (tsa->tsa_next == NULL)
2139  tsa->tsa_next = (TabStatusArray *)
2141  sizeof(TabStatusArray));
2142  tsa = tsa->tsa_next;
2143  }
2144 
2145  /*
2146  * Allocate a PgStat_TableStatus entry within this list entry. We assume
2147  * the entry was already zeroed, either at creation or after last use.
2148  */
2149  entry = &tsa->tsa_entries[tsa->tsa_used++];
2150  entry->t_id = rel_id;
2151  entry->t_shared = isshared;
2152 
2153  /*
2154  * Now we can fill the entry in pgStatTabHash.
2155  */
2156  hash_entry->tsa_entry = entry;
2157 
2158  return entry;
2159 }
int tsa_used
Definition: pgstat.c:197
#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:196
unsigned int Oid
Definition: postgres_ext.h:31
struct TabStatHashEntry TabStatHashEntry
static HTAB * pgStatTabHash
Definition: pgstat.c:215
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:198
MemoryContext TopMemoryContext
Definition: mcxt.c:48
#define HASH_BLOBS
Definition: hsearch.h:97
PgStat_TableStatus * tsa_entry
Definition: pgstat.c:209
Size keysize
Definition: hsearch.h:75
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
static TabStatusArray * pgStatTabList
Definition: pgstat.c:201
static void pgstat_assert_is_up(void)
Definition: pgstat.c:4850
#define TABSTAT_QUANTUM
Definition: pgstat.c:192

◆ get_tabstat_stack_level()

static PgStat_SubXactStatus* get_tabstat_stack_level ( int  nest_level)
static

Definition at line 2191 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_Relations().

2192 {
2193  PgStat_SubXactStatus *xact_state;
2194 
2195  xact_state = pgStatXactStack;
2196  if (xact_state == NULL || xact_state->nest_level != nest_level)
2197  {
2198  xact_state = (PgStat_SubXactStatus *)
2200  sizeof(PgStat_SubXactStatus));
2201  xact_state->nest_level = nest_level;
2202  xact_state->prev = pgStatXactStack;
2203  xact_state->first = NULL;
2204  pgStatXactStack = xact_state;
2205  }
2206  return xact_state;
2207 }
MemoryContext TopTransactionContext
Definition: mcxt.c:53
struct PgStat_SubXactStatus * prev
Definition: pgstat.c:239
static PgStat_SubXactStatus * pgStatXactStack
Definition: pgstat.c:243
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
PgStat_TableXactStatus * first
Definition: pgstat.c:240

◆ pgstat_assert_is_up()

static void pgstat_assert_is_up ( void  )
static

Definition at line 4850 of file pgstat.c.

References Assert.

Referenced by backend_read_statsfile(), find_funcstat_entry(), get_tabstat_entry(), pgstat_clear_snapshot(), pgstat_report_stat(), pgstat_send(), pgstat_send_bgwriter(), and slru_entry().

4851 {
4852  Assert(pgstat_is_initialized && !pgstat_is_shutdown);
4853 }
#define Assert(condition)
Definition: c.h:804

◆ pgstat_clear_snapshot()

void pgstat_clear_snapshot ( void  )

Definition at line 4867 of file pgstat.c.

References MemoryContextDelete(), pgstat_assert_is_up(), and pgstat_clear_backend_activity_snapshot().

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

4868 {
4870 
4871  /* Release memory, if any was allocated */
4872  if (pgStatLocalContext)
4874 
4875  /* Reset variables */
4876  pgStatLocalContext = NULL;
4877  pgStatDBHash = NULL;
4878  replSlotStatHash = NULL;
4879 
4880  /*
4881  * Historically the backend_status.c facilities lived in this file, and
4882  * were reset with the same function. For now keep it that way, and
4883  * forward the reset request.
4884  */
4886 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
static HTAB * pgStatDBHash
Definition: pgstat.c:273
static HTAB * replSlotStatHash
Definition: pgstat.c:284
static void pgstat_assert_is_up(void)
Definition: pgstat.c:4850
static MemoryContext pgStatLocalContext
Definition: pgstat.c:272
void pgstat_clear_backend_activity_snapshot(void)

◆ pgstat_collect_oids()

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

Definition at line 1318 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().

1319 {
1320  HTAB *htab;
1321  HASHCTL hash_ctl;
1322  Relation rel;
1323  TableScanDesc scan;
1324  HeapTuple tup;
1325  Snapshot snapshot;
1326 
1327  hash_ctl.keysize = sizeof(Oid);
1328  hash_ctl.entrysize = sizeof(Oid);
1329  hash_ctl.hcxt = CurrentMemoryContext;
1330  htab = hash_create("Temporary table of OIDs",
1332  &hash_ctl,
1334 
1335  rel = table_open(catalogid, AccessShareLock);
1336  snapshot = RegisterSnapshot(GetLatestSnapshot());
1337  scan = table_beginscan(rel, snapshot, 0, NULL);
1338  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
1339  {
1340  Oid thisoid;
1341  bool isnull;
1342 
1343  thisoid = heap_getattr(tup, anum_oid, RelationGetDescr(rel), &isnull);
1344  Assert(!isnull);
1345 
1347 
1348  (void) hash_search(htab, (void *) &thisoid, HASH_ENTER, NULL);
1349  }
1350  table_endscan(scan);
1351  UnregisterSnapshot(snapshot);
1353 
1354  return htab;
1355 }
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:825
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:867
#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 2286 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().

2287 {
2288  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2289 
2290  if (pgstat_info != NULL)
2291  {
2292  /* We have to log the effect at the proper transactional level */
2293  int nest_level = GetCurrentTransactionNestLevel();
2294 
2295  if (pgstat_info->trans == NULL ||
2296  pgstat_info->trans->nest_level != nest_level)
2297  add_tabstat_xact_level(pgstat_info, nest_level);
2298 
2299  pgstat_info->trans->tuples_deleted++;
2300  }
2301 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:188
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:858
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:2213
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 2240 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().

2241 {
2242  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2243 
2244  if (pgstat_info != NULL)
2245  {
2246  /* We have to log the effect at the proper transactional level */
2247  int nest_level = GetCurrentTransactionNestLevel();
2248 
2249  if (pgstat_info->trans == NULL ||
2250  pgstat_info->trans->nest_level != nest_level)
2251  add_tabstat_xact_level(pgstat_info, nest_level);
2252 
2253  pgstat_info->trans->tuples_inserted += n;
2254  }
2255 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:186
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:858
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:2213
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot 
)

Definition at line 2261 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().

2262 {
2263  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2264 
2265  if (pgstat_info != NULL)
2266  {
2267  /* We have to log the effect at the proper transactional level */
2268  int nest_level = GetCurrentTransactionNestLevel();
2269 
2270  if (pgstat_info->trans == NULL ||
2271  pgstat_info->trans->nest_level != nest_level)
2272  add_tabstat_xact_level(pgstat_info, nest_level);
2273 
2274  pgstat_info->trans->tuples_updated++;
2275 
2276  /* t_tuples_hot_updated is nontransactional, so just advance it */
2277  if (hot)
2278  pgstat_info->t_counts.t_tuples_hot_updated++;
2279  }
2280 }
PgStat_Counter tuples_updated
Definition: pgstat.h:187
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:125
PgStat_TableCounts t_counts
Definition: pgstat.h:177
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:858
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:2213
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176

◆ pgstat_count_slru_flush()

void pgstat_count_slru_flush ( int  slru_idx)

Definition at line 6032 of file pgstat.c.

References PgStat_MsgSLRU::m_flush, and slru_entry().

Referenced by SimpleLruWriteAll().

6033 {
6034  slru_entry(slru_idx)->m_flush += 1;
6035 }
PgStat_Counter m_flush
Definition: pgstat.h:514
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982

◆ pgstat_count_slru_page_exists()

void pgstat_count_slru_page_exists ( int  slru_idx)

Definition at line 6014 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_exists, and slru_entry().

Referenced by SimpleLruDoesPhysicalPageExist().

6015 {
6016  slru_entry(slru_idx)->m_blocks_exists += 1;
6017 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982
PgStat_Counter m_blocks_exists
Definition: pgstat.h:513

◆ pgstat_count_slru_page_hit()

void pgstat_count_slru_page_hit ( int  slru_idx)

Definition at line 6008 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_hit, and slru_entry().

Referenced by SimpleLruReadPage(), and SimpleLruReadPage_ReadOnly().

6009 {
6010  slru_entry(slru_idx)->m_blocks_hit += 1;
6011 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982
PgStat_Counter m_blocks_hit
Definition: pgstat.h:510

◆ pgstat_count_slru_page_read()

void pgstat_count_slru_page_read ( int  slru_idx)

Definition at line 6020 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_read, and slru_entry().

Referenced by SimpleLruReadPage().

6021 {
6022  slru_entry(slru_idx)->m_blocks_read += 1;
6023 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982
PgStat_Counter m_blocks_read
Definition: pgstat.h:511

◆ pgstat_count_slru_page_written()

void pgstat_count_slru_page_written ( int  slru_idx)

Definition at line 6026 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_written, and slru_entry().

Referenced by SlruPhysicalWritePage().

6027 {
6028  slru_entry(slru_idx)->m_blocks_written += 1;
6029 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982
PgStat_Counter m_blocks_written
Definition: pgstat.h:512

◆ pgstat_count_slru_page_zeroed()

void pgstat_count_slru_page_zeroed ( int  slru_idx)

Definition at line 6002 of file pgstat.c.

References PgStat_MsgSLRU::m_blocks_zeroed, and slru_entry().

Referenced by SimpleLruZeroPage().

6003 {
6004  slru_entry(slru_idx)->m_blocks_zeroed += 1;
6005 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:509

◆ pgstat_count_slru_truncate()

void pgstat_count_slru_truncate ( int  slru_idx)

Definition at line 6038 of file pgstat.c.

References PgStat_MsgSLRU::m_truncate, and slru_entry().

Referenced by SimpleLruTruncate().

6039 {
6040  slru_entry(slru_idx)->m_truncate += 1;
6041 }
static PgStat_MsgSLRU * slru_entry(int slru_idx)
Definition: pgstat.c:5982
PgStat_Counter m_truncate
Definition: pgstat.h:515

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

Definition at line 2344 of file pgstat.c.

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

Referenced by ExecRefreshMatView(), and ExecuteTruncateGuts().

2345 {
2346  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
2347 
2348  if (pgstat_info != NULL)
2349  {
2350  /* We have to log the effect at the proper transactional level */
2351  int nest_level = GetCurrentTransactionNestLevel();
2352 
2353  if (pgstat_info->trans == NULL ||
2354  pgstat_info->trans->nest_level != nest_level)
2355  add_tabstat_xact_level(pgstat_info, nest_level);
2356 
2357  pgstat_truncdrop_save_counters(pgstat_info->trans, false);
2358  pgstat_info->trans->tuples_inserted = 0;
2359  pgstat_info->trans->tuples_updated = 0;
2360  pgstat_info->trans->tuples_deleted = 0;
2361  }
2362 }
PgStat_Counter tuples_updated
Definition: pgstat.h:187
static void pgstat_truncdrop_save_counters(PgStat_TableXactStatus *trans, bool is_drop)
Definition: pgstat.c:2315
PgStat_Counter tuples_inserted
Definition: pgstat.h:186
PgStat_Counter tuples_deleted
Definition: pgstat.h:188
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:858
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:2213
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:176

◆ pgstat_db_requested()

static bool pgstat_db_requested ( Oid  databaseid)
static

Definition at line 5842 of file pgstat.c.

References InvalidOid, list_member_oid(), and NIL.

Referenced by pgstat_write_statsfiles().

5843 {
5844  /*
5845  * If any requests are outstanding at all, we should write the stats for
5846  * shared catalogs (the "database" with OID 0). This ensures that
5847  * backends will see up-to-date stats for shared catalogs, even though
5848  * they send inquiry messages mentioning only their own DB.
5849  */
5850  if (databaseid == InvalidOid && pending_write_requests != NIL)
5851  return true;
5852 
5853  /* Search to see if there's an open request to write this database. */
5854  if (list_member_oid(pending_write_requests, databaseid))
5855  return true;
5856 
5857  return false;
5858 }
#define NIL
Definition: pg_list.h:65
static List * pending_write_requests
Definition: pgstat.c:291
#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 1367 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().

1368 {
1369  PgStat_MsgDropdb msg;
1370 
1372  return;
1373 
1375  msg.m_databaseid = databaseid;
1376  pgstat_send(&msg, sizeof(msg));
1377 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3071
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:173
Oid m_databaseid
Definition: pgstat.h:330
PgStat_MsgHdr m_hdr
Definition: pgstat.h:329
#define PGINVALID_SOCKET
Definition: port.h:33
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3058

◆ pgstat_end_function_usage()

void pgstat_end_function_usage ( PgStat_FunctionCallUsage fcu,
bool  finalize 
)

Definition at line 1987 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().

1988 {
1989  PgStat_FunctionCounts *fs = fcu->fs;
1990  instr_time f_total;
1991  instr_time f_others;
1992  instr_time f_self;
1993 
1994  /* stats not wanted? */
1995  if (fs == NULL)
1996  return;
1997 
1998  /* total elapsed time in this function call */
1999  INSTR_TIME_SET_CURRENT(f_total);
2000  INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
2001 
2002  /* self usage: elapsed minus anything already charged to other calls */
2003  f_others = total_func_time;
2004  INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
2005  f_self = f_total;
2006  INSTR_TIME_SUBTRACT(f_self, f_others);
2007 
2008  /* update backend-wide total time */
2010 
2011  /*
2012  * Compute the new f_total_time as the total elapsed time added to the
2013  * pre-call value of f_total_time. This is necessary to avoid
2014  * double-counting any time taken by recursive calls of myself. (We do
2015  * not need any similar kluge for self time, since that already excludes
2016  * any recursive calls.)
2017  */
2018  INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
2019 
2020  /* update counters in function stats table */
2021  if (finalize)
2022  fs->f_numcalls++;
2023  fs->f_total_time = f_total;
2024  INSTR_TIME_ADD(fs->f_self_time, f_self);
2025 
2026  /* indicate that we have something to send */
2027  have_function_stats = true;
2028 }
instr_time f_self_time
Definition: pgstat.h:578
instr_time f_start
Definition: pgstat.h:946
instr_time save_total
Definition: pgstat.h:944
struct timeval instr_time
Definition: instr_time.h:150
instr_time f_total_time
Definition: pgstat.h:577
PgStat_FunctionCounts * fs
Definition: pgstat.h:940
PgStat_Counter f_numcalls
Definition: pgstat.h:576
#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:298
static bool have_function_stats
Definition: pgstat.c:227
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:942

◆ pgstat_fetch_global()

PgStat_GlobalStats* pgstat_fetch_global ( void  )

Definition at line 2935 of file pgstat.c.

References backend_read_statsfile(), and globalStats.

Referenced by pg_stat_get_snapshot_timestamp().

2936 {
2938 
2939  return &globalStats;
2940 }
static PgStat_GlobalStats globalStats
Definition: pgstat.c:281
static void backend_read_statsfile(void)
Definition: pgstat.c:4699

◆ pgstat_fetch_replslot()

PgStat_StatReplSlotEntry* pgstat_fetch_replslot ( NameData  slotname)

Definition at line 2983 of file pgstat.c.

References backend_read_statsfile(), and pgstat_get_replslot_entry().

Referenced by pg_stat_get_replication_slot().

2984 {
2986 
2987  return pgstat_get_replslot_entry(slotname, false);
2988 }
static void backend_read_statsfile(void)
Definition: pgstat.c:4699
static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry(NameData name, bool create_it)
Definition: pgstat.c:5870

◆ pgstat_fetch_slru()

PgStat_SLRUStats* pgstat_fetch_slru ( void  )

Definition at line 2967 of file pgstat.c.

References backend_read_statsfile(), and slruStats.

Referenced by pg_stat_get_slru().

2968 {
2970 
2971  return slruStats;
2972 }
static void backend_read_statsfile(void)
Definition: pgstat.c:4699
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:283

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 2887 of file pgstat.c.

References archiverStats, and backend_read_statsfile().

Referenced by pg_stat_get_archiver().

2888 {
2890 
2891  return &archiverStats;
2892 }
static void backend_read_statsfile(void)
Definition: pgstat.c:4699
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:280

◆ pgstat_fetch_stat_bgwriter()

PgStat_BgWriterStats* pgstat_fetch_stat_bgwriter ( void  )

Definition at line 2903 of file pgstat.c.

References backend_read_statsfile(), and PgStat_GlobalStats::bgwriter.

Referenced by pg_stat_get_bgwriter_buf_written_clean(), pg_stat_get_bgwriter_maxwritten_clean(), pg_stat_get_bgwriter_stat_reset_time(), and pg_stat_get_buf_alloc().

2904 {
2906 
2907  return &globalStats.bgwriter;
2908 }
static PgStat_GlobalStats globalStats
Definition: pgstat.c:281
PgStat_BgWriterStats bgwriter
Definition: pgstat.h:881
static void backend_read_statsfile(void)
Definition: pgstat.c:4699

◆ pgstat_fetch_stat_checkpointer()

◆ pgstat_fetch_stat_dbentry()

PgStat_StatDBEntry* pgstat_fetch_stat_dbentry ( Oid  dbid)

Definition at line 2774 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().

2775 {
2776  /*
2777  * If not done for this transaction, read the statistics collector stats
2778  * file into some hash tables.
2779  */
2781 
2782  /*
2783  * Lookup the requested database; return NULL if not found
2784  */
2786  (void *) &dbid,
2787  HASH_FIND, NULL);
2788 }
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:4699
static HTAB * pgStatDBHash
Definition: pgstat.c:273

◆ pgstat_fetch_stat_funcentry()

PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry ( Oid  func_id)

Definition at line 2857 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().

2858 {
2859  PgStat_StatDBEntry *dbentry;
2860  PgStat_StatFuncEntry *funcentry = NULL;
2861 
2862  /* load the stats file if needed */
2864 
2865  /* Lookup our database, then find the requested function. */
2867  if (dbentry != NULL && dbentry->functions != NULL)
2868  {
2869  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
2870  (void *) &func_id,
2871  HASH_FIND, NULL);
2872  }
2873 
2874  return funcentry;
2875 }
HTAB * functions
Definition: pgstat.h:775
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2774
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:4699
Oid MyDatabaseId
Definition: globals.c:88

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 2801 of file pgstat.c.

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

Referenced by 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().

2802 {
2803  Oid dbid;
2804  PgStat_StatDBEntry *dbentry;
2805  PgStat_StatTabEntry *tabentry;
2806 
2807  /*
2808  * If not done for this transaction, read the statistics collector stats
2809  * file into some hash tables.
2810  */
2812 
2813  /*
2814  * Lookup our database, then look in its table hash table.
2815  */
2816  dbid = MyDatabaseId;
2818  (void *) &dbid,
2819  HASH_FIND, NULL);
2820  if (dbentry != NULL && dbentry->tables != NULL)
2821  {
2822  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2823  (void *) &relid,
2824  HASH_FIND, NULL);
2825  if (tabentry)
2826  return tabentry;
2827  }
2828 
2829  /*
2830  * If we didn't find it, maybe it's a shared table.
2831  */
2832  dbid = InvalidOid;
2834  (void *) &dbid,
2835  HASH_FIND, NULL);
2836  if (dbentry != NULL && dbentry->tables != NULL)
2837  {
2838  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
2839  (void *) &relid,
2840  HASH_FIND, NULL);
2841  if (tabentry)
2842  return tabentry;
2843  }
2844 
2845  return NULL;
2846 }
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:4699
Oid MyDatabaseId
Definition: globals.c:88
#define InvalidOid
Definition: postgres_ext.h:36
static HTAB * pgStatDBHash
Definition: pgstat.c:273

◆ pgstat_fetch_stat_wal()

PgStat_WalStats* pgstat_fetch_stat_wal ( void  )

Definition at line 2951 of file pgstat.c.

References backend_read_statsfile(), and walStats.

Referenced by pg_stat_get_wal().

2952 {
2954 
2955  return &walStats;
2956 }
static PgStat_WalStats walStats
Definition: pgstat.c:282
static void backend_read_statsfile(void)
Definition: pgstat.c:4699

◆ pgstat_get_db_entry()

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

Definition at line 3677 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_autovac(), pgstat_recv_checksum_failure(), pgstat_recv_connect(), pgstat_recv_deadlock(), pgstat_recv_disconnect(), 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().

3678 {
3679  PgStat_StatDBEntry *result;
3680  bool found;
3681  HASHACTION action = (create ? HASH_ENTER : HASH_FIND);
3682 
3683  /* Lookup or create the hash table entry for this database */
3685  &databaseid,
3686  action, &found);
3687 
3688  if (!create && !found)
3689  return NULL;
3690 
3691  /*
3692  * If not found, initialize the new one. This creates empty hash tables
3693  * for tables and functions, too.
3694  */
3695  if (!found)
3696  reset_dbentry_counters(result);
3697 
3698  return result;
3699 }
static void reset_dbentry_counters(PgStat_StatDBEntry *dbentry)
Definition: pgstat.c:3619
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static HTAB * pgStatDBHash
Definition: pgstat.c:273
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 5870 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().

5871 {
5872  PgStat_StatReplSlotEntry *slotent;
5873  bool found;
5874 
5875  if (replSlotStatHash == NULL)
5876  {
5877  HASHCTL hash_ctl;
5878 
5879  /*
5880  * Quick return NULL if the hash table is empty and the caller didn't
5881  * request to create the entry.
5882  */
5883  if (!create)
5884  return NULL;
5885 
5886  hash_ctl.keysize = sizeof(NameData);
5887  hash_ctl.entrysize = sizeof(PgStat_StatReplSlotEntry);
5888  replSlotStatHash = hash_create("Replication slots hash",
5890  &hash_ctl,
5891  HASH_ELEM | HASH_BLOBS);
5892  }
5893 
5895  (void *) &name,
5896  create ? HASH_ENTER : HASH_FIND,
5897  &found);
5898 
5899  if (!slotent)
5900  {
5901  /* not found */
5902  Assert(!create && !found);
5903  return NULL;
5904  }
5905 
5906  /* initialize the entry */
5907  if (create && !found)
5908  {
5909  namestrcpy(&(slotent->slotname), NameStr(name));
5910  pgstat_reset_replslot(slotent, 0);
5911  }
5912 
5913  return slotent;
5914 }
static void pgstat_reset_replslot(PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
Definition: pgstat.c:5923
#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:561
static HTAB * replSlotStatHash
Definition: pgstat.c:284
#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 3708 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, 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(), and pgstat_recv_vacuum().

3709 {
3710  PgStat_StatTabEntry *result;
3711  bool found;
3712  HASHACTION action = (create ? HASH_ENTER : HASH_FIND);
3713 
3714  /* Lookup or create the hash table entry for this table */
3715  result = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
3716  &tableoid,
3717  action, &found);
3718 
3719  if (!create && !found)
3720  return NULL;
3721 
3722  /* If not found, initialize the new one. */
3723  if (!found)
3724  {
3725  result->numscans = 0;
3726  result->tuples_returned = 0;
3727  result->tuples_fetched = 0;
3728  result->tuples_inserted = 0;
3729  result->tuples_updated = 0;
3730  result->tuples_deleted = 0;
3731  result->tuples_hot_updated = 0;
3732  result->n_live_tuples = 0;
3733  result->n_dead_tuples = 0;
3734  result->changes_since_analyze = 0;
3735  result->inserts_since_vacuum = 0;
3736  result->blocks_fetched = 0;
3737  result->blocks_hit = 0;
3738  result->vacuum_timestamp = 0;
3739  result->vacuum_count = 0;
3740  result->autovac_vacuum_timestamp = 0;
3741  result->autovac_vacuum_count = 0;
3742  result->analyze_timestamp = 0;
3743  result->analyze_count = 0;
3744  result->autovac_analyze_timestamp = 0;
3745  result->autovac_analyze_count = 0;
3746  }
3747 
3748  return result;
3749 }
PgStat_Counter analyze_count
Definition: pgstat.h:810
PgStat_Counter tuples_returned
Definition: pgstat.h:789
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:811
PgStat_Counter vacuum_count
Definition: pgstat.h:806
PgStat_Counter numscans
Definition: pgstat.h:787
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:795
PgStat_Counter tuples_inserted
Definition: pgstat.h:792
PgStat_Counter n_live_tuples
Definition: pgstat.h:797
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:800
TimestampTz vacuum_timestamp
Definition: pgstat.h:805
PgStat_Counter n_dead_tuples
Definition: pgstat.h:798
PgStat_Counter tuples_fetched
Definition: pgstat.h:790
PgStat_Counter blocks_hit
Definition: pgstat.h:803
TimestampTz analyze_timestamp
Definition: pgstat.h:809
PgStat_Counter changes_since_analyze
Definition: pgstat.h:799
PgStat_Counter tuples_deleted
Definition: pgstat.h:794
PgStat_Counter tuples_updated
Definition: pgstat.h:793
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:807
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:812
PgStat_Counter blocks_fetched
Definition: pgstat.h:802
HASHACTION
Definition: hsearch.h:111
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:808

◆ pgstat_init()

void pgstat_init ( void  )

Definition at line 392 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().

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

◆ pgstat_init_function_usage()

void pgstat_init_function_usage ( FunctionCallInfo  fcinfo,
PgStat_FunctionCallUsage fcu 
)

Definition at line 1914 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().

1916 {
1917  PgStat_BackendFunctionEntry *htabent;
1918  bool found;
1919 
1920  if (pgstat_track_functions <= fcinfo->flinfo->fn_stats)
1921  {
1922  /* stats not wanted */
1923  fcu->fs = NULL;
1924  return;
1925  }
1926 
1927  if (!pgStatFunctions)
1928  {
1929  /* First time through - initialize function stat table */
1930  HASHCTL hash_ctl;
1931 
1932  hash_ctl.keysize = sizeof(Oid);
1933  hash_ctl.entrysize = sizeof(PgStat_BackendFunctionEntry);
1934  pgStatFunctions = hash_create("Function stat entries",
1936  &hash_ctl,
1937  HASH_ELEM | HASH_BLOBS);
1938  }
1939 
1940  /* Get the stats entry for this function, create if necessary */
1941  htabent = hash_search(pgStatFunctions, &fcinfo->flinfo->fn_oid,
1942  HASH_ENTER, &found);
1943  if (!found)
1944  MemSet(&htabent->f_counts, 0, sizeof(PgStat_FunctionCounts));
1945 
1946  fcu->fs = &htabent->f_counts;
1947 
1948  /* save stats for this function, later used to compensate for recursion */
1949  fcu->save_f_total_time = htabent->f_counts.f_total_time;
1950 
1951  /* save current backend-wide total time */
1952  fcu->save_total = total_func_time;
1953 
1954  /* get clock time as of function start */
1956 }
instr_time f_start
Definition: pgstat.h:946
#define HASH_ELEM
Definition: hsearch.h:95
instr_time save_total
Definition: pgstat.h:944
Size entrysize
Definition: hsearch.h:76
#define MemSet(start, val, len)
Definition: c.h:1008
instr_time f_total_time
Definition: pgstat.h:577
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:940
PgStat_FunctionCounts f_counts
Definition: pgstat.h:588
#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:298
static HTAB * pgStatFunctions
Definition: pgstat.c:221
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
instr_time save_f_total_time
Definition: pgstat.h:942
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry

◆ pgstat_initialize()

void pgstat_initialize ( void  )

Definition at line 3026 of file pgstat.c.

References Assert, before_shmem_exit(), pgstat_shutdown_hook(), and pgWalUsage.

Referenced by BaseInit().

3027 {
3028  Assert(!pgstat_is_initialized);
3029 
3030  /*
3031  * Initialize prevWalUsage with pgWalUsage so that pgstat_send_wal() can
3032  * calculate how much pgWalUsage counters are increased by subtracting
3033  * prevWalUsage from pgWalUsage.
3034  */
3036 
3037  /* Set up a process-exit hook to clean up */
3039 
3040 #ifdef USE_ASSERT_CHECKING
3041  pgstat_is_initialized = true;
3042 #endif
3043 }
static void pgstat_shutdown_hook(int code, Datum arg)
Definition: pgstat.c:2998
WalUsage pgWalUsage
Definition: instrument.c:22
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
#define Assert(condition)
Definition: c.h:804
static WalUsage prevWalUsage
Definition: pgstat.c:141

◆ pgstat_initstats()

void pgstat_initstats ( Relation  rel)

Definition at line 2044 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().

2045 {
2046  Oid rel_id = rel->rd_id;
2047  char relkind = rel->rd_rel->relkind;
2048 
2049  /*
2050  * We only count stats for relations with storage and partitioned tables
2051  */
2052  if (!RELKIND_HAS_STORAGE(relkind) && relkind != RELKIND_PARTITIONED_TABLE)
2053  {
2054  rel->pgstat_info = NULL;
2055  return;
2056  }
2057 
2059  {
2060  /* We're not counting at all */
2061  rel->pgstat_info = NULL;
2062  return;
2063  }
2064 
2065  /*
2066  * If we already set up this relation in the current transaction, nothing
2067  * to do.
2068  */
2069  if (rel->pgstat_info != NULL &&
2070  rel->pgstat_info->t_id == rel_id)
2071  return;
2072 
2073  /* Else find or make the PgStat_TableStatus entry, and update link */
2074  rel->pgstat_info = get_tabstat_entry(rel_id, rel->rd_rel->relisshared);
2075 }
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:173
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:2081
#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 1879 of file pgstat.c.

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

1880 {
1881  PgStat_MsgDummy msg;
1882 
1884  return;
1885 
1887  pgstat_send(&msg, sizeof(msg));
1888 }
static void pgstat_send(void *msg, int len)
Definition: pgstat.c:3071
NON_EXEC_STATIC pgsocket pgStatSock
Definition: pgstat.c:173
#define PGINVALID_SOCKET
Definition: port.h:33
PgStat_MsgHdr m_hdr
Definition: pgstat.h:237
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype)
Definition: pgstat.c:3058

◆ pgstat_read_db_statsfile()

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

Definition at line 4372 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().

4374 {
4375  PgStat_StatTabEntry *tabentry;
4376  PgStat_StatTabEntry tabbuf;
4377  PgStat_StatFuncEntry funcbuf;
4378  PgStat_StatFuncEntry *funcentry;
4379  FILE *fpin;
4380  int32 format_id;
4381  bool found;
4382  char statfile[MAXPGPATH];
4383 
4384  get_dbstat_filename(permanent, false, databaseid, statfile, MAXPGPATH);
4385 
4386  /*
4387  * Try to open the stats file. If it doesn't exist, the backends simply
4388  * return zero for anything and the collector simply starts from scratch
4389  * with empty counters.
4390  *
4391  * ENOENT is a possibility if the stats collector is not running or has
4392  * not yet written the stats file the first time. Any other failure
4393  * condition is suspicious.
4394  */
4395  if ((fpin = AllocateFile(statfile, PG_BINARY_R)) == NULL)
4396  {
4397  if (errno != ENOENT)
4400  errmsg("could not open statistics file \"%s\": %m",
4401  statfile)));
4402  return;
4403  }
4404 
4405  /*
4406  * Verify it's of the expected format.
4407  */
4408  if (fread(&format_id, 1, sizeof(format_id), fpin) != sizeof(format_id) ||
4409  format_id != PGSTAT_FILE_FORMAT_ID)
4410  {
4411  ereport(pgStatRunningInCollector ? LOG : WARNING,
4412  (errmsg("corrupted statistics file \"%s\"", statfile)));
4413  goto done;
4414  }
4415 
4416  /*
4417  * We found an existing collector stats file. Read it and put all the
4418  * hashtable entries into place.
4419  */
4420  for (;;)
4421  {
4422  switch (fgetc(fpin))
4423  {
4424  /*
4425  * 'T' A PgStat_StatTabEntry follows.
4426  */
4427  case 'T':
4428  if (fread(&tabbuf, 1, sizeof(PgStat_StatTabEntry),
4429  fpin) != sizeof(PgStat_StatTabEntry))
4430  {
4431  ereport(pgStatRunningInCollector ? LOG : WARNING,
4432  (errmsg("corrupted statistics file \"%s\"",
4433  statfile)));
4434  goto done;
4435  }
4436 
4437  /*
4438  * Skip if table data not wanted.
4439  */
4440  if (tabhash == NULL)
4441  break;
4442 
4443  tabentry = (PgStat_StatTabEntry *) hash_search(tabhash,
4444  (void *) &tabbuf.tableid,
4445  HASH_ENTER, &found);
4446 
4447  if (found)
4448  {
4449  ereport(pgStatRunningInCollector ? LOG : WARNING,
4450  (errmsg("corrupted statistics file \"%s\"",
4451  statfile)));
4452  goto done;
4453  }
4454 
4455  memcpy(tabentry, &tabbuf, sizeof(tabbuf));
4456  break;
4457 
4458  /*
4459  * 'F' A PgStat_StatFuncEntry follows.
4460  */
4461  case 'F':
4462  if (fread(&funcbuf, 1, sizeof(PgStat_StatFuncEntry),
4463  fpin) != sizeof(PgStat_StatFuncEntry))
4464  {
4465  ereport(pgStatRunningInCollector ? LOG : WARNING,
4466  (errmsg("corrupted statistics file \"%s\"",
4467  statfile)));
4468  goto done;
4469  }
4470 
4471  /*
4472  * Skip if function data not wanted.
4473  */
4474  if (funchash == NULL)
4475  break;
4476 
4477  funcentry = (PgStat_StatFuncEntry *) hash_search(funchash,
4478  (void *) &funcbuf.functionid,
4479  HASH_ENTER, &found);
4480 
4481  if (found)
4482  {
4483  ereport(pgStatRunningInCollector ? LOG : WARNING,
4484  (errmsg("corrupted statistics file \"%s\"",
4485  statfile)));
4486  goto done;
4487  }
4488 
4489  memcpy(funcentry, &funcbuf, sizeof(funcbuf));
4490  break;
4491 
4492  /*
4493  * 'E' The EOF marker of a complete stats file.
4494  */
4495  case 'E':
4496  goto done;
4497 
4498  default:
4499  ereport(pgStatRunningInCollector ? LOG : WARNING,
4500  (errmsg("corrupted statistics file \"%s\"",
4501  statfile)));
4502  goto done;
4503  }
4504  }
4505 
4506 done:
4507  FreeFile(fpin);
4508 
4509  if (permanent)
4510  {
4511  elog(DEBUG2, "removing permanent stats file \"%s\"", statfile);
4512  unlink(statfile);
4513  }
4514 }
static bool pgStatRunningInCollector
Definition: pgstat.c:179
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:2460
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
int FreeFile(FILE *file)
Definition: fd.c:2659
#define PGSTAT_FILE_FORMAT_ID
Definition: pgstat.h:728
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:3920

◆ pgstat_read_db_statsfile_timestamp()

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

Definition at line 4535 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().

4537 {
4538  PgStat_StatDBEntry dbentry;
4539  PgStat_GlobalStats myGlobalStats;
4540  PgStat_ArchiverStats myArchiverStats;
4541  PgStat_WalStats myWalStats;
4542  PgStat_SLRUStats mySLRUStats[SLRU_NUM_ELEMENTS];
4543  PgStat_StatReplSlotEntry myReplSlotStats;
4544  FILE *fpin;
4545  int32 format_id;
4546  const char *statfile = permanent ? PGSTAT_STAT_PERMANENT_FILENAME : pgstat_stat_filename;
4547 
4548  /*
4549  * Try to open the stats file. As above, anything but ENOENT is worthy of
4550  * complaining about.
4551  */
4552  if ((fpin = AllocateFile(statfile, PG_BINARY_R)) == NULL)
4553  {
4554  if (errno != ENOENT)
4557  errmsg("could not open statistics file \"%s\": %m",
4558  statfile)));
4559  return false;
4560  }
4561 
4562  /*
4563  * Verify it's of the expected format.
4564  */
4565  if (fread(&format_id, 1, sizeof(format_id), fpin) != sizeof(format_id) ||
4566  format_id != PGSTAT_FILE_FORMAT_ID)
4567  {
4568  ereport(pgStatRunningInCollector ? LOG : WARNING,
4569  (errmsg("corrupted statistics file \"%s\"", statfile)));
4570  FreeFile(fpin);
4571  return false;
4572  }
4573 
4574  /*
4575  * Read global stats struct
4576  */
4577  if (fread(&myGlobalStats, 1, sizeof(myGlobalStats),
4578  fpin) != sizeof(myGlobalStats))
4579  {
4580  ereport(pgStatRunningInCollector ? LOG : WARNING,
4581  (errmsg("corrupted statistics file \"%s\"", statfile)));
4582  FreeFile(fpin);
4583  return false;
4584  }
4585 
4586  /*
4587  * Read archiver stats struct
4588  */
4589  if (fread(&myArchiverStats, 1, sizeof(myArchiverStats),
4590  fpin) != sizeof(myArchiverStats))
4591  {
4592  ereport(pgStatRunningInCollector ? LOG : WARNING,
4593  (errmsg("corrupted statistics file \"%s\"", statfile)));
4594  FreeFile(fpin);
4595  return false;
4596  }
4597 
4598  /*
4599  * Read WAL stats struct
4600  */
4601  if (fread(&myWalStats, 1, sizeof(myWalStats), fpin) != sizeof(myWalStats))
4602  {
4603  ereport(pgStatRunningInCollector ? LOG : WARNING,
4604  (errmsg("corrupted statistics file \"%s\"", statfile)));
4605  FreeFile(fpin);
4606  return false;
4607  }
4608 
4609  /*
4610  * Read SLRU stats struct
4611  */
4612  if (fread(mySLRUStats, 1, sizeof(mySLRUStats), fpin) != sizeof(mySLRUStats))
4613  {
4614  ereport(pgStatRunningInCollector ? LOG : WARNING,
4615  (errmsg("corrupted statistics file \"%s\"", statfile)));
4616  FreeFile(fpin);
4617  return false;
4618  }
4619 
4620  /* By default, we're going to return the timestamp of the global file. */
4621  *ts = myGlobalStats.stats_timestamp;
4622 
4623  /*
4624  * We found an existing collector stats file. Read it and look for a
4625  * record for the requested database. If found, use its timestamp.
4626  */
4627  for (;;)
4628  {
4629  switch (fgetc(fpin))
4630  {
4631  /*
4632  * 'D' A PgStat_StatDBEntry struct describing a database
4633  * follows.
4634  */
4635  case 'D':
4636  if (fread(&dbentry, 1, offsetof(PgStat_StatDBEntry, tables),
4637  fpin) != offsetof(PgStat_StatDBEntry, tables))
4638  {
4639  ereport(pgStatRunningInCollector ? LOG : WARNING,
4640  (errmsg("corrupted statistics file \"%s\"",
4641  statfile)));
4642  FreeFile(fpin);
4643  return false;
4644  }
4645 
4646  /*
4647  * If this is the DB we're looking for, save its timestamp and
4648  * we're done.
4649  */
4650  if (dbentry.databaseid == databaseid)
4651  {
4652  *ts = dbentry.stats_timestamp;
4653  goto done;
4654  }
4655 
4656  break;
4657 
4658  /*
4659  * 'R' A PgStat_StatReplSlotEntry struct describing a
4660  * replication slot follows.
4661  */
4662  case 'R':
4663  if (fread(&myReplSlotStats, 1, sizeof(PgStat_StatReplSlotEntry), fpin)
4664  != sizeof(PgStat_StatReplSlotEntry))
4665  {
4666  ereport(pgStatRunningInCollector ? LOG : WARNING,
4667  (errmsg("corrupted statistics file \"%s\"",
4668  statfile)));
4669  FreeFile(fpin);
4670  return false;
4671  }
4672  break;
4673 
4674  case 'E':
4675  goto done;
4676 
4677  default:
4678  {
4679  ereport(pgStatRunningInCollector ? LOG : WARNING,
4680  (errmsg("corrupted statistics file \"%s\"",
4681  statfile)));
4682  FreeFile(fpin);
4683  return false;
4684  }
4685  }
4686  }
4687 
4688 done:
4689  FreeFile(fpin);
4690  return true;
4691 }
TimestampTz stats_timestamp
Definition: pgstat.h:768
#define SLRU_NUM_ELEMENTS
Definition: pgstat.c:159
static bool pgStatRunningInCollector
Definition: pgstat.c:179
TimestampTz stats_timestamp
Definition: pgstat.h:878
#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:2460
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
int FreeFile(FILE *file)
Definition: fd.c:2659
#define PGSTAT_FILE_FORMAT_ID
Definition: pgstat.h:728
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 4069 of file pgstat.c.

References AllocateFile(), PgStat_GlobalStats::bgwriter, 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_BgWriterStats::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().

4070 {
4071  PgStat_StatDBEntry *dbentry;
4072  PgStat_StatDBEntry dbbuf;
4073  HASHCTL hash_ctl;
4074  HTAB *dbhash;
4075  FILE *fpin;
4076  int32 format_id;
4077  bool found;
4078  const char *statfile = permanent ? PGSTAT_STAT_PERMANENT_FILENAME : pgstat_stat_filename;
4079  int i;
4080  TimestampTz ts;
4081 
4082  /*
4083  * The tables will live in pgStatLocalContext.
4084  */
4086 
4087  /*
4088  * Create the DB hashtable
4089  */
4090  hash_ctl.keysize = sizeof(Oid);
4091  hash_ctl.entrysize = sizeof(PgStat_StatDBEntry);
4092  hash_ctl.hcxt = pgStatLocalContext;
4093  dbhash = hash_create("Databases hash", PGSTAT_DB_HASH_SIZE, &hash_ctl,
4095 
4096  /*
4097  * Clear out global, archiver, WAL and SLRU statistics so they start from
4098  * zero in case we can't load an existing statsfile.
4099  */
4100  memset(&globalStats, 0, sizeof(globalStats));
4101  memset(&archiverStats, 0, sizeof(archiverStats));
4102  memset(&walStats, 0, sizeof(walStats));
4103  memset(&slruStats, 0, sizeof(slruStats));
4104 
4105  /*
4106  * Set the current timestamp (will be kept only in case we can't load an
4107  * existing statsfile).
4108  */
4109  ts = GetCurrentTimestamp();
4113 
4114  /*
4115  * Set the same reset timestamp for all SLRU items too.
4116  */
4117  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
4118  slruStats[i].stat_reset_timestamp = ts;
4119 
4120  /*
4121  * Try to open the stats file. If it doesn't exist, the backends simply
4122  * return zero for anything and the collector simply starts from scratch
4123  * with empty counters.
4124  *
4125  * ENOENT is a possibility if the stats collector is not running or has
4126  * not yet written the stats file the first time. Any other failure
4127  * condition is suspicious.
4128  */
4129  if ((fpin = AllocateFile(statfile, PG_BINARY_R)) == NULL)
4130  {
4131  if (errno != ENOENT)
4134  errmsg("could not open statistics file \"%s\": %m",
4135  statfile)));
4136  return dbhash;
4137  }
4138 
4139  /*
4140  * Verify it's of the expected format.
4141  */
4142  if (fread(&format_id, 1, sizeof(format_id), fpin) != sizeof(format_id) ||
4143  format_id != PGSTAT_FILE_FORMAT_ID)
4144  {
4145  ereport(pgStatRunningInCollector ? LOG : WARNING,
4146  (errmsg("corrupted statistics file \"%s\"", statfile)));
4147  goto done;
4148  }
4149 
4150  /*
4151  * Read global stats struct
4152  */
4153  if (fread(&globalStats, 1, sizeof(globalStats), fpin) != sizeof(globalStats))
4154  {
4155  ereport(pgStatRunningInCollector ? LOG : WARNING,
4156  (errmsg("corrupted statistics file \"%s\"", statfile)));
4157  memset(&globalStats, 0, sizeof(globalStats));
4158  goto done;
4159  }
4160 
4161  /*
4162  * In the collector, disregard the timestamp we read from the permanent
4163  * stats file; we should be willing to write a temp stats file immediately
4164  * upon the first request from any backend. This only matters if the old
4165  * file's timestamp is less than PGSTAT_STAT_INTERVAL ago, but that's not
4166  * an unusual scenario.
4167  */
4170 
4171  /*
4172  * Read archiver stats struct
4173  */
4174  if (fread(&archiverStats, 1, sizeof(archiverStats), fpin) != sizeof(archiverStats))
4175  {
4176  ereport(pgStatRunningInCollector ? LOG : WARNING,
4177  (errmsg("corrupted statistics file \"%s\"", statfile)));
4178  memset(&archiverStats, 0, sizeof(archiverStats));
4179  goto done;
4180  }
4181 
4182  /*
4183  * Read WAL stats struct
4184  */
4185  if (fread(&walStats, 1, sizeof(walStats), fpin) != sizeof(walStats))
4186  {
4187  ereport(pgStatRunningInCollector ? LOG : WARNING,
4188  (errmsg("corrupted statistics file \"%s\"", statfile)));
4189  memset(&walStats, 0, sizeof(walStats));
4190  goto done;
4191  }
4192 
4193  /*
4194  * Read SLRU stats struct
4195  */
4196  if (fread(slruStats, 1, sizeof(slruStats), fpin) != sizeof(slruStats))
4197  {
4198  ereport(pgStatRunningInCollector ? LOG : WARNING,
4199  (errmsg("corrupted statistics file \"%s\"", statfile)));
4200  memset(&slruStats, 0, sizeof(slruStats));
4201  goto done;
4202  }
4203 
4204  /*
4205  * We found an existing collector stats file. Read it and put all the
4206  * hashtable entries into place.
4207  */
4208  for (;;)
4209  {
4210  switch (fgetc(fpin))
4211  {
4212  /*
4213  * 'D' A PgStat_StatDBEntry struct describing a database
4214  * follows.
4215  */
4216  case 'D':
4217  if (fread(&dbbuf, 1, offsetof(PgStat_StatDBEntry, tables),
4218  fpin) != offsetof(PgStat_StatDBEntry, tables))
4219  {
4220  ereport(pgStatRunningInCollector ? LOG : WARNING,
4221  (errmsg("corrupted statistics file \"%s\"",
4222  statfile)));
4223  goto done;
4224  }
4225 
4226  /*
4227  * Add to the DB hash
4228  */
4229  dbentry = (PgStat_StatDBEntry *) hash_search(dbhash,
4230  (void *) &dbbuf.databaseid,
4231  HASH_ENTER,
4232  &found);
4233  if (found)
4234  {
4235  ereport(pgStatRunningInCollector ? LOG : WARNING,
4236  (errmsg("corrupted statistics file \"%s\"",
4237  statfile)));
4238  goto done;
4239  }
4240 
4241  memcpy(dbentry, &dbbuf, sizeof(PgStat_StatDBEntry));
4242  dbentry->tables = NULL;
4243  dbentry->functions = NULL;
4244 
4245  /*
4246  * In the collector, disregard the timestamp we read from the
4247  * permanent stats file; we should be willing to write a temp
4248  * stats file immediately upon the first request from any
4249  * backend.
4250  */
4252  dbentry->stats_timestamp = 0;
4253 
4254  /*
4255  * Don't create tables/functions hashtables for uninteresting
4256  * databases.
4257  */
4258  if (onlydb != InvalidOid)
4259  {
4260  if (dbbuf.databaseid != onlydb &&
4261  dbbuf.databaseid != InvalidOid)
4262  break;
4263  }
4264 
4265  hash_ctl.keysize = sizeof(Oid);
4266  hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
4267  hash_ctl.hcxt = pgStatLocalContext;
4268  dbentry->tables = hash_create("Per-database table",
4270  &hash_ctl,
4272 
4273  hash_ctl.keysize = sizeof(Oid);
4274  hash_ctl.entrysize = sizeof(PgStat_StatFuncEntry);
4275  hash_ctl.hcxt = pgStatLocalContext;
4276  dbentry->functions = hash_create("Per-database function",
4278  &hash_ctl,
4280 
4281  /*
4282  * If requested, read the data from the database-specific
4283  * file. Otherwise we just leave the hashtables empty.
4284  */
4285  if (deep)
4287  dbentry->tables,
4288  dbentry->functions,
4289  permanent);
4290 
4291  break;
4292 
4293  /*
4294  * 'R' A PgStat_StatReplSlotEntry struct describing a
4295  * replication slot follows.
4296  */
4297  case 'R':
4298  {
4299  PgStat_StatReplSlotEntry slotbuf;
4300  PgStat_StatReplSlotEntry *slotent;
4301 
4302  if (fread(&slotbuf, 1, sizeof(PgStat_StatReplSlotEntry), fpin)
4303  != sizeof(PgStat_StatReplSlotEntry))
4304  {
4305  ereport(pgStatRunningInCollector ? LOG : WARNING,
4306  (errmsg("corrupted statistics file \"%s\"",
4307  statfile)));
4308  goto done;
4309  }
4310 
4311  /* Create hash table if we don't have it already. */
4312  if (replSlotStatHash == NULL)
4313  {
4314  HASHCTL hash_ctl;
4315 
4316  hash_ctl.keysize = sizeof(NameData);
4317  hash_ctl.entrysize = sizeof(PgStat_StatReplSlotEntry);
4318  hash_ctl.hcxt = pgStatLocalContext;
4319  replSlotStatHash = hash_create("Replication slots hash",
4321  &hash_ctl,
4323  }
4324 
4326  (void *) &slotbuf.slotname,
4327  HASH_ENTER, NULL);
4328  memcpy(slotent, &slotbuf, sizeof(PgStat_StatReplSlotEntry));
4329  break;
4330  }
4331 
4332  case 'E':
4333  goto done;
4334 
4335  default:
4336  ereport(pgStatRunningInCollector ? LOG : WARNING,
4337  (errmsg("corrupted statistics file \"%s\"",
4338  statfile)));
4339  goto done;
4340  }
4341  }
4342 
4343 done:
4344  FreeFile(fpin);
4345 
4346  /* If requested to read the permanent file, also get rid of it. */
4347  if (permanent)
4348  {
4349  elog(DEBUG2, "removing permanent stats file \"%s\"", statfile);
4350  unlink(statfile);
4351  }
4352 
4353  return dbhash;
4354 }
#define PGSTAT_DB_HASH_SIZE
Definition: pgstat.c:105
TimestampTz stat_reset_timestamp
Definition: pgstat.h:897
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
TimestampTz stats_timestamp
Definition: pgstat.h:768
MemoryContext hcxt
Definition: hsearch.h:86
static PgStat_GlobalStats globalStats
Definition: pgstat.c:281
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
#define SLRU_NUM_ELEMENTS
Definition: pgstat.c:159
struct PgStat_StatReplSlotEntry PgStat_StatReplSlotEntry
static PgStat_WalStats walStats
Definition: pgstat.c:282
#define PGSTAT_TAB_HASH_SIZE
Definition: pgstat.c:106
PgStat_BgWriterStats bgwriter
Definition: pgstat.h:881
static bool pgStatRunningInCollector
Definition: pgstat.c:179
HTAB * functions
Definition: pgstat.h:775
Size entrysize
Definition: hsearch.h:76
#define PGSTAT_REPLSLOT_HASH_SIZE
Definition: pgstat.c:108
TimestampTz stats_timestamp
Definition: pgstat.h:878
#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
TimestampTz stat_reset_timestamp
Definition: pgstat.h:855
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:2460
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:4836
static void pgstat_read_db_statsfile(Oid databaseid, HTAB *tabhash, HTAB *funchash, bool permanent)
Definition: pgstat.c:4372
#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:280
struct PgStat_StatDBEntry PgStat_StatDBEntry
int FreeFile(FILE *file)
Definition: fd.c:2659
#define PGSTAT_FILE_FORMAT_ID
Definition: pgstat.h:728
TimestampTz stat_reset_timestamp
Definition: pgstat.h:844
int errmsg(const char *fmt,...)
Definition: elog.c:909
static HTAB * replSlotStatHash
Definition: pgstat.c:284
#define elog(elevel,...)
Definition: elog.h:232
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:283
int i
static MemoryContext pgStatLocalContext
Definition: pgstat.c:272
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 5420 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_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().

5421 {
5422  PgStat_StatDBEntry *dbentry;
5423  PgStat_StatTabEntry *tabentry;
5424 
5425  /*
5426  * Store the data in the table's hashtable entry.
5427  */
5428  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5429 
5430  tabentry = pgstat_get_tab_entry(dbentry, msg->m_tableoid, true);
5431 
5432  tabentry->n_live_tuples = msg->m_live_tuples;
5433  tabentry->n_dead_tuples = msg->m_dead_tuples;
5434 
5435  /*
5436  * If commanded, reset changes_since_analyze to zero. This forgets any
5437  * changes that were committed while the ANALYZE was in progress, but we
5438  * have no good way to estimate how many of those there were.
5439  */
5440  if (msg->m_resetcounter)
5441  tabentry->changes_since_analyze = 0;
5442 
5443  if (msg->m_autovacuum)
5444  {
5445  tabentry->autovac_analyze_timestamp = msg->m_analyzetime;
5446  tabentry->autovac_analyze_count++;
5447  }
5448  else
5449  {
5450  tabentry->analyze_timestamp = msg->m_analyzetime;
5451  tabentry->analyze_count++;
5452  }
5453 }
PgStat_Counter analyze_count
Definition: pgstat.h:810
static PgStat_StatTabEntry * pgstat_get_tab_entry(PgStat_StatDBEntry *dbentry, Oid tableoid, bool create)
Definition: pgstat.c:3708
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:811
TimestampTz m_analyzetime
Definition: pgstat.h:434
bool m_resetcounter
Definition: pgstat.h:433
PgStat_Counter n_live_tuples
Definition: pgstat.h:797
PgStat_Counter n_dead_tuples
Definition: pgstat.h:798
PgStat_Counter m_live_tuples
Definition: pgstat.h:435
bool m_autovacuum
Definition: pgstat.h:432
TimestampTz analyze_timestamp
Definition: pgstat.h:809
PgStat_Counter changes_since_analyze
Definition: pgstat.h:799
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:812
PgStat_Counter m_dead_tuples
Definition: pgstat.h:436

◆ pgstat_recv_archiver()

static void pgstat_recv_archiver ( PgStat_MsgArchiver msg,
int  len 
)
static

Definition at line 5463 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().

5464 {
5465  if (msg->m_failed)
5466  {
5467  /* Failed archival attempt */
5469  memcpy(archiverStats.last_failed_wal, msg->m_xlog,
5470  sizeof(archiverStats.last_failed_wal));
5472  }
5473  else
5474  {
5475  /* Successful archival operation */
5477  memcpy(archiverStats.last_archived_wal, msg->m_xlog,
5480  }
5481 }
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:841
char m_xlog[MAX_XFN_CHARS+1]
Definition: pgstat.h:448
PgStat_Counter archived_count
Definition: pgstat.h:836
TimestampTz m_timestamp
Definition: pgstat.h:449
TimestampTz last_failed_timestamp
Definition: pgstat.h:843
PgStat_Counter failed_count
Definition: pgstat.h:840
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:280
TimestampTz last_archived_timestamp
Definition: pgstat.h:839
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:837

◆ pgstat_recv_autovac()

static void pgstat_recv_autovac ( PgStat_MsgAutovacStart msg,
int  len 
)
static

Definition at line 5355 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().

5356 {
5357  PgStat_StatDBEntry *dbentry;
5358 
5359  /*
5360  * Store the last autovacuum time in the database's hashtable entry.
5361  */
5362  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5363 
5364  dbentry->last_autovac_time = msg->m_start_time;
5365 }
TimestampTz last_autovac_time
Definition: pgstat.h:746
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
TimestampTz m_start_time
Definition: pgstat.h:401

◆ pgstat_recv_bgwriter()

static void pgstat_recv_bgwriter ( PgStat_MsgBgWriter msg,
int  len 
)
static

◆ pgstat_recv_checkpointer()

static void pgstat_recv_checkpointer ( PgStat_MsgCheckpointer msg,
int  len 
)
static

Definition at line 5504 of file pgstat.c.

References PgStat_CheckpointerStats::buf_fsync_backend, PgStat_CheckpointerStats::buf_written_backend, PgStat_CheckpointerStats::buf_written_checkpoints, PgStat_CheckpointerStats::checkpoint_sync_time, PgStat_CheckpointerStats::checkpoint_write_time, PgStat_GlobalStats::checkpointer, PgStat_MsgCheckpointer::m_buf_fsync_backend, PgStat_MsgCheckpointer::m_buf_written_backend, PgStat_MsgCheckpointer::m_buf_written_checkpoints, PgStat_MsgCheckpointer::m_checkpoint_sync_time, PgStat_MsgCheckpointer::m_checkpoint_write_time, PgStat_MsgCheckpointer::m_requested_checkpoints, PgStat_MsgCheckpointer::m_timed_checkpoints, PgStat_CheckpointerStats::requested_checkpoints, and PgStat_CheckpointerStats::timed_checkpoints.

Referenced by PgstatCollectorMain().

5505 {
5513 }
PgStat_Counter m_buf_written_backend
Definition: pgstat.h:476
PgStat_Counter requested_checkpoints
Definition: pgstat.h:865
static PgStat_GlobalStats globalStats
Definition: pgstat.c:281
PgStat_Counter m_checkpoint_sync_time
Definition: pgstat.h:479
PgStat_Counter checkpoint_write_time
Definition: pgstat.h:866
PgStat_Counter buf_written_backend
Definition: pgstat.h:869
PgStat_Counter m_timed_checkpoints
Definition: pgstat.h:473
PgStat_Counter m_buf_written_checkpoints
Definition: pgstat.h:475
PgStat_Counter m_checkpoint_write_time
Definition: pgstat.h:478
PgStat_Counter m_buf_fsync_backend
Definition: pgstat.h:477
PgStat_CheckpointerStats checkpointer
Definition: pgstat.h:880
PgStat_Counter m_requested_checkpoints
Definition: pgstat.h:474
PgStat_Counter buf_written_checkpoints
Definition: pgstat.h:868
PgStat_Counter timed_checkpoints
Definition: pgstat.h:864
PgStat_Counter buf_fsync_backend
Definition: pgstat.h:870
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:867

◆ pgstat_recv_checksum_failure()

static void pgstat_recv_checksum_failure ( PgStat_MsgChecksumFailure msg,
int  len 
)
static

Definition at line 5615 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().

5616 {
5617  PgStat_StatDBEntry *dbentry;
5618 
5619  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5620 
5621  dbentry->n_checksum_failures += msg->m_failurecount;
5622  dbentry->last_checksum_failure = msg->m_failure_time;
5623 }
PgStat_Counter n_checksum_failures
Definition: pgstat.h:755
TimestampTz last_checksum_failure
Definition: pgstat.h:756
TimestampTz m_failure_time
Definition: pgstat.h:658
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677

◆ pgstat_recv_connect()

static void pgstat_recv_connect ( PgStat_MsgConnect msg,
int  len 
)
static

Definition at line 5683 of file pgstat.c.

References PgStat_MsgConnect::m_databaseid, PgStat_StatDBEntry::n_sessions, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5684 {
5685  PgStat_StatDBEntry *dbentry;
5686 
5687  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5688  dbentry->n_sessions++;
5689 }
PgStat_Counter n_sessions
Definition: pgstat.h:759
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677

◆ pgstat_recv_deadlock()

static void pgstat_recv_deadlock ( PgStat_MsgDeadlock msg,
int  len 
)
static

Definition at line 5599 of file pgstat.c.

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

Referenced by PgstatCollectorMain().

5600 {
5601  PgStat_StatDBEntry *dbentry;
5602 
5603  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5604 
5605  dbentry->n_deadlocks++;
5606 }
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
PgStat_Counter n_deadlocks
Definition: pgstat.h:754

◆ pgstat_recv_disconnect()

static void pgstat_recv_disconnect ( PgStat_MsgDisconnect msg,
int  len 
)
static

Definition at line 5698 of file pgstat.c.

References DISCONNECT_CLIENT_EOF, DISCONNECT_FATAL, DISCONNECT_KILLED, DISCONNECT_NORMAL, DISCONNECT_NOT_YET, PgStat_MsgDisconnect::m_cause, PgStat_MsgDisconnect::m_databaseid, PgStat_StatDBEntry::n_sessions_abandoned, PgStat_StatDBEntry::n_sessions_fatal, PgStat_StatDBEntry::n_sessions_killed, and pgstat_get_db_entry().

Referenced by PgstatCollectorMain().

5699 {
5700  PgStat_StatDBEntry *dbentry;
5701 
5702  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5703 
5704  switch (msg->m_cause)
5705  {
5706  case DISCONNECT_NOT_YET:
5707  case DISCONNECT_NORMAL:
5708  /* we don't collect these */
5709  break;
5710  case DISCONNECT_CLIENT_EOF:
5711  dbentry->n_sessions_abandoned++;
5712  break;
5713  case DISCONNECT_FATAL:
5714  dbentry->n_sessions_fatal++;
5715  break;
5716  case DISCONNECT_KILLED:
5717  dbentry->n_sessions_killed++;
5718  break;
5719  }
5720 }
SessionEndType m_cause
Definition: pgstat.h:680
PgStat_Counter n_sessions_killed
Definition: pgstat.h:765
PgStat_Counter n_sessions_abandoned
Definition: pgstat.h:763
PgStat_Counter n_sessions_fatal
Definition: pgstat.h:764
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677

◆ pgstat_recv_dropdb()

static void pgstat_recv_dropdb ( PgStat_MsgDropdb msg,
int  len 
)
static

Definition at line 5139 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().

5140 {
5141  Oid dbid = msg->m_databaseid;
5142  PgStat_StatDBEntry *dbentry;
5143 
5144  /*
5145  * Lookup the database in the hashtable.
5146  */
5147  dbentry = pgstat_get_db_entry(dbid, false);
5148 
5149  /*
5150  * If found, remove it (along with the db statfile).
5151  */
5152  if (dbentry)
5153  {
5154  char statfile[MAXPGPATH];
5155 
5156  get_dbstat_filename(false, false, dbid, statfile, MAXPGPATH);
5157 
5158  elog(DEBUG2, "removing stats file \"%s\"", statfile);
5159  unlink(statfile);
5160 
5161  if (dbentry->tables != NULL)
5162  hash_destroy(dbentry->tables);
5163  if (dbentry->functions != NULL)
5164  hash_destroy(dbentry->functions);
5165 
5167  (void *) &dbid,
5168  HASH_REMOVE, NULL) == NULL)
5169  ereport(ERROR,
5170  (errmsg("database hash table corrupted during cleanup --- abort")));
5171  }
5172 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
HTAB * functions
Definition: pgstat.h:775
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:330
#define ereport(elevel,...)
Definition: elog.h:157
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
static HTAB * pgStatDBHash
Definition: pgstat.c:273
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:3920

◆ pgstat_recv_funcpurge()

static void pgstat_recv_funcpurge ( PgStat_MsgFuncpurge msg,
int  len 
)
static

Definition at line 5794 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().

5795 {
5796  PgStat_StatDBEntry *dbentry;
5797  int i;
5798 
5799  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5800 
5801  /*
5802  * No need to purge if we don't even know the database.
5803  */
5804  if (!dbentry || !dbentry->functions)
5805  return;
5806 
5807  /*
5808  * Process all function entries in the message.
5809  */
5810  for (i = 0; i < msg->m_nentries; i++)
5811  {
5812  /* Remove from hashtable if present; we don't care if it's not. */
5813  (void) hash_search(dbentry->functions,
5814  (void *) &(msg->m_functionid[i]),
5815  HASH_REMOVE, NULL);
5816  }
5817 }
HTAB * functions
Definition: pgstat.h:775
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:3677
int i
Oid m_functionid[PGSTAT_NUM_FUNCPURGE]
Definition: pgstat.h:634

◆ pgstat_recv_funcstat()

static void pgstat_recv_funcstat ( PgStat_MsgFuncstat msg,
int  len 
)
static

Definition at line 5746 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().

5747 {
5748  PgStat_FunctionEntry *funcmsg = &(msg->m_entry[0]);
5749  PgStat_StatDBEntry *dbentry;
5750  PgStat_StatFuncEntry *funcentry;
5751  int i;
5752  bool found;
5753 
5754  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5755 
5756  /*
5757  * Process all function entries in the message.
5758  */
5759  for (i = 0; i < msg->m_nentries; i++, funcmsg++)
5760  {
5761  funcentry = (PgStat_StatFuncEntry *) hash_search(dbentry->functions,
5762  (void *) &(funcmsg->f_id),
5763  HASH_ENTER, &found);
5764 
5765  if (!found)
5766  {
5767  /*
5768  * If it's a new function entry, initialize counters to the values
5769  * we just got.
5770  */
5771  funcentry->f_numcalls = funcmsg->f_numcalls;
5772  funcentry->f_total_time = funcmsg->f_total_time;
5773  funcentry->f_self_time = funcmsg->f_self_time;
5774  }
5775  else
5776  {
5777  /*
5778  * Otherwise add the values to the existing entry.
5779  */
5780  funcentry->f_numcalls += funcmsg->f_numcalls;
5781  funcentry->f_total_time += funcmsg->f_total_time;
5782  funcentry->f_self_time += funcmsg->f_self_time;
5783  }
5784  }
5785 }
PgStat_Counter f_self_time
Definition: pgstat.h:600
HTAB * functions
Definition: pgstat.h:775
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter f_total_time
Definition: pgstat.h:826
PgStat_Counter f_numcalls
Definition: pgstat.h:824
PgStat_Counter f_total_time
Definition: pgstat.h:599
PgStat_FunctionEntry m_entry[PGSTAT_NUM_FUNCENTRIES]
Definition: pgstat.h:617
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
int i
PgStat_Counter f_numcalls
Definition: pgstat.h:598
PgStat_Counter f_self_time
Definition: pgstat.h:827

◆ pgstat_recv_inquiry()

static void pgstat_recv_inquiry ( PgStat_MsgInquiry msg,
int  len 
)
static

Definition at line 4896 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().

4897 {
4898  PgStat_StatDBEntry *dbentry;
4899 
4900  elog(DEBUG2, "received inquiry for database %u", msg->databaseid);
4901 
4902  /*
4903  * If there's already a write request for this DB, there's nothing to do.
4904  *
4905  * Note that if a request is found, we return early and skip the below
4906  * check for clock skew. This is okay, since the only way for a DB
4907  * request to be present in the list is that we have been here since the
4908  * last write round. It seems sufficient to check for clock skew once per
4909  * write round.
4910  */
4912  return;
4913 
4914  /*
4915  * Check to see if we last wrote this database at a time >= the requested
4916  * cutoff time. If so, this is a stale request that was generated before
4917  * we updated the DB file, and we don't need to do so again.
4918  *
4919  * If the requestor's local clock time is older than stats_timestamp, we
4920  * should suspect a clock glitch, ie system time going backwards; though
4921  * the more likely explanation is just delayed message receipt. It is
4922  * worth expending a GetCurrentTimestamp call to be sure, since a large
4923  * retreat in the system clock reading could otherwise cause us to neglect
4924  * to update the stats file for a long time.
4925  */
4926  dbentry = pgstat_get_db_entry(msg->databaseid, false);
4927  if (dbentry == NULL)
4928  {
4929  /*
4930  * We have no data for this DB. Enter a write request anyway so that
4931  * the global stats will get updated. This is needed to prevent
4932  * backend_read_statsfile from waiting for data that we cannot supply,
4933  * in the case of a new DB that nobody has yet reported any stats for.
4934  * See the behavior of pgstat_read_db_statsfile_timestamp.
4935  */
4936  }
4937  else if (msg->clock_time < dbentry->stats_timestamp)
4938  {
4939  TimestampTz cur_ts = GetCurrentTimestamp();
4940 
4941  if (cur_ts < dbentry->stats_timestamp)
4942  {
4943  /*
4944  * Sure enough, time went backwards. Force a new stats file write
4945  * to get back in sync; but first, log a complaint.
4946  */
4947  char *writetime;
4948  char *mytime;
4949 
4950  /* Copy because timestamptz_to_str returns a static buffer */
4951  writetime = pstrdup(timestamptz_to_str(dbentry->stats_timestamp));
4952  mytime = pstrdup(timestamptz_to_str(cur_ts));
4953  ereport(LOG,
4954  (errmsg("stats_timestamp %s is later than collector's time %s for database %u",
4955  writetime, mytime, dbentry->databaseid)));
4956  pfree(writetime);
4957  pfree(mytime);
4958  }
4959  else
4960  {
4961  /*
4962  * Nope, it's just an old request. Assuming msg's clock_time is
4963  * >= its cutoff_time, it must be stale, so we can ignore it.
4964  */
4965  return;
4966  }
4967  }
4968  else if (msg->cutoff_time <= dbentry->stats_timestamp)
4969  {
4970  /* Stale request, ignore it */
4971  return;
4972  }
4973 
4974  /*
4975  * We need to write this DB, so create a request.
4976  */
4978  msg->databaseid);
4979 }
TimestampTz stats_timestamp
Definition: pgstat.h:768
static List * pending_write_requests
Definition: pgstat.c:291
TimestampTz clock_time
Definition: pgstat.h:263
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:3677
TimestampTz cutoff_time
Definition: pgstat.h:264
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 5559 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().

5560 {
5561  PgStat_StatDBEntry *dbentry;
5562 
5563  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
5564 
5565  switch (msg->m_reason)
5566  {
5568 
5569  /*
5570  * Since we drop the information about the database as soon as it
5571  * replicates, there is no point in counting these conflicts.
5572  */
5573  break;
5575  dbentry->n_conflict_tablespace++;
5576  break;
5578  dbentry->n_conflict_lock++;
5579  break;
5581  dbentry->n_conflict_snapshot++;
5582  break;
5584  dbentry->n_conflict_bufferpin++;
5585  break;
5587  dbentry->n_conflict_startup_deadlock++;
5588  break;
5589  }
5590 }
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:750
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:751
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:747
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:749
PgStat_Counter n_conflict_lock
Definition: pgstat.h:748
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677

◆ pgstat_recv_replslot()

static void pgstat_recv_replslot ( PgStat_MsgReplSlot msg,
int  len 
)
static

Definition at line 5632 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().

5633 {
5634  if (msg->m_drop)
5635  {
5636  Assert(!msg->m_create);
5637 
5638  /* Remove the replication slot statistics with the given name */
5639  if (replSlotStatHash != NULL)
5641  (void *) &(msg->m_slotname),
5642  HASH_REMOVE,
5643  NULL);
5644  }
5645  else
5646  {
5647  PgStat_StatReplSlotEntry *slotent;
5648 
5649  slotent = pgstat_get_replslot_entry(msg->m_slotname, true);
5650  Assert(slotent);
5651 
5652  if (msg->m_create)
5653  {
5654  /*
5655  * If the message for dropping the slot with the same name gets
5656  * lost, slotent has stats for the old slot. So we initialize all
5657  * counters at slot creation.
5658  */
5659  pgstat_reset_replslot(slotent, 0);
5660  }
5661  else
5662  {
5663  /* Update the replication slot statistics */
5664  slotent->spill_txns += msg->m_spill_txns;
5665  slotent->spill_count += msg->m_spill_count;
5666  slotent->spill_bytes += msg->m_spill_bytes;
5667  slotent->stream_txns += msg->m_stream_txns;
5668  slotent->stream_count += msg->m_stream_count;
5669  slotent->stream_bytes += msg->m_stream_bytes;
5670  slotent->total_txns += msg->m_total_txns;
5671  slotent->total_bytes += msg->m_total_bytes;
5672  }
5673  }
5674 }
static void pgstat_reset_replslot(PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
Definition: pgstat.c:5923
PgStat_Counter spill_bytes
Definition: pgstat.h:923
PgStat_Counter m_spill_bytes
Definition: pgstat.h:531
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
PgStat_Counter m_stream_bytes
Definition: pgstat.h:534
PgStat_Counter m_spill_txns
Definition: pgstat.h:529
PgStat_Counter total_bytes
Definition: pgstat.h:928
PgStat_Counter stream_bytes
Definition: pgstat.h:926
PgStat_Counter spill_txns
Definition: pgstat.h:921
PgStat_Counter m_stream_txns
Definition: pgstat.h:532
#define Assert(condition)
Definition: c.h:804
static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry(NameData name, bool create_it)
Definition: pgstat.c:5870
PgStat_Counter m_total_txns
Definition: pgstat.h:535
PgStat_Counter m_spill_count
Definition: pgstat.h:530
PgStat_Counter m_total_bytes
Definition: pgstat.h:536
PgStat_Counter spill_count
Definition: pgstat.h:922
static HTAB * replSlotStatHash
Definition: pgstat.c:284
PgStat_Counter stream_count
Definition: pgstat.h:925
PgStat_Counter total_txns
Definition: pgstat.h:927
PgStat_Counter m_stream_count
Definition: pgstat.h:533
NameData m_slotname
Definition: pgstat.h:526
PgStat_Counter stream_txns
Definition: pgstat.h:924

◆ pgstat_recv_resetcounter()

static void pgstat_recv_resetcounter ( PgStat_MsgResetcounter msg,
int  len 
)
static

Definition at line 5182 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().

5183 {
5184  PgStat_StatDBEntry *dbentry;
5185 
5186  /*
5187  * Lookup the database in the hashtable. Nothing to do if not there.
5188  */
5189  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5190 
5191  if (!dbentry)
5192  return;
5193 
5194  /*
5195  * We simply throw away all the database's table entries by recreating a
5196  * new hash table for them.
5197  */
5198  if (dbentry->tables != NULL)
5199  hash_destroy(dbentry->tables);
5200  if (dbentry->functions != NULL)
5201  hash_destroy(dbentry->functions);
5202 
5203  dbentry->tables = NULL;
5204  dbentry->functions = NULL;
5205 
5206  /*
5207  * Reset database-level stats, too. This creates empty hash tables for
5208  * tables and functions.
5209  */
5210  reset_dbentry_counters(dbentry);
5211 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
HTAB * functions
Definition: pgstat.h:775
static void reset_dbentry_counters(PgStat_StatDBEntry *dbentry)
Definition: pgstat.c:3619
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677

◆ pgstat_recv_resetreplslotcounter()

static void pgstat_recv_resetreplslotcounter ( PgStat_MsgResetreplslotcounter msg,
int  len 
)
static

Definition at line 5309 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().

5311 {
5312  PgStat_StatReplSlotEntry *slotent;
5313  TimestampTz ts;
5314 
5315  /* Return if we don't have replication slot statistics */
5316  if (replSlotStatHash == NULL)
5317  return;
5318 
5319  ts = GetCurrentTimestamp();
5320  if (msg->clearall)
5321  {
5322  HASH_SEQ_STATUS sstat;
5323 
5325  while ((slotent = (PgStat_StatReplSlotEntry *) hash_seq_search(&sstat)) != NULL)
5326  pgstat_reset_replslot(slotent, ts);
5327  }
5328  else
5329  {
5330  /* Get the slot statistics to reset */
5331  slotent = pgstat_get_replslot_entry(msg->m_slotname, false);
5332 
5333  /*
5334  * Nothing to do if the given slot entry is not found. This could
5335  * happen when the slot with the given name is removed and the
5336  * corresponding statistics entry is also removed before receiving the
5337  * reset message.
5338  */
5339  if (!slotent)
5340  return;
5341 
5342  /* Reset the stats for the requested replication slot */
5343  pgstat_reset_replslot(slotent, ts);
5344  }
5345 }
static void pgstat_reset_replslot(PgStat_StatReplSlotEntry *slotstats, TimestampTz ts)
Definition: pgstat.c:5923
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:5870
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:284

◆ pgstat_recv_resetsharedcounter()

static void pgstat_recv_resetsharedcounter ( PgStat_MsgResetsharedcounter msg,
int  len 
)
static

Definition at line 5220 of file pgstat.c.

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

Referenced by PgstatCollectorMain().

5221 {
5222  if (msg->m_resettarget == RESET_BGWRITER)
5223  {
5224  /* Reset the global, bgwriter and checkpointer statistics for the cluster. */
5225  memset(&globalStats, 0, sizeof(globalStats));
5227  }
5228  else if (msg->m_resettarget == RESET_ARCHIVER)
5229  {
5230  /* Reset the archiver statistics for the cluster. */
5231  memset(&archiverStats, 0, sizeof(archiverStats));
5233  }
5234  else if (msg->m_resettarget == RESET_WAL)
5235  {
5236  /* Reset the WAL statistics for the cluster. */
5237  memset(&walStats, 0, sizeof(walStats));
5239  }
5240 
5241  /*
5242  * Presumably the sender of this message validated the target, don't
5243  * complain here if it's not valid
5244  */
5245 }
TimestampTz stat_reset_timestamp
Definition: pgstat.h:897
static PgStat_GlobalStats globalStats
Definition: pgstat.c:281
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
static PgStat_WalStats walStats
Definition: pgstat.c:282
PgStat_BgWriterStats bgwriter
Definition: pgstat.h:881
TimestampTz stat_reset_timestamp
Definition: pgstat.h:855
PgStat_Shared_Reset_Target m_resettarget
Definition: pgstat.h:353
static PgStat_ArchiverStats archiverStats
Definition: pgstat.c:280
TimestampTz stat_reset_timestamp
Definition: pgstat.h:844

◆ pgstat_recv_resetsinglecounter()

static void pgstat_recv_resetsinglecounter ( PgStat_MsgResetsinglecounter msg,
int  len 
)
static

Definition at line 5255 of file pgstat.c.

References PgStat_StatDBEntry::functions, GetCurrentTimestamp(), HASH_REMOVE, hash_search(), InvalidOid, IsSharedRelation(), 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().

5256 {
5257  PgStat_StatDBEntry *dbentry;
5258 
5259  if (IsSharedRelation(msg->m_objectid))
5260  dbentry = pgstat_get_db_entry(InvalidOid, false);
5261  else
5262  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5263 
5264  if (!dbentry)
5265  return;
5266 
5267  /* Set the reset timestamp for the whole database */
5269 
5270  /* Remove object if it exists, ignore it if not */
5271  if (msg->m_resettype == RESET_TABLE)
5272  (void) hash_search(dbentry->tables, (void *) &(msg->m_objectid),
5273  HASH_REMOVE, NULL);
5274  else if (msg->m_resettype == RESET_FUNCTION)
5275  (void) hash_search(dbentry->functions, (void *) &(msg->m_objectid),
5276  HASH_REMOVE, NULL);
5277 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
HTAB * functions
Definition: pgstat.h:775
TimestampTz stat_reset_timestamp
Definition: pgstat.h:767
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:244
#define InvalidOid
Definition: postgres_ext.h:36
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
PgStat_Single_Reset_Type m_resettype
Definition: pgstat.h:365

◆ pgstat_recv_resetslrucounter()

static void pgstat_recv_resetslrucounter ( PgStat_MsgResetslrucounter msg,
int  len 
)
static

Definition at line 5286 of file pgstat.c.

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

Referenced by PgstatCollectorMain().

5287 {
5288  int i;
5290 
5291  for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
5292  {
5293  /* reset entry with the given index, or all entries (index is -1) */
5294  if ((msg->m_index == -1) || (msg->m_index == i))
5295  {
5296  memset(&slruStats[i], 0, sizeof(slruStats[i]));
5298  }
5299  }
5300 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
int64 TimestampTz
Definition: timestamp.h:39
#define SLRU_NUM_ELEMENTS
Definition: pgstat.c:159
TimestampTz stat_reset_timestamp
Definition: pgstat.h:912
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:283
int i

◆ pgstat_recv_slru()

static void pgstat_recv_slru ( PgStat_MsgSLRU msg,
int  len 
)
static

Definition at line 5541 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().

5542 {
5544  slruStats[msg->m_index].blocks_hit += msg->m_blocks_hit;
5548  slruStats[msg->m_index].flush += msg->m_flush;
5549  slruStats[msg->m_index].truncate += msg->m_truncate;
5550 }
PgStat_Counter m_flush
Definition: pgstat.h:514
PgStat_Counter blocks_exists
Definition: pgstat.h:909
PgStat_Counter m_blocks_exists
Definition: pgstat.h:513
PgStat_Counter m_index
Definition: pgstat.h:508
PgStat_Counter m_blocks_written
Definition: pgstat.h:512
PgStat_Counter blocks_read
Definition: pgstat.h:907
PgStat_Counter blocks_hit
Definition: pgstat.h:906
PgStat_Counter blocks_zeroed
Definition: pgstat.h:905
PgStat_Counter m_blocks_read
Definition: pgstat.h:511
PgStat_Counter flush
Definition: pgstat.h:910
static PgStat_SLRUStats slruStats[SLRU_NUM_ELEMENTS]
Definition: pgstat.c:283
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:509
PgStat_Counter m_truncate
Definition: pgstat.h:515
PgStat_Counter truncate
Definition: pgstat.h:911
PgStat_Counter blocks_written
Definition: pgstat.h:908
PgStat_Counter m_blocks_hit
Definition: pgstat.h:510

◆ pgstat_recv_tabpurge()

static void pgstat_recv_tabpurge ( PgStat_MsgTabpurge msg,
int  len 
)
static

Definition at line 5106 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().

5107 {
5108  PgStat_StatDBEntry *dbentry;
5109  int i;
5110 
5111  dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5112 
5113  /*
5114  * No need to purge if we don't even know the database.
5115  */
5116  if (!dbentry || !dbentry->tables)
5117  return;
5118 
5119  /*
5120  * Process all table entries in the message.
5121  */
5122  for (i = 0; i < msg->m_nentries; i++)
5123  {
5124  /* Remove from hashtable if present; we don't care if it's not. */
5125  (void) hash_search(dbentry->tables,
5126  (void *) &(msg->m_tableid[i]),
5127  HASH_REMOVE, NULL);
5128  }
5129 }
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:318
static PgStat_StatDBEntry * pgstat_get_db_entry(Oid databaseid, bool create)
Definition: pgstat.c:3677
int i

◆ pgstat_recv_tabstat()

static void pgstat_recv_tabstat ( PgStat_MsgTabstat msg,
int  len 
)
static

Definition at line 4989 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, HASH_ENTER, hash_search(), i, PgStat_StatTabEntry::inserts_since_vacuum, PgStat_MsgTabstat::m_active_time, PgStat_MsgTabstat::m_block_read_time, PgStat_MsgTabstat::m_block_write_time, PgStat_MsgTabstat::m_databaseid, PgStat_MsgTabstat::m_entry, PgStat_MsgTabstat::m_idle_in_xact_time, PgStat_MsgTabstat::m_nentries, PgStat_MsgTabstat::m_session_time, 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_truncdropped, PgStat_TableCounts::t_tuples_deleted, PgStat_TableCounts::t_tuples_fetched, PgStat_TableCounts::t_tuples_hot_updated, PgStat_TableCounts::t_tuples_inserted, PgStat_TableCounts::t_tuples_returned, PgStat_TableCounts::t_tuples_updated, PgStat_StatDBEntry::tables, PgStat_StatDBEntry::total_active_time, PgStat_StatDBEntry::total_idle_in_xact_time, PgStat_StatDBEntry::total_session_time, 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().

4990 {
4991  PgStat_StatDBEntry *dbentry;
4992  PgStat_StatTabEntry *tabentry;
4993  int i;
4994  bool found;
4995 
4996  dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
4997 
4998  /*
4999  * Update database-wide stats.
5000  */
5001  dbentry->n_xact_commit += (PgStat_Counter) (msg->m_xact_commit);
5002  dbentry->n_xact_rollback += (PgStat_Counter) (msg->m_xact_rollback);
5003  dbentry->n_block_read_time += msg->m_block_read_time;
5004  dbentry->n_block_write_time += msg->m_block_write_time;
5005 
5006  dbentry->total_session_time += msg->m_session_time;
5007  dbentry->total_active_time += msg->m_active_time;
5009 
5010  /*
5011  * Process all table entries in the message.
5012  */
5013  for (i = 0; i < msg->m_nentries; i++)
5014  {
5015  PgStat_TableEntry *tabmsg = &(msg->m_entry[i]);
5016 
5017  tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
5018  (void *) &(tabmsg->t_id),
5019  HASH_ENTER, &found);
5020 
5021  if (!found)
5022  {
5023  /*
5024  * If it's a new table entry, initialize counters to the values we
5025  * just got.
5026  */
5027  tabentry->numscans = tabmsg->t_counts.t_numscans;
5028  tabentry->tuples_returned = tabmsg->t_counts.t_tuples_returned;
5029  tabentry->tuples_fetched = tabmsg->t_counts.t_tuples_fetched;
5030  tabentry->tuples_inserted = tabmsg->t_counts.t_tuples_inserted;
5031  tabentry->tuples_updated = tabmsg->t_counts.t_tuples_updated;
5032  tabentry->tuples_deleted = tabmsg->t_counts.t_tuples_deleted;
5033  tabentry->tuples_hot_updated = tabmsg->t_counts.t_tuples_hot_updated;
5034  tabentry->n_live_tuples = tabmsg->t_counts.t_delta_live_tuples;
5035  tabentry->n_dead_tuples = tabmsg->t_counts.t_delta_dead_tuples;
5036  tabentry->changes_since_analyze = tabmsg->t_counts.t_changed_tuples;
5037  tabentry->inserts_since_vacuum = tabmsg->t_counts.t_tuples_inserted;
5038  tabentry->