PostgreSQL Source Code  git master
pgstat.h
Go to the documentation of this file.
1 /* ----------
2  * pgstat.h
3  *
4  * Definitions for the PostgreSQL statistics collector daemon.
5  *
6  * Copyright (c) 2001-2020, PostgreSQL Global Development Group
7  *
8  * src/include/pgstat.h
9  * ----------
10  */
11 #ifndef PGSTAT_H
12 #define PGSTAT_H
13 
14 #include "datatype/timestamp.h"
15 #include "libpq/pqcomm.h"
16 #include "miscadmin.h"
17 #include "port/atomics.h"
18 #include "portability/instr_time.h"
19 #include "postmaster/pgarch.h"
20 #include "storage/proc.h"
21 #include "utils/hsearch.h"
22 #include "utils/relcache.h"
23 
24 
25 /* ----------
26  * Paths for the statistics files (relative to installation's $PGDATA).
27  * ----------
28  */
29 #define PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat"
30 #define PGSTAT_STAT_PERMANENT_FILENAME "pg_stat/global.stat"
31 #define PGSTAT_STAT_PERMANENT_TMPFILE "pg_stat/global.tmp"
32 
33 /* Default directory to store temporary statistics data in */
34 #define PG_STAT_TMP_DIR "pg_stat_tmp"
35 
36 /* Values for track_functions GUC variable --- order is significant! */
37 typedef enum TrackFunctionsLevel
38 {
43 
44 /* ----------
45  * The types of backend -> collector messages
46  * ----------
47  */
48 typedef enum StatMsgType
49 {
69 } StatMsgType;
70 
71 /* ----------
72  * The data type used for counters.
73  * ----------
74  */
75 typedef int64 PgStat_Counter;
76 
77 /* ----------
78  * PgStat_TableCounts The actual per-table counts kept by a backend
79  *
80  * This struct should contain only actual event counters, because we memcmp
81  * it against zeroes to detect whether there are any counts to transmit.
82  * It is a component of PgStat_TableStatus (within-backend state) and
83  * PgStat_TableEntry (the transmitted message format).
84  *
85  * Note: for a table, tuples_returned is the number of tuples successfully
86  * fetched by heap_getnext, while tuples_fetched is the number of tuples
87  * successfully fetched by heap_fetch under the control of bitmap indexscans.
88  * For an index, tuples_returned is the number of index entries returned by
89  * the index AM, while tuples_fetched is the number of tuples successfully
90  * fetched by heap_fetch under the control of simple indexscans for this index.
91  *
92  * tuples_inserted/updated/deleted/hot_updated count attempted actions,
93  * regardless of whether the transaction committed. delta_live_tuples,
94  * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
95  * Note that delta_live_tuples and delta_dead_tuples can be negative!
96  * ----------
97  */
98 typedef struct PgStat_TableCounts
99 {
101 
104 
110 
114 
118 
119 /* Possible targets for resetting cluster-wide shared values */
121 {
125 
126 /* Possible object types for resetting single counters */
128 {
132 
133 /* ------------------------------------------------------------
134  * Structures kept in backend local memory while accumulating counts
135  * ------------------------------------------------------------
136  */
137 
138 
139 /* ----------
140  * PgStat_TableStatus Per-table status within a backend
141  *
142  * Many of the event counters are nontransactional, ie, we count events
143  * in committed and aborted transactions alike. For these, we just count
144  * directly in the PgStat_TableStatus. However, delta_live_tuples,
145  * delta_dead_tuples, and changed_tuples must be derived from event counts
146  * with awareness of whether the transaction or subtransaction committed or
147  * aborted. Hence, we also keep a stack of per-(sub)transaction status
148  * records for every table modified in the current transaction. At commit
149  * or abort, we propagate tuples_inserted/updated/deleted up to the
150  * parent subtransaction level, or out to the parent PgStat_TableStatus,
151  * as appropriate.
152  * ----------
153  */
154 typedef struct PgStat_TableStatus
155 {
156  Oid t_id; /* table's OID */
157  bool t_shared; /* is it a shared catalog? */
158  struct PgStat_TableXactStatus *trans; /* lowest subxact's counts */
159  PgStat_TableCounts t_counts; /* event counts to be sent */
161 
162 /* ----------
163  * PgStat_TableXactStatus Per-table, per-subtransaction status
164  * ----------
165  */
167 {
168  PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */
169  PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */
170  PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */
171  bool truncated; /* relation truncated in this (sub)xact */
172  PgStat_Counter inserted_pre_trunc; /* tuples inserted prior to truncate */
173  PgStat_Counter updated_pre_trunc; /* tuples updated prior to truncate */
174  PgStat_Counter deleted_pre_trunc; /* tuples deleted prior to truncate */
175  int nest_level; /* subtransaction nest level */
176  /* links to other structs for same relation: */
177  struct PgStat_TableXactStatus *upper; /* next higher subxact if any */
178  PgStat_TableStatus *parent; /* per-table status */
179  /* structs of same subxact level are linked here: */
180  struct PgStat_TableXactStatus *next; /* next of same subxact */
182 
183 
184 /* ------------------------------------------------------------
185  * Message formats follow
186  * ------------------------------------------------------------
187  */
188 
189 
190 /* ----------
191  * PgStat_MsgHdr The common message header
192  * ----------
193  */
194 typedef struct PgStat_MsgHdr
195 {
197  int m_size;
198 } PgStat_MsgHdr;
199 
200 /* ----------
201  * Space available in a message. This will keep the UDP packets below 1K,
202  * which should fit unfragmented into the MTU of the loopback interface.
203  * (Larger values of PGSTAT_MAX_MSG_SIZE would work for that on most
204  * platforms, but we're being conservative here.)
205  * ----------
206  */
207 #define PGSTAT_MAX_MSG_SIZE 1000
208 #define PGSTAT_MSG_PAYLOAD (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))
209 
210 
211 /* ----------
212  * PgStat_MsgDummy A dummy message, ignored by the collector
213  * ----------
214  */
215 typedef struct PgStat_MsgDummy
216 {
219 
220 
221 /* ----------
222  * PgStat_MsgInquiry Sent by a backend to ask the collector
223  * to write the stats file(s).
224  *
225  * Ordinarily, an inquiry message prompts writing of the global stats file,
226  * the stats file for shared catalogs, and the stats file for the specified
227  * database. If databaseid is InvalidOid, only the first two are written.
228  *
229  * New file(s) will be written only if the existing file has a timestamp
230  * older than the specified cutoff_time; this prevents duplicated effort
231  * when multiple requests arrive at nearly the same time, assuming that
232  * backends send requests with cutoff_times a little bit in the past.
233  *
234  * clock_time should be the requestor's current local time; the collector
235  * uses this to check for the system clock going backward, but it has no
236  * effect unless that occurs. We assume clock_time >= cutoff_time, though.
237  * ----------
238  */
239 
240 typedef struct PgStat_MsgInquiry
241 {
243  TimestampTz clock_time; /* observed local clock time */
244  TimestampTz cutoff_time; /* minimum acceptable file timestamp */
245  Oid databaseid; /* requested DB (InvalidOid => shared only) */
247 
248 
249 /* ----------
250  * PgStat_TableEntry Per-table info in a MsgTabstat
251  * ----------
252  */
253 typedef struct PgStat_TableEntry
254 {
258 
259 /* ----------
260  * PgStat_MsgTabstat Sent by the backend to report table
261  * and buffer access statistics.
262  * ----------
263  */
264 #define PGSTAT_NUM_TABENTRIES \
265  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int) - 2 * sizeof(PgStat_Counter)) \
266  / sizeof(PgStat_TableEntry))
267 
268 typedef struct PgStat_MsgTabstat
269 {
275  PgStat_Counter m_block_read_time; /* times in microseconds */
279 
280 
281 /* ----------
282  * PgStat_MsgTabpurge Sent by the backend to tell the collector
283  * about dead tables.
284  * ----------
285  */
286 #define PGSTAT_NUM_TABPURGE \
287  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
288  / sizeof(Oid))
289 
290 typedef struct PgStat_MsgTabpurge
291 {
297 
298 
299 /* ----------
300  * PgStat_MsgDropdb Sent by the backend to tell the collector
301  * about a dropped database
302  * ----------
303  */
304 typedef struct PgStat_MsgDropdb
305 {
309 
310 
311 /* ----------
312  * PgStat_MsgResetcounter Sent by the backend to tell the collector
313  * to reset counters
314  * ----------
315  */
317 {
321 
322 /* ----------
323  * PgStat_MsgResetsharedcounter Sent by the backend to tell the collector
324  * to reset a shared counter
325  * ----------
326  */
328 {
332 
333 /* ----------
334  * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector
335  * to reset a single counter
336  * ----------
337  */
339 {
345 
346 /* ----------
347  * PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
348  * that a database is going to be processed
349  * ----------
350  */
352 {
357 
358 
359 /* ----------
360  * PgStat_MsgVacuum Sent by the backend or autovacuum daemon
361  * after VACUUM
362  * ----------
363  */
364 typedef struct PgStat_MsgVacuum
365 {
374 
375 
376 /* ----------
377  * PgStat_MsgAnalyze Sent by the backend or autovacuum daemon
378  * after ANALYZE
379  * ----------
380  */
381 typedef struct PgStat_MsgAnalyze
382 {
392 
393 
394 /* ----------
395  * PgStat_MsgArchiver Sent by the archiver to update statistics.
396  * ----------
397  */
398 typedef struct PgStat_MsgArchiver
399 {
401  bool m_failed; /* Failed attempt */
402  char m_xlog[MAX_XFN_CHARS + 1];
405 
406 /* ----------
407  * PgStat_MsgBgWriter Sent by the bgwriter to update statistics.
408  * ----------
409  */
410 typedef struct PgStat_MsgBgWriter
411 {
413 
422  PgStat_Counter m_checkpoint_write_time; /* times in milliseconds */
425 
426 /* ----------
427  * PgStat_MsgRecoveryConflict Sent by the backend upon recovery conflict
428  * ----------
429  */
431 {
433 
435  int m_reason;
437 
438 /* ----------
439  * PgStat_MsgTempFile Sent by the backend upon creating a temp file
440  * ----------
441  */
442 typedef struct PgStat_MsgTempFile
443 {
445 
447  size_t m_filesize;
449 
450 /* ----------
451  * PgStat_FunctionCounts The actual per-function counts kept by a backend
452  *
453  * This struct should contain only actual event counters, because we memcmp
454  * it against zeroes to detect whether there are any counts to transmit.
455  *
456  * Note that the time counters are in instr_time format here. We convert to
457  * microseconds in PgStat_Counter format when transmitting to the collector.
458  * ----------
459  */
460 typedef struct PgStat_FunctionCounts
461 {
466 
467 /* ----------
468  * PgStat_BackendFunctionEntry Entry in backend's per-function hash table
469  * ----------
470  */
472 {
476 
477 /* ----------
478  * PgStat_FunctionEntry Per-function info in a MsgFuncstat
479  * ----------
480  */
481 typedef struct PgStat_FunctionEntry
482 {
485  PgStat_Counter f_total_time; /* times in microseconds */
488 
489 /* ----------
490  * PgStat_MsgFuncstat Sent by the backend to report function
491  * usage statistics.
492  * ----------
493  */
494 #define PGSTAT_NUM_FUNCENTRIES \
495  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
496  / sizeof(PgStat_FunctionEntry))
497 
498 typedef struct PgStat_MsgFuncstat
499 {
505 
506 /* ----------
507  * PgStat_MsgFuncpurge Sent by the backend to tell the collector
508  * about dead functions.
509  * ----------
510  */
511 #define PGSTAT_NUM_FUNCPURGE \
512  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
513  / sizeof(Oid))
514 
515 typedef struct PgStat_MsgFuncpurge
516 {
520  Oid m_functionid[PGSTAT_NUM_FUNCPURGE];
522 
523 /* ----------
524  * PgStat_MsgDeadlock Sent by the backend to tell the collector
525  * about a deadlock that occurred.
526  * ----------
527  */
528 typedef struct PgStat_MsgDeadlock
529 {
533 
534 /* ----------
535  * PgStat_MsgChecksumFailure Sent by the backend to tell the collector
536  * about checksum failures noticed.
537  * ----------
538  */
540 {
546 
547 
548 /* ----------
549  * PgStat_Msg Union over all possible messages.
550  * ----------
551  */
552 typedef union PgStat_Msg
553 {
574 } PgStat_Msg;
575 
576 
577 /* ------------------------------------------------------------
578  * Statistic collector data structures follow
579  *
580  * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
581  * data structures change.
582  * ------------------------------------------------------------
583  */
584 
585 #define PGSTAT_FILE_FORMAT_ID 0x01A5BC9D
586 
587 /* ----------
588  * PgStat_StatDBEntry The collector's data per database
589  * ----------
590  */
591 typedef struct PgStat_StatDBEntry
592 {
614  PgStat_Counter n_block_read_time; /* times in microseconds */
616 
618  TimestampTz stats_timestamp; /* time of db stats file update */
619 
620  /*
621  * tables and functions must be last in the struct, because we don't write
622  * the pointers out to the stats file.
623  */
627 
628 
629 /* ----------
630  * PgStat_StatTabEntry The collector's data per table (or index)
631  * ----------
632  */
633 typedef struct PgStat_StatTabEntry
634 {
636 
638 
641 
646 
651 
654 
655  TimestampTz vacuum_timestamp; /* user initiated vacuum */
657  TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */
659  TimestampTz analyze_timestamp; /* user initiated */
661  TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */
664 
665 
666 /* ----------
667  * PgStat_StatFuncEntry The collector's data per function
668  * ----------
669  */
670 typedef struct PgStat_StatFuncEntry
671 {
673 
675 
676  PgStat_Counter f_total_time; /* times in microseconds */
679 
680 
681 /*
682  * Archiver statistics kept in the stats collector
683  */
684 typedef struct PgStat_ArchiverStats
685 {
686  PgStat_Counter archived_count; /* archival successes */
687  char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
688  * archived */
689  TimestampTz last_archived_timestamp; /* last archival success time */
690  PgStat_Counter failed_count; /* failed archival attempts */
691  char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
692  * last failure */
693  TimestampTz last_failed_timestamp; /* last archival failure time */
696 
697 /*
698  * Global statistics kept in the stats collector
699  */
700 typedef struct PgStat_GlobalStats
701 {
702  TimestampTz stats_timestamp; /* time of stats file update */
705  PgStat_Counter checkpoint_write_time; /* times in milliseconds */
715 
716 
717 /* ----------
718  * Backend states
719  * ----------
720  */
721 typedef enum BackendState
722 {
730 } BackendState;
731 
732 
733 /* ----------
734  * Wait Classes
735  * ----------
736  */
737 #define PG_WAIT_LWLOCK 0x01000000U
738 #define PG_WAIT_LOCK 0x03000000U
739 #define PG_WAIT_BUFFER_PIN 0x04000000U
740 #define PG_WAIT_ACTIVITY 0x05000000U
741 #define PG_WAIT_CLIENT 0x06000000U
742 #define PG_WAIT_EXTENSION 0x07000000U
743 #define PG_WAIT_IPC 0x08000000U
744 #define PG_WAIT_TIMEOUT 0x09000000U
745 #define PG_WAIT_IO 0x0A000000U
746 
747 /* ----------
748  * Wait Events - Activity
749  *
750  * Use this category when a process is waiting because it has no work to do,
751  * unless the "Client" or "Timeout" category describes the situation better.
752  * Typically, this should only be used for background processes.
753  * ----------
754  */
755 typedef enum
756 {
771 
772 /* ----------
773  * Wait Events - Client
774  *
775  * Use this category when a process is waiting to send data to or receive data
776  * from the frontend process to which it is connected. This is never used for
777  * a background process, which has no client connection.
778  * ----------
779  */
780 typedef enum
781 {
792 
793 /* ----------
794  * Wait Events - IPC
795  *
796  * Use this category when a process cannot complete the work it is doing because
797  * it is waiting for a notification from another process.
798  * ----------
799  */
800 typedef enum
801 {
841 } WaitEventIPC;
842 
843 /* ----------
844  * Wait Events - Timeout
845  *
846  * Use this category when a process is waiting for a timeout to expire.
847  * ----------
848  */
849 typedef enum
850 {
857 
858 /* ----------
859  * Wait Events - IO
860  *
861  * Use this category when a process is waiting for a IO.
862  * ----------
863  */
864 typedef enum
865 {
935 } WaitEventIO;
936 
937 /* ----------
938  * Command type for progress reporting purposes
939  * ----------
940  */
942 {
950 
951 #define PGSTAT_NUM_PROGRESS_PARAM 20
952 
953 /* ----------
954  * Shared-memory data structures
955  * ----------
956  */
957 
958 
959 /*
960  * PgBackendSSLStatus
961  *
962  * For each backend, we keep the SSL status in a separate struct, that
963  * is only filled in if SSL is enabled.
964  *
965  * All char arrays must be null-terminated.
966  */
967 typedef struct PgBackendSSLStatus
968 {
969  /* Information about SSL connection */
970  int ssl_bits;
975 
976  /*
977  * serial number is max "20 octets" per RFC 5280, so this size should be
978  * fine
979  */
981 
984 
985 /*
986  * PgBackendGSSStatus
987  *
988  * For each backend, we keep the GSS status in a separate struct, that
989  * is only filled in if GSS is enabled.
990  *
991  * All char arrays must be null-terminated.
992  */
993 typedef struct PgBackendGSSStatus
994 {
995  /* Information about GSSAPI connection */
996  char gss_princ[NAMEDATALEN]; /* GSSAPI Principal used to auth */
997  bool gss_auth; /* If GSSAPI authentication was used */
998  bool gss_enc; /* If encryption is being used */
999 
1001 
1002 
1003 /* ----------
1004  * PgBackendStatus
1005  *
1006  * Each live backend maintains a PgBackendStatus struct in shared memory
1007  * showing its current activity. (The structs are allocated according to
1008  * BackendId, but that is not critical.) Note that the collector process
1009  * has no involvement in, or even access to, these structs.
1010  *
1011  * Each auxiliary process also maintains a PgBackendStatus struct in shared
1012  * memory.
1013  * ----------
1014  */
1015 typedef struct PgBackendStatus
1016 {
1017  /*
1018  * To avoid locking overhead, we use the following protocol: a backend
1019  * increments st_changecount before modifying its entry, and again after
1020  * finishing a modification. A would-be reader should note the value of
1021  * st_changecount, copy the entry into private memory, then check
1022  * st_changecount again. If the value hasn't changed, and if it's even,
1023  * the copy is valid; otherwise start over. This makes updates cheap
1024  * while reads are potentially expensive, but that's the tradeoff we want.
1025  *
1026  * The above protocol needs memory barriers to ensure that the apparent
1027  * order of execution is as it desires. Otherwise, for example, the CPU
1028  * might rearrange the code so that st_changecount is incremented twice
1029  * before the modification on a machine with weak memory ordering. Hence,
1030  * use the macros defined below for manipulating st_changecount, rather
1031  * than touching it directly.
1032  */
1034 
1035  /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */
1037 
1038  /* Type of backends */
1040 
1041  /* Times when current backend, transaction, and activity started */
1046 
1047  /* Database OID, owning user's OID, connection client address */
1051  char *st_clienthostname; /* MUST be null-terminated */
1052 
1053  /* Information about SSL connection */
1054  bool st_ssl;
1056 
1057  /* Information about GSSAPI connection */
1058  bool st_gss;
1060 
1061  /* current state */
1063 
1064  /* application name; MUST be null-terminated */
1065  char *st_appname;
1066 
1067  /*
1068  * Current command string; MUST be null-terminated. Note that this string
1069  * possibly is truncated in the middle of a multi-byte character. As
1070  * activity strings are stored more frequently than read, that allows to
1071  * move the cost of correct truncation to the display side. Use
1072  * pgstat_clip_activity() to truncate correctly.
1073  */
1075 
1076  /*
1077  * Command progress reporting. Any command which wishes can advertise
1078  * that it is running by setting st_progress_command,
1079  * st_progress_command_target, and st_progress_param[].
1080  * st_progress_command_target should be the OID of the relation which the
1081  * command targets (we assume there's just one, as this is meant for
1082  * utility commands), but the meaning of each element in the
1083  * st_progress_param array is command-specific.
1084  */
1087  int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM];
1088 } PgBackendStatus;
1089 
1090 /*
1091  * Macros to load and store st_changecount with appropriate memory barriers.
1092  *
1093  * Use PGSTAT_BEGIN_WRITE_ACTIVITY() before, and PGSTAT_END_WRITE_ACTIVITY()
1094  * after, modifying the current process's PgBackendStatus data. Note that,
1095  * since there is no mechanism for cleaning up st_changecount after an error,
1096  * THESE MACROS FORM A CRITICAL SECTION. Any error between them will be
1097  * promoted to PANIC, causing a database restart to clean up shared memory!
1098  * Hence, keep the critical section as short and straight-line as possible.
1099  * Aside from being safer, that minimizes the window in which readers will
1100  * have to loop.
1101  *
1102  * Reader logic should follow this sketch:
1103  *
1104  * for (;;)
1105  * {
1106  * int before_ct, after_ct;
1107  *
1108  * pgstat_begin_read_activity(beentry, before_ct);
1109  * ... copy beentry data to local memory ...
1110  * pgstat_end_read_activity(beentry, after_ct);
1111  * if (pgstat_read_activity_complete(before_ct, after_ct))
1112  * break;
1113  * CHECK_FOR_INTERRUPTS();
1114  * }
1115  *
1116  * For extra safety, we generally use volatile beentry pointers, although
1117  * the memory barriers should theoretically be sufficient.
1118  */
1119 #define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry) \
1120  do { \
1121  START_CRIT_SECTION(); \
1122  (beentry)->st_changecount++; \
1123  pg_write_barrier(); \
1124  } while (0)
1125 
1126 #define PGSTAT_END_WRITE_ACTIVITY(beentry) \
1127  do { \
1128  pg_write_barrier(); \
1129  (beentry)->st_changecount++; \
1130  Assert(((beentry)->st_changecount & 1) == 0); \
1131  END_CRIT_SECTION(); \
1132  } while (0)
1133 
1134 #define pgstat_begin_read_activity(beentry, before_changecount) \
1135  do { \
1136  (before_changecount) = (beentry)->st_changecount; \
1137  pg_read_barrier(); \
1138  } while (0)
1139 
1140 #define pgstat_end_read_activity(beentry, after_changecount) \
1141  do { \
1142  pg_read_barrier(); \
1143  (after_changecount) = (beentry)->st_changecount; \
1144  } while (0)
1145 
1146 #define pgstat_read_activity_complete(before_changecount, after_changecount) \
1147  ((before_changecount) == (after_changecount) && \
1148  ((before_changecount) & 1) == 0)
1149 
1150 
1151 /* ----------
1152  * LocalPgBackendStatus
1153  *
1154  * When we build the backend status array, we use LocalPgBackendStatus to be
1155  * able to add new values to the struct when needed without adding new fields
1156  * to the shared memory. It contains the backend status as a first member.
1157  * ----------
1158  */
1159 typedef struct LocalPgBackendStatus
1160 {
1161  /*
1162  * Local version of the backend status entry.
1163  */
1165 
1166  /*
1167  * The xid of the current transaction if available, InvalidTransactionId
1168  * if not.
1169  */
1171 
1172  /*
1173  * The xmin of the current session if available, InvalidTransactionId if
1174  * not.
1175  */
1178 
1179 /*
1180  * Working state needed to accumulate per-function-call timing statistics.
1181  */
1183 {
1184  /* Link to function's hashtable entry (must still be there at exit!) */
1185  /* NULL means we are not tracking the current function call */
1187  /* Total time previously charged to function, as of function start */
1189  /* Backend-wide total time as of function start */
1191  /* system clock as of function start */
1194 
1195 
1196 /* ----------
1197  * GUC parameters
1198  * ----------
1199  */
1201 extern PGDLLIMPORT bool pgstat_track_counts;
1204 extern char *pgstat_stat_directory;
1205 extern char *pgstat_stat_tmpname;
1206 extern char *pgstat_stat_filename;
1207 
1208 /*
1209  * BgWriter statistics counters are updated directly by bgwriter and bufmgr
1210  */
1212 
1213 /*
1214  * Updated by pgstat_count_buffer_*_time macros
1215  */
1218 
1219 /* ----------
1220  * Functions called from postmaster
1221  * ----------
1222  */
1223 extern Size BackendStatusShmemSize(void);
1224 extern void CreateSharedBackendStatus(void);
1225 
1226 extern void pgstat_init(void);
1227 extern int pgstat_start(void);
1228 extern void pgstat_reset_all(void);
1229 extern void allow_immediate_pgstat_restart(void);
1230 
1231 #ifdef EXEC_BACKEND
1232 extern void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
1233 #endif
1234 
1235 
1236 /* ----------
1237  * Functions called from backends
1238  * ----------
1239  */
1240 extern void pgstat_ping(void);
1241 
1242 extern void pgstat_report_stat(bool force);
1243 extern void pgstat_vacuum_stat(void);
1244 extern void pgstat_drop_database(Oid databaseid);
1245 
1246 extern void pgstat_clear_snapshot(void);
1247 extern void pgstat_reset_counters(void);
1248 extern void pgstat_reset_shared_counters(const char *);
1250 
1251 extern void pgstat_report_autovac(Oid dboid);
1252 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
1253  PgStat_Counter livetuples, PgStat_Counter deadtuples);
1254 extern void pgstat_report_analyze(Relation rel,
1255  PgStat_Counter livetuples, PgStat_Counter deadtuples,
1256  bool resetcounter);
1257 
1258 extern void pgstat_report_recovery_conflict(int reason);
1259 extern void pgstat_report_deadlock(void);
1260 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
1261 extern void pgstat_report_checksum_failure(void);
1262 
1263 extern void pgstat_initialize(void);
1264 extern void pgstat_bestart(void);
1265 
1266 extern void pgstat_report_activity(BackendState state, const char *cmd_str);
1267 extern void pgstat_report_tempfile(size_t filesize);
1268 extern void pgstat_report_appname(const char *appname);
1269 extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
1270 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
1271 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
1272 extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
1273 extern const char *pgstat_get_crashed_backend_activity(int pid, char *buffer,
1274  int buflen);
1275 
1277  Oid relid);
1278 extern void pgstat_progress_update_param(int index, int64 val);
1279 extern void pgstat_progress_update_multi_param(int nparam, const int *index,
1280  const int64 *val);
1281 extern void pgstat_progress_end_command(void);
1282 
1283 extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
1285 
1286 extern void pgstat_initstats(Relation rel);
1287 
1288 extern char *pgstat_clip_activity(const char *raw_activity);
1289 
1290 /* ----------
1291  * pgstat_report_wait_start() -
1292  *
1293  * Called from places where server process needs to wait. This is called
1294  * to report wait event information. The wait information is stored
1295  * as 4-bytes where first byte represents the wait event class (type of
1296  * wait, for different types of wait, refer WaitClass) and the next
1297  * 3-bytes represent the actual wait event. Currently 2-bytes are used
1298  * for wait event which is sufficient for current usage, 1-byte is
1299  * reserved for future usage.
1300  *
1301  * NB: this *must* be able to survive being called before MyProc has been
1302  * initialized.
1303  * ----------
1304  */
1305 static inline void
1307 {
1308  volatile PGPROC *proc = MyProc;
1309 
1310  if (!pgstat_track_activities || !proc)
1311  return;
1312 
1313  /*
1314  * Since this is a four-byte field which is always read and written as
1315  * four-bytes, updates are atomic.
1316  */
1317  proc->wait_event_info = wait_event_info;
1318 }
1319 
1320 /* ----------
1321  * pgstat_report_wait_end() -
1322  *
1323  * Called to report end of a wait.
1324  *
1325  * NB: this *must* be able to survive being called before MyProc has been
1326  * initialized.
1327  * ----------
1328  */
1329 static inline void
1331 {
1332  volatile PGPROC *proc = MyProc;
1333 
1334  if (!pgstat_track_activities || !proc)
1335  return;
1336 
1337  /*
1338  * Since this is a four-byte field which is always read and written as
1339  * four-bytes, updates are atomic.
1340  */
1341  proc->wait_event_info = 0;
1342 }
1343 
1344 /* nontransactional event counts are simple enough to inline */
1345 
1346 #define pgstat_count_heap_scan(rel) \
1347  do { \
1348  if ((rel)->pgstat_info != NULL) \
1349  (rel)->pgstat_info->t_counts.t_numscans++; \
1350  } while (0)
1351 #define pgstat_count_heap_getnext(rel) \
1352  do { \
1353  if ((rel)->pgstat_info != NULL) \
1354  (rel)->pgstat_info->t_counts.t_tuples_returned++; \
1355  } while (0)
1356 #define pgstat_count_heap_fetch(rel) \
1357  do { \
1358  if ((rel)->pgstat_info != NULL) \
1359  (rel)->pgstat_info->t_counts.t_tuples_fetched++; \
1360  } while (0)
1361 #define pgstat_count_index_scan(rel) \
1362  do { \
1363  if ((rel)->pgstat_info != NULL) \
1364  (rel)->pgstat_info->t_counts.t_numscans++; \
1365  } while (0)
1366 #define pgstat_count_index_tuples(rel, n) \
1367  do { \
1368  if ((rel)->pgstat_info != NULL) \
1369  (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
1370  } while (0)
1371 #define pgstat_count_buffer_read(rel) \
1372  do { \
1373  if ((rel)->pgstat_info != NULL) \
1374  (rel)->pgstat_info->t_counts.t_blocks_fetched++; \
1375  } while (0)
1376 #define pgstat_count_buffer_hit(rel) \
1377  do { \
1378  if ((rel)->pgstat_info != NULL) \
1379  (rel)->pgstat_info->t_counts.t_blocks_hit++; \
1380  } while (0)
1381 #define pgstat_count_buffer_read_time(n) \
1382  (pgStatBlockReadTime += (n))
1383 #define pgstat_count_buffer_write_time(n) \
1384  (pgStatBlockWriteTime += (n))
1385 
1387 extern void pgstat_count_heap_update(Relation rel, bool hot);
1388 extern void pgstat_count_heap_delete(Relation rel);
1389 extern void pgstat_count_truncate(Relation rel);
1390 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
1391 
1393 extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
1396  bool finalize);
1397 
1398 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
1399 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
1400 
1401 extern void AtPrepare_PgStat(void);
1402 extern void PostPrepare_PgStat(void);
1403 
1404 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
1405  void *recdata, uint32 len);
1406 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
1407  void *recdata, uint32 len);
1408 
1409 extern void pgstat_send_archiver(const char *xlog, bool failed);
1410 extern void pgstat_send_bgwriter(void);
1411 
1412 /* ----------
1413  * Support functions for the SQL-callable functions to
1414  * generate the pgstat* views.
1415  * ----------
1416  */
1419 extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid);
1422 extern int pgstat_fetch_stat_numbackends(void);
1425 
1426 #endif /* PGSTAT_H */
void pgstat_report_checksum_failure(void)
Definition: pgstat.c:1550
bool ssl_compression
Definition: pgstat.h:971
struct PgBackendGSSStatus PgBackendGSSStatus
void pgstat_count_truncate(Relation rel)
Definition: pgstat.c:2045
PgStat_MsgAutovacStart msg_autovacuum_start
Definition: pgstat.h:563
PgStat_MsgBgWriter msg_bgwriter
Definition: pgstat.h:567
PgStat_Counter m_buf_fsync_backend
Definition: pgstat.h:420
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2600
void pgstat_initialize(void)
Definition: pgstat.c:2811
PgStat_Counter analyze_count
Definition: pgstat.h:660
instr_time f_self_time
Definition: pgstat.h:464
int pgstat_start(void)
Definition: pgstat.c:724
PgStat_Counter buf_alloc
Definition: pgstat.h:712
PgStat_Counter archived_count
Definition: pgstat.h:686
void pgstat_ping(void)
Definition: pgstat.c:1583
PgStat_Counter m_buf_written_checkpoints
Definition: pgstat.h:416
PgStat_Counter m_buf_alloc
Definition: pgstat.h:421
struct PgStat_MsgFuncpurge PgStat_MsgFuncpurge
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:111
Oid st_progress_command_target
Definition: pgstat.h:1086
PgStat_Counter m_dead_tuples
Definition: pgstat.h:372
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5677
int64 PgStat_Counter
Definition: pgstat.h:75
PgStat_Counter m_checkpoint_write_time
Definition: pgstat.h:422
TimestampTz m_vacuumtime
Definition: pgstat.h:370
PgStat_Counter tuples_updated
Definition: pgstat.h:169
void pgstat_report_xact_timestamp(TimestampTz tstamp)
Definition: pgstat.c:3264
const char * pgstat_get_backend_current_activity(int pid, bool checkUser)
Definition: pgstat.c:4090
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgstat.c:4339
PgStat_Counter tuples_returned
Definition: pgstat.h:639
PgStat_MsgDeadlock msg_deadlock
Definition: pgstat.h:571
uint32 TransactionId
Definition: c.h:513
PgStat_MsgResetsharedcounter msg_resetsharedcounter
Definition: pgstat.h:561
union PgStat_Msg PgStat_Msg
TimestampTz stats_timestamp
Definition: pgstat.h:618
uint32 wait_event_info
Definition: proc.h:176
WaitEventIPC
Definition: pgstat.h:800
void pgstat_progress_update_param(int index, int64 val)
Definition: pgstat.c:3161
TrackFunctionsLevel
Definition: pgstat.h:37
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:103
PgStat_MsgHdr m_hdr
Definition: pgstat.h:444
PgStat_MsgChecksumFailure msg_checksumfailure
Definition: pgstat.h:573
PgStat_Counter m_live_tuples
Definition: pgstat.h:371
TimestampTz clock_time
Definition: pgstat.h:243
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1044
instr_time save_total
Definition: pgstat.h:1190
PgStat_Counter n_blocks_hit
Definition: pgstat.h:597
PGPROC * MyProc
Definition: proc.c:67
int64 TimestampTz
Definition: timestamp.h:39
#define PGSTAT_NUM_TABPURGE
Definition: pgstat.h:286
struct PgStat_MsgTabpurge PgStat_MsgTabpurge
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
Definition: pgstat.c:2074
PgStat_MsgHdr m_hdr
Definition: pgstat.h:353
struct PgStat_MsgArchiver PgStat_MsgArchiver
PgStat_Counter m_timed_checkpoints
Definition: pgstat.h:414
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:607
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3235
PgStat_Counter m_maxwritten_clean
Definition: pgstat.h:418
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:608
void CreateSharedBackendStatus(void)
Definition: pgstat.c:2676
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:108
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
Definition: pgstat.c:3140
PgStat_MsgHdr m_hdr
Definition: pgstat.h:412
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:661
struct PgStat_MsgDeadlock PgStat_MsgDeadlock
struct timeval instr_time
Definition: instr_time.h:150
PgStat_Counter f_self_time
Definition: pgstat.h:486
PgStat_Counter timed_checkpoints
Definition: pgstat.h:703
PgStat_MsgHdr m_hdr
Definition: pgstat.h:517
PgStat_Counter n_checksum_failures
Definition: pgstat.h:612
PgStat_Counter n_temp_files
Definition: pgstat.h:609
PgStat_MsgHdr m_hdr
Definition: pgstat.h:541
Oid m_databaseid
Definition: pgstat.h:367
PgStat_Counter m_buf_written_clean
Definition: pgstat.h:417
PgStat_MsgDummy msg_dummy
Definition: pgstat.h:555
TimestampTz last_checksum_failure
Definition: pgstat.h:613
HTAB * functions
Definition: pgstat.h:625
TransactionId backend_xmin
Definition: pgstat.h:1176
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617
PgStat_Counter n_tuples_returned
Definition: pgstat.h:598
PgStat_Counter vacuum_count
Definition: pgstat.h:656
SockAddr st_clientaddr
Definition: pgstat.h:1050
bool m_autovacuum
Definition: pgstat.h:369
void pgstat_send_archiver(const char *xlog, bool failed)
Definition: pgstat.c:4282
size_t m_filesize
Definition: pgstat.h:447
PgStat_MsgTempFile msg_tempfile
Definition: pgstat.h:572
PgStat_Counter buf_fsync_backend
Definition: pgstat.h:711
struct PgStat_TableCounts PgStat_TableCounts
struct PgStat_MsgDummy PgStat_MsgDummy
TimestampTz stats_timestamp
Definition: pgstat.h:702
TimestampTz stat_reset_timestamp
Definition: pgstat.h:617
instr_time f_total_time
Definition: pgstat.h:463
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:740
struct PgStat_TableXactStatus * next
Definition: pgstat.h:180
TimestampTz m_analyzetime
Definition: pgstat.h:388
ProgressCommandType st_progress_command
Definition: pgstat.h:1085
void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: pgstat.c:2358
PgStat_Counter numscans
Definition: pgstat.h:637
PgStat_TableCounts t_counts
Definition: pgstat.h:159
struct PgBackendSSLStatus PgBackendSSLStatus
struct PgStat_MsgRecoveryConflict PgStat_MsgRecoveryConflict
Datum ssl_client_serial(PG_FUNCTION_ARGS)
Definition: sslinfo.c:100
#define PG_WAIT_IO
Definition: pgstat.h:745
unsigned int Oid
Definition: postgres_ext.h:31
struct PgStat_ArchiverStats PgStat_ArchiverStats
PgStat_Counter deleted_pre_trunc
Definition: pgstat.h:174
PgStat_MsgAnalyze msg_analyze
Definition: pgstat.h:565
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:645
PgStat_Counter f_total_time
Definition: pgstat.h:676
BackendState st_state
Definition: pgstat.h:1062
PgStat_Counter t_tuples_returned
Definition: pgstat.h:102
PgStat_Shared_Reset_Target
Definition: pgstat.h:120
char * st_clienthostname
Definition: pgstat.h:1051
PgStat_Counter tuples_inserted
Definition: pgstat.h:642
PgStat_FunctionCounts * fs
Definition: pgstat.h:1186
PgStat_Counter f_numcalls
Definition: pgstat.h:462
PgStat_MsgHdr msg_hdr
Definition: pgstat.h:554
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
#define PGDLLIMPORT
Definition: c.h:1280
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2455
PgStat_Counter n_xact_commit
Definition: pgstat.h:594
void pgstat_report_deadlock(void)
Definition: pgstat.c:1507
bool m_resetcounter
Definition: pgstat.h:387
Definition: type.h:89
PgStat_MsgBgWriter BgWriterStats
Definition: pgstat.c:142
Oid st_databaseid
Definition: pgstat.h:1048
#define NAMEDATALEN
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:951
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:596
struct PgStat_TableEntry PgStat_TableEntry
PgStat_Counter n_live_tuples
Definition: pgstat.h:647
PgStat_Counter m_requested_checkpoints
Definition: pgstat.h:415
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:650
Definition: dynahash.c:209
struct PgStat_MsgAnalyze PgStat_MsgAnalyze
unsigned short uint16
Definition: c.h:366
PgStat_FunctionCounts f_counts
Definition: pgstat.h:474
PgStat_MsgHdr m_hdr
Definition: pgstat.h:530
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
PgStat_MsgFuncpurge msg_funcpurge
Definition: pgstat.h:569
char * pgstat_stat_tmpname
Definition: pgstat.c:135
PgStat_Counter buf_written_backend
Definition: pgstat.h:710
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:604
TransactionId backend_xid
Definition: pgstat.h:1170
void AtEOSubXact_PgStat(bool isCommit, int nestDepth)
Definition: pgstat.c:2177
TimestampTz vacuum_timestamp
Definition: pgstat.h:655
PgStat_Counter t_tuples_updated
Definition: pgstat.h:106
PgStat_MsgHdr m_hdr
Definition: pgstat.h:432
PgStat_Counter pgStatBlockReadTime
Definition: pgstat.c:222
#define PG_WAIT_CLIENT
Definition: pgstat.h:741
void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1360
PgStat_Counter checkpoint_write_time
Definition: pgstat.h:705
PgStat_Counter n_dead_tuples
Definition: pgstat.h:648
TimestampTz m_failure_time
Definition: pgstat.h:544
struct PgStat_MsgTempFile PgStat_MsgTempFile
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2565
void allow_immediate_pgstat_restart(void)
Definition: pgstat.c:787
PgStat_Counter f_numcalls
Definition: pgstat.h:674
TimestampTz last_autovac_time
Definition: pgstat.h:603
WaitEventClient
Definition: pgstat.h:780
struct PgStat_GlobalStats PgStat_GlobalStats
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:600
Oid m_databaseid
Definition: pgstat.h:307
PgStat_Counter buf_written_checkpoints
Definition: pgstat.h:707
PgStat_Counter tuples_inserted
Definition: pgstat.h:168
struct PgStat_MsgDropdb PgStat_MsgDropdb
PgStat_Counter pgStatBlockWriteTime
Definition: pgstat.c:223
struct PgStat_MsgInquiry PgStat_MsgInquiry
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1690
char * st_activity_raw
Definition: pgstat.h:1074
char * pgstat_stat_directory
Definition: pgstat.c:133
void pgstat_report_stat(bool force)
Definition: pgstat.c:809
void pgstat_vacuum_stat(void)
Definition: pgstat.c:1019
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:112
PgStat_Counter tuples_fetched
Definition: pgstat.h:640
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
Definition: pgstat.c:1944
unsigned int uint32
Definition: c.h:367
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:606
PgStat_MsgHdr m_hdr
Definition: pgstat.h:306
PgStat_Counter m_block_write_time
Definition: pgstat.h:276
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1330
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1045
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:602
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: pgstat.c:2394
PgStat_Counter n_conflict_lock
Definition: pgstat.h:605
WaitEventTimeout
Definition: pgstat.h:849
char * st_appname
Definition: pgstat.h:1065
PgStat_Counter t_blocks_hit
Definition: pgstat.h:116
void pgstat_init(void)
Definition: pgstat.c:349
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:177
PgStat_Counter n_xact_rollback
Definition: pgstat.h:595
int m_xact_rollback
Definition: pgstat.h:274
PgStat_MsgHdr m_hdr
Definition: pgstat.h:318
void pgstat_progress_end_command(void)
Definition: pgstat.c:3212
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:107
PgStat_Counter buf_written_clean
Definition: pgstat.h:708
Datum ssl_issuer_dn(PG_FUNCTION_ARGS)
Definition: sslinfo.c:378
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2584
void AtEOXact_PgStat(bool isCommit, bool parallel)
Definition: pgstat.c:2090
void pgstat_report_recovery_conflict(int reason)
Definition: pgstat.c:1487
PgStat_MsgRecoveryConflict msg_recoveryconflict
Definition: pgstat.h:570
struct PgStat_MsgTabstat PgStat_MsgTabstat
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
PgStat_MsgHdr m_hdr
Definition: pgstat.h:292
PgStat_Counter m_live_tuples
Definition: pgstat.h:389
void pgstat_drop_database(Oid databaseid)
Definition: pgstat.c:1251
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3443
struct PgStat_MsgResetsharedcounter PgStat_MsgResetsharedcounter
struct PgStat_FunctionCounts PgStat_FunctionCounts
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3498
PgBackendStatus backendStatus
Definition: pgstat.h:1164
bool m_autovacuum
Definition: pgstat.h:386
#define PGSTAT_NUM_FUNCENTRIES
Definition: pgstat.h:494
PgStat_Counter tuples_deleted
Definition: pgstat.h:170
struct PgStat_MsgBgWriter PgStat_MsgBgWriter
TimestampTz m_timestamp
Definition: pgstat.h:403
#define PGSTAT_NUM_TABENTRIES
Definition: pgstat.h:264
struct PgStat_MsgResetsinglecounter PgStat_MsgResetsinglecounter
void pgstat_reset_counters(void)
Definition: pgstat.c:1307
#define MAX_XFN_CHARS
Definition: pgarch.h:26
BackendType st_backendType
Definition: pgstat.h:1039
PgStat_Counter f_total_time
Definition: pgstat.h:485
PgStat_Counter blocks_hit
Definition: pgstat.h:653
TimestampTz analyze_timestamp
Definition: pgstat.h:659
TimestampTz last_failed_timestamp
Definition: pgstat.h:693
PgStat_Counter changes_since_analyze
Definition: pgstat.h:649
StatMsgType
Definition: pgstat.h:48
PgStat_Shared_Reset_Target m_resettarget
Definition: pgstat.h:330
void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
Definition: pgstat.c:1406
PgStat_Counter t_numscans
Definition: pgstat.h:100
struct PgStat_MsgVacuum PgStat_MsgVacuum
PgStat_Single_Reset_Type
Definition: pgstat.h:127
Size BackendStatusShmemSize(void)
Definition: pgstat.c:2648
struct PgStat_TableXactStatus PgStat_TableXactStatus
Datum ssl_version(PG_FUNCTION_ARGS)
Definition: sslinfo.c:55
PGDLLIMPORT bool pgstat_track_counts
Definition: pgstat.c:125
PgStat_Counter n_tuples_updated
Definition: pgstat.h:601
Datum ssl_client_dn(PG_FUNCTION_ARGS)
Definition: sslinfo.c:359
char * pgstat_stat_filename
Definition: pgstat.c:134
PgStat_MsgHdr m_hdr
Definition: pgstat.h:217
PgStat_Counter t_changed_tuples
Definition: pgstat.h:113
PgStat_MsgTabstat msg_tabstat
Definition: pgstat.h:557
PgStat_MsgHdr m_hdr
Definition: pgstat.h:270
void pgstat_send_bgwriter(void)
Definition: pgstat.c:4303
struct PgStat_MsgChecksumFailure PgStat_MsgChecksumFailure
ProgressCommandType
Definition: pgstat.h:941
PgStat_Counter m_checkpoint_sync_time
Definition: pgstat.h:423
PgStat_MsgVacuum msg_vacuum
Definition: pgstat.h:564
Definition: regguts.h:298
PgStat_MsgHdr m_hdr
Definition: pgstat.h:500
PgStat_Counter failed_count
Definition: pgstat.h:690
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
PgStat_Counter n_block_write_time
Definition: pgstat.h:615
PgStat_Counter m_buf_written_backend
Definition: pgstat.h:419
PgStat_MsgHdr m_hdr
Definition: pgstat.h:366
void pgstat_count_heap_delete(Relation rel)
Definition: pgstat.c:1990
PgStat_Counter tuples_deleted
Definition: pgstat.h:644
struct PgStat_StatTabEntry PgStat_StatTabEntry
PgStat_TableCounts t_counts
Definition: pgstat.h:256
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:172
PgStat_Counter tuples_updated
Definition: pgstat.h:643
size_t Size
Definition: c.h:466
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:706
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1306
void pgstat_report_tempfile(size_t filesize)
Definition: pgstat.c:1562
PGDLLIMPORT bool pgstat_track_activities
Definition: pgstat.c:124
struct PgStat_FunctionEntry PgStat_FunctionEntry
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:657
PgStat_Counter maxwritten_clean
Definition: pgstat.h:709
PgStat_Counter n_block_read_time
Definition: pgstat.h:614
PgStat_Counter m_block_read_time
Definition: pgstat.h:275
struct PgStat_MsgFuncstat PgStat_MsgFuncstat
TimestampTz stat_reset_timestamp
Definition: pgstat.h:713
void pgstat_bestart(void)
Definition: pgstat.c:2853
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:158
struct PgStat_TableStatus PgStat_TableStatus
struct PgBackendStatus PgBackendStatus
#define pg_attribute_noreturn()
Definition: c.h:145
struct PgStat_StatDBEntry PgStat_StatDBEntry
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:662
void pgstat_report_autovac(Oid dboid)
Definition: pgstat.c:1384
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:173
PgStat_MsgHdr m_hdr
Definition: pgstat.h:383
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
Definition: pgstat.c:1528
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:3062
void pgstat_count_heap_update(Relation rel, bool hot)
Definition: pgstat.c:1965
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1670
void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
TimestampTz cutoff_time
Definition: pgstat.h:244
Datum ssl_cipher(PG_FUNCTION_ARGS)
Definition: sslinfo.c:68
WaitEventIO
Definition: pgstat.h:864
TimestampTz stat_reset_timestamp
Definition: pgstat.h:694
TimestampTz last_archived_timestamp
Definition: pgstat.h:689
TimestampTz m_start_time
Definition: pgstat.h:355
PgStat_Counter n_deadlocks
Definition: pgstat.h:611
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:744
#define PG_WAIT_IPC
Definition: pgstat.h:743
struct PgStat_MsgAutovacStart PgStat_MsgAutovacStart
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1043
PgStat_MsgArchiver msg_archiver
Definition: pgstat.h:566
int st_changecount
Definition: pgstat.h:1033
const char * pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
Definition: pgstat.c:4168
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
Definition: pgstat.c:1434
PgStat_MsgResetsinglecounter msg_resetsinglecounter
Definition: pgstat.h:562
PgStat_Counter requested_checkpoints
Definition: pgstat.h:704
StatMsgType m_type
Definition: pgstat.h:196
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
Definition: pgstat.c:3183
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid funcid)
Definition: pgstat.c:2511
instr_time save_f_total_time
Definition: pgstat.h:1188
PgStat_MsgResetcounter msg_resetcounter
Definition: pgstat.h:560
BackendState
Definition: pgstat.h:721
void pgstat_reset_all(void)
Definition: pgstat.c:682
BackendType
Definition: miscadmin.h:309
PgStat_Counter f_numcalls
Definition: pgstat.h:484
struct PgStat_MsgResetcounter PgStat_MsgResetcounter
PgStat_Counter f_self_time
Definition: pgstat.h:677
PgStat_Counter m_dead_tuples
Definition: pgstat.h:390
Definition: proc.h:95
PgStat_Counter blocks_fetched
Definition: pgstat.h:652
void AtPrepare_PgStat(void)
Definition: pgstat.c:2276
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
struct PgStat_MsgHdr PgStat_MsgHdr
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1042
PgStat_MsgInquiry msg_inquiry
Definition: pgstat.h:556
PgStat_MsgDropdb msg_dropdb
Definition: pgstat.h:559
int m_size
Definition: pgstat.h:197
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1055
PgStat_Single_Reset_Type m_resettype
Definition: pgstat.h:342
void pgstat_initstats(Relation rel)
Definition: pgstat.c:1747
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:105
long val
Definition: informix.c:664
void pgstat_reset_shared_counters(const char *)
Definition: pgstat.c:1329
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6440
PgStat_MsgTabpurge msg_tabpurge
Definition: pgstat.h:558
#define PGSTAT_NUM_FUNCPURGE
Definition: pgstat.h:511
PGDLLIMPORT int pgstat_track_activity_query_size
Definition: pgstat.c:127
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1059
PgStat_TableStatus * parent
Definition: pgstat.h:178
PGDLLIMPORT int pgstat_track_functions
Definition: pgstat.c:126
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:115
PgStat_MsgHdr m_hdr
Definition: pgstat.h:400
void PostPrepare_PgStat(void)
Definition: pgstat.c:2325
PgStat_MsgFuncstat msg_funcstat
Definition: pgstat.h:568
struct LocalPgBackendStatus LocalPgBackendStatus
WaitEventActivity
Definition: pgstat.h:755
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:599
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:658
PgStat_MsgHdr m_hdr
Definition: pgstat.h:242
PgStat_Counter n_temp_bytes
Definition: pgstat.h:610