4 * Definitions for the PostgreSQL cumulative statistics system.
6 * Copyright (c) 2001-2024, PostgreSQL Global Development Group
14 #include "datatype/timestamp.h"
15 #include "portability/instr_time.h"
16 #include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
17 #include "utils/backend_progress.h" /* for backward compatibility */
18 #include "utils/backend_status.h" /* for backward compatibility */
19 #include "utils/relcache.h"
20 #include "utils/wait_event.h" /* for backward compatibility */
24 * Paths for the statistics files (relative to installation's $PGDATA).
27 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
28 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/pgstat.stat"
29 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/pgstat.tmp"
31 /* Default directory to store temporary statistics data in */
32 #define PG_STAT_TMP_DIR "pg_stat_tmp"
34 /* The types of statistics entries */
35 typedef enum PgStat_Kind
37 /* use 0 for INVALID, to catch zero-initialized data */
38 PGSTAT_KIND_INVALID
= 0,
40 /* stats for variable-numbered objects */
41 PGSTAT_KIND_DATABASE
, /* database-wide statistics */
42 PGSTAT_KIND_RELATION
, /* per-table statistics */
43 PGSTAT_KIND_FUNCTION
, /* per-function statistics */
44 PGSTAT_KIND_REPLSLOT
, /* per-slot statistics */
45 PGSTAT_KIND_SUBSCRIPTION
, /* per-subscription statistics */
47 /* stats for fixed-numbered objects */
50 PGSTAT_KIND_CHECKPOINTER
,
56 #define PGSTAT_KIND_FIRST_VALID PGSTAT_KIND_DATABASE
57 #define PGSTAT_KIND_LAST PGSTAT_KIND_WAL
58 #define PGSTAT_NUM_KINDS (PGSTAT_KIND_LAST + 1)
60 /* Values for track_functions GUC variable --- order is significant! */
61 typedef enum TrackFunctionsLevel
66 } TrackFunctionsLevel
;
68 typedef enum PgStat_FetchConsistency
70 PGSTAT_FETCH_CONSISTENCY_NONE
,
71 PGSTAT_FETCH_CONSISTENCY_CACHE
,
72 PGSTAT_FETCH_CONSISTENCY_SNAPSHOT
,
73 } PgStat_FetchConsistency
;
75 /* Values to track the cause of session termination */
76 typedef enum SessionEndType
78 DISCONNECT_NOT_YET
, /* still active */
80 DISCONNECT_CLIENT_EOF
,
86 * The data type used for counters.
89 typedef int64 PgStat_Counter
;
92 /* ------------------------------------------------------------
93 * Structures kept in backend local memory while accumulating counts
94 * ------------------------------------------------------------
98 * PgStat_FunctionCounts The actual per-function counts kept by a backend
100 * This struct should contain only actual event counters, because we memcmp
101 * it against zeroes to detect whether there are any pending stats.
103 * Note that the time counters are in instr_time format here. We convert to
104 * microseconds in PgStat_Counter format when flushing out pending statistics.
107 typedef struct PgStat_FunctionCounts
109 PgStat_Counter numcalls
;
110 instr_time total_time
;
111 instr_time self_time
;
112 } PgStat_FunctionCounts
;
115 * Working state needed to accumulate per-function-call timing statistics.
117 typedef struct PgStat_FunctionCallUsage
119 /* Link to function's hashtable entry (must still be there at exit!) */
120 /* NULL means we are not tracking the current function call */
121 PgStat_FunctionCounts
*fs
;
122 /* Total time previously charged to function, as of function start */
123 instr_time save_f_total_time
;
124 /* Backend-wide total time as of function start */
125 instr_time save_total
;
126 /* system clock as of function start */
128 } PgStat_FunctionCallUsage
;
131 * PgStat_BackendSubEntry Non-flushed subscription stats.
134 typedef struct PgStat_BackendSubEntry
136 PgStat_Counter apply_error_count
;
137 PgStat_Counter sync_error_count
;
138 } PgStat_BackendSubEntry
;
141 * PgStat_TableCounts The actual per-table counts kept by a backend
143 * This struct should contain only actual event counters, because we memcmp
144 * it against zeroes to detect whether there are any stats updates to apply.
145 * It is a component of PgStat_TableStatus (within-backend state).
147 * Note: for a table, tuples_returned is the number of tuples successfully
148 * fetched by heap_getnext, while tuples_fetched is the number of tuples
149 * successfully fetched by heap_fetch under the control of bitmap indexscans.
150 * For an index, tuples_returned is the number of index entries returned by
151 * the index AM, while tuples_fetched is the number of tuples successfully
152 * fetched by heap_fetch under the control of simple indexscans for this index.
154 * tuples_inserted/updated/deleted/hot_updated/newpage_updated count attempted
155 * actions, regardless of whether the transaction committed. delta_live_tuples,
156 * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
157 * Note that delta_live_tuples and delta_dead_tuples can be negative!
160 typedef struct PgStat_TableCounts
162 PgStat_Counter numscans
;
164 PgStat_Counter tuples_returned
;
165 PgStat_Counter tuples_fetched
;
167 PgStat_Counter tuples_inserted
;
168 PgStat_Counter tuples_updated
;
169 PgStat_Counter tuples_deleted
;
170 PgStat_Counter tuples_hot_updated
;
171 PgStat_Counter tuples_newpage_updated
;
174 PgStat_Counter delta_live_tuples
;
175 PgStat_Counter delta_dead_tuples
;
176 PgStat_Counter changed_tuples
;
178 PgStat_Counter blocks_fetched
;
179 PgStat_Counter blocks_hit
;
180 } PgStat_TableCounts
;
183 * PgStat_TableStatus Per-table status within a backend
185 * Many of the event counters are nontransactional, ie, we count events
186 * in committed and aborted transactions alike. For these, we just count
187 * directly in the PgStat_TableStatus. However, delta_live_tuples,
188 * delta_dead_tuples, and changed_tuples must be derived from event counts
189 * with awareness of whether the transaction or subtransaction committed or
190 * aborted. Hence, we also keep a stack of per-(sub)transaction status
191 * records for every table modified in the current transaction. At commit
192 * or abort, we propagate tuples_inserted/updated/deleted up to the
193 * parent subtransaction level, or out to the parent PgStat_TableStatus,
197 typedef struct PgStat_TableStatus
199 Oid id
; /* table's OID */
200 bool shared
; /* is it a shared catalog? */
201 struct PgStat_TableXactStatus
*trans
; /* lowest subxact's counts */
202 PgStat_TableCounts counts
; /* event counts to be sent */
203 Relation relation
; /* rel that is using this entry */
204 } PgStat_TableStatus
;
207 * PgStat_TableXactStatus Per-table, per-subtransaction status
210 typedef struct PgStat_TableXactStatus
212 PgStat_Counter tuples_inserted
; /* tuples inserted in (sub)xact */
213 PgStat_Counter tuples_updated
; /* tuples updated in (sub)xact */
214 PgStat_Counter tuples_deleted
; /* tuples deleted in (sub)xact */
215 bool truncdropped
; /* relation truncated/dropped in this
217 /* tuples i/u/d prior to truncate/drop */
218 PgStat_Counter inserted_pre_truncdrop
;
219 PgStat_Counter updated_pre_truncdrop
;
220 PgStat_Counter deleted_pre_truncdrop
;
221 int nest_level
; /* subtransaction nest level */
222 /* links to other structs for same relation: */
223 struct PgStat_TableXactStatus
*upper
; /* next higher subxact if any */
224 PgStat_TableStatus
*parent
; /* per-table status */
225 /* structs of same subxact level are linked here: */
226 struct PgStat_TableXactStatus
*next
; /* next of same subxact */
227 } PgStat_TableXactStatus
;
230 /* ------------------------------------------------------------
231 * Data structures on disk and in shared memory follow
233 * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
234 * data structures change.
235 * ------------------------------------------------------------
238 #define PGSTAT_FILE_FORMAT_ID 0x01A5BCAC
240 typedef struct PgStat_ArchiverStats
242 PgStat_Counter archived_count
; /* archival successes */
243 char last_archived_wal
[MAX_XFN_CHARS
+ 1]; /* last WAL file
245 TimestampTz last_archived_timestamp
; /* last archival success time */
246 PgStat_Counter failed_count
; /* failed archival attempts */
247 char last_failed_wal
[MAX_XFN_CHARS
+ 1]; /* WAL file involved in
249 TimestampTz last_failed_timestamp
; /* last archival failure time */
250 TimestampTz stat_reset_timestamp
;
251 } PgStat_ArchiverStats
;
253 typedef struct PgStat_BgWriterStats
255 PgStat_Counter buf_written_clean
;
256 PgStat_Counter maxwritten_clean
;
257 PgStat_Counter buf_alloc
;
258 TimestampTz stat_reset_timestamp
;
259 } PgStat_BgWriterStats
;
261 typedef struct PgStat_CheckpointerStats
263 PgStat_Counter num_timed
;
264 PgStat_Counter num_requested
;
265 PgStat_Counter restartpoints_timed
;
266 PgStat_Counter restartpoints_requested
;
267 PgStat_Counter restartpoints_performed
;
268 PgStat_Counter write_time
; /* times in milliseconds */
269 PgStat_Counter sync_time
;
270 PgStat_Counter buffers_written
;
271 TimestampTz stat_reset_timestamp
;
272 } PgStat_CheckpointerStats
;
276 * Types related to counting IO operations
278 typedef enum IOObject
281 IOOBJECT_TEMP_RELATION
,
284 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
286 typedef enum IOContext
294 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
308 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
310 typedef struct PgStat_BktypeIO
312 PgStat_Counter counts
[IOOBJECT_NUM_TYPES
][IOCONTEXT_NUM_TYPES
][IOOP_NUM_TYPES
];
313 PgStat_Counter times
[IOOBJECT_NUM_TYPES
][IOCONTEXT_NUM_TYPES
][IOOP_NUM_TYPES
];
316 typedef struct PgStat_IO
318 TimestampTz stat_reset_timestamp
;
319 PgStat_BktypeIO stats
[BACKEND_NUM_TYPES
];
323 typedef struct PgStat_StatDBEntry
325 PgStat_Counter xact_commit
;
326 PgStat_Counter xact_rollback
;
327 PgStat_Counter blocks_fetched
;
328 PgStat_Counter blocks_hit
;
329 PgStat_Counter tuples_returned
;
330 PgStat_Counter tuples_fetched
;
331 PgStat_Counter tuples_inserted
;
332 PgStat_Counter tuples_updated
;
333 PgStat_Counter tuples_deleted
;
334 TimestampTz last_autovac_time
;
335 PgStat_Counter conflict_tablespace
;
336 PgStat_Counter conflict_lock
;
337 PgStat_Counter conflict_snapshot
;
338 PgStat_Counter conflict_logicalslot
;
339 PgStat_Counter conflict_bufferpin
;
340 PgStat_Counter conflict_startup_deadlock
;
341 PgStat_Counter temp_files
;
342 PgStat_Counter temp_bytes
;
343 PgStat_Counter deadlocks
;
344 PgStat_Counter checksum_failures
;
345 TimestampTz last_checksum_failure
;
346 PgStat_Counter blk_read_time
; /* times in microseconds */
347 PgStat_Counter blk_write_time
;
348 PgStat_Counter sessions
;
349 PgStat_Counter session_time
;
350 PgStat_Counter active_time
;
351 PgStat_Counter idle_in_transaction_time
;
352 PgStat_Counter sessions_abandoned
;
353 PgStat_Counter sessions_fatal
;
354 PgStat_Counter sessions_killed
;
356 TimestampTz stat_reset_timestamp
;
357 } PgStat_StatDBEntry
;
359 typedef struct PgStat_StatFuncEntry
361 PgStat_Counter numcalls
;
363 PgStat_Counter total_time
; /* times in microseconds */
364 PgStat_Counter self_time
;
365 } PgStat_StatFuncEntry
;
367 typedef struct PgStat_StatReplSlotEntry
369 PgStat_Counter spill_txns
;
370 PgStat_Counter spill_count
;
371 PgStat_Counter spill_bytes
;
372 PgStat_Counter stream_txns
;
373 PgStat_Counter stream_count
;
374 PgStat_Counter stream_bytes
;
375 PgStat_Counter total_txns
;
376 PgStat_Counter total_bytes
;
377 TimestampTz stat_reset_timestamp
;
378 } PgStat_StatReplSlotEntry
;
380 typedef struct PgStat_SLRUStats
382 PgStat_Counter blocks_zeroed
;
383 PgStat_Counter blocks_hit
;
384 PgStat_Counter blocks_read
;
385 PgStat_Counter blocks_written
;
386 PgStat_Counter blocks_exists
;
387 PgStat_Counter flush
;
388 PgStat_Counter truncate
;
389 TimestampTz stat_reset_timestamp
;
392 typedef struct PgStat_StatSubEntry
394 PgStat_Counter apply_error_count
;
395 PgStat_Counter sync_error_count
;
396 TimestampTz stat_reset_timestamp
;
397 } PgStat_StatSubEntry
;
399 typedef struct PgStat_StatTabEntry
401 PgStat_Counter numscans
;
402 TimestampTz lastscan
;
404 PgStat_Counter tuples_returned
;
405 PgStat_Counter tuples_fetched
;
407 PgStat_Counter tuples_inserted
;
408 PgStat_Counter tuples_updated
;
409 PgStat_Counter tuples_deleted
;
410 PgStat_Counter tuples_hot_updated
;
411 PgStat_Counter tuples_newpage_updated
;
413 PgStat_Counter live_tuples
;
414 PgStat_Counter dead_tuples
;
415 PgStat_Counter mod_since_analyze
;
416 PgStat_Counter ins_since_vacuum
;
418 PgStat_Counter blocks_fetched
;
419 PgStat_Counter blocks_hit
;
421 TimestampTz last_vacuum_time
; /* user initiated vacuum */
422 PgStat_Counter vacuum_count
;
423 TimestampTz last_autovacuum_time
; /* autovacuum initiated */
424 PgStat_Counter autovacuum_count
;
425 TimestampTz last_analyze_time
; /* user initiated */
426 PgStat_Counter analyze_count
;
427 TimestampTz last_autoanalyze_time
; /* autovacuum initiated */
428 PgStat_Counter autoanalyze_count
;
429 } PgStat_StatTabEntry
;
431 typedef struct PgStat_WalStats
433 PgStat_Counter wal_records
;
434 PgStat_Counter wal_fpi
;
436 PgStat_Counter wal_buffers_full
;
437 PgStat_Counter wal_write
;
438 PgStat_Counter wal_sync
;
439 PgStat_Counter wal_write_time
;
440 PgStat_Counter wal_sync_time
;
441 TimestampTz stat_reset_timestamp
;
445 * This struct stores wal-related durations as instr_time, which makes it
446 * cheaper and easier to accumulate them, by not requiring type
447 * conversions. During stats flush instr_time will be converted into
450 typedef struct PgStat_PendingWalStats
452 PgStat_Counter wal_buffers_full
;
453 PgStat_Counter wal_write
;
454 PgStat_Counter wal_sync
;
455 instr_time wal_write_time
;
456 instr_time wal_sync_time
;
457 } PgStat_PendingWalStats
;
461 * Functions in pgstat.c
464 /* functions called from postmaster */
465 extern Size
StatsShmemSize(void);
466 extern void StatsShmemInit(void);
468 /* Functions called during server startup / shutdown */
469 extern void pgstat_restore_stats(void);
470 extern void pgstat_discard_stats(void);
471 extern void pgstat_before_server_shutdown(int code
, Datum arg
);
473 /* Functions for backend initialization */
474 extern void pgstat_initialize(void);
476 /* Functions called from backends */
477 extern long pgstat_report_stat(bool force
);
478 extern void pgstat_force_next_flush(void);
480 extern void pgstat_reset_counters(void);
481 extern void pgstat_reset(PgStat_Kind kind
, Oid dboid
, Oid objoid
);
482 extern void pgstat_reset_of_kind(PgStat_Kind kind
);
484 /* stats accessors */
485 extern void pgstat_clear_snapshot(void);
486 extern TimestampTz
pgstat_get_stat_snapshot_timestamp(bool *have_snapshot
);
489 extern PgStat_Kind
pgstat_get_kind_from_str(char *kind_str
);
490 extern bool pgstat_have_entry(PgStat_Kind kind
, Oid dboid
, Oid objoid
);
494 * Functions in pgstat_archiver.c
497 extern void pgstat_report_archiver(const char *xlog
, bool failed
);
498 extern PgStat_ArchiverStats
*pgstat_fetch_stat_archiver(void);
502 * Functions in pgstat_bgwriter.c
505 extern void pgstat_report_bgwriter(void);
506 extern PgStat_BgWriterStats
*pgstat_fetch_stat_bgwriter(void);
510 * Functions in pgstat_checkpointer.c
513 extern void pgstat_report_checkpointer(void);
514 extern PgStat_CheckpointerStats
*pgstat_fetch_stat_checkpointer(void);
518 * Functions in pgstat_io.c
521 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO
*backend_io
,
523 extern void pgstat_count_io_op(IOObject io_object
, IOContext io_context
, IOOp io_op
);
524 extern void pgstat_count_io_op_n(IOObject io_object
, IOContext io_context
, IOOp io_op
, uint32 cnt
);
525 extern instr_time
pgstat_prepare_io_time(bool track_io_guc
);
526 extern void pgstat_count_io_op_time(IOObject io_object
, IOContext io_context
,
527 IOOp io_op
, instr_time start_time
, uint32 cnt
);
529 extern PgStat_IO
*pgstat_fetch_stat_io(void);
530 extern const char *pgstat_get_io_context_name(IOContext io_context
);
531 extern const char *pgstat_get_io_object_name(IOObject io_object
);
533 extern bool pgstat_tracks_io_bktype(BackendType bktype
);
534 extern bool pgstat_tracks_io_object(BackendType bktype
,
535 IOObject io_object
, IOContext io_context
);
536 extern bool pgstat_tracks_io_op(BackendType bktype
, IOObject io_object
,
537 IOContext io_context
, IOOp io_op
);
541 * Functions in pgstat_database.c
544 extern void pgstat_drop_database(Oid databaseid
);
545 extern void pgstat_report_autovac(Oid dboid
);
546 extern void pgstat_report_recovery_conflict(int reason
);
547 extern void pgstat_report_deadlock(void);
548 extern void pgstat_report_checksum_failures_in_db(Oid dboid
, int failurecount
);
549 extern void pgstat_report_checksum_failure(void);
550 extern void pgstat_report_connect(Oid dboid
);
552 #define pgstat_count_buffer_read_time(n) \
553 (pgStatBlockReadTime += (n))
554 #define pgstat_count_buffer_write_time(n) \
555 (pgStatBlockWriteTime += (n))
556 #define pgstat_count_conn_active_time(n) \
557 (pgStatActiveTime += (n))
558 #define pgstat_count_conn_txn_idle_time(n) \
559 (pgStatTransactionIdleTime += (n))
561 extern PgStat_StatDBEntry
*pgstat_fetch_stat_dbentry(Oid dboid
);
565 * Functions in pgstat_function.c
568 extern void pgstat_create_function(Oid proid
);
569 extern void pgstat_drop_function(Oid proid
);
571 struct FunctionCallInfoBaseData
;
572 extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData
*fcinfo
,
573 PgStat_FunctionCallUsage
*fcu
);
574 extern void pgstat_end_function_usage(PgStat_FunctionCallUsage
*fcu
,
577 extern PgStat_StatFuncEntry
*pgstat_fetch_stat_funcentry(Oid func_id
);
578 extern PgStat_FunctionCounts
*find_funcstat_entry(Oid func_id
);
582 * Functions in pgstat_relation.c
585 extern void pgstat_create_relation(Relation rel
);
586 extern void pgstat_drop_relation(Relation rel
);
587 extern void pgstat_copy_relation_stats(Relation dst
, Relation src
);
589 extern void pgstat_init_relation(Relation rel
);
590 extern void pgstat_assoc_relation(Relation rel
);
591 extern void pgstat_unlink_relation(Relation rel
);
593 extern void pgstat_report_vacuum(Oid tableoid
, bool shared
,
594 PgStat_Counter livetuples
, PgStat_Counter deadtuples
);
595 extern void pgstat_report_analyze(Relation rel
,
596 PgStat_Counter livetuples
, PgStat_Counter deadtuples
,
600 * If stats are enabled, but pending data hasn't been prepared yet, call
601 * pgstat_assoc_relation() to do so. See its comment for why this is done
602 * separately from pgstat_init_relation().
604 #define pgstat_should_count_relation(rel) \
605 (likely((rel)->pgstat_info != NULL) ? true : \
606 ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
608 /* nontransactional event counts are simple enough to inline */
610 #define pgstat_count_heap_scan(rel) \
612 if (pgstat_should_count_relation(rel)) \
613 (rel)->pgstat_info->counts.numscans++; \
615 #define pgstat_count_heap_getnext(rel) \
617 if (pgstat_should_count_relation(rel)) \
618 (rel)->pgstat_info->counts.tuples_returned++; \
620 #define pgstat_count_heap_fetch(rel) \
622 if (pgstat_should_count_relation(rel)) \
623 (rel)->pgstat_info->counts.tuples_fetched++; \
625 #define pgstat_count_index_scan(rel) \
627 if (pgstat_should_count_relation(rel)) \
628 (rel)->pgstat_info->counts.numscans++; \
630 #define pgstat_count_index_tuples(rel, n) \
632 if (pgstat_should_count_relation(rel)) \
633 (rel)->pgstat_info->counts.tuples_returned += (n); \
635 #define pgstat_count_buffer_read(rel) \
637 if (pgstat_should_count_relation(rel)) \
638 (rel)->pgstat_info->counts.blocks_fetched++; \
640 #define pgstat_count_buffer_hit(rel) \
642 if (pgstat_should_count_relation(rel)) \
643 (rel)->pgstat_info->counts.blocks_hit++; \
646 extern void pgstat_count_heap_insert(Relation rel
, PgStat_Counter n
);
647 extern void pgstat_count_heap_update(Relation rel
, bool hot
, bool newpage
);
648 extern void pgstat_count_heap_delete(Relation rel
);
649 extern void pgstat_count_truncate(Relation rel
);
650 extern void pgstat_update_heap_dead_tuples(Relation rel
, int delta
);
652 extern void pgstat_twophase_postcommit(TransactionId xid
, uint16 info
,
653 void *recdata
, uint32 len
);
654 extern void pgstat_twophase_postabort(TransactionId xid
, uint16 info
,
655 void *recdata
, uint32 len
);
657 extern PgStat_StatTabEntry
*pgstat_fetch_stat_tabentry(Oid relid
);
658 extern PgStat_StatTabEntry
*pgstat_fetch_stat_tabentry_ext(bool shared
,
660 extern PgStat_TableStatus
*find_tabstat_entry(Oid rel_id
);
664 * Functions in pgstat_replslot.c
667 extern void pgstat_reset_replslot(const char *name
);
668 struct ReplicationSlot
;
669 extern void pgstat_report_replslot(struct ReplicationSlot
*slot
, const PgStat_StatReplSlotEntry
*repSlotStat
);
670 extern void pgstat_create_replslot(struct ReplicationSlot
*slot
);
671 extern void pgstat_acquire_replslot(struct ReplicationSlot
*slot
);
672 extern void pgstat_drop_replslot(struct ReplicationSlot
*slot
);
673 extern PgStat_StatReplSlotEntry
*pgstat_fetch_replslot(NameData slotname
);
677 * Functions in pgstat_slru.c
680 extern void pgstat_reset_slru(const char *);
681 extern void pgstat_count_slru_page_zeroed(int slru_idx
);
682 extern void pgstat_count_slru_page_hit(int slru_idx
);
683 extern void pgstat_count_slru_page_read(int slru_idx
);
684 extern void pgstat_count_slru_page_written(int slru_idx
);
685 extern void pgstat_count_slru_page_exists(int slru_idx
);
686 extern void pgstat_count_slru_flush(int slru_idx
);
687 extern void pgstat_count_slru_truncate(int slru_idx
);
688 extern const char *pgstat_get_slru_name(int slru_idx
);
689 extern int pgstat_get_slru_index(const char *name
);
690 extern PgStat_SLRUStats
*pgstat_fetch_slru(void);
694 * Functions in pgstat_subscription.c
697 extern void pgstat_report_subscription_error(Oid subid
, bool is_apply_error
);
698 extern void pgstat_create_subscription(Oid subid
);
699 extern void pgstat_drop_subscription(Oid subid
);
700 extern PgStat_StatSubEntry
*pgstat_fetch_stat_subscription(Oid subid
);
704 * Functions in pgstat_xact.c
707 extern void AtEOXact_PgStat(bool isCommit
, bool parallel
);
708 extern void AtEOSubXact_PgStat(bool isCommit
, int nestDepth
);
709 extern void AtPrepare_PgStat(void);
710 extern void PostPrepare_PgStat(void);
711 struct xl_xact_stats_item
;
712 extern int pgstat_get_transactional_drops(bool isCommit
, struct xl_xact_stats_item
**items
);
713 extern void pgstat_execute_transactional_drops(int ndrops
, struct xl_xact_stats_item
*items
, bool is_redo
);
717 * Functions in pgstat_wal.c
720 extern void pgstat_report_wal(bool force
);
721 extern PgStat_WalStats
*pgstat_fetch_stat_wal(void);
725 * Variables in pgstat.c
729 extern PGDLLIMPORT
bool pgstat_track_counts
;
730 extern PGDLLIMPORT
int pgstat_track_functions
;
731 extern PGDLLIMPORT
int pgstat_fetch_consistency
;
735 * Variables in pgstat_bgwriter.c
738 /* updated directly by bgwriter and bufmgr */
739 extern PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
;
743 * Variables in pgstat_checkpointer.c
747 * Checkpointer statistics counters are updated directly by checkpointer and
750 extern PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
;
754 * Variables in pgstat_database.c
757 /* Updated by pgstat_count_buffer_*_time macros */
758 extern PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
;
759 extern PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
;
762 * Updated by pgstat_count_conn_*_time macros, called by
763 * pgstat_report_activity().
765 extern PGDLLIMPORT PgStat_Counter pgStatActiveTime
;
766 extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
;
768 /* updated by the traffic cop and in errfinish() */
769 extern PGDLLIMPORT SessionEndType pgStatSessionEndCause
;
773 * Variables in pgstat_wal.c
776 /* updated directly by backends and background processes */
777 extern PGDLLIMPORT PgStat_PendingWalStats PendingWalStats
;
780 #endif /* PGSTAT_H */