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 {
71 } StatMsgType;
72 
73 /* ----------
74  * The data type used for counters.
75  * ----------
76  */
77 typedef int64 PgStat_Counter;
78 
79 /* ----------
80  * PgStat_TableCounts The actual per-table counts kept by a backend
81  *
82  * This struct should contain only actual event counters, because we memcmp
83  * it against zeroes to detect whether there are any counts to transmit.
84  * It is a component of PgStat_TableStatus (within-backend state) and
85  * PgStat_TableEntry (the transmitted message format).
86  *
87  * Note: for a table, tuples_returned is the number of tuples successfully
88  * fetched by heap_getnext, while tuples_fetched is the number of tuples
89  * successfully fetched by heap_fetch under the control of bitmap indexscans.
90  * For an index, tuples_returned is the number of index entries returned by
91  * the index AM, while tuples_fetched is the number of tuples successfully
92  * fetched by heap_fetch under the control of simple indexscans for this index.
93  *
94  * tuples_inserted/updated/deleted/hot_updated count attempted actions,
95  * regardless of whether the transaction committed. delta_live_tuples,
96  * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
97  * Note that delta_live_tuples and delta_dead_tuples can be negative!
98  * ----------
99  */
100 typedef struct PgStat_TableCounts
101 {
103 
106 
112 
116 
120 
121 /* Possible targets for resetting cluster-wide shared values */
123 {
127 
128 /* Possible object types for resetting single counters */
130 {
134 
135 /* ------------------------------------------------------------
136  * Structures kept in backend local memory while accumulating counts
137  * ------------------------------------------------------------
138  */
139 
140 
141 /* ----------
142  * PgStat_TableStatus Per-table status within a backend
143  *
144  * Many of the event counters are nontransactional, ie, we count events
145  * in committed and aborted transactions alike. For these, we just count
146  * directly in the PgStat_TableStatus. However, delta_live_tuples,
147  * delta_dead_tuples, and changed_tuples must be derived from event counts
148  * with awareness of whether the transaction or subtransaction committed or
149  * aborted. Hence, we also keep a stack of per-(sub)transaction status
150  * records for every table modified in the current transaction. At commit
151  * or abort, we propagate tuples_inserted/updated/deleted up to the
152  * parent subtransaction level, or out to the parent PgStat_TableStatus,
153  * as appropriate.
154  * ----------
155  */
156 typedef struct PgStat_TableStatus
157 {
158  Oid t_id; /* table's OID */
159  bool t_shared; /* is it a shared catalog? */
160  struct PgStat_TableXactStatus *trans; /* lowest subxact's counts */
161  PgStat_TableCounts t_counts; /* event counts to be sent */
163 
164 /* ----------
165  * PgStat_TableXactStatus Per-table, per-subtransaction status
166  * ----------
167  */
169 {
170  PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */
171  PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */
172  PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */
173  bool truncated; /* relation truncated in this (sub)xact */
174  PgStat_Counter inserted_pre_trunc; /* tuples inserted prior to truncate */
175  PgStat_Counter updated_pre_trunc; /* tuples updated prior to truncate */
176  PgStat_Counter deleted_pre_trunc; /* tuples deleted prior to truncate */
177  int nest_level; /* subtransaction nest level */
178  /* links to other structs for same relation: */
179  struct PgStat_TableXactStatus *upper; /* next higher subxact if any */
180  PgStat_TableStatus *parent; /* per-table status */
181  /* structs of same subxact level are linked here: */
182  struct PgStat_TableXactStatus *next; /* next of same subxact */
184 
185 
186 /* ------------------------------------------------------------
187  * Message formats follow
188  * ------------------------------------------------------------
189  */
190 
191 
192 /* ----------
193  * PgStat_MsgHdr The common message header
194  * ----------
195  */
196 typedef struct PgStat_MsgHdr
197 {
199  int m_size;
200 } PgStat_MsgHdr;
201 
202 /* ----------
203  * Space available in a message. This will keep the UDP packets below 1K,
204  * which should fit unfragmented into the MTU of the loopback interface.
205  * (Larger values of PGSTAT_MAX_MSG_SIZE would work for that on most
206  * platforms, but we're being conservative here.)
207  * ----------
208  */
209 #define PGSTAT_MAX_MSG_SIZE 1000
210 #define PGSTAT_MSG_PAYLOAD (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))
211 
212 
213 /* ----------
214  * PgStat_MsgDummy A dummy message, ignored by the collector
215  * ----------
216  */
217 typedef struct PgStat_MsgDummy
218 {
221 
222 
223 /* ----------
224  * PgStat_MsgInquiry Sent by a backend to ask the collector
225  * to write the stats file(s).
226  *
227  * Ordinarily, an inquiry message prompts writing of the global stats file,
228  * the stats file for shared catalogs, and the stats file for the specified
229  * database. If databaseid is InvalidOid, only the first two are written.
230  *
231  * New file(s) will be written only if the existing file has a timestamp
232  * older than the specified cutoff_time; this prevents duplicated effort
233  * when multiple requests arrive at nearly the same time, assuming that
234  * backends send requests with cutoff_times a little bit in the past.
235  *
236  * clock_time should be the requestor's current local time; the collector
237  * uses this to check for the system clock going backward, but it has no
238  * effect unless that occurs. We assume clock_time >= cutoff_time, though.
239  * ----------
240  */
241 
242 typedef struct PgStat_MsgInquiry
243 {
245  TimestampTz clock_time; /* observed local clock time */
246  TimestampTz cutoff_time; /* minimum acceptable file timestamp */
247  Oid databaseid; /* requested DB (InvalidOid => shared only) */
249 
250 
251 /* ----------
252  * PgStat_TableEntry Per-table info in a MsgTabstat
253  * ----------
254  */
255 typedef struct PgStat_TableEntry
256 {
260 
261 /* ----------
262  * PgStat_MsgTabstat Sent by the backend to report table
263  * and buffer access statistics.
264  * ----------
265  */
266 #define PGSTAT_NUM_TABENTRIES \
267  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int) - 2 * sizeof(PgStat_Counter)) \
268  / sizeof(PgStat_TableEntry))
269 
270 typedef struct PgStat_MsgTabstat
271 {
277  PgStat_Counter m_block_read_time; /* times in microseconds */
281 
282 
283 /* ----------
284  * PgStat_MsgTabpurge Sent by the backend to tell the collector
285  * about dead tables.
286  * ----------
287  */
288 #define PGSTAT_NUM_TABPURGE \
289  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
290  / sizeof(Oid))
291 
292 typedef struct PgStat_MsgTabpurge
293 {
299 
300 
301 /* ----------
302  * PgStat_MsgDropdb Sent by the backend to tell the collector
303  * about a dropped database
304  * ----------
305  */
306 typedef struct PgStat_MsgDropdb
307 {
311 
312 
313 /* ----------
314  * PgStat_MsgResetcounter Sent by the backend to tell the collector
315  * to reset counters
316  * ----------
317  */
319 {
323 
324 /* ----------
325  * PgStat_MsgResetsharedcounter Sent by the backend to tell the collector
326  * to reset a shared counter
327  * ----------
328  */
330 {
334 
335 /* ----------
336  * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector
337  * to reset a single counter
338  * ----------
339  */
341 {
347 
348 /* ----------
349  * PgStat_MsgResetslrucounter Sent by the backend to tell the collector
350  * to reset a SLRU counter
351  * ----------
352  */
354 {
356  int m_index;
358 
359 /* ----------
360  * PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
361  * that a database is going to be processed
362  * ----------
363  */
365 {
370 
371 
372 /* ----------
373  * PgStat_MsgVacuum Sent by the backend or autovacuum daemon
374  * after VACUUM
375  * ----------
376  */
377 typedef struct PgStat_MsgVacuum
378 {
387 
388 
389 /* ----------
390  * PgStat_MsgAnalyze Sent by the backend or autovacuum daemon
391  * after ANALYZE
392  * ----------
393  */
394 typedef struct PgStat_MsgAnalyze
395 {
405 
406 
407 /* ----------
408  * PgStat_MsgArchiver Sent by the archiver to update statistics.
409  * ----------
410  */
411 typedef struct PgStat_MsgArchiver
412 {
414  bool m_failed; /* Failed attempt */
415  char m_xlog[MAX_XFN_CHARS + 1];
418 
419 /* ----------
420  * PgStat_MsgBgWriter Sent by the bgwriter to update statistics.
421  * ----------
422  */
423 typedef struct PgStat_MsgBgWriter
424 {
426 
435  PgStat_Counter m_checkpoint_write_time; /* times in milliseconds */
438 
439 /* ----------
440  * PgStat_MsgSLRU Sent by a backend to update SLRU statistics.
441  * ----------
442  */
443 typedef struct PgStat_MsgSLRU
444 {
455 
456 /* ----------
457  * PgStat_MsgRecoveryConflict Sent by the backend upon recovery conflict
458  * ----------
459  */
461 {
463 
465  int m_reason;
467 
468 /* ----------
469  * PgStat_MsgTempFile Sent by the backend upon creating a temp file
470  * ----------
471  */
472 typedef struct PgStat_MsgTempFile
473 {
475 
477  size_t m_filesize;
479 
480 /* ----------
481  * PgStat_FunctionCounts The actual per-function counts kept by a backend
482  *
483  * This struct should contain only actual event counters, because we memcmp
484  * it against zeroes to detect whether there are any counts to transmit.
485  *
486  * Note that the time counters are in instr_time format here. We convert to
487  * microseconds in PgStat_Counter format when transmitting to the collector.
488  * ----------
489  */
490 typedef struct PgStat_FunctionCounts
491 {
496 
497 /* ----------
498  * PgStat_BackendFunctionEntry Entry in backend's per-function hash table
499  * ----------
500  */
502 {
506 
507 /* ----------
508  * PgStat_FunctionEntry Per-function info in a MsgFuncstat
509  * ----------
510  */
511 typedef struct PgStat_FunctionEntry
512 {
515  PgStat_Counter f_total_time; /* times in microseconds */
518 
519 /* ----------
520  * PgStat_MsgFuncstat Sent by the backend to report function
521  * usage statistics.
522  * ----------
523  */
524 #define PGSTAT_NUM_FUNCENTRIES \
525  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
526  / sizeof(PgStat_FunctionEntry))
527 
528 typedef struct PgStat_MsgFuncstat
529 {
535 
536 /* ----------
537  * PgStat_MsgFuncpurge Sent by the backend to tell the collector
538  * about dead functions.
539  * ----------
540  */
541 #define PGSTAT_NUM_FUNCPURGE \
542  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
543  / sizeof(Oid))
544 
545 typedef struct PgStat_MsgFuncpurge
546 {
550  Oid m_functionid[PGSTAT_NUM_FUNCPURGE];
552 
553 /* ----------
554  * PgStat_MsgDeadlock Sent by the backend to tell the collector
555  * about a deadlock that occurred.
556  * ----------
557  */
558 typedef struct PgStat_MsgDeadlock
559 {
563 
564 /* ----------
565  * PgStat_MsgChecksumFailure Sent by the backend to tell the collector
566  * about checksum failures noticed.
567  * ----------
568  */
570 {
576 
577 
578 /* ----------
579  * PgStat_Msg Union over all possible messages.
580  * ----------
581  */
582 typedef union PgStat_Msg
583 {
606 } PgStat_Msg;
607 
608 
609 /* ------------------------------------------------------------
610  * Statistic collector data structures follow
611  *
612  * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
613  * data structures change.
614  * ------------------------------------------------------------
615  */
616 
617 #define PGSTAT_FILE_FORMAT_ID 0x01A5BC9D
618 
619 /* ----------
620  * PgStat_StatDBEntry The collector's data per database
621  * ----------
622  */
623 typedef struct PgStat_StatDBEntry
624 {
646  PgStat_Counter n_block_read_time; /* times in microseconds */
648 
650  TimestampTz stats_timestamp; /* time of db stats file update */
651 
652  /*
653  * tables and functions must be last in the struct, because we don't write
654  * the pointers out to the stats file.
655  */
659 
660 
661 /* ----------
662  * PgStat_StatTabEntry The collector's data per table (or index)
663  * ----------
664  */
665 typedef struct PgStat_StatTabEntry
666 {
668 
670 
673 
678 
683 
686 
687  TimestampTz vacuum_timestamp; /* user initiated vacuum */
689  TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */
691  TimestampTz analyze_timestamp; /* user initiated */
693  TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */
696 
697 
698 /* ----------
699  * PgStat_StatFuncEntry The collector's data per function
700  * ----------
701  */
702 typedef struct PgStat_StatFuncEntry
703 {
705 
707 
708  PgStat_Counter f_total_time; /* times in microseconds */
711 
712 
713 /*
714  * Archiver statistics kept in the stats collector
715  */
716 typedef struct PgStat_ArchiverStats
717 {
718  PgStat_Counter archived_count; /* archival successes */
719  char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
720  * archived */
721  TimestampTz last_archived_timestamp; /* last archival success time */
722  PgStat_Counter failed_count; /* failed archival attempts */
723  char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
724  * last failure */
725  TimestampTz last_failed_timestamp; /* last archival failure time */
728 
729 /*
730  * Global statistics kept in the stats collector
731  */
732 typedef struct PgStat_GlobalStats
733 {
734  TimestampTz stats_timestamp; /* time of stats file update */
737  PgStat_Counter checkpoint_write_time; /* times in milliseconds */
747 
748 /*
749  * SLRU statistics kept in the stats collector
750  */
751 typedef struct PgStat_SLRUStats
752 {
762 
763 
764 /* ----------
765  * Backend states
766  * ----------
767  */
768 typedef enum BackendState
769 {
777 } BackendState;
778 
779 
780 /* ----------
781  * Wait Classes
782  * ----------
783  */
784 #define PG_WAIT_LWLOCK 0x01000000U
785 #define PG_WAIT_LOCK 0x03000000U
786 #define PG_WAIT_BUFFER_PIN 0x04000000U
787 #define PG_WAIT_ACTIVITY 0x05000000U
788 #define PG_WAIT_CLIENT 0x06000000U
789 #define PG_WAIT_EXTENSION 0x07000000U
790 #define PG_WAIT_IPC 0x08000000U
791 #define PG_WAIT_TIMEOUT 0x09000000U
792 #define PG_WAIT_IO 0x0A000000U
793 
794 /* ----------
795  * Wait Events - Activity
796  *
797  * Use this category when a process is waiting because it has no work to do,
798  * unless the "Client" or "Timeout" category describes the situation better.
799  * Typically, this should only be used for background processes.
800  * ----------
801  */
802 typedef enum
803 {
818 
819 /* ----------
820  * Wait Events - Client
821  *
822  * Use this category when a process is waiting to send data to or receive data
823  * from the frontend process to which it is connected. This is never used for
824  * a background process, which has no client connection.
825  * ----------
826  */
827 typedef enum
828 {
839 
840 /* ----------
841  * Wait Events - IPC
842  *
843  * Use this category when a process cannot complete the work it is doing because
844  * it is waiting for a notification from another process.
845  * ----------
846  */
847 typedef enum
848 {
891 } WaitEventIPC;
892 
893 /* ----------
894  * Wait Events - Timeout
895  *
896  * Use this category when a process is waiting for a timeout to expire.
897  * ----------
898  */
899 typedef enum
900 {
907 
908 /* ----------
909  * Wait Events - IO
910  *
911  * Use this category when a process is waiting for a IO.
912  * ----------
913  */
914 typedef enum
915 {
990 } WaitEventIO;
991 
992 /* ----------
993  * Command type for progress reporting purposes
994  * ----------
995  */
997 {
1005 
1006 #define PGSTAT_NUM_PROGRESS_PARAM 20
1007 
1008 /* ----------
1009  * Shared-memory data structures
1010  * ----------
1011  */
1012 
1013 
1014 /*
1015  * PgBackendSSLStatus
1016  *
1017  * For each backend, we keep the SSL status in a separate struct, that
1018  * is only filled in if SSL is enabled.
1019  *
1020  * All char arrays must be null-terminated.
1021  */
1022 typedef struct PgBackendSSLStatus
1023 {
1024  /* Information about SSL connection */
1030 
1031  /*
1032  * serial number is max "20 octets" per RFC 5280, so this size should be
1033  * fine
1034  */
1036 
1039 
1040 /*
1041  * PgBackendGSSStatus
1042  *
1043  * For each backend, we keep the GSS status in a separate struct, that
1044  * is only filled in if GSS is enabled.
1045  *
1046  * All char arrays must be null-terminated.
1047  */
1048 typedef struct PgBackendGSSStatus
1049 {
1050  /* Information about GSSAPI connection */
1051  char gss_princ[NAMEDATALEN]; /* GSSAPI Principal used to auth */
1052  bool gss_auth; /* If GSSAPI authentication was used */
1053  bool gss_enc; /* If encryption is being used */
1054 
1056 
1057 
1058 /* ----------
1059  * PgBackendStatus
1060  *
1061  * Each live backend maintains a PgBackendStatus struct in shared memory
1062  * showing its current activity. (The structs are allocated according to
1063  * BackendId, but that is not critical.) Note that the collector process
1064  * has no involvement in, or even access to, these structs.
1065  *
1066  * Each auxiliary process also maintains a PgBackendStatus struct in shared
1067  * memory.
1068  * ----------
1069  */
1070 typedef struct PgBackendStatus
1071 {
1072  /*
1073  * To avoid locking overhead, we use the following protocol: a backend
1074  * increments st_changecount before modifying its entry, and again after
1075  * finishing a modification. A would-be reader should note the value of
1076  * st_changecount, copy the entry into private memory, then check
1077  * st_changecount again. If the value hasn't changed, and if it's even,
1078  * the copy is valid; otherwise start over. This makes updates cheap
1079  * while reads are potentially expensive, but that's the tradeoff we want.
1080  *
1081  * The above protocol needs memory barriers to ensure that the apparent
1082  * order of execution is as it desires. Otherwise, for example, the CPU
1083  * might rearrange the code so that st_changecount is incremented twice
1084  * before the modification on a machine with weak memory ordering. Hence,
1085  * use the macros defined below for manipulating st_changecount, rather
1086  * than touching it directly.
1087  */
1089 
1090  /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */
1092 
1093  /* Type of backends */
1095 
1096  /* Times when current backend, transaction, and activity started */
1101 
1102  /* Database OID, owning user's OID, connection client address */
1106  char *st_clienthostname; /* MUST be null-terminated */
1107 
1108  /* Information about SSL connection */
1109  bool st_ssl;
1111 
1112  /* Information about GSSAPI connection */
1113  bool st_gss;
1115 
1116  /* current state */
1118 
1119  /* application name; MUST be null-terminated */
1120  char *st_appname;
1121 
1122  /*
1123  * Current command string; MUST be null-terminated. Note that this string
1124  * possibly is truncated in the middle of a multi-byte character. As
1125  * activity strings are stored more frequently than read, that allows to
1126  * move the cost of correct truncation to the display side. Use
1127  * pgstat_clip_activity() to truncate correctly.
1128  */
1130 
1131  /*
1132  * Command progress reporting. Any command which wishes can advertise
1133  * that it is running by setting st_progress_command,
1134  * st_progress_command_target, and st_progress_param[].
1135  * st_progress_command_target should be the OID of the relation which the
1136  * command targets (we assume there's just one, as this is meant for
1137  * utility commands), but the meaning of each element in the
1138  * st_progress_param array is command-specific.
1139  */
1142  int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM];
1143 } PgBackendStatus;
1144 
1145 /*
1146  * Macros to load and store st_changecount with appropriate memory barriers.
1147  *
1148  * Use PGSTAT_BEGIN_WRITE_ACTIVITY() before, and PGSTAT_END_WRITE_ACTIVITY()
1149  * after, modifying the current process's PgBackendStatus data. Note that,
1150  * since there is no mechanism for cleaning up st_changecount after an error,
1151  * THESE MACROS FORM A CRITICAL SECTION. Any error between them will be
1152  * promoted to PANIC, causing a database restart to clean up shared memory!
1153  * Hence, keep the critical section as short and straight-line as possible.
1154  * Aside from being safer, that minimizes the window in which readers will
1155  * have to loop.
1156  *
1157  * Reader logic should follow this sketch:
1158  *
1159  * for (;;)
1160  * {
1161  * int before_ct, after_ct;
1162  *
1163  * pgstat_begin_read_activity(beentry, before_ct);
1164  * ... copy beentry data to local memory ...
1165  * pgstat_end_read_activity(beentry, after_ct);
1166  * if (pgstat_read_activity_complete(before_ct, after_ct))
1167  * break;
1168  * CHECK_FOR_INTERRUPTS();
1169  * }
1170  *
1171  * For extra safety, we generally use volatile beentry pointers, although
1172  * the memory barriers should theoretically be sufficient.
1173  */
1174 #define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry) \
1175  do { \
1176  START_CRIT_SECTION(); \
1177  (beentry)->st_changecount++; \
1178  pg_write_barrier(); \
1179  } while (0)
1180 
1181 #define PGSTAT_END_WRITE_ACTIVITY(beentry) \
1182  do { \
1183  pg_write_barrier(); \
1184  (beentry)->st_changecount++; \
1185  Assert(((beentry)->st_changecount & 1) == 0); \
1186  END_CRIT_SECTION(); \
1187  } while (0)
1188 
1189 #define pgstat_begin_read_activity(beentry, before_changecount) \
1190  do { \
1191  (before_changecount) = (beentry)->st_changecount; \
1192  pg_read_barrier(); \
1193  } while (0)
1194 
1195 #define pgstat_end_read_activity(beentry, after_changecount) \
1196  do { \
1197  pg_read_barrier(); \
1198  (after_changecount) = (beentry)->st_changecount; \
1199  } while (0)
1200 
1201 #define pgstat_read_activity_complete(before_changecount, after_changecount) \
1202  ((before_changecount) == (after_changecount) && \
1203  ((before_changecount) & 1) == 0)
1204 
1205 
1206 /* ----------
1207  * LocalPgBackendStatus
1208  *
1209  * When we build the backend status array, we use LocalPgBackendStatus to be
1210  * able to add new values to the struct when needed without adding new fields
1211  * to the shared memory. It contains the backend status as a first member.
1212  * ----------
1213  */
1214 typedef struct LocalPgBackendStatus
1215 {
1216  /*
1217  * Local version of the backend status entry.
1218  */
1220 
1221  /*
1222  * The xid of the current transaction if available, InvalidTransactionId
1223  * if not.
1224  */
1226 
1227  /*
1228  * The xmin of the current session if available, InvalidTransactionId if
1229  * not.
1230  */
1233 
1234 /*
1235  * Working state needed to accumulate per-function-call timing statistics.
1236  */
1238 {
1239  /* Link to function's hashtable entry (must still be there at exit!) */
1240  /* NULL means we are not tracking the current function call */
1242  /* Total time previously charged to function, as of function start */
1244  /* Backend-wide total time as of function start */
1246  /* system clock as of function start */
1249 
1250 
1251 /* ----------
1252  * GUC parameters
1253  * ----------
1254  */
1256 extern PGDLLIMPORT bool pgstat_track_counts;
1259 extern char *pgstat_stat_directory;
1260 extern char *pgstat_stat_tmpname;
1261 extern char *pgstat_stat_filename;
1262 
1263 /*
1264  * BgWriter statistics counters are updated directly by bgwriter and bufmgr
1265  */
1267 
1268 /*
1269  * Updated by pgstat_count_buffer_*_time macros
1270  */
1273 
1274 /* ----------
1275  * Functions called from postmaster
1276  * ----------
1277  */
1278 extern Size BackendStatusShmemSize(void);
1279 extern void CreateSharedBackendStatus(void);
1280 
1281 extern void pgstat_init(void);
1282 extern int pgstat_start(void);
1283 extern void pgstat_reset_all(void);
1284 extern void allow_immediate_pgstat_restart(void);
1285 
1286 #ifdef EXEC_BACKEND
1287 extern void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
1288 #endif
1289 
1290 
1291 /* ----------
1292  * Functions called from backends
1293  * ----------
1294  */
1295 extern void pgstat_ping(void);
1296 
1297 extern void pgstat_report_stat(bool force);
1298 extern void pgstat_vacuum_stat(void);
1299 extern void pgstat_drop_database(Oid databaseid);
1300 
1301 extern void pgstat_clear_snapshot(void);
1302 extern void pgstat_reset_counters(void);
1303 extern void pgstat_reset_shared_counters(const char *);
1305 extern void pgstat_reset_slru_counter(const char *);
1306 
1307 extern void pgstat_report_autovac(Oid dboid);
1308 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
1309  PgStat_Counter livetuples, PgStat_Counter deadtuples);
1310 extern void pgstat_report_analyze(Relation rel,
1311  PgStat_Counter livetuples, PgStat_Counter deadtuples,
1312  bool resetcounter);
1313 
1314 extern void pgstat_report_recovery_conflict(int reason);
1315 extern void pgstat_report_deadlock(void);
1316 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
1317 extern void pgstat_report_checksum_failure(void);
1318 
1319 extern void pgstat_initialize(void);
1320 extern void pgstat_bestart(void);
1321 
1322 extern void pgstat_report_activity(BackendState state, const char *cmd_str);
1323 extern void pgstat_report_tempfile(size_t filesize);
1324 extern void pgstat_report_appname(const char *appname);
1325 extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
1326 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
1327 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
1328 extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
1329 extern const char *pgstat_get_crashed_backend_activity(int pid, char *buffer,
1330  int buflen);
1331 
1333  Oid relid);
1334 extern void pgstat_progress_update_param(int index, int64 val);
1335 extern void pgstat_progress_update_multi_param(int nparam, const int *index,
1336  const int64 *val);
1337 extern void pgstat_progress_end_command(void);
1338 
1339 extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
1341 
1342 extern void pgstat_initstats(Relation rel);
1343 
1344 extern char *pgstat_clip_activity(const char *raw_activity);
1345 
1346 /* ----------
1347  * pgstat_report_wait_start() -
1348  *
1349  * Called from places where server process needs to wait. This is called
1350  * to report wait event information. The wait information is stored
1351  * as 4-bytes where first byte represents the wait event class (type of
1352  * wait, for different types of wait, refer WaitClass) and the next
1353  * 3-bytes represent the actual wait event. Currently 2-bytes are used
1354  * for wait event which is sufficient for current usage, 1-byte is
1355  * reserved for future usage.
1356  *
1357  * NB: this *must* be able to survive being called before MyProc has been
1358  * initialized.
1359  * ----------
1360  */
1361 static inline void
1363 {
1364  volatile PGPROC *proc = MyProc;
1365 
1366  if (!pgstat_track_activities || !proc)
1367  return;
1368 
1369  /*
1370  * Since this is a four-byte field which is always read and written as
1371  * four-bytes, updates are atomic.
1372  */
1373  proc->wait_event_info = wait_event_info;
1374 }
1375 
1376 /* ----------
1377  * pgstat_report_wait_end() -
1378  *
1379  * Called to report end of a wait.
1380  *
1381  * NB: this *must* be able to survive being called before MyProc has been
1382  * initialized.
1383  * ----------
1384  */
1385 static inline void
1387 {
1388  volatile PGPROC *proc = MyProc;
1389 
1390  if (!pgstat_track_activities || !proc)
1391  return;
1392 
1393  /*
1394  * Since this is a four-byte field which is always read and written as
1395  * four-bytes, updates are atomic.
1396  */
1397  proc->wait_event_info = 0;
1398 }
1399 
1400 /* nontransactional event counts are simple enough to inline */
1401 
1402 #define pgstat_count_heap_scan(rel) \
1403  do { \
1404  if ((rel)->pgstat_info != NULL) \
1405  (rel)->pgstat_info->t_counts.t_numscans++; \
1406  } while (0)
1407 #define pgstat_count_heap_getnext(rel) \
1408  do { \
1409  if ((rel)->pgstat_info != NULL) \
1410  (rel)->pgstat_info->t_counts.t_tuples_returned++; \
1411  } while (0)
1412 #define pgstat_count_heap_fetch(rel) \
1413  do { \
1414  if ((rel)->pgstat_info != NULL) \
1415  (rel)->pgstat_info->t_counts.t_tuples_fetched++; \
1416  } while (0)
1417 #define pgstat_count_index_scan(rel) \
1418  do { \
1419  if ((rel)->pgstat_info != NULL) \
1420  (rel)->pgstat_info->t_counts.t_numscans++; \
1421  } while (0)
1422 #define pgstat_count_index_tuples(rel, n) \
1423  do { \
1424  if ((rel)->pgstat_info != NULL) \
1425  (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
1426  } while (0)
1427 #define pgstat_count_buffer_read(rel) \
1428  do { \
1429  if ((rel)->pgstat_info != NULL) \
1430  (rel)->pgstat_info->t_counts.t_blocks_fetched++; \
1431  } while (0)
1432 #define pgstat_count_buffer_hit(rel) \
1433  do { \
1434  if ((rel)->pgstat_info != NULL) \
1435  (rel)->pgstat_info->t_counts.t_blocks_hit++; \
1436  } while (0)
1437 #define pgstat_count_buffer_read_time(n) \
1438  (pgStatBlockReadTime += (n))
1439 #define pgstat_count_buffer_write_time(n) \
1440  (pgStatBlockWriteTime += (n))
1441 
1443 extern void pgstat_count_heap_update(Relation rel, bool hot);
1444 extern void pgstat_count_heap_delete(Relation rel);
1445 extern void pgstat_count_truncate(Relation rel);
1446 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
1447 
1449 extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
1452  bool finalize);
1453 
1454 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
1455 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
1456 
1457 extern void AtPrepare_PgStat(void);
1458 extern void PostPrepare_PgStat(void);
1459 
1460 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
1461  void *recdata, uint32 len);
1462 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
1463  void *recdata, uint32 len);
1464 
1465 extern void pgstat_send_archiver(const char *xlog, bool failed);
1466 extern void pgstat_send_bgwriter(void);
1467 
1468 /* ----------
1469  * Support functions for the SQL-callable functions to
1470  * generate the pgstat* views.
1471  * ----------
1472  */
1475 extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid);
1478 extern int pgstat_fetch_stat_numbackends(void);
1481 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
1482 
1483 extern void pgstat_count_slru_page_zeroed(int slru_idx);
1484 extern void pgstat_count_slru_page_hit(int slru_idx);
1485 extern void pgstat_count_slru_page_read(int slru_idx);
1486 extern void pgstat_count_slru_page_written(int slru_idx);
1487 extern void pgstat_count_slru_page_exists(int slru_idx);
1488 extern void pgstat_count_slru_flush(int slru_idx);
1489 extern void pgstat_count_slru_truncate(int slru_idx);
1490 extern const char *pgstat_slru_name(int slru_idx);
1491 extern int pgstat_slru_index(const char *name);
1492 
1493 #endif /* PGSTAT_H */
void pgstat_report_checksum_failure(void)
Definition: pgstat.c:1607
bool ssl_compression
Definition: pgstat.h:1026
struct PgBackendGSSStatus PgBackendGSSStatus
void pgstat_count_truncate(Relation rel)
Definition: pgstat.c:2098
PgStat_MsgResetslrucounter msg_resetslrucounter
Definition: pgstat.h:593
PgStat_MsgAutovacStart msg_autovacuum_start
Definition: pgstat.h:594
PgStat_MsgBgWriter msg_bgwriter
Definition: pgstat.h:598
PgStat_Counter m_buf_fsync_backend
Definition: pgstat.h:433
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2653
void pgstat_initialize(void)
Definition: pgstat.c:2881
PgStat_Counter analyze_count
Definition: pgstat.h:692
instr_time f_self_time
Definition: pgstat.h:494
int pgstat_start(void)
Definition: pgstat.c:754
#define pg_attribute_noreturn()
Definition: c.h:145
PgStat_Counter buf_alloc
Definition: pgstat.h:744
PgStat_Counter archived_count
Definition: pgstat.h:718
void pgstat_ping(void)
Definition: pgstat.c:1640
PgStat_Counter m_buf_written_checkpoints
Definition: pgstat.h:429
PgStat_Counter m_buf_alloc
Definition: pgstat.h:434
struct PgStat_MsgFuncpurge PgStat_MsgFuncpurge
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:113
Oid st_progress_command_target
Definition: pgstat.h:1141
PgStat_Counter m_dead_tuples
Definition: pgstat.h:385
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5864
int64 PgStat_Counter
Definition: pgstat.h:77
PgStat_Counter m_checkpoint_write_time
Definition: pgstat.h:435
TimestampTz m_vacuumtime
Definition: pgstat.h:383
PgStat_Counter tuples_updated
Definition: pgstat.h:171
void pgstat_report_xact_timestamp(TimestampTz tstamp)
Definition: pgstat.c:3334
const char * pgstat_get_backend_current_activity(int pid, bool checkUser)
Definition: pgstat.c:4184
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgstat.c:4471
PgStat_Counter m_flush
Definition: pgstat.h:452
PgStat_Counter tuples_returned
Definition: pgstat.h:671
PgStat_MsgDeadlock msg_deadlock
Definition: pgstat.h:603
void pgstat_count_slru_page_exists(int slru_idx)
Definition: pgstat.c:6778
uint32 TransactionId
Definition: c.h:520
PgStat_MsgResetsharedcounter msg_resetsharedcounter
Definition: pgstat.h:591
union PgStat_Msg PgStat_Msg
TimestampTz stats_timestamp
Definition: pgstat.h:650
uint32 wait_event_info
Definition: proc.h:214
WaitEventIPC
Definition: pgstat.h:847
void pgstat_progress_update_param(int index, int64 val)
Definition: pgstat.c:3231
TrackFunctionsLevel
Definition: pgstat.h:37
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:105
PgStat_MsgHdr m_hdr
Definition: pgstat.h:474
PgStat_MsgChecksumFailure msg_checksumfailure
Definition: pgstat.h:605
PgStat_Counter m_live_tuples
Definition: pgstat.h:384
void pgstat_count_slru_page_written(int slru_idx)
Definition: pgstat.c:6790
TimestampTz clock_time
Definition: pgstat.h:245
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1099
instr_time save_total
Definition: pgstat.h:1245
PgStat_Counter n_blocks_hit
Definition: pgstat.h:629
PGPROC * MyProc
Definition: proc.c:67
int64 TimestampTz
Definition: timestamp.h:39
#define PGSTAT_NUM_TABPURGE
Definition: pgstat.h:288
struct PgStat_MsgTabpurge PgStat_MsgTabpurge
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
Definition: pgstat.c:2127
PgStat_MsgHdr m_hdr
Definition: pgstat.h:366
struct PgStat_MsgArchiver PgStat_MsgArchiver
PgStat_Counter m_timed_checkpoints
Definition: pgstat.h:427
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:639
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3305
PgStat_Counter m_maxwritten_clean
Definition: pgstat.h:431
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:640
void CreateSharedBackendStatus(void)
Definition: pgstat.c:2746
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:110
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
Definition: pgstat.c:3210
PgStat_MsgHdr m_hdr
Definition: pgstat.h:425
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:693
struct PgStat_MsgDeadlock PgStat_MsgDeadlock
struct timeval instr_time
Definition: instr_time.h:150
PgStat_Counter f_self_time
Definition: pgstat.h:516
PgStat_Counter timed_checkpoints
Definition: pgstat.h:735
TimestampTz stat_reset_timestamp
Definition: pgstat.h:760
PgStat_MsgHdr m_hdr
Definition: pgstat.h:547
PgStat_Counter n_checksum_failures
Definition: pgstat.h:644
PgStat_Counter n_temp_files
Definition: pgstat.h:641
PgStat_MsgHdr m_hdr
Definition: pgstat.h:571
Oid m_databaseid
Definition: pgstat.h:380
PgStat_Counter m_buf_written_clean
Definition: pgstat.h:430
PgStat_MsgDummy msg_dummy
Definition: pgstat.h:585
TimestampTz last_checksum_failure
Definition: pgstat.h:645
HTAB * functions
Definition: pgstat.h:657
TransactionId backend_xmin
Definition: pgstat.h:1231
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2670
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat.c:2687
PgStat_Counter n_tuples_returned
Definition: pgstat.h:630
PgStat_Counter vacuum_count
Definition: pgstat.h:688
SockAddr st_clientaddr
Definition: pgstat.h:1105
bool m_autovacuum
Definition: pgstat.h:382
void pgstat_send_archiver(const char *xlog, bool failed)
Definition: pgstat.c:4376
size_t m_filesize
Definition: pgstat.h:477
PgStat_MsgTempFile msg_tempfile
Definition: pgstat.h:604
PgStat_Counter buf_fsync_backend
Definition: pgstat.h:743
struct PgStat_TableCounts PgStat_TableCounts
struct PgStat_MsgDummy PgStat_MsgDummy
TimestampTz stats_timestamp
Definition: pgstat.h:734
TimestampTz stat_reset_timestamp
Definition: pgstat.h:649
instr_time f_total_time
Definition: pgstat.h:493
void pgstat_reset_slru_counter(const char *)
Definition: pgstat.c:1419
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:787
struct PgStat_TableXactStatus * next
Definition: pgstat.h:182
TimestampTz m_analyzetime
Definition: pgstat.h:401
ProgressCommandType st_progress_command
Definition: pgstat.h:1140
void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: pgstat.c:2411
PgStat_Counter numscans
Definition: pgstat.h:669
PgStat_TableCounts t_counts
Definition: pgstat.h:161
PgStat_Counter blocks_exists
Definition: pgstat.h:757
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:792
unsigned int Oid
Definition: postgres_ext.h:31
struct PgStat_ArchiverStats PgStat_ArchiverStats
PgStat_Counter deleted_pre_trunc
Definition: pgstat.h:176
PgStat_Counter m_blocks_exists
Definition: pgstat.h:451
PgStat_MsgAnalyze msg_analyze
Definition: pgstat.h:596
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:677
PgStat_Counter f_total_time
Definition: pgstat.h:708
BackendState st_state
Definition: pgstat.h:1117
PgStat_Counter t_tuples_returned
Definition: pgstat.h:104
PgStat_Shared_Reset_Target
Definition: pgstat.h:122
char * st_clienthostname
Definition: pgstat.h:1106
PgStat_Counter tuples_inserted
Definition: pgstat.h:674
PgStat_FunctionCounts * fs
Definition: pgstat.h:1241
PgStat_Counter f_numcalls
Definition: pgstat.h:492
PgStat_MsgHdr msg_hdr
Definition: pgstat.h:584
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
#define PGDLLIMPORT
Definition: c.h:1257
struct PgStat_SLRUStats PgStat_SLRUStats
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2508
PgStat_Counter n_xact_commit
Definition: pgstat.h:626
void pgstat_report_deadlock(void)
Definition: pgstat.c:1564
bool m_resetcounter
Definition: pgstat.h:400
Definition: type.h:89
PgStat_MsgBgWriter BgWriterStats
Definition: pgstat.c:142
PgStat_MsgHdr m_hdr
Definition: pgstat.h:445
Oid st_databaseid
Definition: pgstat.h:1103
#define NAMEDATALEN
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:1006
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:628
struct PgStat_TableEntry PgStat_TableEntry
const char * pgstat_slru_name(int slru_idx)
Definition: pgstat.c:6733
PgStat_Counter n_live_tuples
Definition: pgstat.h:679
PgStat_Counter m_requested_checkpoints
Definition: pgstat.h:428
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:682
Definition: dynahash.c:218
struct PgStat_MsgAnalyze PgStat_MsgAnalyze
unsigned short uint16
Definition: c.h:373
PgStat_MsgSLRU msg_slru
Definition: pgstat.h:599
PgStat_FunctionCounts f_counts
Definition: pgstat.h:504
PgStat_MsgHdr m_hdr
Definition: pgstat.h:560
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1928
PgStat_MsgFuncpurge msg_funcpurge
Definition: pgstat.h:601
char * pgstat_stat_tmpname
Definition: pgstat.c:135
PgStat_Counter buf_written_backend
Definition: pgstat.h:742
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:636
TransactionId backend_xid
Definition: pgstat.h:1225
void AtEOSubXact_PgStat(bool isCommit, int nestDepth)
Definition: pgstat.c:2230
TimestampTz vacuum_timestamp
Definition: pgstat.h:687
PgStat_Counter t_tuples_updated
Definition: pgstat.h:108
PgStat_MsgHdr m_hdr
Definition: pgstat.h:355
PgStat_MsgHdr m_hdr
Definition: pgstat.h:462
PgStat_Counter pgStatBlockReadTime
Definition: pgstat.c:248
#define PG_WAIT_CLIENT
Definition: pgstat.h:788
void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1393
PgStat_Counter checkpoint_write_time
Definition: pgstat.h:737
PgStat_Counter n_dead_tuples
Definition: pgstat.h:680
PgStat_Counter m_index
Definition: pgstat.h:446
TimestampTz m_failure_time
Definition: pgstat.h:574
struct PgStat_MsgTempFile PgStat_MsgTempFile
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2618
void allow_immediate_pgstat_restart(void)
Definition: pgstat.c:817
PgStat_Counter f_numcalls
Definition: pgstat.h:706
TimestampTz last_autovac_time
Definition: pgstat.h:635
WaitEventClient
Definition: pgstat.h:827
struct PgStat_GlobalStats PgStat_GlobalStats
void pgstat_count_slru_page_read(int slru_idx)
Definition: pgstat.c:6784
PgStat_Counter m_blocks_written
Definition: pgstat.h:450
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:632
Oid m_databaseid
Definition: pgstat.h:309
PgStat_Counter buf_written_checkpoints
Definition: pgstat.h:739
PgStat_Counter tuples_inserted
Definition: pgstat.h:170
struct PgStat_MsgDropdb PgStat_MsgDropdb
PgStat_Counter pgStatBlockWriteTime
Definition: pgstat.c:249
struct PgStat_MsgSLRU PgStat_MsgSLRU
struct PgStat_MsgInquiry PgStat_MsgInquiry
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1747
char * st_activity_raw
Definition: pgstat.h:1129
char * pgstat_stat_directory
Definition: pgstat.c:133
PgStat_Counter blocks_read
Definition: pgstat.h:755
void pgstat_report_stat(bool force)
Definition: pgstat.c:839
void pgstat_vacuum_stat(void)
Definition: pgstat.c:1052
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:114
PgStat_Counter tuples_fetched
Definition: pgstat.h:672
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
Definition: pgstat.c:1997
unsigned int uint32
Definition: c.h:374
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:638
PgStat_MsgHdr m_hdr
Definition: pgstat.h:308
PgStat_Counter m_block_write_time
Definition: pgstat.h:278
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1386
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1100
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:634
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: pgstat.c:2447
PgStat_Counter n_conflict_lock
Definition: pgstat.h:637
WaitEventTimeout
Definition: pgstat.h:899
PgStat_Counter blocks_hit
Definition: pgstat.h:754
char * st_appname
Definition: pgstat.h:1120
PgStat_Counter t_blocks_hit
Definition: pgstat.h:118
void pgstat_init(void)
Definition: pgstat.c:379
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:179
PgStat_Counter n_xact_rollback
Definition: pgstat.h:627
int m_xact_rollback
Definition: pgstat.h:276
PgStat_MsgHdr m_hdr
Definition: pgstat.h:320
void pgstat_progress_end_command(void)
Definition: pgstat.c:3282
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:109
PgStat_Counter buf_written_clean
Definition: pgstat.h:740
Datum ssl_issuer_dn(PG_FUNCTION_ARGS)
Definition: sslinfo.c:378
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2637
void AtEOXact_PgStat(bool isCommit, bool parallel)
Definition: pgstat.c:2143
void pgstat_report_recovery_conflict(int reason)
Definition: pgstat.c:1544
PgStat_Counter blocks_zeroed
Definition: pgstat.h:753
PgStat_MsgRecoveryConflict msg_recoveryconflict
Definition: pgstat.h:602
struct PgStat_MsgTabstat PgStat_MsgTabstat
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2596
PgStat_MsgHdr m_hdr
Definition: pgstat.h:294
PgStat_Counter m_live_tuples
Definition: pgstat.h:402
void pgstat_drop_database(Oid databaseid)
Definition: pgstat.c:1284
void pgstat_count_slru_truncate(int slru_idx)
Definition: pgstat.c:6802
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3513
struct PgStat_MsgResetsharedcounter PgStat_MsgResetsharedcounter
struct PgStat_FunctionCounts PgStat_FunctionCounts
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3568
PgBackendStatus backendStatus
Definition: pgstat.h:1219
bool m_autovacuum
Definition: pgstat.h:399
#define PGSTAT_NUM_FUNCENTRIES
Definition: pgstat.h:524
PgStat_Counter tuples_deleted
Definition: pgstat.h:172
struct PgStat_MsgBgWriter PgStat_MsgBgWriter
TimestampTz m_timestamp
Definition: pgstat.h:416
#define PGSTAT_NUM_TABENTRIES
Definition: pgstat.h:266
struct PgStat_MsgResetsinglecounter PgStat_MsgResetsinglecounter
void pgstat_reset_counters(void)
Definition: pgstat.c:1340
#define MAX_XFN_CHARS
Definition: pgarch.h:26
BackendType st_backendType
Definition: pgstat.h:1094
PgStat_Counter f_total_time
Definition: pgstat.h:515
PgStat_Counter blocks_hit
Definition: pgstat.h:685
TimestampTz analyze_timestamp
Definition: pgstat.h:691
TimestampTz last_failed_timestamp
Definition: pgstat.h:725
PgStat_Counter changes_since_analyze
Definition: pgstat.h:681
StatMsgType
Definition: pgstat.h:48
PgStat_Shared_Reset_Target m_resettarget
Definition: pgstat.h:332
void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
Definition: pgstat.c:1463
PgStat_Counter t_numscans
Definition: pgstat.h:102
struct PgStat_MsgVacuum PgStat_MsgVacuum
PgStat_Single_Reset_Type
Definition: pgstat.h:129
Size BackendStatusShmemSize(void)
Definition: pgstat.c:2718
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:633
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:219
PgStat_Counter t_changed_tuples
Definition: pgstat.h:115
PgStat_MsgTabstat msg_tabstat
Definition: pgstat.h:587
PgStat_MsgHdr m_hdr
Definition: pgstat.h:272
void pgstat_send_bgwriter(void)
Definition: pgstat.c:4397
struct PgStat_MsgChecksumFailure PgStat_MsgChecksumFailure
ProgressCommandType
Definition: pgstat.h:996
PgStat_Counter m_checkpoint_sync_time
Definition: pgstat.h:436
PgStat_MsgVacuum msg_vacuum
Definition: pgstat.h:595
Definition: regguts.h:298
PgStat_MsgHdr m_hdr
Definition: pgstat.h:530
PgStat_Counter failed_count
Definition: pgstat.h:722
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2481
PgStat_Counter n_block_write_time
Definition: pgstat.h:647
PgStat_Counter m_buf_written_backend
Definition: pgstat.h:432
PgStat_Counter m_blocks_read
Definition: pgstat.h:449
PgStat_MsgHdr m_hdr
Definition: pgstat.h:379
void pgstat_count_heap_delete(Relation rel)
Definition: pgstat.c:2043
PgStat_Counter tuples_deleted
Definition: pgstat.h:676
struct PgStat_StatTabEntry PgStat_StatTabEntry
PgStat_TableCounts t_counts
Definition: pgstat.h:258
PgStat_Counter flush
Definition: pgstat.h:758
void pgstat_count_slru_flush(int slru_idx)
Definition: pgstat.c:6796
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:174
PgStat_Counter tuples_updated
Definition: pgstat.h:675
size_t Size
Definition: c.h:473
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:738
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1362
void pgstat_report_tempfile(size_t filesize)
Definition: pgstat.c:1619
PGDLLIMPORT bool pgstat_track_activities
Definition: pgstat.c:124
struct PgStat_FunctionEntry PgStat_FunctionEntry
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:689
PgStat_Counter maxwritten_clean
Definition: pgstat.h:741
PgStat_Counter n_block_read_time
Definition: pgstat.h:646
PgStat_Counter m_block_read_time
Definition: pgstat.h:277
struct PgStat_MsgFuncstat PgStat_MsgFuncstat
const char * name
Definition: encode.c:561
TimestampTz stat_reset_timestamp
Definition: pgstat.h:745
void pgstat_bestart(void)
Definition: pgstat.c:2923
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:160
struct PgStat_TableStatus PgStat_TableStatus
struct PgBackendStatus PgBackendStatus
struct PgStat_StatDBEntry PgStat_StatDBEntry
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:694
void pgstat_report_autovac(Oid dboid)
Definition: pgstat.c:1441
int pgstat_slru_index(const char *name)
Definition: pgstat.c:6711
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:175
void pgstat_count_slru_page_hit(int slru_idx)
Definition: pgstat.c:6772
PgStat_MsgHdr m_hdr
Definition: pgstat.h:396
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
Definition: pgstat.c:1585
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:3132
void pgstat_count_heap_update(Relation rel, bool hot)
Definition: pgstat.c:2018
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1727
void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
TimestampTz cutoff_time
Definition: pgstat.h:246
Datum ssl_cipher(PG_FUNCTION_ARGS)
Definition: sslinfo.c:68
WaitEventIO
Definition: pgstat.h:914
TimestampTz stat_reset_timestamp
Definition: pgstat.h:726
TimestampTz last_archived_timestamp
Definition: pgstat.h:721
TimestampTz m_start_time
Definition: pgstat.h:368
PgStat_Counter n_deadlocks
Definition: pgstat.h:643
struct PgStat_MsgResetslrucounter PgStat_MsgResetslrucounter
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:791
#define PG_WAIT_IPC
Definition: pgstat.h:790
struct PgStat_MsgAutovacStart PgStat_MsgAutovacStart
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1098
PgStat_MsgArchiver msg_archiver
Definition: pgstat.h:597
int st_changecount
Definition: pgstat.h:1088
const char * pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
Definition: pgstat.c:4262
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
Definition: pgstat.c:1491
PgStat_MsgResetsinglecounter msg_resetsinglecounter
Definition: pgstat.h:592
PgStat_Counter requested_checkpoints
Definition: pgstat.h:736
StatMsgType m_type
Definition: pgstat.h:198
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
Definition: pgstat.c:3253
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid funcid)
Definition: pgstat.c:2564
instr_time save_f_total_time
Definition: pgstat.h:1243
PgStat_MsgResetcounter msg_resetcounter
Definition: pgstat.h:590
BackendState
Definition: pgstat.h:768
void pgstat_reset_all(void)
Definition: pgstat.c:712
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:447
BackendType
Definition: miscadmin.h:310
PgStat_Counter f_numcalls
Definition: pgstat.h:514
struct PgStat_MsgResetcounter PgStat_MsgResetcounter
PgStat_Counter f_self_time
Definition: pgstat.h:709
PgStat_Counter m_dead_tuples
Definition: pgstat.h:403
Definition: proc.h:112
PgStat_Counter blocks_fetched
Definition: pgstat.h:684
PgStat_Counter m_truncate
Definition: pgstat.h:453
void AtPrepare_PgStat(void)
Definition: pgstat.c:2329
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
struct PgStat_MsgHdr PgStat_MsgHdr
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1097
PgStat_MsgInquiry msg_inquiry
Definition: pgstat.h:586
PgStat_Counter truncate
Definition: pgstat.h:759
PgStat_MsgDropdb msg_dropdb
Definition: pgstat.h:589
int m_size
Definition: pgstat.h:199
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1110
PgStat_Single_Reset_Type m_resettype
Definition: pgstat.h:344
void pgstat_initstats(Relation rel)
Definition: pgstat.c:1804
void pgstat_count_slru_page_zeroed(int slru_idx)
Definition: pgstat.c:6766
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:107
long val
Definition: informix.c:664
void pgstat_reset_shared_counters(const char *)
Definition: pgstat.c:1362
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6668
PgStat_Counter blocks_written
Definition: pgstat.h:756
PgStat_MsgTabpurge msg_tabpurge
Definition: pgstat.h:588
#define PGSTAT_NUM_FUNCPURGE
Definition: pgstat.h:541
PGDLLIMPORT int pgstat_track_activity_query_size
Definition: pgstat.c:127
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1114
PgStat_TableStatus * parent
Definition: pgstat.h:180
PGDLLIMPORT int pgstat_track_functions
Definition: pgstat.c:126
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:117
PgStat_MsgHdr m_hdr
Definition: pgstat.h:413
void PostPrepare_PgStat(void)
Definition: pgstat.c:2378
PgStat_MsgFuncstat msg_funcstat
Definition: pgstat.h:600
struct LocalPgBackendStatus LocalPgBackendStatus
PgStat_Counter m_blocks_hit
Definition: pgstat.h:448
WaitEventActivity
Definition: pgstat.h:802
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:631
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:690
PgStat_MsgHdr m_hdr
Definition: pgstat.h:244
PgStat_Counter n_temp_bytes
Definition: pgstat.h:642