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