pgstat.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /* ----------
  2. * pgstat.h
  3. *
  4. * Definitions for the PostgreSQL cumulative statistics system.
  5. *
  6. * Copyright (c) 2001-2022, PostgreSQL Global Development Group
  7. *
  8. * src/include/pgstat.h
  9. * ----------
  10. */
  11. #ifndef PGSTAT_H
  12. #define PGSTAT_H
  13. #include "datatype/timestamp.h"
  14. #include "portability/instr_time.h"
  15. #include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
  16. #include "utils/backend_progress.h" /* for backward compatibility */
  17. #include "utils/backend_status.h" /* for backward compatibility */
  18. #include "utils/relcache.h"
  19. #include "utils/wait_event.h" /* for backward compatibility */
  20. /* ----------
  21. * Paths for the statistics files (relative to installation's $PGDATA).
  22. * ----------
  23. */
  24. #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
  25. #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/pgstat.stat"
  26. #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/pgstat.tmp"
  27. /* Default directory to store temporary statistics data in */
  28. #define PG_STAT_TMP_DIR "pg_stat_tmp"
  29. /* The types of statistics entries */
  30. typedef enum PgStat_Kind
  31. {
  32. /* use 0 for INVALID, to catch zero-initialized data */
  33. PGSTAT_KIND_INVALID = 0,
  34. /* stats for variable-numbered objects */
  35. PGSTAT_KIND_DATABASE, /* database-wide statistics */
  36. PGSTAT_KIND_RELATION, /* per-table statistics */
  37. PGSTAT_KIND_FUNCTION, /* per-function statistics */
  38. PGSTAT_KIND_REPLSLOT, /* per-slot statistics */
  39. PGSTAT_KIND_SUBSCRIPTION, /* per-subscription statistics */
  40. /* stats for fixed-numbered objects */
  41. PGSTAT_KIND_ARCHIVER,
  42. PGSTAT_KIND_BGWRITER,
  43. PGSTAT_KIND_CHECKPOINTER,
  44. PGSTAT_KIND_SLRU,
  45. PGSTAT_KIND_WAL,
  46. } PgStat_Kind;
  47. #define PGSTAT_KIND_FIRST_VALID PGSTAT_KIND_DATABASE
  48. #define PGSTAT_KIND_LAST PGSTAT_KIND_WAL
  49. #define PGSTAT_NUM_KINDS (PGSTAT_KIND_LAST + 1)
  50. /* Values for track_functions GUC variable --- order is significant! */
  51. typedef enum TrackFunctionsLevel
  52. {
  53. TRACK_FUNC_OFF,
  54. TRACK_FUNC_PL,
  55. TRACK_FUNC_ALL
  56. } TrackFunctionsLevel;
  57. typedef enum PgStat_FetchConsistency
  58. {
  59. PGSTAT_FETCH_CONSISTENCY_NONE,
  60. PGSTAT_FETCH_CONSISTENCY_CACHE,
  61. PGSTAT_FETCH_CONSISTENCY_SNAPSHOT,
  62. } PgStat_FetchConsistency;
  63. /* Values to track the cause of session termination */
  64. typedef enum SessionEndType
  65. {
  66. DISCONNECT_NOT_YET, /* still active */
  67. DISCONNECT_NORMAL,
  68. DISCONNECT_CLIENT_EOF,
  69. DISCONNECT_FATAL,
  70. DISCONNECT_KILLED
  71. } SessionEndType;
  72. /* ----------
  73. * The data type used for counters.
  74. * ----------
  75. */
  76. typedef int64 PgStat_Counter;
  77. /* ------------------------------------------------------------
  78. * Structures kept in backend local memory while accumulating counts
  79. * ------------------------------------------------------------
  80. */
  81. /* ----------
  82. * PgStat_FunctionCounts The actual per-function counts kept by a backend
  83. *
  84. * This struct should contain only actual event counters, because we memcmp
  85. * it against zeroes to detect whether there are any pending stats.
  86. *
  87. * Note that the time counters are in instr_time format here. We convert to
  88. * microseconds in PgStat_Counter format when flushing out pending statistics.
  89. * ----------
  90. */
  91. typedef struct PgStat_FunctionCounts
  92. {
  93. PgStat_Counter f_numcalls;
  94. instr_time f_total_time;
  95. instr_time f_self_time;
  96. } PgStat_FunctionCounts;
  97. /* ----------
  98. * PgStat_BackendFunctionEntry Non-flushed function stats.
  99. * ----------
  100. */
  101. typedef struct PgStat_BackendFunctionEntry
  102. {
  103. PgStat_FunctionCounts f_counts;
  104. } PgStat_BackendFunctionEntry;
  105. /*
  106. * Working state needed to accumulate per-function-call timing statistics.
  107. */
  108. typedef struct PgStat_FunctionCallUsage
  109. {
  110. /* Link to function's hashtable entry (must still be there at exit!) */
  111. /* NULL means we are not tracking the current function call */
  112. PgStat_FunctionCounts *fs;
  113. /* Total time previously charged to function, as of function start */
  114. instr_time save_f_total_time;
  115. /* Backend-wide total time as of function start */
  116. instr_time save_total;
  117. /* system clock as of function start */
  118. instr_time f_start;
  119. } PgStat_FunctionCallUsage;
  120. /* ----------
  121. * PgStat_BackendSubEntry Non-flushed subscription stats.
  122. * ----------
  123. */
  124. typedef struct PgStat_BackendSubEntry
  125. {
  126. PgStat_Counter apply_error_count;
  127. PgStat_Counter sync_error_count;
  128. } PgStat_BackendSubEntry;
  129. /* ----------
  130. * PgStat_TableCounts The actual per-table counts kept by a backend
  131. *
  132. * This struct should contain only actual event counters, because we memcmp
  133. * it against zeroes to detect whether there are any stats updates to apply.
  134. * It is a component of PgStat_TableStatus (within-backend state).
  135. *
  136. * Note: for a table, tuples_returned is the number of tuples successfully
  137. * fetched by heap_getnext, while tuples_fetched is the number of tuples
  138. * successfully fetched by heap_fetch under the control of bitmap indexscans.
  139. * For an index, tuples_returned is the number of index entries returned by
  140. * the index AM, while tuples_fetched is the number of tuples successfully
  141. * fetched by heap_fetch under the control of simple indexscans for this index.
  142. *
  143. * tuples_inserted/updated/deleted/hot_updated count attempted actions,
  144. * regardless of whether the transaction committed. delta_live_tuples,
  145. * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
  146. * Note that delta_live_tuples and delta_dead_tuples can be negative!
  147. * ----------
  148. */
  149. typedef struct PgStat_TableCounts
  150. {
  151. PgStat_Counter t_numscans;
  152. PgStat_Counter t_tuples_returned;
  153. PgStat_Counter t_tuples_fetched;
  154. PgStat_Counter t_tuples_inserted;
  155. PgStat_Counter t_tuples_updated;
  156. PgStat_Counter t_tuples_deleted;
  157. PgStat_Counter t_tuples_hot_updated;
  158. bool t_truncdropped;
  159. PgStat_Counter t_delta_live_tuples;
  160. PgStat_Counter t_delta_dead_tuples;
  161. PgStat_Counter t_changed_tuples;
  162. PgStat_Counter t_blocks_fetched;
  163. PgStat_Counter t_blocks_hit;
  164. } PgStat_TableCounts;
  165. /* ----------
  166. * PgStat_TableStatus Per-table status within a backend
  167. *
  168. * Many of the event counters are nontransactional, ie, we count events
  169. * in committed and aborted transactions alike. For these, we just count
  170. * directly in the PgStat_TableStatus. However, delta_live_tuples,
  171. * delta_dead_tuples, and changed_tuples must be derived from event counts
  172. * with awareness of whether the transaction or subtransaction committed or
  173. * aborted. Hence, we also keep a stack of per-(sub)transaction status
  174. * records for every table modified in the current transaction. At commit
  175. * or abort, we propagate tuples_inserted/updated/deleted up to the
  176. * parent subtransaction level, or out to the parent PgStat_TableStatus,
  177. * as appropriate.
  178. * ----------
  179. */
  180. typedef struct PgStat_TableStatus
  181. {
  182. Oid t_id; /* table's OID */
  183. bool t_shared; /* is it a shared catalog? */
  184. struct PgStat_TableXactStatus *trans; /* lowest subxact's counts */
  185. PgStat_TableCounts t_counts; /* event counts to be sent */
  186. Relation relation; /* rel that is using this entry */
  187. } PgStat_TableStatus;
  188. /* ----------
  189. * PgStat_TableXactStatus Per-table, per-subtransaction status
  190. * ----------
  191. */
  192. typedef struct PgStat_TableXactStatus
  193. {
  194. PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */
  195. PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */
  196. PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */
  197. bool truncdropped; /* relation truncated/dropped in this
  198. * (sub)xact */
  199. /* tuples i/u/d prior to truncate/drop */
  200. PgStat_Counter inserted_pre_truncdrop;
  201. PgStat_Counter updated_pre_truncdrop;
  202. PgStat_Counter deleted_pre_truncdrop;
  203. int nest_level; /* subtransaction nest level */
  204. /* links to other structs for same relation: */
  205. struct PgStat_TableXactStatus *upper; /* next higher subxact if any */
  206. PgStat_TableStatus *parent; /* per-table status */
  207. /* structs of same subxact level are linked here: */
  208. struct PgStat_TableXactStatus *next; /* next of same subxact */
  209. } PgStat_TableXactStatus;
  210. /* ------------------------------------------------------------
  211. * Data structures on disk and in shared memory follow
  212. *
  213. * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
  214. * data structures change.
  215. * ------------------------------------------------------------
  216. */
  217. #define PGSTAT_FILE_FORMAT_ID 0x01A5BCA7
  218. typedef struct PgStat_ArchiverStats
  219. {
  220. PgStat_Counter archived_count; /* archival successes */
  221. char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
  222. * archived */
  223. TimestampTz last_archived_timestamp; /* last archival success time */
  224. PgStat_Counter failed_count; /* failed archival attempts */
  225. char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
  226. * last failure */
  227. TimestampTz last_failed_timestamp; /* last archival failure time */
  228. TimestampTz stat_reset_timestamp;
  229. } PgStat_ArchiverStats;
  230. typedef struct PgStat_BgWriterStats
  231. {
  232. PgStat_Counter buf_written_clean;
  233. PgStat_Counter maxwritten_clean;
  234. PgStat_Counter buf_alloc;
  235. TimestampTz stat_reset_timestamp;
  236. } PgStat_BgWriterStats;
  237. typedef struct PgStat_CheckpointerStats
  238. {
  239. PgStat_Counter timed_checkpoints;
  240. PgStat_Counter requested_checkpoints;
  241. PgStat_Counter checkpoint_write_time; /* times in milliseconds */
  242. PgStat_Counter checkpoint_sync_time;
  243. PgStat_Counter buf_written_checkpoints;
  244. PgStat_Counter buf_written_backend;
  245. PgStat_Counter buf_fsync_backend;
  246. } PgStat_CheckpointerStats;
  247. typedef struct PgStat_StatDBEntry
  248. {
  249. PgStat_Counter n_xact_commit;
  250. PgStat_Counter n_xact_rollback;
  251. PgStat_Counter n_blocks_fetched;
  252. PgStat_Counter n_blocks_hit;
  253. PgStat_Counter n_tuples_returned;
  254. PgStat_Counter n_tuples_fetched;
  255. PgStat_Counter n_tuples_inserted;
  256. PgStat_Counter n_tuples_updated;
  257. PgStat_Counter n_tuples_deleted;
  258. TimestampTz last_autovac_time;
  259. PgStat_Counter n_conflict_tablespace;
  260. PgStat_Counter n_conflict_lock;
  261. PgStat_Counter n_conflict_snapshot;
  262. PgStat_Counter n_conflict_bufferpin;
  263. PgStat_Counter n_conflict_startup_deadlock;
  264. PgStat_Counter n_temp_files;
  265. PgStat_Counter n_temp_bytes;
  266. PgStat_Counter n_deadlocks;
  267. PgStat_Counter n_checksum_failures;
  268. TimestampTz last_checksum_failure;
  269. PgStat_Counter n_block_read_time; /* times in microseconds */
  270. PgStat_Counter n_block_write_time;
  271. PgStat_Counter n_sessions;
  272. PgStat_Counter total_session_time;
  273. PgStat_Counter total_active_time;
  274. PgStat_Counter total_idle_in_xact_time;
  275. PgStat_Counter n_sessions_abandoned;
  276. PgStat_Counter n_sessions_fatal;
  277. PgStat_Counter n_sessions_killed;
  278. TimestampTz stat_reset_timestamp;
  279. } PgStat_StatDBEntry;
  280. typedef struct PgStat_StatFuncEntry
  281. {
  282. PgStat_Counter f_numcalls;
  283. PgStat_Counter f_total_time; /* times in microseconds */
  284. PgStat_Counter f_self_time;
  285. } PgStat_StatFuncEntry;
  286. typedef struct PgStat_StatReplSlotEntry
  287. {
  288. /*
  289. * In PG 15 this field is unused, but not removed, to avoid changing
  290. * PGSTAT_FILE_FORMAT_ID.
  291. */
  292. NameData slotname_unused;
  293. PgStat_Counter spill_txns;
  294. PgStat_Counter spill_count;
  295. PgStat_Counter spill_bytes;
  296. PgStat_Counter stream_txns;
  297. PgStat_Counter stream_count;
  298. PgStat_Counter stream_bytes;
  299. PgStat_Counter total_txns;
  300. PgStat_Counter total_bytes;
  301. TimestampTz stat_reset_timestamp;
  302. } PgStat_StatReplSlotEntry;
  303. typedef struct PgStat_SLRUStats
  304. {
  305. PgStat_Counter blocks_zeroed;
  306. PgStat_Counter blocks_hit;
  307. PgStat_Counter blocks_read;
  308. PgStat_Counter blocks_written;
  309. PgStat_Counter blocks_exists;
  310. PgStat_Counter flush;
  311. PgStat_Counter truncate;
  312. TimestampTz stat_reset_timestamp;
  313. } PgStat_SLRUStats;
  314. typedef struct PgStat_StatSubEntry
  315. {
  316. PgStat_Counter apply_error_count;
  317. PgStat_Counter sync_error_count;
  318. TimestampTz stat_reset_timestamp;
  319. } PgStat_StatSubEntry;
  320. typedef struct PgStat_StatTabEntry
  321. {
  322. PgStat_Counter numscans;
  323. PgStat_Counter tuples_returned;
  324. PgStat_Counter tuples_fetched;
  325. PgStat_Counter tuples_inserted;
  326. PgStat_Counter tuples_updated;
  327. PgStat_Counter tuples_deleted;
  328. PgStat_Counter tuples_hot_updated;
  329. PgStat_Counter n_live_tuples;
  330. PgStat_Counter n_dead_tuples;
  331. PgStat_Counter changes_since_analyze;
  332. PgStat_Counter inserts_since_vacuum;
  333. PgStat_Counter blocks_fetched;
  334. PgStat_Counter blocks_hit;
  335. TimestampTz vacuum_timestamp; /* user initiated vacuum */
  336. PgStat_Counter vacuum_count;
  337. TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */
  338. PgStat_Counter autovac_vacuum_count;
  339. TimestampTz analyze_timestamp; /* user initiated */
  340. PgStat_Counter analyze_count;
  341. TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */
  342. PgStat_Counter autovac_analyze_count;
  343. } PgStat_StatTabEntry;
  344. typedef struct PgStat_WalStats
  345. {
  346. PgStat_Counter wal_records;
  347. PgStat_Counter wal_fpi;
  348. uint64 wal_bytes;
  349. PgStat_Counter wal_buffers_full;
  350. PgStat_Counter wal_write;
  351. PgStat_Counter wal_sync;
  352. PgStat_Counter wal_write_time;
  353. PgStat_Counter wal_sync_time;
  354. TimestampTz stat_reset_timestamp;
  355. } PgStat_WalStats;
  356. /*
  357. * Functions in pgstat.c
  358. */
  359. /* functions called from postmaster */
  360. extern Size StatsShmemSize(void);
  361. extern void StatsShmemInit(void);
  362. /* Functions called during server startup / shutdown */
  363. extern void pgstat_restore_stats(void);
  364. extern void pgstat_discard_stats(void);
  365. extern void pgstat_before_server_shutdown(int code, Datum arg);
  366. /* Functions for backend initialization */
  367. extern void pgstat_initialize(void);
  368. /* Functions called from backends */
  369. extern long pgstat_report_stat(bool force);
  370. extern void pgstat_force_next_flush(void);
  371. extern void pgstat_reset_counters(void);
  372. extern void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objectid);
  373. extern void pgstat_reset_of_kind(PgStat_Kind kind);
  374. /* stats accessors */
  375. extern void pgstat_clear_snapshot(void);
  376. extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
  377. /* helpers */
  378. extern PgStat_Kind pgstat_get_kind_from_str(char *kind_str);
  379. extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
  380. /* GUC hook for stats_fetch_consistency */
  381. extern void assign_stats_fetch_consistency(int newval, void *extra);
  382. /*
  383. * Functions in pgstat_archiver.c
  384. */
  385. extern void pgstat_report_archiver(const char *xlog, bool failed);
  386. extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void);
  387. /*
  388. * Functions in pgstat_bgwriter.c
  389. */
  390. extern void pgstat_report_bgwriter(void);
  391. extern PgStat_BgWriterStats *pgstat_fetch_stat_bgwriter(void);
  392. /*
  393. * Functions in pgstat_checkpointer.c
  394. */
  395. extern void pgstat_report_checkpointer(void);
  396. extern PgStat_CheckpointerStats *pgstat_fetch_stat_checkpointer(void);
  397. /*
  398. * Functions in pgstat_database.c
  399. */
  400. extern void pgstat_drop_database(Oid databaseid);
  401. extern void pgstat_report_autovac(Oid dboid);
  402. extern void pgstat_report_recovery_conflict(int reason);
  403. extern void pgstat_report_deadlock(void);
  404. extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
  405. extern void pgstat_report_checksum_failure(void);
  406. extern void pgstat_report_connect(Oid dboid);
  407. #define pgstat_count_buffer_read_time(n) \
  408. (pgStatBlockReadTime += (n))
  409. #define pgstat_count_buffer_write_time(n) \
  410. (pgStatBlockWriteTime += (n))
  411. #define pgstat_count_conn_active_time(n) \
  412. (pgStatActiveTime += (n))
  413. #define pgstat_count_conn_txn_idle_time(n) \
  414. (pgStatTransactionIdleTime += (n))
  415. extern PgStat_StatDBEntry *pgstat_fetch_stat_dbentry(Oid dbid);
  416. /*
  417. * Functions in pgstat_function.c
  418. */
  419. extern void pgstat_create_function(Oid proid);
  420. extern void pgstat_drop_function(Oid proid);
  421. struct FunctionCallInfoBaseData;
  422. extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
  423. PgStat_FunctionCallUsage *fcu);
  424. extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
  425. bool finalize);
  426. extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid);
  427. extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
  428. /*
  429. * Functions in pgstat_relation.c
  430. */
  431. extern void pgstat_create_relation(Relation rel);
  432. extern void pgstat_drop_relation(Relation rel);
  433. extern void pgstat_copy_relation_stats(Relation dstrel, Relation srcrel);
  434. extern void pgstat_init_relation(Relation rel);
  435. extern void pgstat_assoc_relation(Relation rel);
  436. extern void pgstat_unlink_relation(Relation rel);
  437. extern void pgstat_report_vacuum(Oid tableoid, bool shared,
  438. PgStat_Counter livetuples, PgStat_Counter deadtuples);
  439. extern void pgstat_report_analyze(Relation rel,
  440. PgStat_Counter livetuples, PgStat_Counter deadtuples,
  441. bool resetcounter);
  442. /*
  443. * If stats are enabled, but pending data hasn't been prepared yet, call
  444. * pgstat_assoc_relation() to do so. See its comment for why this is done
  445. * separately from pgstat_init_relation().
  446. */
  447. #define pgstat_should_count_relation(rel) \
  448. (likely((rel)->pgstat_info != NULL) ? true : \
  449. ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
  450. /* nontransactional event counts are simple enough to inline */
  451. #define pgstat_count_heap_scan(rel) \
  452. do { \
  453. if (pgstat_should_count_relation(rel)) \
  454. (rel)->pgstat_info->t_counts.t_numscans++; \
  455. } while (0)
  456. #define pgstat_count_heap_getnext(rel) \
  457. do { \
  458. if (pgstat_should_count_relation(rel)) \
  459. (rel)->pgstat_info->t_counts.t_tuples_returned++; \
  460. } while (0)
  461. #define pgstat_count_heap_fetch(rel) \
  462. do { \
  463. if (pgstat_should_count_relation(rel)) \
  464. (rel)->pgstat_info->t_counts.t_tuples_fetched++; \
  465. } while (0)
  466. #define pgstat_count_index_scan(rel) \
  467. do { \
  468. if (pgstat_should_count_relation(rel)) \
  469. (rel)->pgstat_info->t_counts.t_numscans++; \
  470. } while (0)
  471. #define pgstat_count_index_tuples(rel, n) \
  472. do { \
  473. if (pgstat_should_count_relation(rel)) \
  474. (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
  475. } while (0)
  476. #define pgstat_count_buffer_read(rel) \
  477. do { \
  478. if (pgstat_should_count_relation(rel)) \
  479. (rel)->pgstat_info->t_counts.t_blocks_fetched++; \
  480. } while (0)
  481. #define pgstat_count_buffer_hit(rel) \
  482. do { \
  483. if (pgstat_should_count_relation(rel)) \
  484. (rel)->pgstat_info->t_counts.t_blocks_hit++; \
  485. } while (0)
  486. extern void pgstat_count_heap_insert(Relation rel, PgStat_Counter n);
  487. extern void pgstat_count_heap_update(Relation rel, bool hot);
  488. extern void pgstat_count_heap_delete(Relation rel);
  489. extern void pgstat_count_truncate(Relation rel);
  490. extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
  491. extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
  492. void *recdata, uint32 len);
  493. extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
  494. void *recdata, uint32 len);
  495. extern PgStat_StatTabEntry *pgstat_fetch_stat_tabentry(Oid relid);
  496. extern PgStat_StatTabEntry *pgstat_fetch_stat_tabentry_ext(bool shared,
  497. Oid relid);
  498. extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
  499. /*
  500. * Functions in pgstat_replslot.c
  501. */
  502. extern void pgstat_reset_replslot(const char *name);
  503. struct ReplicationSlot;
  504. extern void pgstat_report_replslot(struct ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat);
  505. extern void pgstat_create_replslot(struct ReplicationSlot *slot);
  506. extern void pgstat_acquire_replslot(struct ReplicationSlot *slot);
  507. extern void pgstat_drop_replslot(struct ReplicationSlot *slot);
  508. extern PgStat_StatReplSlotEntry *pgstat_fetch_replslot(NameData slotname);
  509. /*
  510. * Functions in pgstat_slru.c
  511. */
  512. extern void pgstat_reset_slru(const char *);
  513. extern void pgstat_count_slru_page_zeroed(int slru_idx);
  514. extern void pgstat_count_slru_page_hit(int slru_idx);
  515. extern void pgstat_count_slru_page_read(int slru_idx);
  516. extern void pgstat_count_slru_page_written(int slru_idx);
  517. extern void pgstat_count_slru_page_exists(int slru_idx);
  518. extern void pgstat_count_slru_flush(int slru_idx);
  519. extern void pgstat_count_slru_truncate(int slru_idx);
  520. extern const char *pgstat_get_slru_name(int slru_idx);
  521. extern int pgstat_get_slru_index(const char *name);
  522. extern PgStat_SLRUStats *pgstat_fetch_slru(void);
  523. /*
  524. * Functions in pgstat_subscription.c
  525. */
  526. extern void pgstat_report_subscription_error(Oid subid, bool is_apply_error);
  527. extern void pgstat_create_subscription(Oid subid);
  528. extern void pgstat_drop_subscription(Oid subid);
  529. extern PgStat_StatSubEntry *pgstat_fetch_stat_subscription(Oid subid);
  530. /*
  531. * Functions in pgstat_xact.c
  532. */
  533. extern void AtEOXact_PgStat(bool isCommit, bool parallel);
  534. extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
  535. extern void AtPrepare_PgStat(void);
  536. extern void PostPrepare_PgStat(void);
  537. struct xl_xact_stats_item;
  538. extern int pgstat_get_transactional_drops(bool isCommit, struct xl_xact_stats_item **items);
  539. extern void pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, bool is_redo);
  540. /*
  541. * Functions in pgstat_wal.c
  542. */
  543. extern void pgstat_report_wal(bool force);
  544. extern PgStat_WalStats *pgstat_fetch_stat_wal(void);
  545. /*
  546. * Variables in pgstat.c
  547. */
  548. /* GUC parameters */
  549. extern PGDLLIMPORT bool pgstat_track_counts;
  550. extern PGDLLIMPORT int pgstat_track_functions;
  551. extern PGDLLIMPORT int pgstat_fetch_consistency;
  552. /*
  553. * Variables in pgstat_bgwriter.c
  554. */
  555. /* updated directly by bgwriter and bufmgr */
  556. extern PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats;
  557. /*
  558. * Variables in pgstat_checkpointer.c
  559. */
  560. /*
  561. * Checkpointer statistics counters are updated directly by checkpointer and
  562. * bufmgr.
  563. */
  564. extern PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats;
  565. /*
  566. * Variables in pgstat_database.c
  567. */
  568. /* Updated by pgstat_count_buffer_*_time macros */
  569. extern PGDLLIMPORT PgStat_Counter pgStatBlockReadTime;
  570. extern PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime;
  571. /*
  572. * Updated by pgstat_count_conn_*_time macros, called by
  573. * pgstat_report_activity().
  574. */
  575. extern PGDLLIMPORT PgStat_Counter pgStatActiveTime;
  576. extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime;
  577. /* updated by the traffic cop and in errfinish() */
  578. extern PGDLLIMPORT SessionEndType pgStatSessionEndCause;
  579. /*
  580. * Variables in pgstat_wal.c
  581. */
  582. /* updated directly by backends and background processes */
  583. extern PGDLLIMPORT PgStat_WalStats PendingWalStats;
  584. #endif /* PGSTAT_H */