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-2021, 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 /* Values to track the cause of session termination */
45 typedef enum SessionEndType
46 {
47  DISCONNECT_NOT_YET, /* still active */
53 
54 /* ----------
55  * The types of backend -> collector messages
56  * ----------
57  */
58 typedef enum StatMsgType
59 {
85 } StatMsgType;
86 
87 /* ----------
88  * The data type used for counters.
89  * ----------
90  */
91 typedef int64 PgStat_Counter;
92 
93 /* ----------
94  * PgStat_TableCounts The actual per-table counts kept by a backend
95  *
96  * This struct should contain only actual event counters, because we memcmp
97  * it against zeroes to detect whether there are any counts to transmit.
98  * It is a component of PgStat_TableStatus (within-backend state) and
99  * PgStat_TableEntry (the transmitted message format).
100  *
101  * Note: for a table, tuples_returned is the number of tuples successfully
102  * fetched by heap_getnext, while tuples_fetched is the number of tuples
103  * successfully fetched by heap_fetch under the control of bitmap indexscans.
104  * For an index, tuples_returned is the number of index entries returned by
105  * the index AM, while tuples_fetched is the number of tuples successfully
106  * fetched by heap_fetch under the control of simple indexscans for this index.
107  *
108  * tuples_inserted/updated/deleted/hot_updated count attempted actions,
109  * regardless of whether the transaction committed. delta_live_tuples,
110  * delta_dead_tuples, and changed_tuples are set depending on commit or abort.
111  * Note that delta_live_tuples and delta_dead_tuples can be negative!
112  * ----------
113  */
114 typedef struct PgStat_TableCounts
115 {
117 
120 
126 
130 
134 
135 /* Possible targets for resetting cluster-wide shared values */
137 {
142 
143 /* Possible object types for resetting single counters */
145 {
149 
150 /* ------------------------------------------------------------
151  * Structures kept in backend local memory while accumulating counts
152  * ------------------------------------------------------------
153  */
154 
155 
156 /* ----------
157  * PgStat_TableStatus Per-table status within a backend
158  *
159  * Many of the event counters are nontransactional, ie, we count events
160  * in committed and aborted transactions alike. For these, we just count
161  * directly in the PgStat_TableStatus. However, delta_live_tuples,
162  * delta_dead_tuples, and changed_tuples must be derived from event counts
163  * with awareness of whether the transaction or subtransaction committed or
164  * aborted. Hence, we also keep a stack of per-(sub)transaction status
165  * records for every table modified in the current transaction. At commit
166  * or abort, we propagate tuples_inserted/updated/deleted up to the
167  * parent subtransaction level, or out to the parent PgStat_TableStatus,
168  * as appropriate.
169  * ----------
170  */
171 typedef struct PgStat_TableStatus
172 {
173  Oid t_id; /* table's OID */
174  bool t_shared; /* is it a shared catalog? */
175  struct PgStat_TableXactStatus *trans; /* lowest subxact's counts */
176  PgStat_TableCounts t_counts; /* event counts to be sent */
178 
179 /* ----------
180  * PgStat_TableXactStatus Per-table, per-subtransaction status
181  * ----------
182  */
184 {
185  PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */
186  PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */
187  PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */
188  bool truncated; /* relation truncated in this (sub)xact */
189  PgStat_Counter inserted_pre_trunc; /* tuples inserted prior to truncate */
190  PgStat_Counter updated_pre_trunc; /* tuples updated prior to truncate */
191  PgStat_Counter deleted_pre_trunc; /* tuples deleted prior to truncate */
192  int nest_level; /* subtransaction nest level */
193  /* links to other structs for same relation: */
194  struct PgStat_TableXactStatus *upper; /* next higher subxact if any */
195  PgStat_TableStatus *parent; /* per-table status */
196  /* structs of same subxact level are linked here: */
197  struct PgStat_TableXactStatus *next; /* next of same subxact */
199 
200 
201 /* ------------------------------------------------------------
202  * Message formats follow
203  * ------------------------------------------------------------
204  */
205 
206 
207 /* ----------
208  * PgStat_MsgHdr The common message header
209  * ----------
210  */
211 typedef struct PgStat_MsgHdr
212 {
214  int m_size;
215 } PgStat_MsgHdr;
216 
217 /* ----------
218  * Space available in a message. This will keep the UDP packets below 1K,
219  * which should fit unfragmented into the MTU of the loopback interface.
220  * (Larger values of PGSTAT_MAX_MSG_SIZE would work for that on most
221  * platforms, but we're being conservative here.)
222  * ----------
223  */
224 #define PGSTAT_MAX_MSG_SIZE 1000
225 #define PGSTAT_MSG_PAYLOAD (PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))
226 
227 
228 /* ----------
229  * PgStat_MsgDummy A dummy message, ignored by the collector
230  * ----------
231  */
232 typedef struct PgStat_MsgDummy
233 {
236 
237 
238 /* ----------
239  * PgStat_MsgInquiry Sent by a backend to ask the collector
240  * to write the stats file(s).
241  *
242  * Ordinarily, an inquiry message prompts writing of the global stats file,
243  * the stats file for shared catalogs, and the stats file for the specified
244  * database. If databaseid is InvalidOid, only the first two are written.
245  *
246  * New file(s) will be written only if the existing file has a timestamp
247  * older than the specified cutoff_time; this prevents duplicated effort
248  * when multiple requests arrive at nearly the same time, assuming that
249  * backends send requests with cutoff_times a little bit in the past.
250  *
251  * clock_time should be the requestor's current local time; the collector
252  * uses this to check for the system clock going backward, but it has no
253  * effect unless that occurs. We assume clock_time >= cutoff_time, though.
254  * ----------
255  */
256 
257 typedef struct PgStat_MsgInquiry
258 {
260  TimestampTz clock_time; /* observed local clock time */
261  TimestampTz cutoff_time; /* minimum acceptable file timestamp */
262  Oid databaseid; /* requested DB (InvalidOid => shared only) */
264 
265 
266 /* ----------
267  * PgStat_TableEntry Per-table info in a MsgTabstat
268  * ----------
269  */
270 typedef struct PgStat_TableEntry
271 {
275 
276 /* ----------
277  * PgStat_MsgTabstat Sent by the backend to report table
278  * and buffer access statistics.
279  * ----------
280  */
281 #define PGSTAT_NUM_TABENTRIES \
282  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int) - 2 * sizeof(PgStat_Counter)) \
283  / sizeof(PgStat_TableEntry))
284 
285 typedef struct PgStat_MsgTabstat
286 {
292  PgStat_Counter m_block_read_time; /* times in microseconds */
296 
297 
298 /* ----------
299  * PgStat_MsgTabpurge Sent by the backend to tell the collector
300  * about dead tables.
301  * ----------
302  */
303 #define PGSTAT_NUM_TABPURGE \
304  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
305  / sizeof(Oid))
306 
307 typedef struct PgStat_MsgTabpurge
308 {
314 
315 
316 /* ----------
317  * PgStat_MsgDropdb Sent by the backend to tell the collector
318  * about a dropped database
319  * ----------
320  */
321 typedef struct PgStat_MsgDropdb
322 {
326 
327 
328 /* ----------
329  * PgStat_MsgResetcounter Sent by the backend to tell the collector
330  * to reset counters
331  * ----------
332  */
334 {
338 
339 /* ----------
340  * PgStat_MsgResetsharedcounter Sent by the backend to tell the collector
341  * to reset a shared counter
342  * ----------
343  */
345 {
349 
350 /* ----------
351  * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector
352  * to reset a single counter
353  * ----------
354  */
356 {
362 
363 /* ----------
364  * PgStat_MsgResetslrucounter Sent by the backend to tell the collector
365  * to reset a SLRU counter
366  * ----------
367  */
369 {
371  int m_index;
373 
374 /* ----------
375  * PgStat_MsgResetreplslotcounter Sent by the backend to tell the collector
376  * to reset replication slot counter(s)
377  * ----------
378  */
380 {
382  char m_slotname[NAMEDATALEN];
383  bool clearall;
385 
386 /* ----------
387  * PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
388  * that a database is going to be processed
389  * ----------
390  */
392 {
397 
398 
399 /* ----------
400  * PgStat_MsgVacuum Sent by the backend or autovacuum daemon
401  * after VACUUM
402  * ----------
403  */
404 typedef struct PgStat_MsgVacuum
405 {
414 
415 
416 /* ----------
417  * PgStat_MsgAnalyze Sent by the backend or autovacuum daemon
418  * after ANALYZE
419  * ----------
420  */
421 typedef struct PgStat_MsgAnalyze
422 {
432 
433 
434 /* ----------
435  * PgStat_MsgArchiver Sent by the archiver to update statistics.
436  * ----------
437  */
438 typedef struct PgStat_MsgArchiver
439 {
441  bool m_failed; /* Failed attempt */
442  char m_xlog[MAX_XFN_CHARS + 1];
445 
446 /* ----------
447  * PgStat_MsgBgWriter Sent by the bgwriter to update statistics.
448  * ----------
449  */
450 typedef struct PgStat_MsgBgWriter
451 {
453 
462  PgStat_Counter m_checkpoint_write_time; /* times in milliseconds */
465 
466 /* ----------
467  * PgStat_MsgWal Sent by backends and background processes to update WAL statistics.
468  * ----------
469  */
470 typedef struct PgStat_MsgWal
471 {
475  uint64 m_wal_bytes;
477 } PgStat_MsgWal;
478 
479 /* ----------
480  * PgStat_MsgSLRU Sent by a backend to update SLRU statistics.
481  * ----------
482  */
483 typedef struct PgStat_MsgSLRU
484 {
495 
496 /* ----------
497  * PgStat_MsgReplSlot Sent by a backend or a wal sender to update replication
498  * slot statistics.
499  * ----------
500  */
501 typedef struct PgStat_MsgReplSlot
502 {
504  char m_slotname[NAMEDATALEN];
505  bool m_drop;
513 
514 
515 /* ----------
516  * PgStat_MsgRecoveryConflict Sent by the backend upon recovery conflict
517  * ----------
518  */
520 {
522 
524  int m_reason;
526 
527 /* ----------
528  * PgStat_MsgTempFile Sent by the backend upon creating a temp file
529  * ----------
530  */
531 typedef struct PgStat_MsgTempFile
532 {
534 
536  size_t m_filesize;
538 
539 /* ----------
540  * PgStat_FunctionCounts The actual per-function counts kept by a backend
541  *
542  * This struct should contain only actual event counters, because we memcmp
543  * it against zeroes to detect whether there are any counts to transmit.
544  *
545  * Note that the time counters are in instr_time format here. We convert to
546  * microseconds in PgStat_Counter format when transmitting to the collector.
547  * ----------
548  */
549 typedef struct PgStat_FunctionCounts
550 {
555 
556 /* ----------
557  * PgStat_BackendFunctionEntry Entry in backend's per-function hash table
558  * ----------
559  */
561 {
565 
566 /* ----------
567  * PgStat_FunctionEntry Per-function info in a MsgFuncstat
568  * ----------
569  */
570 typedef struct PgStat_FunctionEntry
571 {
574  PgStat_Counter f_total_time; /* times in microseconds */
577 
578 /* ----------
579  * PgStat_MsgFuncstat Sent by the backend to report function
580  * usage statistics.
581  * ----------
582  */
583 #define PGSTAT_NUM_FUNCENTRIES \
584  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
585  / sizeof(PgStat_FunctionEntry))
586 
587 typedef struct PgStat_MsgFuncstat
588 {
594 
595 /* ----------
596  * PgStat_MsgFuncpurge Sent by the backend to tell the collector
597  * about dead functions.
598  * ----------
599  */
600 #define PGSTAT_NUM_FUNCPURGE \
601  ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \
602  / sizeof(Oid))
603 
604 typedef struct PgStat_MsgFuncpurge
605 {
609  Oid m_functionid[PGSTAT_NUM_FUNCPURGE];
611 
612 /* ----------
613  * PgStat_MsgDeadlock Sent by the backend to tell the collector
614  * about a deadlock that occurred.
615  * ----------
616  */
617 typedef struct PgStat_MsgDeadlock
618 {
622 
623 /* ----------
624  * PgStat_MsgChecksumFailure Sent by the backend to tell the collector
625  * about checksum failures noticed.
626  * ----------
627  */
629 {
635 
636 /* ----------
637  * PgStat_MsgConn Sent by the backend to update connection statistics.
638  * ----------
639  */
640 typedef struct PgStat_MsgConn
641 {
650 
651 
652 /* ----------
653  * PgStat_Msg Union over all possible messages.
654  * ----------
655  */
656 typedef union PgStat_Msg
657 {
684 } PgStat_Msg;
685 
686 
687 /* ------------------------------------------------------------
688  * Statistic collector data structures follow
689  *
690  * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these
691  * data structures change.
692  * ------------------------------------------------------------
693  */
694 
695 #define PGSTAT_FILE_FORMAT_ID 0x01A5BCA0
696 
697 /* ----------
698  * PgStat_StatDBEntry The collector's data per database
699  * ----------
700  */
701 typedef struct PgStat_StatDBEntry
702 {
724  PgStat_Counter n_block_read_time; /* times in microseconds */
733 
735  TimestampTz stats_timestamp; /* time of db stats file update */
736 
737  /*
738  * tables and functions must be last in the struct, because we don't write
739  * the pointers out to the stats file.
740  */
744 
745 
746 /* ----------
747  * PgStat_StatTabEntry The collector's data per table (or index)
748  * ----------
749  */
750 typedef struct PgStat_StatTabEntry
751 {
753 
755 
758 
763 
768 
771 
772  TimestampTz vacuum_timestamp; /* user initiated vacuum */
774  TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */
776  TimestampTz analyze_timestamp; /* user initiated */
778  TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */
781 
782 
783 /* ----------
784  * PgStat_StatFuncEntry The collector's data per function
785  * ----------
786  */
787 typedef struct PgStat_StatFuncEntry
788 {
790 
792 
793  PgStat_Counter f_total_time; /* times in microseconds */
796 
797 
798 /*
799  * Archiver statistics kept in the stats collector
800  */
801 typedef struct PgStat_ArchiverStats
802 {
803  PgStat_Counter archived_count; /* archival successes */
804  char last_archived_wal[MAX_XFN_CHARS + 1]; /* last WAL file
805  * archived */
806  TimestampTz last_archived_timestamp; /* last archival success time */
807  PgStat_Counter failed_count; /* failed archival attempts */
808  char last_failed_wal[MAX_XFN_CHARS + 1]; /* WAL file involved in
809  * last failure */
810  TimestampTz last_failed_timestamp; /* last archival failure time */
813 
814 /*
815  * Global statistics kept in the stats collector
816  */
817 typedef struct PgStat_GlobalStats
818 {
819  TimestampTz stats_timestamp; /* time of stats file update */
822  PgStat_Counter checkpoint_write_time; /* times in milliseconds */
832 
833 /*
834  * WAL statistics kept in the stats collector
835  */
836 typedef struct PgStat_WalStats
837 {
840  uint64 wal_bytes;
844 
845 /*
846  * SLRU statistics kept in the stats collector
847  */
848 typedef struct PgStat_SLRUStats
849 {
859 
860 /*
861  * Replication slot statistics kept in the stats collector
862  */
863 typedef struct PgStat_ReplSlotStats
864 {
865  char slotname[NAMEDATALEN];
874 
875 /* ----------
876  * Backend states
877  * ----------
878  */
879 typedef enum BackendState
880 {
888 } BackendState;
889 
890 
891 /* ----------
892  * Wait Classes
893  * ----------
894  */
895 #define PG_WAIT_LWLOCK 0x01000000U
896 #define PG_WAIT_LOCK 0x03000000U
897 #define PG_WAIT_BUFFER_PIN 0x04000000U
898 #define PG_WAIT_ACTIVITY 0x05000000U
899 #define PG_WAIT_CLIENT 0x06000000U
900 #define PG_WAIT_EXTENSION 0x07000000U
901 #define PG_WAIT_IPC 0x08000000U
902 #define PG_WAIT_TIMEOUT 0x09000000U
903 #define PG_WAIT_IO 0x0A000000U
904 
905 /* ----------
906  * Wait Events - Activity
907  *
908  * Use this category when a process is waiting because it has no work to do,
909  * unless the "Client" or "Timeout" category describes the situation better.
910  * Typically, this should only be used for background processes.
911  * ----------
912  */
913 typedef enum
914 {
929 
930 /* ----------
931  * Wait Events - Client
932  *
933  * Use this category when a process is waiting to send data to or receive data
934  * from the frontend process to which it is connected. This is never used for
935  * a background process, which has no client connection.
936  * ----------
937  */
938 typedef enum
939 {
950 
951 /* ----------
952  * Wait Events - IPC
953  *
954  * Use this category when a process cannot complete the work it is doing because
955  * it is waiting for a notification from another process.
956  * ----------
957  */
958 typedef enum
959 {
1002 } WaitEventIPC;
1003 
1004 /* ----------
1005  * Wait Events - Timeout
1006  *
1007  * Use this category when a process is waiting for a timeout to expire.
1008  * ----------
1009  */
1010 typedef enum
1011 {
1018 
1019 /* ----------
1020  * Wait Events - IO
1021  *
1022  * Use this category when a process is waiting for a IO.
1023  * ----------
1024  */
1025 typedef enum
1026 {
1101 } WaitEventIO;
1102 
1103 /* ----------
1104  * Command type for progress reporting purposes
1105  * ----------
1106  */
1108 {
1117 
1118 #define PGSTAT_NUM_PROGRESS_PARAM 20
1119 
1120 /* ----------
1121  * Shared-memory data structures
1122  * ----------
1123  */
1124 
1125 
1126 /*
1127  * PgBackendSSLStatus
1128  *
1129  * For each backend, we keep the SSL status in a separate struct, that
1130  * is only filled in if SSL is enabled.
1131  *
1132  * All char arrays must be null-terminated.
1133  */
1134 typedef struct PgBackendSSLStatus
1135 {
1136  /* Information about SSL connection */
1142 
1143  /*
1144  * serial number is max "20 octets" per RFC 5280, so this size should be
1145  * fine
1146  */
1148 
1151 
1152 /*
1153  * PgBackendGSSStatus
1154  *
1155  * For each backend, we keep the GSS status in a separate struct, that
1156  * is only filled in if GSS is enabled.
1157  *
1158  * All char arrays must be null-terminated.
1159  */
1160 typedef struct PgBackendGSSStatus
1161 {
1162  /* Information about GSSAPI connection */
1163  char gss_princ[NAMEDATALEN]; /* GSSAPI Principal used to auth */
1164  bool gss_auth; /* If GSSAPI authentication was used */
1165  bool gss_enc; /* If encryption is being used */
1166 
1168 
1169 
1170 /* ----------
1171  * PgBackendStatus
1172  *
1173  * Each live backend maintains a PgBackendStatus struct in shared memory
1174  * showing its current activity. (The structs are allocated according to
1175  * BackendId, but that is not critical.) Note that the collector process
1176  * has no involvement in, or even access to, these structs.
1177  *
1178  * Each auxiliary process also maintains a PgBackendStatus struct in shared
1179  * memory.
1180  * ----------
1181  */
1182 typedef struct PgBackendStatus
1183 {
1184  /*
1185  * To avoid locking overhead, we use the following protocol: a backend
1186  * increments st_changecount before modifying its entry, and again after
1187  * finishing a modification. A would-be reader should note the value of
1188  * st_changecount, copy the entry into private memory, then check
1189  * st_changecount again. If the value hasn't changed, and if it's even,
1190  * the copy is valid; otherwise start over. This makes updates cheap
1191  * while reads are potentially expensive, but that's the tradeoff we want.
1192  *
1193  * The above protocol needs memory barriers to ensure that the apparent
1194  * order of execution is as it desires. Otherwise, for example, the CPU
1195  * might rearrange the code so that st_changecount is incremented twice
1196  * before the modification on a machine with weak memory ordering. Hence,
1197  * use the macros defined below for manipulating st_changecount, rather
1198  * than touching it directly.
1199  */
1201 
1202  /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */
1204 
1205  /* Type of backends */
1207 
1208  /* Times when current backend, transaction, and activity started */
1213 
1214  /* Database OID, owning user's OID, connection client address */
1218  char *st_clienthostname; /* MUST be null-terminated */
1219 
1220  /* Information about SSL connection */
1221  bool st_ssl;
1223 
1224  /* Information about GSSAPI connection */
1225  bool st_gss;
1227 
1228  /* current state */
1230 
1231  /* application name; MUST be null-terminated */
1232  char *st_appname;
1233 
1234  /*
1235  * Current command string; MUST be null-terminated. Note that this string
1236  * possibly is truncated in the middle of a multi-byte character. As
1237  * activity strings are stored more frequently than read, that allows to
1238  * move the cost of correct truncation to the display side. Use
1239  * pgstat_clip_activity() to truncate correctly.
1240  */
1242 
1243  /*
1244  * Command progress reporting. Any command which wishes can advertise
1245  * that it is running by setting st_progress_command,
1246  * st_progress_command_target, and st_progress_param[].
1247  * st_progress_command_target should be the OID of the relation which the
1248  * command targets (we assume there's just one, as this is meant for
1249  * utility commands), but the meaning of each element in the
1250  * st_progress_param array is command-specific.
1251  */
1254  int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM];
1255 } PgBackendStatus;
1256 
1257 /*
1258  * Macros to load and store st_changecount with appropriate memory barriers.
1259  *
1260  * Use PGSTAT_BEGIN_WRITE_ACTIVITY() before, and PGSTAT_END_WRITE_ACTIVITY()
1261  * after, modifying the current process's PgBackendStatus data. Note that,
1262  * since there is no mechanism for cleaning up st_changecount after an error,
1263  * THESE MACROS FORM A CRITICAL SECTION. Any error between them will be
1264  * promoted to PANIC, causing a database restart to clean up shared memory!
1265  * Hence, keep the critical section as short and straight-line as possible.
1266  * Aside from being safer, that minimizes the window in which readers will
1267  * have to loop.
1268  *
1269  * Reader logic should follow this sketch:
1270  *
1271  * for (;;)
1272  * {
1273  * int before_ct, after_ct;
1274  *
1275  * pgstat_begin_read_activity(beentry, before_ct);
1276  * ... copy beentry data to local memory ...
1277  * pgstat_end_read_activity(beentry, after_ct);
1278  * if (pgstat_read_activity_complete(before_ct, after_ct))
1279  * break;
1280  * CHECK_FOR_INTERRUPTS();
1281  * }
1282  *
1283  * For extra safety, we generally use volatile beentry pointers, although
1284  * the memory barriers should theoretically be sufficient.
1285  */
1286 #define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry) \
1287  do { \
1288  START_CRIT_SECTION(); \
1289  (beentry)->st_changecount++; \
1290  pg_write_barrier(); \
1291  } while (0)
1292 
1293 #define PGSTAT_END_WRITE_ACTIVITY(beentry) \
1294  do { \
1295  pg_write_barrier(); \
1296  (beentry)->st_changecount++; \
1297  Assert(((beentry)->st_changecount & 1) == 0); \
1298  END_CRIT_SECTION(); \
1299  } while (0)
1300 
1301 #define pgstat_begin_read_activity(beentry, before_changecount) \
1302  do { \
1303  (before_changecount) = (beentry)->st_changecount; \
1304  pg_read_barrier(); \
1305  } while (0)
1306 
1307 #define pgstat_end_read_activity(beentry, after_changecount) \
1308  do { \
1309  pg_read_barrier(); \
1310  (after_changecount) = (beentry)->st_changecount; \
1311  } while (0)
1312 
1313 #define pgstat_read_activity_complete(before_changecount, after_changecount) \
1314  ((before_changecount) == (after_changecount) && \
1315  ((before_changecount) & 1) == 0)
1316 
1317 
1318 /* ----------
1319  * LocalPgBackendStatus
1320  *
1321  * When we build the backend status array, we use LocalPgBackendStatus to be
1322  * able to add new values to the struct when needed without adding new fields
1323  * to the shared memory. It contains the backend status as a first member.
1324  * ----------
1325  */
1326 typedef struct LocalPgBackendStatus
1327 {
1328  /*
1329  * Local version of the backend status entry.
1330  */
1332 
1333  /*
1334  * The xid of the current transaction if available, InvalidTransactionId
1335  * if not.
1336  */
1338 
1339  /*
1340  * The xmin of the current session if available, InvalidTransactionId if
1341  * not.
1342  */
1345 
1346 /*
1347  * Working state needed to accumulate per-function-call timing statistics.
1348  */
1350 {
1351  /* Link to function's hashtable entry (must still be there at exit!) */
1352  /* NULL means we are not tracking the current function call */
1354  /* Total time previously charged to function, as of function start */
1356  /* Backend-wide total time as of function start */
1358  /* system clock as of function start */
1361 
1362 
1363 /* ----------
1364  * GUC parameters
1365  * ----------
1366  */
1368 extern PGDLLIMPORT bool pgstat_track_counts;
1371 extern char *pgstat_stat_directory;
1372 extern char *pgstat_stat_tmpname;
1373 extern char *pgstat_stat_filename;
1374 
1375 /*
1376  * BgWriter statistics counters are updated directly by bgwriter and bufmgr
1377  */
1379 
1380 /*
1381  * WAL statistics counter is updated by backends and background processes
1382  */
1383 extern PgStat_MsgWal WalStats;
1384 
1385 /*
1386  * Updated by pgstat_count_buffer_*_time macros
1387  */
1390 
1391 /*
1392  * Updated by the traffic cop and in errfinish()
1393  */
1395 
1396 /* ----------
1397  * Functions called from postmaster
1398  * ----------
1399  */
1400 extern Size BackendStatusShmemSize(void);
1401 extern void CreateSharedBackendStatus(void);
1402 
1403 extern void pgstat_init(void);
1404 extern int pgstat_start(void);
1405 extern void pgstat_reset_all(void);
1406 extern void allow_immediate_pgstat_restart(void);
1407 
1408 #ifdef EXEC_BACKEND
1409 extern void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
1410 #endif
1411 
1412 
1413 /* ----------
1414  * Functions called from backends
1415  * ----------
1416  */
1417 extern void pgstat_ping(void);
1418 
1419 extern void pgstat_report_stat(bool force);
1420 extern void pgstat_vacuum_stat(void);
1421 extern void pgstat_drop_database(Oid databaseid);
1422 
1423 extern void pgstat_clear_snapshot(void);
1424 extern void pgstat_reset_counters(void);
1425 extern void pgstat_reset_shared_counters(const char *);
1427 extern void pgstat_reset_slru_counter(const char *);
1428 extern void pgstat_reset_replslot_counter(const char *name);
1429 
1430 extern void pgstat_report_autovac(Oid dboid);
1431 extern void pgstat_report_vacuum(Oid tableoid, bool shared,
1432  PgStat_Counter livetuples, PgStat_Counter deadtuples);
1433 extern void pgstat_report_analyze(Relation rel,
1434  PgStat_Counter livetuples, PgStat_Counter deadtuples,
1435  bool resetcounter);
1436 
1437 extern void pgstat_report_recovery_conflict(int reason);
1438 extern void pgstat_report_deadlock(void);
1439 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
1440 extern void pgstat_report_checksum_failure(void);
1441 extern void pgstat_report_replslot(const char *slotname, int spilltxns, int spillcount,
1442  int spillbytes, int streamtxns, int streamcount, int streambytes);
1443 extern void pgstat_report_replslot_drop(const char *slotname);
1444 
1445 extern void pgstat_initialize(void);
1446 extern void pgstat_bestart(void);
1447 
1448 extern void pgstat_report_activity(BackendState state, const char *cmd_str);
1449 extern void pgstat_report_tempfile(size_t filesize);
1450 extern void pgstat_report_appname(const char *appname);
1451 extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
1452 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
1453 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
1454 extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
1455 extern const char *pgstat_get_crashed_backend_activity(int pid, char *buffer,
1456  int buflen);
1457 
1459  Oid relid);
1460 extern void pgstat_progress_update_param(int index, int64 val);
1461 extern void pgstat_progress_update_multi_param(int nparam, const int *index,
1462  const int64 *val);
1463 extern void pgstat_progress_end_command(void);
1464 
1465 extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
1467 
1468 extern void pgstat_initstats(Relation rel);
1469 
1470 extern char *pgstat_clip_activity(const char *raw_activity);
1471 
1472 /* ----------
1473  * pgstat_report_wait_start() -
1474  *
1475  * Called from places where server process needs to wait. This is called
1476  * to report wait event information. The wait information is stored
1477  * as 4-bytes where first byte represents the wait event class (type of
1478  * wait, for different types of wait, refer WaitClass) and the next
1479  * 3-bytes represent the actual wait event. Currently 2-bytes are used
1480  * for wait event which is sufficient for current usage, 1-byte is
1481  * reserved for future usage.
1482  *
1483  * NB: this *must* be able to survive being called before MyProc has been
1484  * initialized.
1485  * ----------
1486  */
1487 static inline void
1489 {
1490  volatile PGPROC *proc = MyProc;
1491 
1492  if (!pgstat_track_activities || !proc)
1493  return;
1494 
1495  /*
1496  * Since this is a four-byte field which is always read and written as
1497  * four-bytes, updates are atomic.
1498  */
1499  proc->wait_event_info = wait_event_info;
1500 }
1501 
1502 /* ----------
1503  * pgstat_report_wait_end() -
1504  *
1505  * Called to report end of a wait.
1506  *
1507  * NB: this *must* be able to survive being called before MyProc has been
1508  * initialized.
1509  * ----------
1510  */
1511 static inline void
1513 {
1514  volatile PGPROC *proc = MyProc;
1515 
1516  if (!pgstat_track_activities || !proc)
1517  return;
1518 
1519  /*
1520  * Since this is a four-byte field which is always read and written as
1521  * four-bytes, updates are atomic.
1522  */
1523  proc->wait_event_info = 0;
1524 }
1525 
1526 /* nontransactional event counts are simple enough to inline */
1527 
1528 #define pgstat_count_heap_scan(rel) \
1529  do { \
1530  if ((rel)->pgstat_info != NULL) \
1531  (rel)->pgstat_info->t_counts.t_numscans++; \
1532  } while (0)
1533 #define pgstat_count_heap_getnext(rel) \
1534  do { \
1535  if ((rel)->pgstat_info != NULL) \
1536  (rel)->pgstat_info->t_counts.t_tuples_returned++; \
1537  } while (0)
1538 #define pgstat_count_heap_fetch(rel) \
1539  do { \
1540  if ((rel)->pgstat_info != NULL) \
1541  (rel)->pgstat_info->t_counts.t_tuples_fetched++; \
1542  } while (0)
1543 #define pgstat_count_index_scan(rel) \
1544  do { \
1545  if ((rel)->pgstat_info != NULL) \
1546  (rel)->pgstat_info->t_counts.t_numscans++; \
1547  } while (0)
1548 #define pgstat_count_index_tuples(rel, n) \
1549  do { \
1550  if ((rel)->pgstat_info != NULL) \
1551  (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
1552  } while (0)
1553 #define pgstat_count_buffer_read(rel) \
1554  do { \
1555  if ((rel)->pgstat_info != NULL) \
1556  (rel)->pgstat_info->t_counts.t_blocks_fetched++; \
1557  } while (0)
1558 #define pgstat_count_buffer_hit(rel) \
1559  do { \
1560  if ((rel)->pgstat_info != NULL) \
1561  (rel)->pgstat_info->t_counts.t_blocks_hit++; \
1562  } while (0)
1563 #define pgstat_count_buffer_read_time(n) \
1564  (pgStatBlockReadTime += (n))
1565 #define pgstat_count_buffer_write_time(n) \
1566  (pgStatBlockWriteTime += (n))
1567 
1569 extern void pgstat_count_heap_update(Relation rel, bool hot);
1570 extern void pgstat_count_heap_delete(Relation rel);
1571 extern void pgstat_count_truncate(Relation rel);
1572 extern void pgstat_update_heap_dead_tuples(Relation rel, int delta);
1573 
1575 extern void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo,
1578  bool finalize);
1579 
1580 extern void AtEOXact_PgStat(bool isCommit, bool parallel);
1581 extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth);
1582 
1583 extern void AtPrepare_PgStat(void);
1584 extern void PostPrepare_PgStat(void);
1585 
1586 extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info,
1587  void *recdata, uint32 len);
1588 extern void pgstat_twophase_postabort(TransactionId xid, uint16 info,
1589  void *recdata, uint32 len);
1590 
1591 extern void pgstat_send_archiver(const char *xlog, bool failed);
1592 extern void pgstat_send_bgwriter(void);
1593 extern void pgstat_send_wal(void);
1594 
1595 /* ----------
1596  * Support functions for the SQL-callable functions to
1597  * generate the pgstat* views.
1598  * ----------
1599  */
1602 extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid);
1605 extern int pgstat_fetch_stat_numbackends(void);
1609 extern PgStat_SLRUStats *pgstat_fetch_slru(void);
1610 extern PgStat_ReplSlotStats *pgstat_fetch_replslot(int *nslots_p);
1611 
1612 extern void pgstat_count_slru_page_zeroed(int slru_idx);
1613 extern void pgstat_count_slru_page_hit(int slru_idx);
1614 extern void pgstat_count_slru_page_read(int slru_idx);
1615 extern void pgstat_count_slru_page_written(int slru_idx);
1616 extern void pgstat_count_slru_page_exists(int slru_idx);
1617 extern void pgstat_count_slru_flush(int slru_idx);
1618 extern void pgstat_count_slru_truncate(int slru_idx);
1619 extern const char *pgstat_slru_name(int slru_idx);
1620 extern int pgstat_slru_index(const char *name);
1621 
1622 #endif /* PGSTAT_H */
void pgstat_report_checksum_failure(void)
Definition: pgstat.c:1744
bool ssl_compression
Definition: pgstat.h:1138
struct PgBackendGSSStatus PgBackendGSSStatus
void pgstat_count_truncate(Relation rel)
Definition: pgstat.c:2276
PgStat_MsgResetslrucounter msg_resetslrucounter
Definition: pgstat.h:667
PgStat_MsgAutovacStart msg_autovacuum_start
Definition: pgstat.h:669
PgStat_MsgBgWriter msg_bgwriter
Definition: pgstat.h:673
PgStat_Counter m_buf_fsync_backend
Definition: pgstat.h:460
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2831
void pgstat_initialize(void)
Definition: pgstat.c:3096
PgStat_Counter analyze_count
Definition: pgstat.h:777
instr_time f_self_time
Definition: pgstat.h:553
int pgstat_start(void)
Definition: pgstat.c:781
#define pg_attribute_noreturn()
Definition: c.h:167
PgStat_Counter buf_alloc
Definition: pgstat.h:829
PgStat_Counter archived_count
Definition: pgstat.h:803
PgStat_MsgHdr m_hdr
Definition: pgstat.h:472
void pgstat_ping(void)
Definition: pgstat.c:1820
PgStat_Counter m_buf_written_checkpoints
Definition: pgstat.h:456
PgStat_Counter m_buf_alloc
Definition: pgstat.h:461
struct PgStat_MsgFuncpurge PgStat_MsgFuncpurge
PgStat_Counter t_delta_live_tuples
Definition: pgstat.h:127
Oid st_progress_command_target
Definition: pgstat.h:1253
PgStat_Counter m_dead_tuples
Definition: pgstat.h:412
void pgstat_clear_snapshot(void)
Definition: pgstat.c:6270
PgStat_Counter stream_count
Definition: pgstat.h:870
PgStat_Counter wal_records
Definition: pgstat.h:838
int64 PgStat_Counter
Definition: pgstat.h:91
PgStat_Counter m_checkpoint_write_time
Definition: pgstat.h:462
TimestampTz m_vacuumtime
Definition: pgstat.h:410
PgStat_Counter tuples_updated
Definition: pgstat.h:186
void pgstat_report_xact_timestamp(TimestampTz tstamp)
Definition: pgstat.c:3581
const char * pgstat_get_backend_current_activity(int pid, bool checkUser)
Definition: pgstat.c:4431
TimestampTz stat_reset_timestamp
Definition: pgstat.h:842
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgstat.c:4769
PgStat_Counter m_flush
Definition: pgstat.h:492
struct PgStat_MsgResetreplslotcounter PgStat_MsgResetreplslotcounter
PgStat_Counter tuples_returned
Definition: pgstat.h:756
PgStat_MsgDeadlock msg_deadlock
Definition: pgstat.h:679
void pgstat_count_slru_page_exists(int slru_idx)
Definition: pgstat.c:7384
uint32 TransactionId
Definition: c.h:575
PgStat_MsgResetsharedcounter msg_resetsharedcounter
Definition: pgstat.h:665
union PgStat_Msg PgStat_Msg
TimestampTz stats_timestamp
Definition: pgstat.h:735
uint32 wait_event_info
Definition: proc.h:224
WaitEventIPC
Definition: pgstat.h:958
void pgstat_progress_update_param(int index, int64 val)
Definition: pgstat.c:3478
PgStat_MsgHdr m_hdr
Definition: pgstat.h:642
TrackFunctionsLevel
Definition: pgstat.h:37
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:119
PgStat_MsgHdr m_hdr
Definition: pgstat.h:533
PgStat_MsgChecksumFailure msg_checksumfailure
Definition: pgstat.h:681
PgStat_Counter m_live_tuples
Definition: pgstat.h:411
void pgstat_count_slru_page_written(int slru_idx)
Definition: pgstat.c:7396
TimestampTz clock_time
Definition: pgstat.h:260
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1211
instr_time save_total
Definition: pgstat.h:1357
PgStat_Counter n_blocks_hit
Definition: pgstat.h:707
void pgstat_send_wal(void)
Definition: pgstat.c:4676
PGPROC * MyProc
Definition: proc.c:68
int64 TimestampTz
Definition: timestamp.h:39
#define PGSTAT_NUM_TABPURGE
Definition: pgstat.h:303
struct PgStat_MsgTabpurge PgStat_MsgTabpurge
void pgstat_update_heap_dead_tuples(Relation rel, int delta)
Definition: pgstat.c:2305
PgStat_MsgHdr m_hdr
Definition: pgstat.h:393
struct PgStat_MsgArchiver PgStat_MsgArchiver
PgStat_Counter m_timed_checkpoints
Definition: pgstat.h:454
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:717
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3552
PgStat_Counter m_maxwritten_clean
Definition: pgstat.h:458
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:718
void CreateSharedBackendStatus(void)
Definition: pgstat.c:2961
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:124
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
Definition: pgstat.c:3457
PgStat_MsgHdr m_hdr
Definition: pgstat.h:452
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:778
struct PgStat_MsgDeadlock PgStat_MsgDeadlock
struct timeval instr_time
Definition: instr_time.h:150
PgStat_Counter f_self_time
Definition: pgstat.h:575
PgStat_Counter timed_checkpoints
Definition: pgstat.h:820
TimestampTz stat_reset_timestamp
Definition: pgstat.h:857
PgStat_MsgHdr m_hdr
Definition: pgstat.h:606
PgStat_Counter n_checksum_failures
Definition: pgstat.h:722
TimestampTz stat_reset_timestamp
Definition: pgstat.h:872
PgStat_Counter n_temp_files
Definition: pgstat.h:719
PgStat_MsgHdr m_hdr
Definition: pgstat.h:630
Oid m_databaseid
Definition: pgstat.h:407
PgStat_Counter m_buf_written_clean
Definition: pgstat.h:457
PgStat_MsgDummy msg_dummy
Definition: pgstat.h:659
TimestampTz last_checksum_failure
Definition: pgstat.h:723
uint64 m_wal_bytes
Definition: pgstat.h:475
PgStat_Counter m_spill_bytes
Definition: pgstat.h:508
HTAB * functions
Definition: pgstat.h:742
TransactionId backend_xmin
Definition: pgstat.h:1343
PgStat_Counter m_active_time
Definition: pgstat.h:646
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2848
void pgstat_reset_replslot_counter(const char *name)
Definition: pgstat.c:1525
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat.c:2880
PgStat_Counter n_tuples_returned
Definition: pgstat.h:708
struct PgStat_MsgReplSlot PgStat_MsgReplSlot
PgStat_Counter vacuum_count
Definition: pgstat.h:773
SockAddr st_clientaddr
Definition: pgstat.h:1217
bool m_autovacuum
Definition: pgstat.h:409
void pgstat_send_archiver(const char *xlog, bool failed)
Definition: pgstat.c:4623
size_t m_filesize
Definition: pgstat.h:536
PgStat_MsgTempFile msg_tempfile
Definition: pgstat.h:680
PgStat_Counter buf_fsync_backend
Definition: pgstat.h:828
struct PgStat_TableCounts PgStat_TableCounts
struct PgStat_MsgDummy PgStat_MsgDummy
TimestampTz stats_timestamp
Definition: pgstat.h:819
PgStat_Counter spill_txns
Definition: pgstat.h:866
TimestampTz stat_reset_timestamp
Definition: pgstat.h:734
PgStat_MsgWal msg_wal
Definition: pgstat.h:674
instr_time f_total_time
Definition: pgstat.h:552
void pgstat_reset_slru_counter(const char *)
Definition: pgstat.c:1501
#define PG_WAIT_ACTIVITY
Definition: pgstat.h:898
struct PgStat_TableXactStatus * next
Definition: pgstat.h:197
struct PgStat_ReplSlotStats PgStat_ReplSlotStats
TimestampTz m_analyzetime
Definition: pgstat.h:428
ProgressCommandType st_progress_command
Definition: pgstat.h:1252
void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: pgstat.c:2589
PgStat_Counter numscans
Definition: pgstat.h:754
PgStat_TableCounts t_counts
Definition: pgstat.h:176
PgStat_Counter blocks_exists
Definition: pgstat.h:854
struct PgBackendSSLStatus PgBackendSSLStatus
struct PgStat_MsgRecoveryConflict PgStat_MsgRecoveryConflict
Datum ssl_client_serial(PG_FUNCTION_ARGS)
Definition: sslinfo.c:113
#define PG_WAIT_IO
Definition: pgstat.h:903
unsigned int Oid
Definition: postgres_ext.h:31
struct PgStat_ArchiverStats PgStat_ArchiverStats
PgStat_Counter deleted_pre_trunc
Definition: pgstat.h:191
PgStat_Counter m_blocks_exists
Definition: pgstat.h:491
PgStat_MsgAnalyze msg_analyze
Definition: pgstat.h:671
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:762
PgStat_Counter f_total_time
Definition: pgstat.h:793
PgStat_Counter spill_bytes
Definition: pgstat.h:868
BackendState st_state
Definition: pgstat.h:1229
PgStat_Counter t_tuples_returned
Definition: pgstat.h:118
PgStat_Shared_Reset_Target
Definition: pgstat.h:136
char * st_clienthostname
Definition: pgstat.h:1218
PgStat_Counter tuples_inserted
Definition: pgstat.h:759
PgStat_FunctionCounts * fs
Definition: pgstat.h:1353
PgStat_Counter f_numcalls
Definition: pgstat.h:551
PgStat_MsgHdr msg_hdr
Definition: pgstat.h:658
struct PgStat_StatFuncEntry PgStat_StatFuncEntry
struct PgStat_FunctionCallUsage PgStat_FunctionCallUsage
#define PGDLLIMPORT
Definition: c.h:1305
struct PgStat_SLRUStats PgStat_SLRUStats
PgStat_Counter m_stream_bytes
Definition: pgstat.h:511
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2686
PgStat_Counter n_xact_commit
Definition: pgstat.h:704
void pgstat_report_deadlock(void)
Definition: pgstat.c:1701
PgStat_MsgWal WalStats
Definition: pgstat.c:145
bool m_resetcounter
Definition: pgstat.h:427
Definition: type.h:89
PgStat_Counter stream_bytes
Definition: pgstat.h:871
PgStat_MsgBgWriter BgWriterStats
Definition: pgstat.c:144
PgStat_MsgHdr m_hdr
Definition: pgstat.h:485
void pgstat_report_replslot(const char *slotname, int spilltxns, int spillcount, int spillbytes, int streamtxns, int streamcount, int streambytes)
Definition: pgstat.c:1776
Oid st_databaseid
Definition: pgstat.h:1215
#define NAMEDATALEN
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:1118
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:706
PgStat_Counter n_sessions_killed
Definition: pgstat.h:732
struct PgStat_TableEntry PgStat_TableEntry
const char * pgstat_slru_name(int slru_idx)
Definition: pgstat.c:7339
PgStat_Counter n_live_tuples
Definition: pgstat.h:764
PgStat_Counter m_requested_checkpoints
Definition: pgstat.h:455
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:767
Definition: dynahash.c:219
Oid m_databaseid
Definition: pgstat.h:643
struct PgStat_MsgAnalyze PgStat_MsgAnalyze
unsigned short uint16
Definition: c.h:428
PgStat_MsgSLRU msg_slru
Definition: pgstat.h:675
PgStat_FunctionCounts f_counts
Definition: pgstat.h:563
PgStat_MsgHdr m_hdr
Definition: pgstat.h:619
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:2106
PgStat_MsgFuncpurge msg_funcpurge
Definition: pgstat.h:677
char * pgstat_stat_tmpname
Definition: pgstat.c:137
PgStat_Counter buf_written_backend
Definition: pgstat.h:827
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:714
PgStat_Counter m_spill_txns
Definition: pgstat.h:506
TransactionId backend_xid
Definition: pgstat.h:1337
void AtEOSubXact_PgStat(bool isCommit, int nestDepth)
Definition: pgstat.c:2408
TimestampTz vacuum_timestamp
Definition: pgstat.h:772
PgStat_Counter t_tuples_updated
Definition: pgstat.h:122
PgStat_MsgHdr m_hdr
Definition: pgstat.h:370
PgStat_MsgHdr m_hdr
Definition: pgstat.h:521
PgStat_Counter total_active_time
Definition: pgstat.h:728
PgStat_Counter pgStatBlockReadTime
Definition: pgstat.c:259
#define PG_WAIT_CLIENT
Definition: pgstat.h:899
void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1475
PgStat_Counter checkpoint_write_time
Definition: pgstat.h:822
PgStat_Counter n_sessions_abandoned
Definition: pgstat.h:730
PgStat_Counter n_dead_tuples
Definition: pgstat.h:765
PgStat_Counter m_index
Definition: pgstat.h:486
PgStat_Counter wal_fpi
Definition: pgstat.h:839
TimestampTz m_failure_time
Definition: pgstat.h:633
struct PgStat_MsgTempFile PgStat_MsgTempFile
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2796
void allow_immediate_pgstat_restart(void)
Definition: pgstat.c:844
PgStat_Counter f_numcalls
Definition: pgstat.h:791
TimestampTz last_autovac_time
Definition: pgstat.h:713
WaitEventClient
Definition: pgstat.h:938
struct PgStat_GlobalStats PgStat_GlobalStats
void pgstat_count_slru_page_read(int slru_idx)
Definition: pgstat.c:7390
PgStat_Counter m_blocks_written
Definition: pgstat.h:490
PgStat_Counter n_sessions_fatal
Definition: pgstat.h:731
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:710
Oid m_databaseid
Definition: pgstat.h:324
PgStat_Counter buf_written_checkpoints
Definition: pgstat.h:824
PgStat_Counter tuples_inserted
Definition: pgstat.h:185
struct PgStat_MsgDropdb PgStat_MsgDropdb
PgStat_Counter pgStatBlockWriteTime
Definition: pgstat.c:260
struct PgStat_MsgSLRU PgStat_MsgSLRU
struct PgStat_MsgInquiry PgStat_MsgInquiry
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1926
char * st_activity_raw
Definition: pgstat.h:1241
char * pgstat_stat_directory
Definition: pgstat.c:135
PgStat_Counter blocks_read
Definition: pgstat.h:852
PgStat_Counter total_idle_in_xact_time
Definition: pgstat.h:729
void pgstat_report_stat(bool force)
Definition: pgstat.c:870
void pgstat_vacuum_stat(void)
Definition: pgstat.c:1091
PgStat_Counter t_delta_dead_tuples
Definition: pgstat.h:128
SessionEndType
Definition: pgstat.h:45
PgStat_Counter tuples_fetched
Definition: pgstat.h:757
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
Definition: pgstat.c:2175
unsigned int uint32
Definition: c.h:429
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:716
PgStat_MsgHdr m_hdr
Definition: pgstat.h:323
PgStat_Counter m_block_write_time
Definition: pgstat.h:293
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1512
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1212
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:712
void pgstat_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: pgstat.c:2625
PgStat_Counter n_conflict_lock
Definition: pgstat.h:715
WaitEventTimeout
Definition: pgstat.h:1010
PgStat_Counter blocks_hit
Definition: pgstat.h:851
PgStat_Counter total_session_time
Definition: pgstat.h:727
char * st_appname
Definition: pgstat.h:1232
PgStat_Counter t_blocks_hit
Definition: pgstat.h:132
void pgstat_init(void)
Definition: pgstat.c:404
struct PgStat_WalStats PgStat_WalStats
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:194
PgStat_Counter n_xact_rollback
Definition: pgstat.h:705
PgStat_Counter m_wal_buffers_full
Definition: pgstat.h:476
int m_xact_rollback
Definition: pgstat.h:291
PgStat_MsgHdr m_hdr
Definition: pgstat.h:335
SessionEndType pgStatSessionEndCause
Definition: pgstat.c:263
void pgstat_progress_end_command(void)
Definition: pgstat.c:3529
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:123
PgStat_Counter buf_written_clean
Definition: pgstat.h:825
Datum ssl_issuer_dn(PG_FUNCTION_ARGS)
Definition: sslinfo.c:325
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2815
void AtEOXact_PgStat(bool isCommit, bool parallel)
Definition: pgstat.c:2321
void pgstat_report_recovery_conflict(int reason)
Definition: pgstat.c:1681
PgStat_Counter blocks_zeroed
Definition: pgstat.h:850
PgStat_MsgRecoveryConflict msg_recoveryconflict
Definition: pgstat.h:678
struct PgStat_MsgTabstat PgStat_MsgTabstat
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2774
PgStat_MsgHdr m_hdr
Definition: pgstat.h:309
PgStat_Counter m_idle_in_xact_time
Definition: pgstat.h:647
PgStat_Counter m_live_tuples
Definition: pgstat.h:429
void pgstat_drop_database(Oid databaseid)
Definition: pgstat.c:1322
void pgstat_count_slru_truncate(int slru_idx)
Definition: pgstat.c:7408
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3760
struct PgStat_MsgResetsharedcounter PgStat_MsgResetsharedcounter
struct PgStat_FunctionCounts PgStat_FunctionCounts
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3815
PgBackendStatus backendStatus
Definition: pgstat.h:1331
bool m_autovacuum
Definition: pgstat.h:426
#define PGSTAT_NUM_FUNCENTRIES
Definition: pgstat.h:583
PgStat_Counter tuples_deleted
Definition: pgstat.h:187
struct PgStat_MsgBgWriter PgStat_MsgBgWriter
TimestampTz m_timestamp
Definition: pgstat.h:443
#define PGSTAT_NUM_TABENTRIES
Definition: pgstat.h:281
struct PgStat_MsgResetsinglecounter PgStat_MsgResetsinglecounter
void pgstat_reset_counters(void)
Definition: pgstat.c:1420
#define MAX_XFN_CHARS
Definition: pgarch.h:26
BackendType st_backendType
Definition: pgstat.h:1206
PgStat_Counter f_total_time
Definition: pgstat.h:574
PgStat_Counter blocks_hit
Definition: pgstat.h:770
TimestampTz analyze_timestamp
Definition: pgstat.h:776
TimestampTz last_failed_timestamp
Definition: pgstat.h:810
PgStat_Counter changes_since_analyze
Definition: pgstat.h:766
StatMsgType
Definition: pgstat.h:58
PgStat_Shared_Reset_Target m_resettarget
Definition: pgstat.h:347
void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
Definition: pgstat.c:1600
PgStat_Counter t_numscans
Definition: pgstat.h:116
struct PgStat_MsgVacuum PgStat_MsgVacuum
PgStat_Single_Reset_Type
Definition: pgstat.h:144
Size BackendStatusShmemSize(void)
Definition: pgstat.c:2928
struct PgStat_TableXactStatus PgStat_TableXactStatus
Datum ssl_version(PG_FUNCTION_ARGS)
Definition: sslinfo.c:54
PGDLLIMPORT bool pgstat_track_counts
Definition: pgstat.c:127
PgStat_Counter n_tuples_updated
Definition: pgstat.h:711
Datum ssl_client_dn(PG_FUNCTION_ARGS)
Definition: sslinfo.c:298
uint64 wal_bytes
Definition: pgstat.h:840
PgStat_Counter m_stream_txns
Definition: pgstat.h:509
void pgstat_report_replslot_drop(const char *slotname)
Definition: pgstat.c:1803
char * pgstat_stat_filename
Definition: pgstat.c:136
PgStat_MsgHdr m_hdr
Definition: pgstat.h:234
PgStat_Counter t_changed_tuples
Definition: pgstat.h:129
struct PgStat_MsgWal PgStat_MsgWal
PgStat_MsgTabstat msg_tabstat
Definition: pgstat.h:661
PgStat_MsgHdr m_hdr
Definition: pgstat.h:287
void pgstat_send_bgwriter(void)
Definition: pgstat.c:4644
struct PgStat_MsgChecksumFailure PgStat_MsgChecksumFailure
ProgressCommandType
Definition: pgstat.h:1107
PgStat_Counter m_checkpoint_sync_time
Definition: pgstat.h:463
PgStat_MsgVacuum msg_vacuum
Definition: pgstat.h:670
Definition: regguts.h:298
PgStat_MsgHdr m_hdr
Definition: pgstat.h:589
PgStat_Counter n_sessions
Definition: pgstat.h:726
PgStat_Counter failed_count
Definition: pgstat.h:807
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2659
PgStat_Counter n_block_write_time
Definition: pgstat.h:725
PgStat_Counter m_buf_written_backend
Definition: pgstat.h:459
PgStat_Counter m_blocks_read
Definition: pgstat.h:489
PgStat_MsgHdr m_hdr
Definition: pgstat.h:406
void pgstat_count_heap_delete(Relation rel)
Definition: pgstat.c:2221
PgStat_Counter tuples_deleted
Definition: pgstat.h:761
struct PgStat_StatTabEntry PgStat_StatTabEntry
PgStat_Counter m_wal_fpi
Definition: pgstat.h:474
PgStat_TableCounts t_counts
Definition: pgstat.h:273
PgStat_Counter flush
Definition: pgstat.h:855
void pgstat_count_slru_flush(int slru_idx)
Definition: pgstat.c:7402
PgStat_Counter inserted_pre_trunc
Definition: pgstat.h:189
PgStat_Counter tuples_updated
Definition: pgstat.h:760
size_t Size
Definition: c.h:528
PgStat_Counter checkpoint_sync_time
Definition: pgstat.h:823
PgStat_Counter m_spill_count
Definition: pgstat.h:507
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1488
void pgstat_report_tempfile(size_t filesize)
Definition: pgstat.c:1756
PgStat_MsgConn msg_conn
Definition: pgstat.h:683
PGDLLIMPORT bool pgstat_track_activities
Definition: pgstat.c:126
struct PgStat_FunctionEntry PgStat_FunctionEntry
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:774
PgStat_Counter maxwritten_clean
Definition: pgstat.h:826
PgStat_Counter n_block_read_time
Definition: pgstat.h:724
PgStat_Counter m_block_read_time
Definition: pgstat.h:292
struct PgStat_MsgFuncstat PgStat_MsgFuncstat
const char * name
Definition: encode.c:515
TimestampTz stat_reset_timestamp
Definition: pgstat.h:830
void pgstat_bestart(void)
Definition: pgstat.c:3145
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:175
struct PgStat_TableStatus PgStat_TableStatus
PgStat_MsgResetreplslotcounter msg_resetreplslotcounter
Definition: pgstat.h:668
struct PgBackendStatus PgBackendStatus
struct PgStat_StatDBEntry PgStat_StatDBEntry
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:779
void pgstat_report_autovac(Oid dboid)
Definition: pgstat.c:1578
int pgstat_slru_index(const char *name)
Definition: pgstat.c:7317
PgStat_Counter updated_pre_trunc
Definition: pgstat.h:190
void pgstat_count_slru_page_hit(int slru_idx)
Definition: pgstat.c:7378
PgStat_MsgHdr m_hdr
Definition: pgstat.h:423
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
Definition: pgstat.c:1722
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:3355
void pgstat_count_heap_update(Relation rel, bool hot)
Definition: pgstat.c:2196
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1906
void pgstat_init_function_usage(struct FunctionCallInfoBaseData *fcinfo, PgStat_FunctionCallUsage *fcu)
PgStat_Counter m_session_time
Definition: pgstat.h:645
TimestampTz cutoff_time
Definition: pgstat.h:261
Datum ssl_cipher(PG_FUNCTION_ARGS)
Definition: sslinfo.c:74
WaitEventIO
Definition: pgstat.h:1025
TimestampTz stat_reset_timestamp
Definition: pgstat.h:811
TimestampTz last_archived_timestamp
Definition: pgstat.h:806
TimestampTz m_start_time
Definition: pgstat.h:395
PgStat_Counter n_deadlocks
Definition: pgstat.h:721
struct PgStat_MsgConn PgStat_MsgConn
struct PgStat_MsgResetslrucounter PgStat_MsgResetslrucounter
#define PG_WAIT_TIMEOUT
Definition: pgstat.h:902
#define PG_WAIT_IPC
Definition: pgstat.h:901
struct PgStat_MsgAutovacStart PgStat_MsgAutovacStart
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1210
PgStat_MsgArchiver msg_archiver
Definition: pgstat.h:672
int st_changecount
Definition: pgstat.h:1200
const char * pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
Definition: pgstat.c:4509
void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
Definition: pgstat.c:1628
PgStat_MsgResetsinglecounter msg_resetsinglecounter
Definition: pgstat.h:666
PgStat_Counter requested_checkpoints
Definition: pgstat.h:821
StatMsgType m_type
Definition: pgstat.h:213
PgStat_MsgHdr m_hdr
Definition: pgstat.h:503
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
Definition: pgstat.c:3500
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid funcid)
Definition: pgstat.c:2742
instr_time save_f_total_time
Definition: pgstat.h:1355
PgStat_MsgResetcounter msg_resetcounter
Definition: pgstat.h:664
BackendState
Definition: pgstat.h:879
void pgstat_reset_all(void)
Definition: pgstat.c:739
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition: pgstat.c:2864
PgStat_Counter m_stream_count
Definition: pgstat.h:510
PgStat_Counter m_blocks_zeroed
Definition: pgstat.h:487
BackendType
Definition: miscadmin.h:311
PgStat_MsgReplSlot msg_replslot
Definition: pgstat.h:682
PgStat_Counter f_numcalls
Definition: pgstat.h:573
struct PgStat_MsgResetcounter PgStat_MsgResetcounter
PgStat_Counter wal_buffers_full
Definition: pgstat.h:841
PgStat_Counter f_self_time
Definition: pgstat.h:794
PgStat_Counter m_dead_tuples
Definition: pgstat.h:430
PgStat_ReplSlotStats * pgstat_fetch_replslot(int *nslots_p)
Definition: pgstat.c:2897
Definition: proc.h:121
PgStat_Counter blocks_fetched
Definition: pgstat.h:769
PgStat_Counter m_truncate
Definition: pgstat.h:493
void AtPrepare_PgStat(void)
Definition: pgstat.c:2507
struct PgStat_BackendFunctionEntry PgStat_BackendFunctionEntry
struct PgStat_MsgHdr PgStat_MsgHdr
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1209
PgStat_MsgInquiry msg_inquiry
Definition: pgstat.h:660
PgStat_Counter truncate
Definition: pgstat.h:856
PgStat_MsgDropdb msg_dropdb
Definition: pgstat.h:663
int m_size
Definition: pgstat.h:214
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1222
PgStat_Single_Reset_Type m_resettype
Definition: pgstat.h:359
void pgstat_initstats(Relation rel)
Definition: pgstat.c:1983
PgStat_Counter m_count
Definition: pgstat.h:644
void pgstat_count_slru_page_zeroed(int slru_idx)
Definition: pgstat.c:7372
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:121
long val
Definition: informix.c:664
void pgstat_reset_shared_counters(const char *)
Definition: pgstat.c:1442
PgStat_Counter spill_count
Definition: pgstat.h:867
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:7220
PgStat_Counter blocks_written
Definition: pgstat.h:853
PgStat_MsgTabpurge msg_tabpurge
Definition: pgstat.h:662
#define PGSTAT_NUM_FUNCPURGE
Definition: pgstat.h:600
PGDLLIMPORT int pgstat_track_activity_query_size
Definition: pgstat.c:129
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1226
PgStat_TableStatus * parent
Definition: pgstat.h:195
PGDLLIMPORT int pgstat_track_functions
Definition: pgstat.c:128
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:131
PgStat_MsgHdr m_hdr
Definition: pgstat.h:440
void PostPrepare_PgStat(void)
Definition: pgstat.c:2556
PgStat_MsgFuncstat msg_funcstat
Definition: pgstat.h:676
struct LocalPgBackendStatus LocalPgBackendStatus
PgStat_Counter m_blocks_hit
Definition: pgstat.h:488
WaitEventActivity
Definition: pgstat.h:913
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:709
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:775
PgStat_MsgHdr m_hdr
Definition: pgstat.h:259
PgStat_Counter m_wal_records
Definition: pgstat.h:473
SessionEndType m_disconnect
Definition: pgstat.h:648
PgStat_Counter n_temp_bytes
Definition: pgstat.h:720
PgStat_Counter stream_txns
Definition: pgstat.h:869