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 {
985 } WaitEventIO;
986 
987 /* ----------
988  * Command type for progress reporting purposes
989  * ----------
990  */
992 {
1000 
1001 #define PGSTAT_NUM_PROGRESS_PARAM 20
1002 
1003 /* ----------
1004  * Shared-memory data structures
1005  * ----------
1006  */
1007 
1008 
1009 /*
1010  * PgBackendSSLStatus
1011  *
1012  * For each backend, we keep the SSL status in a separate struct, that
1013  * is only filled in if SSL is enabled.
1014  *
1015  * All char arrays must be null-terminated.
1016  */
1017 typedef struct PgBackendSSLStatus
1018 {
1019  /* Information about SSL connection */
1025 
1026  /*
1027  * serial number is max "20 octets" per RFC 5280, so this size should be
1028  * fine
1029  */
1031 
1034 
1035 /*
1036  * PgBackendGSSStatus
1037  *
1038  * For each backend, we keep the GSS status in a separate struct, that
1039  * is only filled in if GSS is enabled.
1040  *
1041  * All char arrays must be null-terminated.
1042  */
1043 typedef struct PgBackendGSSStatus
1044 {
1045  /* Information about GSSAPI connection */
1046  char gss_princ[NAMEDATALEN]; /* GSSAPI Principal used to auth */
1047  bool gss_auth; /* If GSSAPI authentication was used */
1048  bool gss_enc; /* If encryption is being used */
1049 
1051 
1052 
1053 /* ----------
1054  * PgBackendStatus
1055  *
1056  * Each live backend maintains a PgBackendStatus struct in shared memory
1057  * showing its current activity. (The structs are allocated according to
1058  * BackendId, but that is not critical.) Note that the collector process
1059  * has no involvement in, or even access to, these structs.
1060  *
1061  * Each auxiliary process also maintains a PgBackendStatus struct in shared
1062  * memory.
1063  * ----------
1064  */
1065 typedef struct PgBackendStatus
1066 {
1067  /*
1068  * To avoid locking overhead, we use the following protocol: a backend
1069  * increments st_changecount before modifying its entry, and again after
1070  * finishing a modification. A would-be reader should note the value of
1071  * st_changecount, copy the entry into private memory, then check
1072  * st_changecount again. If the value hasn't changed, and if it's even,
1073  * the copy is valid; otherwise start over. This makes updates cheap
1074  * while reads are potentially expensive, but that's the tradeoff we want.
1075  *
1076  * The above protocol needs memory barriers to ensure that the apparent
1077  * order of execution is as it desires. Otherwise, for example, the CPU
1078  * might rearrange the code so that st_changecount is incremented twice
1079  * before the modification on a machine with weak memory ordering. Hence,
1080  * use the macros defined below for manipulating st_changecount, rather
1081  * than touching it directly.
1082  */
1084 
1085  /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */
1087 
1088  /* Type of backends */
1090 
1091  /* Times when current backend, transaction, and activity started */
1096 
1097  /* Database OID, owning user's OID, connection client address */
1101  char *st_clienthostname; /* MUST be null-terminated */
1102 
1103  /* Information about SSL connection */
1104  bool st_ssl;
1106 
1107  /* Information about GSSAPI connection */
1108  bool st_gss;
1110 
1111  /* current state */
1113 
1114  /* application name; MUST be null-terminated */
1115  char *st_appname;
1116 
1117  /*
1118  * Current command string; MUST be null-terminated. Note that this string
1119  * possibly is truncated in the middle of a multi-byte character. As
1120  * activity strings are stored more frequently than read, that allows to
1121  * move the cost of correct truncation to the display side. Use
1122  * pgstat_clip_activity() to truncate correctly.
1123  */
1125 
1126  /*
1127  * Command progress reporting. Any command which wishes can advertise
1128  * that it is running by setting st_progress_command,
1129  * st_progress_command_target, and st_progress_param[].
1130  * st_progress_command_target should be the OID of the relation which the
1131  * command targets (we assume there's just one, as this is meant for
1132  * utility commands), but the meaning of each element in the
1133  * st_progress_param array is command-specific.
1134  */
1137  int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM];
1138 } PgBackendStatus;
1139 
1140 /*
1141  * Macros to load and store st_changecount with appropriate memory barriers.
1142  *
1143  * Use PGSTAT_BEGIN_WRITE_ACTIVITY() before, and PGSTAT_END_WRITE_ACTIVITY()
1144  * after, modifying the current process's PgBackendStatus data. Note that,
1145  * since there is no mechanism for cleaning up st_changecount after an error,
1146  * THESE MACROS FORM A CRITICAL SECTION. Any error between them will be
1147  * promoted to PANIC, causing a database restart to clean up shared memory!
1148  * Hence, keep the critical section as short and straight-line as possible.
1149  * Aside from being safer, that minimizes the window in which readers will
1150  * have to loop.
1151  *
1152  * Reader logic should follow this sketch:
1153  *
1154  * for (;;)
1155  * {
1156  * int before_ct, after_ct;
1157  *
1158  * pgstat_begin_read_activity(beentry, before_ct);
1159  * ... copy beentry data to local memory ...
1160  * pgstat_end_read_activity(beentry, after_ct);
1161  * if (pgstat_read_activity_complete(before_ct, after_ct))
1162  * break;
1163  * CHECK_FOR_INTERRUPTS();
1164  * }
1165  *
1166  * For extra safety, we generally use volatile beentry pointers, although
1167  * the memory barriers should theoretically be sufficient.
1168  */
1169 #define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry) \
1170  do { \
1171  START_CRIT_SECTION(); \
1172  (beentry)->st_changecount++; \
1173  pg_write_barrier(); \
1174  } while (0)
1175 
1176 #define PGSTAT_END_WRITE_ACTIVITY(beentry) \
1177  do { \
1178  pg_write_barrier(); \
1179  (beentry)->st_changecount++; \
1180  Assert(((beentry)->st_changecount & 1) == 0); \
1181  END_CRIT_SECTION(); \
1182  } while (0)
1183 
1184 #define pgstat_begin_read_activity(beentry, before_changecount) \
1185  do { \
1186  (before_changecount) = (beentry)->st_changecount; \
1187  pg_read_barrier(); \
1188  } while (0)
1189 
1190 #define pgstat_end_read_activity(beentry, after_changecount) \
1191  do { \
1192  pg_read_barrier(); \
1193  (after_changecount) = (beentry)->st_changecount; \
1194  } while (0)
1195 
1196 #define pgstat_read_activity_complete(before_changecount, after_changecount) \
1197  ((before_changecount) == (after_changecount) && \
1198  ((before_changecount) & 1) == 0)
1199 
1200 
1201 /* ----------
1202  * LocalPgBackendStatus
1203  *
1204  * When we build the backend status array, we use LocalPgBackendStatus to be
1205  * able to add new values to the struct when needed without adding new fields
1206  * to the shared memory. It contains the backend status as a first member.
1207  * ----------
1208  */
1209 typedef struct LocalPgBackendStatus
1210 {
1211  /*
1212  * Local version of the backend status entry.
1213  */
1215 
1216  /*
1217  * The xid of the current transaction if available, InvalidTransactionId
1218  * if not.
1219  */
1221 
1222  /*
1223  * The xmin of the current session if available, InvalidTransactionId if
1224  * not.
1225  */
1228 
1229 /*
1230  * Working state needed to accumulate per-function-call timing statistics.
1231  */
1233 {
1234  /* Link to function's hashtable entry (must still be there at exit!) */
1235  /* NULL means we are not tracking the current function call */
1237  /* Total time previously charged to function, as of function start */
1239  /* Backend-wide total time as of function start */
1241  /* system clock as of function start */
1244 
1245 
1246 /* ----------
1247  * GUC parameters
1248  * ----------
1249  */
1251 extern PGDLLIMPORT bool pgstat_track_counts;
1254 extern char *pgstat_stat_directory;
1255 extern char *pgstat_stat_tmpname;
1256 extern char *pgstat_stat_filename;
1257 
1258 /*
1259  * BgWriter statistics counters are updated directly by bgwriter and bufmgr
1260  */
1262 
1263 /*
1264  * Updated by pgstat_count_buffer_*_time macros
1265  */
1268 
1269 /* ----------
1270  * Functions called from postmaster
1271  * ----------
1272  */
1273 extern Size BackendStatusShmemSize(void);
1274 extern void CreateSharedBackendStatus(void);
1275 
1276 extern void pgstat_init(void);
1277 extern int pgstat_start(void);
1278 extern void pgstat_reset_all(void);
1279 extern void allow_immediate_pgstat_restart(void);
1280 
1281 #ifdef EXEC_BACKEND
1282 extern void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
1283 #endif
1284 
1285 
1286 /* ----------
1287  * Functions called from backends
1288  * ----------
1289  */
1290 extern void pgstat_ping(void);
1291 
1292 extern void pgstat_report_stat(bool force);
1293 extern void pgstat_vacuum_stat(void);
1294 extern void pgstat_drop_database(Oid databaseid);
1295 
1296 extern void pgstat_clear_snapshot(void);
1297 extern void pgstat_reset_counters(void);
1298 extern void pgstat_reset_shared_counters(const char *);
1300 extern void pgstat_reset_slru_counter(const char *);
1301 
1302 extern void pgstat_report_autovac(Oid dboid);
1303 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
1304  PgStat_Counter livetuples, PgStat_Counter deadtuples);
1305 extern void pgstat_report_analyze(Relation rel,
1306  PgStat_Counter livetuples, PgStat_Counter deadtuples,
1307  bool resetcounter);
1308 
1309 extern void pgstat_report_recovery_conflict(int reason);
1310 extern void pgstat_report_deadlock(void);
1311 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
1312 extern void pgstat_report_checksum_failure(void);
1313 
1314 extern void pgstat_initialize(void);
1315 extern void pgstat_bestart(void);
1316 
1317 extern void pgstat_report_activity(BackendState state, const char *cmd_str);
1318 extern void pgstat_report_tempfile(size_t filesize);
1319 extern void pgstat_report_appname(const char *appname);
1320 extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
1321 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
1322 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
1323 extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
1324 extern const char *pgstat_get_crashed_backend_activity(int pid, char *buffer,
1325  int buflen);
1326 
1328  Oid relid);
1329 extern void pgstat_progress_update_param(int index, int64 val);
1330 extern void pgstat_progress_update_multi_param(int nparam, const int *index,
1331  const int64 *val);
1332 extern void pgstat_progress_end_command(void);
1333 
1334 extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
1336 
1337 extern void pgstat_initstats(Relation rel);
1338 
1339 extern char *pgstat_clip_activity(const char *raw_activity);
1340 
1341 /* ----------
1342  * pgstat_report_wait_start() -
1343  *
1344  * Called from places where server process needs to wait. This is called
1345  * to report wait event information. The wait information is stored
1346  * as 4-bytes where first byte represents the wait event class (type of
1347  * wait, for different types of wait, refer WaitClass) and the next
1348  * 3-bytes represent the actual wait event. Currently 2-bytes are used
1349  * for wait event which is sufficient for current usage, 1-byte is
1350  * reserved for future usage.
1351  *
1352  * NB: this *must* be able to survive being called before MyProc has been
1353  * initialized.
1354  * ----------
1355  */
1356 static inline void
1358 {
1359  volatile PGPROC *proc = MyProc;
1360 
1361  if (!pgstat_track_activities || !proc)
1362  return;
1363 
1364  /*
1365  * Since this is a four-byte field which is always read and written as
1366  * four-bytes, updates are atomic.
1367  */
1368  proc->wait_event_info = wait_event_info;
1369 }
1370 
1371 /* ----------
1372  * pgstat_report_wait_end() -
1373  *
1374  * Called to report end of a wait.
1375  *
1376  * NB: this *must* be able to survive being called before MyProc has been
1377  * initialized.
1378  * ----------
1379  */
1380 static inline void
1382 {
1383  volatile PGPROC *proc = MyProc;
1384 
1385  if (!pgstat_track_activities || !proc)
1386  return;
1387 
1388  /*
1389  * Since this is a four-byte field which is always read and written as
1390  * four-bytes, updates are atomic.
1391  */
1392  proc->wait_event_info = 0;
1393 }
1394 
1395 /* nontransactional event counts are simple enough to inline */
1396 
1397 #define pgstat_count_heap_scan(rel) \
1398  do { \
1399  if ((rel)->pgstat_info != NULL) \
1400  (rel)->pgstat_info->t_counts.t_numscans++; \
1401  } while (0)
1402 #define pgstat_count_heap_getnext(rel) \
1403  do { \
1404  if ((rel)->pgstat_info != NULL) \
1405  (rel)->pgstat_info->t_counts.t_tuples_returned++; \
1406  } while (0)
1407 #define pgstat_count_heap_fetch(rel) \
1408  do { \
1409  if ((rel)->pgstat_info != NULL) \
1410  (rel)->pgstat_info->t_counts.t_tuples_fetched++; \
1411  } while (0)
1412 #define pgstat_count_index_scan(rel) \
1413  do { \
1414  if ((rel)->pgstat_info != NULL) \
1415  (rel)->pgstat_info->t_counts.t_numscans++; \
1416  } while (0)
1417 #define pgstat_count_index_tuples(rel, n) \
1418  do { \
1419  if ((rel)->pgstat_info != NULL) \
1420  (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
1421  } while (0)
1422 #define pgstat_count_buffer_read(rel) \
1423  do { \
1424  if ((rel)->pgstat_info != NULL) \
1425  (rel)->pgstat_info->t_counts.t_blocks_fetched++; \
1426  } while (0)
1427 #define pgstat_count_buffer_hit(rel) \
1428  do { \
1429  if ((rel)->pgstat_info != NULL) \
1430  (rel)->pgstat_info->t_counts.t_blocks_hit++; \
1431  } while (0)
1432 #define pgstat_count_buffer_read_time(n) \
1433  (pgStatBlockReadTime += (n))
1434 #define pgstat_count_buffer_write_time(n) \
1435  (pgStatBlockWriteTime += (n))
1436 
1438 extern void pgstat_count_heap_update(Relation rel, bool hot);
1439 extern void pgstat_count_heap_delete(Relation rel);
1440 extern void pgstat_count_truncate(Relation rel);
1441 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
1442 
1444 extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
1447  bool finalize);
1448 
1449 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
1450 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
1451 
1452 extern void AtPrepare_PgStat(void);
1453 extern void PostPrepare_PgStat(void);
1454 
1455 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
1456  void *recdata, uint32 len);
1457 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
1458  void *recdata, uint32 len);
1459 
1460 extern void pgstat_send_archiver(const char *xlog, bool failed);
1461 extern void pgstat_send_bgwriter(void);
1462 
1463 /* ----------
1464  * Support functions for the SQL-callable functions to
1465  * generate the pgstat* views.
1466  * ----------
1467  */
1470 extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid);
1473 extern int pgstat_fetch_stat_numbackends(void);
1476 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
1477 
1478 extern void pgstat_count_slru_page_zeroed(int slru_idx);
1479 extern void pgstat_count_slru_page_hit(int slru_idx);
1480 extern void pgstat_count_slru_page_read(int slru_idx);
1481 extern void pgstat_count_slru_page_written(int slru_idx);
1482 extern void pgstat_count_slru_page_exists(int slru_idx);
1483 extern void pgstat_count_slru_flush(int slru_idx);
1484 extern void pgstat_count_slru_truncate(int slru_idx);
1485 extern const char *pgstat_slru_name(int slru_idx);
1486 extern int pgstat_slru_index(const char *name);
1487 
1488 #endif /* PGSTAT_H */
void pgstat_report_checksum_failure(void)
Definition: pgstat.c:1607
bool ssl_compression
Definition: pgstat.h:1021
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:1136
PgStat_Counter m_dead_tuples
Definition: pgstat.h:385
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5840
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:4169
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgstat.c:4456
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:6754
uint32 TransactionId
Definition: c.h:513
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:185
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:6766
TimestampTz clock_time
Definition: pgstat.h:245
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1094
instr_time save_total
Definition: pgstat.h:1240
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:1226
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:1100
bool m_autovacuum
Definition: pgstat.h:382
void pgstat_send_archiver(const char *xlog, bool failed)
Definition: pgstat.c:4361
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:1135
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:1112
PgStat_Counter t_tuples_returned
Definition: pgstat.h:104
PgStat_Shared_Reset_Target
Definition: pgstat.h:122
char * st_clienthostname
Definition: pgstat.h:1101
PgStat_Counter tuples_inserted
Definition: pgstat.h:674
PgStat_FunctionCounts * fs
Definition: pgstat.h:1236
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:1279
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:1098
#define NAMEDATALEN
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:1001
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:6709
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:210
struct PgStat_MsgAnalyze PgStat_MsgAnalyze
unsigned short uint16
Definition: c.h:366
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:1220
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:6760
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:1124
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:367
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:1381
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1095
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:1115
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:6778
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:1214
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:1089
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:4382
struct PgStat_MsgChecksumFailure PgStat_MsgChecksumFailure
ProgressCommandType
Definition: pgstat.h:991
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:6772
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:174
PgStat_Counter tuples_updated
Definition: pgstat.h:675
size_t Size
Definition: c.h:466
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:738
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1357
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:6687
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:175
void pgstat_count_slru_page_hit(int slru_idx)
Definition: pgstat.c:6748
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:1093
PgStat_MsgArchiver msg_archiver
Definition: pgstat.h:597
int st_changecount
Definition: pgstat.h:1083
const char * pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
Definition: pgstat.c:4247
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:1238
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:309
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:102
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:1092
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:1105
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:6742
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:6644
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:1109
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