4 * Definitions for the PostgreSQL cumulative statistics system.
6 * Copyright (c) 2001-2023, 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 timed_checkpoints
;
264 PgStat_Counter requested_checkpoints
;
265 PgStat_Counter checkpoint_write_time
; /* times in milliseconds */
266 PgStat_Counter checkpoint_sync_time
;
267 PgStat_Counter buf_written_checkpoints
;
268 PgStat_Counter buf_written_backend
;
269 PgStat_Counter buf_fsync_backend
;
270 } PgStat_CheckpointerStats
;
274 * Types related to counting IO operations
276 typedef enum IOObject
279 IOOBJECT_TEMP_RELATION
,
282 #define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
284 typedef enum IOContext
292 #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
306 #define IOOP_NUM_TYPES (IOOP_WRITEBACK + 1)
308 typedef struct PgStat_BktypeIO
310 PgStat_Counter counts
[IOOBJECT_NUM_TYPES
][IOCONTEXT_NUM_TYPES
][IOOP_NUM_TYPES
];
311 PgStat_Counter times
[IOOBJECT_NUM_TYPES
][IOCONTEXT_NUM_TYPES
][IOOP_NUM_TYPES
];
314 typedef struct PgStat_IO
316 TimestampTz stat_reset_timestamp
;
317 PgStat_BktypeIO stats
[BACKEND_NUM_TYPES
];
321 typedef struct PgStat_StatDBEntry
323 PgStat_Counter xact_commit
;
324 PgStat_Counter xact_rollback
;
325 PgStat_Counter blocks_fetched
;
326 PgStat_Counter blocks_hit
;
327 PgStat_Counter tuples_returned
;
328 PgStat_Counter tuples_fetched
;
329 PgStat_Counter tuples_inserted
;
330 PgStat_Counter tuples_updated
;
331 PgStat_Counter tuples_deleted
;
332 TimestampTz last_autovac_time
;
333 PgStat_Counter conflict_tablespace
;
334 PgStat_Counter conflict_lock
;
335 PgStat_Counter conflict_snapshot
;
336 PgStat_Counter conflict_logicalslot
;
337 PgStat_Counter conflict_bufferpin
;
338 PgStat_Counter conflict_startup_deadlock
;
339 PgStat_Counter temp_files
;
340 PgStat_Counter temp_bytes
;
341 PgStat_Counter deadlocks
;
342 PgStat_Counter checksum_failures
;
343 TimestampTz last_checksum_failure
;
344 PgStat_Counter blk_read_time
; /* times in microseconds */
345 PgStat_Counter blk_write_time
;
346 PgStat_Counter sessions
;
347 PgStat_Counter session_time
;
348 PgStat_Counter active_time
;
349 PgStat_Counter idle_in_transaction_time
;
350 PgStat_Counter sessions_abandoned
;
351 PgStat_Counter sessions_fatal
;
352 PgStat_Counter sessions_killed
;
354 TimestampTz stat_reset_timestamp
;
355 } PgStat_StatDBEntry
;
357 typedef struct PgStat_StatFuncEntry
359 PgStat_Counter numcalls
;
361 PgStat_Counter total_time
; /* times in microseconds */
362 PgStat_Counter self_time
;
363 } PgStat_StatFuncEntry
;
365 typedef struct PgStat_StatReplSlotEntry
367 PgStat_Counter spill_txns
;
368 PgStat_Counter spill_count
;
369 PgStat_Counter spill_bytes
;
370 PgStat_Counter stream_txns
;
371 PgStat_Counter stream_count
;
372 PgStat_Counter stream_bytes
;
373 PgStat_Counter total_txns
;
374 PgStat_Counter total_bytes
;
375 TimestampTz stat_reset_timestamp
;
376 } PgStat_StatReplSlotEntry
;
378 typedef struct PgStat_SLRUStats
380 PgStat_Counter blocks_zeroed
;
381 PgStat_Counter blocks_hit
;
382 PgStat_Counter blocks_read
;
383 PgStat_Counter blocks_written
;
384 PgStat_Counter blocks_exists
;
385 PgStat_Counter flush
;
386 PgStat_Counter truncate
;
387 TimestampTz stat_reset_timestamp
;
390 typedef struct PgStat_StatSubEntry
392 PgStat_Counter apply_error_count
;
393 PgStat_Counter sync_error_count
;
394 TimestampTz stat_reset_timestamp
;
395 } PgStat_StatSubEntry
;
397 typedef struct PgStat_StatTabEntry
399 PgStat_Counter numscans
;
400 TimestampTz lastscan
;
402 PgStat_Counter tuples_returned
;
403 PgStat_Counter tuples_fetched
;
405 PgStat_Counter tuples_inserted
;
406 PgStat_Counter tuples_updated
;
407 PgStat_Counter tuples_deleted
;
408 PgStat_Counter tuples_hot_updated
;
409 PgStat_Counter tuples_newpage_updated
;
411 PgStat_Counter live_tuples
;
412 PgStat_Counter dead_tuples
;
413 PgStat_Counter mod_since_analyze
;
414 PgStat_Counter ins_since_vacuum
;
416 PgStat_Counter blocks_fetched
;
417 PgStat_Counter blocks_hit
;
419 TimestampTz last_vacuum_time
; /* user initiated vacuum */
420 PgStat_Counter vacuum_count
;
421 TimestampTz last_autovacuum_time
; /* autovacuum initiated */
422 PgStat_Counter autovacuum_count
;
423 TimestampTz last_analyze_time
; /* user initiated */
424 PgStat_Counter analyze_count
;
425 TimestampTz last_autoanalyze_time
; /* autovacuum initiated */
426 PgStat_Counter autoanalyze_count
;
427 } PgStat_StatTabEntry
;
429 typedef struct PgStat_WalStats
431 PgStat_Counter wal_records
;
432 PgStat_Counter wal_fpi
;
434 PgStat_Counter wal_buffers_full
;
435 PgStat_Counter wal_write
;
436 PgStat_Counter wal_sync
;
437 PgStat_Counter wal_write_time
;
438 PgStat_Counter wal_sync_time
;
439 TimestampTz stat_reset_timestamp
;
443 * This struct stores wal-related durations as instr_time, which makes it
444 * cheaper and easier to accumulate them, by not requiring type
445 * conversions. During stats flush instr_time will be converted into
448 typedef struct PgStat_PendingWalStats
450 PgStat_Counter wal_buffers_full
;
451 PgStat_Counter wal_write
;
452 PgStat_Counter wal_sync
;
453 instr_time wal_write_time
;
454 instr_time wal_sync_time
;
455 } PgStat_PendingWalStats
;
459 * Functions in pgstat.c
462 /* functions called from postmaster */
463 extern Size
StatsShmemSize(void);
464 extern void StatsShmemInit(void);
466 /* Functions called during server startup / shutdown */
467 extern void pgstat_restore_stats(void);
468 extern void pgstat_discard_stats(void);
469 extern void pgstat_before_server_shutdown(int code
, Datum arg
);
471 /* Functions for backend initialization */
472 extern void pgstat_initialize(void);
474 /* Functions called from backends */
475 extern long pgstat_report_stat(bool force
);
476 extern void pgstat_force_next_flush(void);
478 extern void pgstat_reset_counters(void);
479 extern void pgstat_reset(PgStat_Kind kind
, Oid dboid
, Oid objoid
);
480 extern void pgstat_reset_of_kind(PgStat_Kind kind
);
482 /* stats accessors */
483 extern void pgstat_clear_snapshot(void);
484 extern TimestampTz
pgstat_get_stat_snapshot_timestamp(bool *have_snapshot
);
487 extern PgStat_Kind
pgstat_get_kind_from_str(char *kind_str
);
488 extern bool pgstat_have_entry(PgStat_Kind kind
, Oid dboid
, Oid objoid
);
492 * Functions in pgstat_archiver.c
495 extern void pgstat_report_archiver(const char *xlog
, bool failed
);
496 extern PgStat_ArchiverStats
*pgstat_fetch_stat_archiver(void);
500 * Functions in pgstat_bgwriter.c
503 extern void pgstat_report_bgwriter(void);
504 extern PgStat_BgWriterStats
*pgstat_fetch_stat_bgwriter(void);
508 * Functions in pgstat_checkpointer.c
511 extern void pgstat_report_checkpointer(void);
512 extern PgStat_CheckpointerStats
*pgstat_fetch_stat_checkpointer(void);
516 * Functions in pgstat_io.c
519 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO
*backend_io
,
521 extern void pgstat_count_io_op(IOObject io_object
, IOContext io_context
, IOOp io_op
);
522 extern void pgstat_count_io_op_n(IOObject io_object
, IOContext io_context
, IOOp io_op
, uint32 cnt
);
523 extern instr_time
pgstat_prepare_io_time(void);
524 extern void pgstat_count_io_op_time(IOObject io_object
, IOContext io_context
,
525 IOOp io_op
, instr_time start_time
, uint32 cnt
);
527 extern PgStat_IO
*pgstat_fetch_stat_io(void);
528 extern const char *pgstat_get_io_context_name(IOContext io_context
);
529 extern const char *pgstat_get_io_object_name(IOObject io_object
);
531 extern bool pgstat_tracks_io_bktype(BackendType bktype
);
532 extern bool pgstat_tracks_io_object(BackendType bktype
,
533 IOObject io_object
, IOContext io_context
);
534 extern bool pgstat_tracks_io_op(BackendType bktype
, IOObject io_object
,
535 IOContext io_context
, IOOp io_op
);
539 * Functions in pgstat_database.c
542 extern void pgstat_drop_database(Oid databaseid
);
543 extern void pgstat_report_autovac(Oid dboid
);
544 extern void pgstat_report_recovery_conflict(int reason
);
545 extern void pgstat_report_deadlock(void);
546 extern void pgstat_report_checksum_failures_in_db(Oid dboid
, int failurecount
);
547 extern void pgstat_report_checksum_failure(void);
548 extern void pgstat_report_connect(Oid dboid
);
550 #define pgstat_count_buffer_read_time(n) \
551 (pgStatBlockReadTime += (n))
552 #define pgstat_count_buffer_write_time(n) \
553 (pgStatBlockWriteTime += (n))
554 #define pgstat_count_conn_active_time(n) \
555 (pgStatActiveTime += (n))
556 #define pgstat_count_conn_txn_idle_time(n) \
557 (pgStatTransactionIdleTime += (n))
559 extern PgStat_StatDBEntry
*pgstat_fetch_stat_dbentry(Oid dboid
);
563 * Functions in pgstat_function.c
566 extern void pgstat_create_function(Oid proid
);
567 extern void pgstat_drop_function(Oid proid
);
569 struct FunctionCallInfoBaseData
;
570 extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData
*fcinfo
,
571 PgStat_FunctionCallUsage
*fcu
);
572 extern void pgstat_end_function_usage(PgStat_FunctionCallUsage
*fcu
,
575 extern PgStat_StatFuncEntry
*pgstat_fetch_stat_funcentry(Oid func_id
);
576 extern PgStat_FunctionCounts
*find_funcstat_entry(Oid func_id
);
580 * Functions in pgstat_relation.c
583 extern void pgstat_create_relation(Relation rel
);
584 extern void pgstat_drop_relation(Relation rel
);
585 extern void pgstat_copy_relation_stats(Relation dst
, Relation src
);
587 extern void pgstat_init_relation(Relation rel
);
588 extern void pgstat_assoc_relation(Relation rel
);
589 extern void pgstat_unlink_relation(Relation rel
);
591 extern void pgstat_report_vacuum(Oid tableoid
, bool shared
,
592 PgStat_Counter livetuples
, PgStat_Counter deadtuples
);
593 extern void pgstat_report_analyze(Relation rel
,
594 PgStat_Counter livetuples
, PgStat_Counter deadtuples
,
598 * If stats are enabled, but pending data hasn't been prepared yet, call
599 * pgstat_assoc_relation() to do so. See its comment for why this is done
600 * separately from pgstat_init_relation().
602 #define pgstat_should_count_relation(rel) \
603 (likely((rel)->pgstat_info != NULL) ? true : \
604 ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false))
606 /* nontransactional event counts are simple enough to inline */
608 #define pgstat_count_heap_scan(rel) \
610 if (pgstat_should_count_relation(rel)) \
611 (rel)->pgstat_info->counts.numscans++; \
613 #define pgstat_count_heap_getnext(rel) \
615 if (pgstat_should_count_relation(rel)) \
616 (rel)->pgstat_info->counts.tuples_returned++; \
618 #define pgstat_count_heap_fetch(rel) \
620 if (pgstat_should_count_relation(rel)) \
621 (rel)->pgstat_info->counts.tuples_fetched++; \
623 #define pgstat_count_index_scan(rel) \
625 if (pgstat_should_count_relation(rel)) \
626 (rel)->pgstat_info->counts.numscans++; \
628 #define pgstat_count_index_tuples(rel, n) \
630 if (pgstat_should_count_relation(rel)) \
631 (rel)->pgstat_info->counts.tuples_returned += (n); \
633 #define pgstat_count_buffer_read(rel) \
635 if (pgstat_should_count_relation(rel)) \
636 (rel)->pgstat_info->counts.blocks_fetched++; \
638 #define pgstat_count_buffer_hit(rel) \
640 if (pgstat_should_count_relation(rel)) \
641 (rel)->pgstat_info->counts.blocks_hit++; \
644 extern void pgstat_count_heap_insert(Relation rel
, PgStat_Counter n
);
645 extern void pgstat_count_heap_update(Relation rel
, bool hot
, bool newpage
);
646 extern void pgstat_count_heap_delete(Relation rel
);
647 extern void pgstat_count_truncate(Relation rel
);
648 extern void pgstat_update_heap_dead_tuples(Relation rel
, int delta
);
650 extern void pgstat_twophase_postcommit(TransactionId xid
, uint16 info
,
651 void *recdata
, uint32 len
);
652 extern void pgstat_twophase_postabort(TransactionId xid
, uint16 info
,
653 void *recdata
, uint32 len
);
655 extern PgStat_StatTabEntry
*pgstat_fetch_stat_tabentry(Oid relid
);
656 extern PgStat_StatTabEntry
*pgstat_fetch_stat_tabentry_ext(bool shared
,
658 extern PgStat_TableStatus
*find_tabstat_entry(Oid rel_id
);
662 * Functions in pgstat_replslot.c
665 extern void pgstat_reset_replslot(const char *name
);
666 struct ReplicationSlot
;
667 extern void pgstat_report_replslot(struct ReplicationSlot
*slot
, const PgStat_StatReplSlotEntry
*repSlotStat
);
668 extern void pgstat_create_replslot(struct ReplicationSlot
*slot
);
669 extern void pgstat_acquire_replslot(struct ReplicationSlot
*slot
);
670 extern void pgstat_drop_replslot(struct ReplicationSlot
*slot
);
671 extern PgStat_StatReplSlotEntry
*pgstat_fetch_replslot(NameData slotname
);
675 * Functions in pgstat_slru.c
678 extern void pgstat_reset_slru(const char *);
679 extern void pgstat_count_slru_page_zeroed(int slru_idx
);
680 extern void pgstat_count_slru_page_hit(int slru_idx
);
681 extern void pgstat_count_slru_page_read(int slru_idx
);
682 extern void pgstat_count_slru_page_written(int slru_idx
);
683 extern void pgstat_count_slru_page_exists(int slru_idx
);
684 extern void pgstat_count_slru_flush(int slru_idx
);
685 extern void pgstat_count_slru_truncate(int slru_idx
);
686 extern const char *pgstat_get_slru_name(int slru_idx
);
687 extern int pgstat_get_slru_index(const char *name
);
688 extern PgStat_SLRUStats
*pgstat_fetch_slru(void);
692 * Functions in pgstat_subscription.c
695 extern void pgstat_report_subscription_error(Oid subid
, bool is_apply_error
);
696 extern void pgstat_create_subscription(Oid subid
);
697 extern void pgstat_drop_subscription(Oid subid
);
698 extern PgStat_StatSubEntry
*pgstat_fetch_stat_subscription(Oid subid
);
702 * Functions in pgstat_xact.c
705 extern void AtEOXact_PgStat(bool isCommit
, bool parallel
);
706 extern void AtEOSubXact_PgStat(bool isCommit
, int nestDepth
);
707 extern void AtPrepare_PgStat(void);
708 extern void PostPrepare_PgStat(void);
709 struct xl_xact_stats_item
;
710 extern int pgstat_get_transactional_drops(bool isCommit
, struct xl_xact_stats_item
**items
);
711 extern void pgstat_execute_transactional_drops(int ndrops
, struct xl_xact_stats_item
*items
, bool is_redo
);
715 * Functions in pgstat_wal.c
718 extern void pgstat_report_wal(bool force
);
719 extern PgStat_WalStats
*pgstat_fetch_stat_wal(void);
723 * Variables in pgstat.c
727 extern PGDLLIMPORT
bool pgstat_track_counts
;
728 extern PGDLLIMPORT
int pgstat_track_functions
;
729 extern PGDLLIMPORT
int pgstat_fetch_consistency
;
733 * Variables in pgstat_bgwriter.c
736 /* updated directly by bgwriter and bufmgr */
737 extern PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats
;
741 * Variables in pgstat_checkpointer.c
745 * Checkpointer statistics counters are updated directly by checkpointer and
748 extern PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats
;
752 * Variables in pgstat_database.c
755 /* Updated by pgstat_count_buffer_*_time macros */
756 extern PGDLLIMPORT PgStat_Counter pgStatBlockReadTime
;
757 extern PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime
;
760 * Updated by pgstat_count_conn_*_time macros, called by
761 * pgstat_report_activity().
763 extern PGDLLIMPORT PgStat_Counter pgStatActiveTime
;
764 extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime
;
766 /* updated by the traffic cop and in errfinish() */
767 extern PGDLLIMPORT SessionEndType pgStatSessionEndCause
;
771 * Variables in pgstat_wal.c
774 /* updated directly by backends and background processes */
775 extern PGDLLIMPORT PgStat_PendingWalStats PendingWalStats
;
778 #endif /* PGSTAT_H */