PostgreSQL Source Code  git master
pgstatfuncs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pgstatfuncs.c
4  * Functions for accessing various forms of statistics data
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/utils/adt/pgstatfuncs.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/htup_details.h"
18 #include "access/xlog.h"
19 #include "access/xlogprefetcher.h"
20 #include "catalog/pg_authid.h"
21 #include "catalog/pg_type.h"
22 #include "common/ip.h"
23 #include "funcapi.h"
24 #include "miscadmin.h"
25 #include "pgstat.h"
27 #include "postmaster/postmaster.h"
28 #include "storage/proc.h"
29 #include "storage/procarray.h"
30 #include "utils/acl.h"
31 #include "utils/builtins.h"
32 #include "utils/inet.h"
33 #include "utils/timestamp.h"
34 
35 #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var))))
36 
37 #define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
38 
39 Datum
41 {
42  Oid relid = PG_GETARG_OID(0);
43  int64 result;
44  PgStat_StatTabEntry *tabentry;
45 
46  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
47  result = 0;
48  else
49  result = (int64) (tabentry->numscans);
50 
51  PG_RETURN_INT64(result);
52 }
53 
54 
55 Datum
57 {
58  Oid relid = PG_GETARG_OID(0);
59  int64 result;
60  PgStat_StatTabEntry *tabentry;
61 
62  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
63  result = 0;
64  else
65  result = (int64) (tabentry->tuples_returned);
66 
67  PG_RETURN_INT64(result);
68 }
69 
70 
71 Datum
73 {
74  Oid relid = PG_GETARG_OID(0);
75  int64 result;
76  PgStat_StatTabEntry *tabentry;
77 
78  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
79  result = 0;
80  else
81  result = (int64) (tabentry->tuples_fetched);
82 
83  PG_RETURN_INT64(result);
84 }
85 
86 
87 Datum
89 {
90  Oid relid = PG_GETARG_OID(0);
91  int64 result;
92  PgStat_StatTabEntry *tabentry;
93 
94  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
95  result = 0;
96  else
97  result = (int64) (tabentry->tuples_inserted);
98 
99  PG_RETURN_INT64(result);
100 }
101 
102 
103 Datum
105 {
106  Oid relid = PG_GETARG_OID(0);
107  int64 result;
108  PgStat_StatTabEntry *tabentry;
109 
110  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
111  result = 0;
112  else
113  result = (int64) (tabentry->tuples_updated);
114 
115  PG_RETURN_INT64(result);
116 }
117 
118 
119 Datum
121 {
122  Oid relid = PG_GETARG_OID(0);
123  int64 result;
124  PgStat_StatTabEntry *tabentry;
125 
126  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
127  result = 0;
128  else
129  result = (int64) (tabentry->tuples_deleted);
130 
131  PG_RETURN_INT64(result);
132 }
133 
134 
135 Datum
137 {
138  Oid relid = PG_GETARG_OID(0);
139  int64 result;
140  PgStat_StatTabEntry *tabentry;
141 
142  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
143  result = 0;
144  else
145  result = (int64) (tabentry->tuples_hot_updated);
146 
147  PG_RETURN_INT64(result);
148 }
149 
150 
151 Datum
153 {
154  Oid relid = PG_GETARG_OID(0);
155  int64 result;
156  PgStat_StatTabEntry *tabentry;
157 
158  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
159  result = 0;
160  else
161  result = (int64) (tabentry->n_live_tuples);
162 
163  PG_RETURN_INT64(result);
164 }
165 
166 
167 Datum
169 {
170  Oid relid = PG_GETARG_OID(0);
171  int64 result;
172  PgStat_StatTabEntry *tabentry;
173 
174  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
175  result = 0;
176  else
177  result = (int64) (tabentry->n_dead_tuples);
178 
179  PG_RETURN_INT64(result);
180 }
181 
182 
183 Datum
185 {
186  Oid relid = PG_GETARG_OID(0);
187  int64 result;
188  PgStat_StatTabEntry *tabentry;
189 
190  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
191  result = 0;
192  else
193  result = (int64) (tabentry->changes_since_analyze);
194 
195  PG_RETURN_INT64(result);
196 }
197 
198 
199 Datum
201 {
202  Oid relid = PG_GETARG_OID(0);
203  int64 result;
204  PgStat_StatTabEntry *tabentry;
205 
206  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
207  result = 0;
208  else
209  result = (int64) (tabentry->inserts_since_vacuum);
210 
211  PG_RETURN_INT64(result);
212 }
213 
214 
215 Datum
217 {
218  Oid relid = PG_GETARG_OID(0);
219  int64 result;
220  PgStat_StatTabEntry *tabentry;
221 
222  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
223  result = 0;
224  else
225  result = (int64) (tabentry->blocks_fetched);
226 
227  PG_RETURN_INT64(result);
228 }
229 
230 
231 Datum
233 {
234  Oid relid = PG_GETARG_OID(0);
235  int64 result;
236  PgStat_StatTabEntry *tabentry;
237 
238  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
239  result = 0;
240  else
241  result = (int64) (tabentry->blocks_hit);
242 
243  PG_RETURN_INT64(result);
244 }
245 
246 Datum
248 {
249  Oid relid = PG_GETARG_OID(0);
250  TimestampTz result;
251  PgStat_StatTabEntry *tabentry;
252 
253  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
254  result = 0;
255  else
256  result = tabentry->vacuum_timestamp;
257 
258  if (result == 0)
259  PG_RETURN_NULL();
260  else
261  PG_RETURN_TIMESTAMPTZ(result);
262 }
263 
264 Datum
266 {
267  Oid relid = PG_GETARG_OID(0);
268  TimestampTz result;
269  PgStat_StatTabEntry *tabentry;
270 
271  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
272  result = 0;
273  else
274  result = tabentry->autovac_vacuum_timestamp;
275 
276  if (result == 0)
277  PG_RETURN_NULL();
278  else
279  PG_RETURN_TIMESTAMPTZ(result);
280 }
281 
282 Datum
284 {
285  Oid relid = PG_GETARG_OID(0);
286  TimestampTz result;
287  PgStat_StatTabEntry *tabentry;
288 
289  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
290  result = 0;
291  else
292  result = tabentry->analyze_timestamp;
293 
294  if (result == 0)
295  PG_RETURN_NULL();
296  else
297  PG_RETURN_TIMESTAMPTZ(result);
298 }
299 
300 Datum
302 {
303  Oid relid = PG_GETARG_OID(0);
304  TimestampTz result;
305  PgStat_StatTabEntry *tabentry;
306 
307  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
308  result = 0;
309  else
310  result = tabentry->autovac_analyze_timestamp;
311 
312  if (result == 0)
313  PG_RETURN_NULL();
314  else
315  PG_RETURN_TIMESTAMPTZ(result);
316 }
317 
318 Datum
320 {
321  Oid relid = PG_GETARG_OID(0);
322  int64 result;
323  PgStat_StatTabEntry *tabentry;
324 
325  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
326  result = 0;
327  else
328  result = (int64) (tabentry->vacuum_count);
329 
330  PG_RETURN_INT64(result);
331 }
332 
333 Datum
335 {
336  Oid relid = PG_GETARG_OID(0);
337  int64 result;
338  PgStat_StatTabEntry *tabentry;
339 
340  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
341  result = 0;
342  else
343  result = (int64) (tabentry->autovac_vacuum_count);
344 
345  PG_RETURN_INT64(result);
346 }
347 
348 Datum
350 {
351  Oid relid = PG_GETARG_OID(0);
352  int64 result;
353  PgStat_StatTabEntry *tabentry;
354 
355  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
356  result = 0;
357  else
358  result = (int64) (tabentry->analyze_count);
359 
360  PG_RETURN_INT64(result);
361 }
362 
363 Datum
365 {
366  Oid relid = PG_GETARG_OID(0);
367  int64 result;
368  PgStat_StatTabEntry *tabentry;
369 
370  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
371  result = 0;
372  else
373  result = (int64) (tabentry->autovac_analyze_count);
374 
375  PG_RETURN_INT64(result);
376 }
377 
378 Datum
380 {
381  Oid funcid = PG_GETARG_OID(0);
382  PgStat_StatFuncEntry *funcentry;
383 
384  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
385  PG_RETURN_NULL();
386  PG_RETURN_INT64(funcentry->f_numcalls);
387 }
388 
389 Datum
391 {
392  Oid funcid = PG_GETARG_OID(0);
393  PgStat_StatFuncEntry *funcentry;
394 
395  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
396  PG_RETURN_NULL();
397  /* convert counter from microsec to millisec for display */
398  PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
399 }
400 
401 Datum
403 {
404  Oid funcid = PG_GETARG_OID(0);
405  PgStat_StatFuncEntry *funcentry;
406 
407  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
408  PG_RETURN_NULL();
409  /* convert counter from microsec to millisec for display */
410  PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
411 }
412 
413 Datum
415 {
416  FuncCallContext *funcctx;
417  int *fctx;
418  int32 result;
419 
420  /* stuff done only on the first call of the function */
421  if (SRF_IS_FIRSTCALL())
422  {
423  /* create a function context for cross-call persistence */
424  funcctx = SRF_FIRSTCALL_INIT();
425 
427  2 * sizeof(int));
428  funcctx->user_fctx = fctx;
429 
430  fctx[0] = 0;
431  fctx[1] = pgstat_fetch_stat_numbackends();
432  }
433 
434  /* stuff done on every call of the function */
435  funcctx = SRF_PERCALL_SETUP();
436  fctx = funcctx->user_fctx;
437 
438  fctx[0] += 1;
439  result = fctx[0];
440 
441  if (result <= fctx[1])
442  {
443  /* do when there is more left to send */
444  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
445  }
446  else
447  {
448  /* do when there is no more left */
449  SRF_RETURN_DONE(funcctx);
450  }
451 }
452 
453 /*
454  * Returns command progress information for the named command.
455  */
456 Datum
458 {
459 #define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
460  int num_backends = pgstat_fetch_stat_numbackends();
461  int curr_backend;
462  char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
463  ProgressCommandType cmdtype;
464  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
465 
466  /* Translate command name into command type code. */
467  if (pg_strcasecmp(cmd, "VACUUM") == 0)
468  cmdtype = PROGRESS_COMMAND_VACUUM;
469  else if (pg_strcasecmp(cmd, "ANALYZE") == 0)
470  cmdtype = PROGRESS_COMMAND_ANALYZE;
471  else if (pg_strcasecmp(cmd, "CLUSTER") == 0)
472  cmdtype = PROGRESS_COMMAND_CLUSTER;
473  else if (pg_strcasecmp(cmd, "CREATE INDEX") == 0)
475  else if (pg_strcasecmp(cmd, "BASEBACKUP") == 0)
476  cmdtype = PROGRESS_COMMAND_BASEBACKUP;
477  else if (pg_strcasecmp(cmd, "COPY") == 0)
478  cmdtype = PROGRESS_COMMAND_COPY;
479  else
480  ereport(ERROR,
481  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
482  errmsg("invalid command name: \"%s\"", cmd)));
483 
484  SetSingleFuncCall(fcinfo, 0);
485 
486  /* 1-based index */
487  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
488  {
489  LocalPgBackendStatus *local_beentry;
490  PgBackendStatus *beentry;
492  bool nulls[PG_STAT_GET_PROGRESS_COLS];
493  int i;
494 
495  MemSet(values, 0, sizeof(values));
496  MemSet(nulls, 0, sizeof(nulls));
497 
498  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
499 
500  if (!local_beentry)
501  continue;
502 
503  beentry = &local_beentry->backendStatus;
504 
505  /*
506  * Report values for only those backends which are running the given
507  * command.
508  */
509  if (!beentry || beentry->st_progress_command != cmdtype)
510  continue;
511 
512  /* Value available to all callers */
513  values[0] = Int32GetDatum(beentry->st_procpid);
514  values[1] = ObjectIdGetDatum(beentry->st_databaseid);
515 
516  /* show rest of the values including relid only to role members */
517  if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
518  {
520  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
521  values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
522  }
523  else
524  {
525  nulls[2] = true;
526  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
527  nulls[i + 3] = true;
528  }
529 
530  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
531  }
532 
533  return (Datum) 0;
534 }
535 
536 /*
537  * Returns activity of PG backends.
538  */
539 Datum
541 {
542 #define PG_STAT_GET_ACTIVITY_COLS 30
543  int num_backends = pgstat_fetch_stat_numbackends();
544  int curr_backend;
545  int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
546  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
547 
548  SetSingleFuncCall(fcinfo, 0);
549 
550  /* 1-based index */
551  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
552  {
553  /* for each row */
555  bool nulls[PG_STAT_GET_ACTIVITY_COLS];
556  LocalPgBackendStatus *local_beentry;
557  PgBackendStatus *beentry;
558  PGPROC *proc;
559  const char *wait_event_type = NULL;
560  const char *wait_event = NULL;
561 
562  MemSet(values, 0, sizeof(values));
563  MemSet(nulls, 0, sizeof(nulls));
564 
565  /* Get the next one in the list */
566  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
567  if (!local_beentry)
568  {
569  int i;
570 
571  /* Ignore missing entries if looking for specific PID */
572  if (pid != -1)
573  continue;
574 
575  for (i = 0; i < lengthof(nulls); i++)
576  nulls[i] = true;
577 
578  nulls[5] = false;
579  values[5] = CStringGetTextDatum("<backend information not available>");
580 
581  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
582  continue;
583  }
584 
585  beentry = &local_beentry->backendStatus;
586 
587  /* If looking for specific PID, ignore all the others */
588  if (pid != -1 && beentry->st_procpid != pid)
589  continue;
590 
591  /* Values available to all callers */
592  if (beentry->st_databaseid != InvalidOid)
593  values[0] = ObjectIdGetDatum(beentry->st_databaseid);
594  else
595  nulls[0] = true;
596 
597  values[1] = Int32GetDatum(beentry->st_procpid);
598 
599  if (beentry->st_userid != InvalidOid)
600  values[2] = ObjectIdGetDatum(beentry->st_userid);
601  else
602  nulls[2] = true;
603 
604  if (beentry->st_appname)
605  values[3] = CStringGetTextDatum(beentry->st_appname);
606  else
607  nulls[3] = true;
608 
609  if (TransactionIdIsValid(local_beentry->backend_xid))
610  values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
611  else
612  nulls[15] = true;
613 
614  if (TransactionIdIsValid(local_beentry->backend_xmin))
615  values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
616  else
617  nulls[16] = true;
618 
619  /* Values only available to role member or pg_read_all_stats */
620  if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
621  {
622  SockAddr zero_clientaddr;
623  char *clipped_activity;
624 
625  switch (beentry->st_state)
626  {
627  case STATE_IDLE:
628  values[4] = CStringGetTextDatum("idle");
629  break;
630  case STATE_RUNNING:
631  values[4] = CStringGetTextDatum("active");
632  break;
634  values[4] = CStringGetTextDatum("idle in transaction");
635  break;
636  case STATE_FASTPATH:
637  values[4] = CStringGetTextDatum("fastpath function call");
638  break;
640  values[4] = CStringGetTextDatum("idle in transaction (aborted)");
641  break;
642  case STATE_DISABLED:
643  values[4] = CStringGetTextDatum("disabled");
644  break;
645  case STATE_UNDEFINED:
646  nulls[4] = true;
647  break;
648  }
649 
650  clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
651  values[5] = CStringGetTextDatum(clipped_activity);
652  pfree(clipped_activity);
653 
654  /* leader_pid */
655  nulls[28] = true;
656 
657  proc = BackendPidGetProc(beentry->st_procpid);
658 
659  if (proc == NULL && (beentry->st_backendType != B_BACKEND))
660  {
661  /*
662  * For an auxiliary process, retrieve process info from
663  * AuxiliaryProcs stored in shared-memory.
664  */
665  proc = AuxiliaryPidGetProc(beentry->st_procpid);
666  }
667 
668  /*
669  * If a PGPROC entry was retrieved, display wait events and lock
670  * group leader information if any. To avoid extra overhead, no
671  * extra lock is being held, so there is no guarantee of
672  * consistency across multiple rows.
673  */
674  if (proc != NULL)
675  {
676  uint32 raw_wait_event;
677  PGPROC *leader;
678 
679  raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
680  wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
681  wait_event = pgstat_get_wait_event(raw_wait_event);
682 
683  leader = proc->lockGroupLeader;
684 
685  /*
686  * Show the leader only for active parallel workers. This
687  * leaves the field as NULL for the leader of a parallel
688  * group.
689  */
690  if (leader && leader->pid != beentry->st_procpid)
691  {
692  values[28] = Int32GetDatum(leader->pid);
693  nulls[28] = false;
694  }
695  }
696 
697  if (wait_event_type)
698  values[6] = CStringGetTextDatum(wait_event_type);
699  else
700  nulls[6] = true;
701 
702  if (wait_event)
703  values[7] = CStringGetTextDatum(wait_event);
704  else
705  nulls[7] = true;
706 
707  /*
708  * Don't expose transaction time for walsenders; it confuses
709  * monitoring, particularly because we don't keep the time up-to-
710  * date.
711  */
712  if (beentry->st_xact_start_timestamp != 0 &&
713  beentry->st_backendType != B_WAL_SENDER)
715  else
716  nulls[8] = true;
717 
718  if (beentry->st_activity_start_timestamp != 0)
720  else
721  nulls[9] = true;
722 
723  if (beentry->st_proc_start_timestamp != 0)
725  else
726  nulls[10] = true;
727 
728  if (beentry->st_state_start_timestamp != 0)
730  else
731  nulls[11] = true;
732 
733  /* A zeroed client addr means we don't know */
734  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
735  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
736  sizeof(zero_clientaddr)) == 0)
737  {
738  nulls[12] = true;
739  nulls[13] = true;
740  nulls[14] = true;
741  }
742  else
743  {
744  if (beentry->st_clientaddr.addr.ss_family == AF_INET
745 #ifdef HAVE_IPV6
746  || beentry->st_clientaddr.addr.ss_family == AF_INET6
747 #endif
748  )
749  {
750  char remote_host[NI_MAXHOST];
751  char remote_port[NI_MAXSERV];
752  int ret;
753 
754  remote_host[0] = '\0';
755  remote_port[0] = '\0';
756  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
757  beentry->st_clientaddr.salen,
758  remote_host, sizeof(remote_host),
759  remote_port, sizeof(remote_port),
761  if (ret == 0)
762  {
763  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
765  CStringGetDatum(remote_host));
766  if (beentry->st_clienthostname &&
767  beentry->st_clienthostname[0])
769  else
770  nulls[13] = true;
771  values[14] = Int32GetDatum(atoi(remote_port));
772  }
773  else
774  {
775  nulls[12] = true;
776  nulls[13] = true;
777  nulls[14] = true;
778  }
779  }
780  else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
781  {
782  /*
783  * Unix sockets always reports NULL for host and -1 for
784  * port, so it's possible to tell the difference to
785  * connections we have no permissions to view, or with
786  * errors.
787  */
788  nulls[12] = true;
789  nulls[13] = true;
790  values[14] = Int32GetDatum(-1);
791  }
792  else
793  {
794  /* Unknown address type, should never happen */
795  nulls[12] = true;
796  nulls[13] = true;
797  nulls[14] = true;
798  }
799  }
800  /* Add backend type */
801  if (beentry->st_backendType == B_BG_WORKER)
802  {
803  const char *bgw_type;
804 
805  bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
806  if (bgw_type)
807  values[17] = CStringGetTextDatum(bgw_type);
808  else
809  nulls[17] = true;
810  }
811  else
812  values[17] =
814 
815  /* SSL information */
816  if (beentry->st_ssl)
817  {
818  values[18] = BoolGetDatum(true); /* ssl */
821  values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
822 
823  if (beentry->st_sslstatus->ssl_client_dn[0])
825  else
826  nulls[22] = true;
827 
828  if (beentry->st_sslstatus->ssl_client_serial[0])
832  Int32GetDatum(-1));
833  else
834  nulls[23] = true;
835 
836  if (beentry->st_sslstatus->ssl_issuer_dn[0])
838  else
839  nulls[24] = true;
840  }
841  else
842  {
843  values[18] = BoolGetDatum(false); /* ssl */
844  nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = true;
845  }
846 
847  /* GSSAPI information */
848  if (beentry->st_gss)
849  {
850  values[25] = BoolGetDatum(beentry->st_gssstatus->gss_auth); /* gss_auth */
852  values[27] = BoolGetDatum(beentry->st_gssstatus->gss_enc); /* GSS Encryption in use */
853  }
854  else
855  {
856  values[25] = BoolGetDatum(false); /* gss_auth */
857  nulls[26] = true; /* No GSS principal */
858  values[27] = BoolGetDatum(false); /* GSS Encryption not in
859  * use */
860  }
861  if (beentry->st_query_id == 0)
862  nulls[29] = true;
863  else
864  values[29] = UInt64GetDatum(beentry->st_query_id);
865  }
866  else
867  {
868  /* No permissions to view data about this session */
869  values[5] = CStringGetTextDatum("<insufficient privilege>");
870  nulls[4] = true;
871  nulls[6] = true;
872  nulls[7] = true;
873  nulls[8] = true;
874  nulls[9] = true;
875  nulls[10] = true;
876  nulls[11] = true;
877  nulls[12] = true;
878  nulls[13] = true;
879  nulls[14] = true;
880  nulls[17] = true;
881  nulls[18] = true;
882  nulls[19] = true;
883  nulls[20] = true;
884  nulls[21] = true;
885  nulls[22] = true;
886  nulls[23] = true;
887  nulls[24] = true;
888  nulls[25] = true;
889  nulls[26] = true;
890  nulls[27] = true;
891  nulls[28] = true;
892  nulls[29] = true;
893  }
894 
895  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
896 
897  /* If only a single backend was requested, and we found it, break. */
898  if (pid != -1)
899  break;
900  }
901 
902  return (Datum) 0;
903 }
904 
905 
906 Datum
908 {
910 }
911 
912 
913 Datum
915 {
916  int32 beid = PG_GETARG_INT32(0);
917  PgBackendStatus *beentry;
918 
919  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
920  PG_RETURN_NULL();
921 
922  PG_RETURN_INT32(beentry->st_procpid);
923 }
924 
925 
926 Datum
928 {
929  int32 beid = PG_GETARG_INT32(0);
930  PgBackendStatus *beentry;
931 
932  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
933  PG_RETURN_NULL();
934 
935  PG_RETURN_OID(beentry->st_databaseid);
936 }
937 
938 
939 Datum
941 {
942  int32 beid = PG_GETARG_INT32(0);
943  PgBackendStatus *beentry;
944 
945  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
946  PG_RETURN_NULL();
947 
948  PG_RETURN_OID(beentry->st_userid);
949 }
950 
951 
952 Datum
954 {
955  int32 beid = PG_GETARG_INT32(0);
956  PgBackendStatus *beentry;
957  const char *activity;
958  char *clipped_activity;
959  text *ret;
960 
961  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
962  activity = "<backend information not available>";
963  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
964  activity = "<insufficient privilege>";
965  else if (*(beentry->st_activity_raw) == '\0')
966  activity = "<command string not enabled>";
967  else
968  activity = beentry->st_activity_raw;
969 
970  clipped_activity = pgstat_clip_activity(activity);
971  ret = cstring_to_text(activity);
972  pfree(clipped_activity);
973 
974  PG_RETURN_TEXT_P(ret);
975 }
976 
977 Datum
979 {
980  int32 beid = PG_GETARG_INT32(0);
981  PgBackendStatus *beentry;
982  PGPROC *proc;
983  const char *wait_event_type = NULL;
984 
985  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
986  wait_event_type = "<backend information not available>";
987  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
988  wait_event_type = "<insufficient privilege>";
989  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
990  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
991 
992  if (!wait_event_type)
993  PG_RETURN_NULL();
994 
995  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
996 }
997 
998 Datum
1000 {
1001  int32 beid = PG_GETARG_INT32(0);
1002  PgBackendStatus *beentry;
1003  PGPROC *proc;
1004  const char *wait_event = NULL;
1005 
1006  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1007  wait_event = "<backend information not available>";
1008  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1009  wait_event = "<insufficient privilege>";
1010  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1011  wait_event = pgstat_get_wait_event(proc->wait_event_info);
1012 
1013  if (!wait_event)
1014  PG_RETURN_NULL();
1015 
1016  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
1017 }
1018 
1019 
1020 Datum
1022 {
1023  int32 beid = PG_GETARG_INT32(0);
1024  TimestampTz result;
1025  PgBackendStatus *beentry;
1026 
1027  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1028  PG_RETURN_NULL();
1029 
1030  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1031  PG_RETURN_NULL();
1032 
1033  result = beentry->st_activity_start_timestamp;
1034 
1035  /*
1036  * No time recorded for start of current query -- this is the case if the
1037  * user hasn't enabled query-level stats collection.
1038  */
1039  if (result == 0)
1040  PG_RETURN_NULL();
1041 
1042  PG_RETURN_TIMESTAMPTZ(result);
1043 }
1044 
1045 
1046 Datum
1048 {
1049  int32 beid = PG_GETARG_INT32(0);
1050  TimestampTz result;
1051  PgBackendStatus *beentry;
1052 
1053  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1054  PG_RETURN_NULL();
1055 
1056  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1057  PG_RETURN_NULL();
1058 
1059  result = beentry->st_xact_start_timestamp;
1060 
1061  if (result == 0) /* not in a transaction */
1062  PG_RETURN_NULL();
1063 
1064  PG_RETURN_TIMESTAMPTZ(result);
1065 }
1066 
1067 
1068 Datum
1070 {
1071  int32 beid = PG_GETARG_INT32(0);
1072  TimestampTz result;
1073  PgBackendStatus *beentry;
1074 
1075  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1076  PG_RETURN_NULL();
1077 
1078  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1079  PG_RETURN_NULL();
1080 
1081  result = beentry->st_proc_start_timestamp;
1082 
1083  if (result == 0) /* probably can't happen? */
1084  PG_RETURN_NULL();
1085 
1086  PG_RETURN_TIMESTAMPTZ(result);
1087 }
1088 
1089 
1090 Datum
1092 {
1093  int32 beid = PG_GETARG_INT32(0);
1094  PgBackendStatus *beentry;
1095  SockAddr zero_clientaddr;
1096  char remote_host[NI_MAXHOST];
1097  int ret;
1098 
1099  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1100  PG_RETURN_NULL();
1101 
1102  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1103  PG_RETURN_NULL();
1104 
1105  /* A zeroed client addr means we don't know */
1106  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1107  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1108  sizeof(zero_clientaddr)) == 0)
1109  PG_RETURN_NULL();
1110 
1111  switch (beentry->st_clientaddr.addr.ss_family)
1112  {
1113  case AF_INET:
1114 #ifdef HAVE_IPV6
1115  case AF_INET6:
1116 #endif
1117  break;
1118  default:
1119  PG_RETURN_NULL();
1120  }
1121 
1122  remote_host[0] = '\0';
1123  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1124  beentry->st_clientaddr.salen,
1125  remote_host, sizeof(remote_host),
1126  NULL, 0,
1128  if (ret != 0)
1129  PG_RETURN_NULL();
1130 
1131  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1132 
1134  CStringGetDatum(remote_host)));
1135 }
1136 
1137 Datum
1139 {
1140  int32 beid = PG_GETARG_INT32(0);
1141  PgBackendStatus *beentry;
1142  SockAddr zero_clientaddr;
1143  char remote_port[NI_MAXSERV];
1144  int ret;
1145 
1146  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1147  PG_RETURN_NULL();
1148 
1149  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1150  PG_RETURN_NULL();
1151 
1152  /* A zeroed client addr means we don't know */
1153  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1154  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1155  sizeof(zero_clientaddr)) == 0)
1156  PG_RETURN_NULL();
1157 
1158  switch (beentry->st_clientaddr.addr.ss_family)
1159  {
1160  case AF_INET:
1161 #ifdef HAVE_IPV6
1162  case AF_INET6:
1163 #endif
1164  break;
1165  case AF_UNIX:
1166  PG_RETURN_INT32(-1);
1167  default:
1168  PG_RETURN_NULL();
1169  }
1170 
1171  remote_port[0] = '\0';
1172  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1173  beentry->st_clientaddr.salen,
1174  NULL, 0,
1175  remote_port, sizeof(remote_port),
1177  if (ret != 0)
1178  PG_RETURN_NULL();
1179 
1181  CStringGetDatum(remote_port)));
1182 }
1183 
1184 
1185 Datum
1187 {
1188  Oid dbid = PG_GETARG_OID(0);
1189  int32 result;
1190  int tot_backends = pgstat_fetch_stat_numbackends();
1191  int beid;
1192 
1193  result = 0;
1194  for (beid = 1; beid <= tot_backends; beid++)
1195  {
1196  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1197 
1198  if (beentry && beentry->st_databaseid == dbid)
1199  result++;
1200  }
1201 
1202  PG_RETURN_INT32(result);
1203 }
1204 
1205 
1206 Datum
1208 {
1209  Oid dbid = PG_GETARG_OID(0);
1210  int64 result;
1211  PgStat_StatDBEntry *dbentry;
1212 
1213  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1214  result = 0;
1215  else
1216  result = (int64) (dbentry->n_xact_commit);
1217 
1218  PG_RETURN_INT64(result);
1219 }
1220 
1221 
1222 Datum
1224 {
1225  Oid dbid = PG_GETARG_OID(0);
1226  int64 result;
1227  PgStat_StatDBEntry *dbentry;
1228 
1229  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1230  result = 0;
1231  else
1232  result = (int64) (dbentry->n_xact_rollback);
1233 
1234  PG_RETURN_INT64(result);
1235 }
1236 
1237 
1238 Datum
1240 {
1241  Oid dbid = PG_GETARG_OID(0);
1242  int64 result;
1243  PgStat_StatDBEntry *dbentry;
1244 
1245  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1246  result = 0;
1247  else
1248  result = (int64) (dbentry->n_blocks_fetched);
1249 
1250  PG_RETURN_INT64(result);
1251 }
1252 
1253 
1254 Datum
1256 {
1257  Oid dbid = PG_GETARG_OID(0);
1258  int64 result;
1259  PgStat_StatDBEntry *dbentry;
1260 
1261  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1262  result = 0;
1263  else
1264  result = (int64) (dbentry->n_blocks_hit);
1265 
1266  PG_RETURN_INT64(result);
1267 }
1268 
1269 
1270 Datum
1272 {
1273  Oid dbid = PG_GETARG_OID(0);
1274  int64 result;
1275  PgStat_StatDBEntry *dbentry;
1276 
1277  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1278  result = 0;
1279  else
1280  result = (int64) (dbentry->n_tuples_returned);
1281 
1282  PG_RETURN_INT64(result);
1283 }
1284 
1285 
1286 Datum
1288 {
1289  Oid dbid = PG_GETARG_OID(0);
1290  int64 result;
1291  PgStat_StatDBEntry *dbentry;
1292 
1293  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1294  result = 0;
1295  else
1296  result = (int64) (dbentry->n_tuples_fetched);
1297 
1298  PG_RETURN_INT64(result);
1299 }
1300 
1301 
1302 Datum
1304 {
1305  Oid dbid = PG_GETARG_OID(0);
1306  int64 result;
1307  PgStat_StatDBEntry *dbentry;
1308 
1309  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1310  result = 0;
1311  else
1312  result = (int64) (dbentry->n_tuples_inserted);
1313 
1314  PG_RETURN_INT64(result);
1315 }
1316 
1317 
1318 Datum
1320 {
1321  Oid dbid = PG_GETARG_OID(0);
1322  int64 result;
1323  PgStat_StatDBEntry *dbentry;
1324 
1325  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1326  result = 0;
1327  else
1328  result = (int64) (dbentry->n_tuples_updated);
1329 
1330  PG_RETURN_INT64(result);
1331 }
1332 
1333 
1334 Datum
1336 {
1337  Oid dbid = PG_GETARG_OID(0);
1338  int64 result;
1339  PgStat_StatDBEntry *dbentry;
1340 
1341  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1342  result = 0;
1343  else
1344  result = (int64) (dbentry->n_tuples_deleted);
1345 
1346  PG_RETURN_INT64(result);
1347 }
1348 
1349 Datum
1351 {
1352  Oid dbid = PG_GETARG_OID(0);
1353  TimestampTz result;
1354  PgStat_StatDBEntry *dbentry;
1355 
1356  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1357  result = 0;
1358  else
1359  result = dbentry->stat_reset_timestamp;
1360 
1361  if (result == 0)
1362  PG_RETURN_NULL();
1363  else
1364  PG_RETURN_TIMESTAMPTZ(result);
1365 }
1366 
1367 Datum
1369 {
1370  Oid dbid = PG_GETARG_OID(0);
1371  int64 result;
1372  PgStat_StatDBEntry *dbentry;
1373 
1374  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1375  result = 0;
1376  else
1377  result = dbentry->n_temp_files;
1378 
1379  PG_RETURN_INT64(result);
1380 }
1381 
1382 
1383 Datum
1385 {
1386  Oid dbid = PG_GETARG_OID(0);
1387  int64 result;
1388  PgStat_StatDBEntry *dbentry;
1389 
1390  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1391  result = 0;
1392  else
1393  result = dbentry->n_temp_bytes;
1394 
1395  PG_RETURN_INT64(result);
1396 }
1397 
1398 Datum
1400 {
1401  Oid dbid = PG_GETARG_OID(0);
1402  int64 result;
1403  PgStat_StatDBEntry *dbentry;
1404 
1405  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1406  result = 0;
1407  else
1408  result = (int64) (dbentry->n_conflict_tablespace);
1409 
1410  PG_RETURN_INT64(result);
1411 }
1412 
1413 Datum
1415 {
1416  Oid dbid = PG_GETARG_OID(0);
1417  int64 result;
1418  PgStat_StatDBEntry *dbentry;
1419 
1420  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1421  result = 0;
1422  else
1423  result = (int64) (dbentry->n_conflict_lock);
1424 
1425  PG_RETURN_INT64(result);
1426 }
1427 
1428 Datum
1430 {
1431  Oid dbid = PG_GETARG_OID(0);
1432  int64 result;
1433  PgStat_StatDBEntry *dbentry;
1434 
1435  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1436  result = 0;
1437  else
1438  result = (int64) (dbentry->n_conflict_snapshot);
1439 
1440  PG_RETURN_INT64(result);
1441 }
1442 
1443 Datum
1445 {
1446  Oid dbid = PG_GETARG_OID(0);
1447  int64 result;
1448  PgStat_StatDBEntry *dbentry;
1449 
1450  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1451  result = 0;
1452  else
1453  result = (int64) (dbentry->n_conflict_bufferpin);
1454 
1455  PG_RETURN_INT64(result);
1456 }
1457 
1458 Datum
1460 {
1461  Oid dbid = PG_GETARG_OID(0);
1462  int64 result;
1463  PgStat_StatDBEntry *dbentry;
1464 
1465  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1466  result = 0;
1467  else
1468  result = (int64) (dbentry->n_conflict_startup_deadlock);
1469 
1470  PG_RETURN_INT64(result);
1471 }
1472 
1473 Datum
1475 {
1476  Oid dbid = PG_GETARG_OID(0);
1477  int64 result;
1478  PgStat_StatDBEntry *dbentry;
1479 
1480  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1481  result = 0;
1482  else
1483  result = (int64) (dbentry->n_conflict_tablespace +
1484  dbentry->n_conflict_lock +
1485  dbentry->n_conflict_snapshot +
1486  dbentry->n_conflict_bufferpin +
1487  dbentry->n_conflict_startup_deadlock);
1488 
1489  PG_RETURN_INT64(result);
1490 }
1491 
1492 Datum
1494 {
1495  Oid dbid = PG_GETARG_OID(0);
1496  int64 result;
1497  PgStat_StatDBEntry *dbentry;
1498 
1499  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1500  result = 0;
1501  else
1502  result = (int64) (dbentry->n_deadlocks);
1503 
1504  PG_RETURN_INT64(result);
1505 }
1506 
1507 Datum
1509 {
1510  Oid dbid = PG_GETARG_OID(0);
1511  int64 result;
1512  PgStat_StatDBEntry *dbentry;
1513 
1514  if (!DataChecksumsEnabled())
1515  PG_RETURN_NULL();
1516 
1517  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1518  result = 0;
1519  else
1520  result = (int64) (dbentry->n_checksum_failures);
1521 
1522  PG_RETURN_INT64(result);
1523 }
1524 
1525 Datum
1527 {
1528  Oid dbid = PG_GETARG_OID(0);
1529  TimestampTz result;
1530  PgStat_StatDBEntry *dbentry;
1531 
1532  if (!DataChecksumsEnabled())
1533  PG_RETURN_NULL();
1534 
1535  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1536  result = 0;
1537  else
1538  result = dbentry->last_checksum_failure;
1539 
1540  if (result == 0)
1541  PG_RETURN_NULL();
1542  else
1543  PG_RETURN_TIMESTAMPTZ(result);
1544 }
1545 
1546 Datum
1548 {
1549  Oid dbid = PG_GETARG_OID(0);
1550  double result;
1551  PgStat_StatDBEntry *dbentry;
1552 
1553  /* convert counter from microsec to millisec for display */
1554  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1555  result = 0;
1556  else
1557  result = ((double) dbentry->n_block_read_time) / 1000.0;
1558 
1559  PG_RETURN_FLOAT8(result);
1560 }
1561 
1562 Datum
1564 {
1565  Oid dbid = PG_GETARG_OID(0);
1566  double result;
1567  PgStat_StatDBEntry *dbentry;
1568 
1569  /* convert counter from microsec to millisec for display */
1570  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1571  result = 0;
1572  else
1573  result = ((double) dbentry->n_block_write_time) / 1000.0;
1574 
1575  PG_RETURN_FLOAT8(result);
1576 }
1577 
1578 Datum
1580 {
1581  Oid dbid = PG_GETARG_OID(0);
1582  double result = 0.0;
1583  PgStat_StatDBEntry *dbentry;
1584 
1585  /* convert counter from microsec to millisec for display */
1586  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1587  result = ((double) dbentry->total_session_time) / 1000.0;
1588 
1589  PG_RETURN_FLOAT8(result);
1590 }
1591 
1592 Datum
1594 {
1595  Oid dbid = PG_GETARG_OID(0);
1596  double result = 0.0;
1597  PgStat_StatDBEntry *dbentry;
1598 
1599  /* convert counter from microsec to millisec for display */
1600  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1601  result = ((double) dbentry->total_active_time) / 1000.0;
1602 
1603  PG_RETURN_FLOAT8(result);
1604 }
1605 
1606 Datum
1608 {
1609  Oid dbid = PG_GETARG_OID(0);
1610  double result = 0.0;
1611  PgStat_StatDBEntry *dbentry;
1612 
1613  /* convert counter from microsec to millisec for display */
1614  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1615  result = ((double) dbentry->total_idle_in_xact_time) / 1000.0;
1616 
1617  PG_RETURN_FLOAT8(result);
1618 }
1619 
1620 Datum
1622 {
1623  Oid dbid = PG_GETARG_OID(0);
1624  int64 result = 0;
1625  PgStat_StatDBEntry *dbentry;
1626 
1627  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1628  result = (int64) (dbentry->n_sessions);
1629 
1630  PG_RETURN_INT64(result);
1631 }
1632 
1633 Datum
1635 {
1636  Oid dbid = PG_GETARG_OID(0);
1637  int64 result = 0;
1638  PgStat_StatDBEntry *dbentry;
1639 
1640  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1641  result = (int64) (dbentry->n_sessions_abandoned);
1642 
1643  PG_RETURN_INT64(result);
1644 }
1645 
1646 Datum
1648 {
1649  Oid dbid = PG_GETARG_OID(0);
1650  int64 result = 0;
1651  PgStat_StatDBEntry *dbentry;
1652 
1653  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1654  result = (int64) (dbentry->n_sessions_fatal);
1655 
1656  PG_RETURN_INT64(result);
1657 }
1658 
1659 Datum
1661 {
1662  Oid dbid = PG_GETARG_OID(0);
1663  int64 result = 0;
1664  PgStat_StatDBEntry *dbentry;
1665 
1666  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1667  result = (int64) (dbentry->n_sessions_killed);
1668 
1669  PG_RETURN_INT64(result);
1670 }
1671 
1672 Datum
1674 {
1675  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->timed_checkpoints);
1676 }
1677 
1678 Datum
1680 {
1681  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->requested_checkpoints);
1682 }
1683 
1684 Datum
1686 {
1687  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buf_written_checkpoints);
1688 }
1689 
1690 Datum
1692 {
1693  PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1694 }
1695 
1696 Datum
1698 {
1699  PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
1700 }
1701 
1702 Datum
1704 {
1705  /* time is already in msec, just convert to double for presentation */
1706  PG_RETURN_FLOAT8((double)
1707  pgstat_fetch_stat_checkpointer()->checkpoint_write_time);
1708 }
1709 
1710 Datum
1712 {
1713  /* time is already in msec, just convert to double for presentation */
1714  PG_RETURN_FLOAT8((double)
1715  pgstat_fetch_stat_checkpointer()->checkpoint_sync_time);
1716 }
1717 
1718 Datum
1720 {
1721  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
1722 }
1723 
1724 Datum
1726 {
1727  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buf_written_backend);
1728 }
1729 
1730 Datum
1732 {
1733  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buf_fsync_backend);
1734 }
1735 
1736 Datum
1738 {
1740 }
1741 
1742 /*
1743  * Returns statistics of WAL activity
1744  */
1745 Datum
1747 {
1748 #define PG_STAT_GET_WAL_COLS 9
1749  TupleDesc tupdesc;
1751  bool nulls[PG_STAT_GET_WAL_COLS];
1752  char buf[256];
1753  PgStat_WalStats *wal_stats;
1754 
1755  /* Initialise values and NULL flags arrays */
1756  MemSet(values, 0, sizeof(values));
1757  MemSet(nulls, 0, sizeof(nulls));
1758 
1759  /* Initialise attributes information in the tuple descriptor */
1761  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1762  INT8OID, -1, 0);
1763  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1764  INT8OID, -1, 0);
1765  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1766  NUMERICOID, -1, 0);
1767  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_buffers_full",
1768  INT8OID, -1, 0);
1769  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_write",
1770  INT8OID, -1, 0);
1771  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "wal_sync",
1772  INT8OID, -1, 0);
1773  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "wal_write_time",
1774  FLOAT8OID, -1, 0);
1775  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "wal_sync_time",
1776  FLOAT8OID, -1, 0);
1777  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "stats_reset",
1778  TIMESTAMPTZOID, -1, 0);
1779 
1780  BlessTupleDesc(tupdesc);
1781 
1782  /* Get statistics about WAL activity */
1783  wal_stats = pgstat_fetch_stat_wal();
1784 
1785  /* Fill values and NULLs */
1786  values[0] = Int64GetDatum(wal_stats->wal_records);
1787  values[1] = Int64GetDatum(wal_stats->wal_fpi);
1788 
1789  /* Convert to numeric. */
1790  snprintf(buf, sizeof buf, UINT64_FORMAT, wal_stats->wal_bytes);
1793  ObjectIdGetDatum(0),
1794  Int32GetDatum(-1));
1795 
1796  values[3] = Int64GetDatum(wal_stats->wal_buffers_full);
1797  values[4] = Int64GetDatum(wal_stats->wal_write);
1798  values[5] = Int64GetDatum(wal_stats->wal_sync);
1799 
1800  /* Convert counters from microsec to millisec for display */
1801  values[6] = Float8GetDatum(((double) wal_stats->wal_write_time) / 1000.0);
1802  values[7] = Float8GetDatum(((double) wal_stats->wal_sync_time) / 1000.0);
1803 
1805 
1806  /* Returns the record as Datum */
1808 }
1809 
1810 /*
1811  * Returns statistics of SLRU caches.
1812  */
1813 Datum
1815 {
1816 #define PG_STAT_GET_SLRU_COLS 9
1817  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1818  int i;
1819  PgStat_SLRUStats *stats;
1820 
1821  SetSingleFuncCall(fcinfo, 0);
1822 
1823  /* request SLRU stats from the cumulative stats system */
1824  stats = pgstat_fetch_slru();
1825 
1826  for (i = 0;; i++)
1827  {
1828  /* for each row */
1830  bool nulls[PG_STAT_GET_SLRU_COLS];
1832  const char *name;
1833 
1835 
1836  if (!name)
1837  break;
1838 
1839  stat = stats[i];
1840  MemSet(values, 0, sizeof(values));
1841  MemSet(nulls, 0, sizeof(nulls));
1842 
1844  values[1] = Int64GetDatum(stat.blocks_zeroed);
1845  values[2] = Int64GetDatum(stat.blocks_hit);
1846  values[3] = Int64GetDatum(stat.blocks_read);
1847  values[4] = Int64GetDatum(stat.blocks_written);
1848  values[5] = Int64GetDatum(stat.blocks_exists);
1849  values[6] = Int64GetDatum(stat.flush);
1850  values[7] = Int64GetDatum(stat.truncate);
1851  values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1852 
1853  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1854  }
1855 
1856  return (Datum) 0;
1857 }
1858 
1859 Datum
1861 {
1862  Oid relid = PG_GETARG_OID(0);
1863  int64 result;
1864  PgStat_TableStatus *tabentry;
1865 
1866  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1867  result = 0;
1868  else
1869  result = (int64) (tabentry->t_counts.t_numscans);
1870 
1871  PG_RETURN_INT64(result);
1872 }
1873 
1874 Datum
1876 {
1877  Oid relid = PG_GETARG_OID(0);
1878  int64 result;
1879  PgStat_TableStatus *tabentry;
1880 
1881  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1882  result = 0;
1883  else
1884  result = (int64) (tabentry->t_counts.t_tuples_returned);
1885 
1886  PG_RETURN_INT64(result);
1887 }
1888 
1889 Datum
1891 {
1892  Oid relid = PG_GETARG_OID(0);
1893  int64 result;
1894  PgStat_TableStatus *tabentry;
1895 
1896  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1897  result = 0;
1898  else
1899  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1900 
1901  PG_RETURN_INT64(result);
1902 }
1903 
1904 Datum
1906 {
1907  Oid relid = PG_GETARG_OID(0);
1908  int64 result;
1909  PgStat_TableStatus *tabentry;
1911 
1912  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1913  result = 0;
1914  else
1915  {
1916  result = tabentry->t_counts.t_tuples_inserted;
1917  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1918  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1919  result += trans->tuples_inserted;
1920  }
1921 
1922  PG_RETURN_INT64(result);
1923 }
1924 
1925 Datum
1927 {
1928  Oid relid = PG_GETARG_OID(0);
1929  int64 result;
1930  PgStat_TableStatus *tabentry;
1932 
1933  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1934  result = 0;
1935  else
1936  {
1937  result = tabentry->t_counts.t_tuples_updated;
1938  /* live subtransactions' counts aren't in t_tuples_updated yet */
1939  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1940  result += trans->tuples_updated;
1941  }
1942 
1943  PG_RETURN_INT64(result);
1944 }
1945 
1946 Datum
1948 {
1949  Oid relid = PG_GETARG_OID(0);
1950  int64 result;
1951  PgStat_TableStatus *tabentry;
1953 
1954  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1955  result = 0;
1956  else
1957  {
1958  result = tabentry->t_counts.t_tuples_deleted;
1959  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1960  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1961  result += trans->tuples_deleted;
1962  }
1963 
1964  PG_RETURN_INT64(result);
1965 }
1966 
1967 Datum
1969 {
1970  Oid relid = PG_GETARG_OID(0);
1971  int64 result;
1972  PgStat_TableStatus *tabentry;
1973 
1974  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1975  result = 0;
1976  else
1977  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1978 
1979  PG_RETURN_INT64(result);
1980 }
1981 
1982 Datum
1984 {
1985  Oid relid = PG_GETARG_OID(0);
1986  int64 result;
1987  PgStat_TableStatus *tabentry;
1988 
1989  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1990  result = 0;
1991  else
1992  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1993 
1994  PG_RETURN_INT64(result);
1995 }
1996 
1997 Datum
1999 {
2000  Oid relid = PG_GETARG_OID(0);
2001  int64 result;
2002  PgStat_TableStatus *tabentry;
2003 
2004  if ((tabentry = find_tabstat_entry(relid)) == NULL)
2005  result = 0;
2006  else
2007  result = (int64) (tabentry->t_counts.t_blocks_hit);
2008 
2009  PG_RETURN_INT64(result);
2010 }
2011 
2012 Datum
2014 {
2015  Oid funcid = PG_GETARG_OID(0);
2016  PgStat_BackendFunctionEntry *funcentry;
2017 
2018  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
2019  PG_RETURN_NULL();
2020  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
2021 }
2022 
2023 Datum
2025 {
2026  Oid funcid = PG_GETARG_OID(0);
2027  PgStat_BackendFunctionEntry *funcentry;
2028 
2029  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
2030  PG_RETURN_NULL();
2032 }
2033 
2034 Datum
2036 {
2037  Oid funcid = PG_GETARG_OID(0);
2038  PgStat_BackendFunctionEntry *funcentry;
2039 
2040  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
2041  PG_RETURN_NULL();
2043 }
2044 
2045 
2046 /* Get the timestamp of the current statistics snapshot */
2047 Datum
2049 {
2050  bool have_snapshot;
2051  TimestampTz ts;
2052 
2053  ts = pgstat_get_stat_snapshot_timestamp(&have_snapshot);
2054 
2055  if (!have_snapshot)
2056  PG_RETURN_NULL();
2057 
2059 }
2060 
2061 /* Discard the active statistics snapshot */
2062 Datum
2064 {
2066 
2067  PG_RETURN_VOID();
2068 }
2069 
2070 
2071 /* Force statistics to be reported at the next occasion */
2072 Datum
2074 {
2076 
2077  PG_RETURN_VOID();
2078 }
2079 
2080 
2081 /* Reset all counters for the current database */
2082 Datum
2084 {
2086 
2087  PG_RETURN_VOID();
2088 }
2089 
2090 /* Reset some shared cluster-wide counters */
2091 Datum
2093 {
2094  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2095 
2096  if (strcmp(target, "archiver") == 0)
2098  else if (strcmp(target, "bgwriter") == 0)
2099  {
2100  /*
2101  * Historically checkpointer was part of bgwriter, continue to reset
2102  * both for now.
2103  */
2106  }
2107  else if (strcmp(target, "recovery_prefetch") == 0)
2109  else if (strcmp(target, "wal") == 0)
2111  else
2112  ereport(ERROR,
2113  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2114  errmsg("unrecognized reset target: \"%s\"", target),
2115  errhint("Target must be \"archiver\", \"bgwriter\", \"recovery_prefetch\", or \"wal\".")));
2116 
2117  PG_RETURN_VOID();
2118 }
2119 
2120 /* Reset a single counter in the current database */
2121 Datum
2123 {
2124  Oid taboid = PG_GETARG_OID(0);
2125 
2127 
2128  PG_RETURN_VOID();
2129 }
2130 
2131 Datum
2133 {
2134  Oid funcoid = PG_GETARG_OID(0);
2135 
2137 
2138  PG_RETURN_VOID();
2139 }
2140 
2141 /* Reset SLRU counters (a specific one or all of them). */
2142 Datum
2144 {
2145  char *target = NULL;
2146 
2147  if (PG_ARGISNULL(0))
2149  else
2150  {
2151  target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2152  pgstat_reset_slru(target);
2153  }
2154 
2155  PG_RETURN_VOID();
2156 }
2157 
2158 /* Reset replication slots stats (a specific one or all of them). */
2159 Datum
2161 {
2162  char *target = NULL;
2163 
2164  if (PG_ARGISNULL(0))
2166  else
2167  {
2168  target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2169  pgstat_reset_replslot(target);
2170  }
2171 
2172  PG_RETURN_VOID();
2173 }
2174 
2175 /* Reset subscription stats (a specific one or all of them) */
2176 Datum
2178 {
2179  Oid subid;
2180 
2181  if (PG_ARGISNULL(0))
2182  {
2183  /* Clear all subscription stats */
2185  }
2186  else
2187  {
2188  subid = PG_GETARG_OID(0);
2189 
2190  if (!OidIsValid(subid))
2191  ereport(ERROR,
2192  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2193  errmsg("invalid subscription OID %u", subid)));
2195  }
2196 
2197  PG_RETURN_VOID();
2198 }
2199 
2200 Datum
2202 {
2203  TupleDesc tupdesc;
2204  Datum values[7];
2205  bool nulls[7];
2206  PgStat_ArchiverStats *archiver_stats;
2207 
2208  /* Initialise values and NULL flags arrays */
2209  MemSet(values, 0, sizeof(values));
2210  MemSet(nulls, 0, sizeof(nulls));
2211 
2212  /* Initialise attributes information in the tuple descriptor */
2213  tupdesc = CreateTemplateTupleDesc(7);
2214  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2215  INT8OID, -1, 0);
2216  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2217  TEXTOID, -1, 0);
2218  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2219  TIMESTAMPTZOID, -1, 0);
2220  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2221  INT8OID, -1, 0);
2222  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2223  TEXTOID, -1, 0);
2224  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2225  TIMESTAMPTZOID, -1, 0);
2226  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2227  TIMESTAMPTZOID, -1, 0);
2228 
2229  BlessTupleDesc(tupdesc);
2230 
2231  /* Get statistics about the archiver process */
2232  archiver_stats = pgstat_fetch_stat_archiver();
2233 
2234  /* Fill values and NULLs */
2235  values[0] = Int64GetDatum(archiver_stats->archived_count);
2236  if (*(archiver_stats->last_archived_wal) == '\0')
2237  nulls[1] = true;
2238  else
2239  values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2240 
2241  if (archiver_stats->last_archived_timestamp == 0)
2242  nulls[2] = true;
2243  else
2244  values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
2245 
2246  values[3] = Int64GetDatum(archiver_stats->failed_count);
2247  if (*(archiver_stats->last_failed_wal) == '\0')
2248  nulls[4] = true;
2249  else
2250  values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2251 
2252  if (archiver_stats->last_failed_timestamp == 0)
2253  nulls[5] = true;
2254  else
2255  values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2256 
2257  if (archiver_stats->stat_reset_timestamp == 0)
2258  nulls[6] = true;
2259  else
2260  values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2261 
2262  /* Returns the record as Datum */
2264 }
2265 
2266 /*
2267  * Get the statistics for the replication slot. If the slot statistics is not
2268  * available, return all-zeroes stats.
2269  */
2270 Datum
2272 {
2273 #define PG_STAT_GET_REPLICATION_SLOT_COLS 10
2274  text *slotname_text = PG_GETARG_TEXT_P(0);
2275  NameData slotname;
2276  TupleDesc tupdesc;
2279  PgStat_StatReplSlotEntry *slotent;
2280  PgStat_StatReplSlotEntry allzero;
2281 
2282  /* Initialise values and NULL flags arrays */
2283  MemSet(values, 0, sizeof(values));
2284  MemSet(nulls, 0, sizeof(nulls));
2285 
2286  /* Initialise attributes information in the tuple descriptor */
2288  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
2289  TEXTOID, -1, 0);
2290  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "spill_txns",
2291  INT8OID, -1, 0);
2292  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "spill_count",
2293  INT8OID, -1, 0);
2294  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "spill_bytes",
2295  INT8OID, -1, 0);
2296  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stream_txns",
2297  INT8OID, -1, 0);
2298  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stream_count",
2299  INT8OID, -1, 0);
2300  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
2301  INT8OID, -1, 0);
2302  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
2303  INT8OID, -1, 0);
2304  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
2305  INT8OID, -1, 0);
2306  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
2307  TIMESTAMPTZOID, -1, 0);
2308  BlessTupleDesc(tupdesc);
2309 
2310  namestrcpy(&slotname, text_to_cstring(slotname_text));
2311  slotent = pgstat_fetch_replslot(slotname);
2312  if (!slotent)
2313  {
2314  /*
2315  * If the slot is not found, initialise its stats. This is possible if
2316  * the create slot message is lost.
2317  */
2318  memset(&allzero, 0, sizeof(PgStat_StatReplSlotEntry));
2319  slotent = &allzero;
2320  }
2321 
2322  values[0] = CStringGetTextDatum(NameStr(slotname));
2323  values[1] = Int64GetDatum(slotent->spill_txns);
2324  values[2] = Int64GetDatum(slotent->spill_count);
2325  values[3] = Int64GetDatum(slotent->spill_bytes);
2326  values[4] = Int64GetDatum(slotent->stream_txns);
2327  values[5] = Int64GetDatum(slotent->stream_count);
2328  values[6] = Int64GetDatum(slotent->stream_bytes);
2329  values[7] = Int64GetDatum(slotent->total_txns);
2330  values[8] = Int64GetDatum(slotent->total_bytes);
2331 
2332  if (slotent->stat_reset_timestamp == 0)
2333  nulls[9] = true;
2334  else
2336 
2337  /* Returns the record as Datum */
2339 }
2340 
2341 /*
2342  * Get the subscription statistics for the given subscription. If the
2343  * subscription statistics is not available, return all-zeros stats.
2344  */
2345 Datum
2347 {
2348 #define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
2349  Oid subid = PG_GETARG_OID(0);
2350  TupleDesc tupdesc;
2353  PgStat_StatSubEntry *subentry;
2354  PgStat_StatSubEntry allzero;
2355 
2356  /* Get subscription stats */
2357  subentry = pgstat_fetch_stat_subscription(subid);
2358 
2359  /* Initialise attributes information in the tuple descriptor */
2361  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subid",
2362  OIDOID, -1, 0);
2363  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
2364  INT8OID, -1, 0);
2365  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_error_count",
2366  INT8OID, -1, 0);
2367  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "stats_reset",
2368  TIMESTAMPTZOID, -1, 0);
2369  BlessTupleDesc(tupdesc);
2370 
2371  /* Initialise values and NULL flags arrays */
2372  MemSet(values, 0, sizeof(values));
2373  MemSet(nulls, 0, sizeof(nulls));
2374 
2375  if (!subentry)
2376  {
2377  /* If the subscription is not found, initialise its stats */
2378  memset(&allzero, 0, sizeof(PgStat_StatSubEntry));
2379  subentry = &allzero;
2380  }
2381 
2382  /* subid */
2383  values[0] = ObjectIdGetDatum(subid);
2384 
2385  /* apply_error_count */
2386  values[1] = Int64GetDatum(subentry->apply_error_count);
2387 
2388  /* sync_error_count */
2389  values[2] = Int64GetDatum(subentry->sync_error_count);
2390 
2391  /* stats_reset */
2392  if (subentry->stat_reset_timestamp == 0)
2393  nulls[3] = true;
2394  else
2396 
2397  /* Returns the record as Datum */
2399 }
2400 
2401 /*
2402  * Checks for presence of stats for object with provided kind, database oid,
2403  * object oid.
2404  *
2405  * This is useful for tests, but not really anything else. Therefore not
2406  * documented.
2407  */
2408 Datum
2410 {
2411  char *stats_type = text_to_cstring(PG_GETARG_TEXT_P(0));
2412  Oid dboid = PG_GETARG_OID(1);
2413  Oid objoid = PG_GETARG_OID(2);
2414  PgStat_Kind kind = pgstat_get_kind_from_str(stats_type);
2415 
2416  PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objoid));
2417 }
int16 AttrNumber
Definition: attnum.h:21
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:617
#define PGSTAT_NUM_PROGRESS_PARAM
ProgressCommandType
@ PROGRESS_COMMAND_ANALYZE
@ PROGRESS_COMMAND_CLUSTER
@ PROGRESS_COMMAND_CREATE_INDEX
@ PROGRESS_COMMAND_VACUUM
@ PROGRESS_COMMAND_BASEBACKUP
@ PROGRESS_COMMAND_COPY
int pgstat_fetch_stat_numbackends(void)
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
char * pgstat_clip_activity(const char *raw_activity)
@ STATE_UNDEFINED
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_IDLE
@ STATE_IDLEINTRANSACTION
@ STATE_DISABLED
@ STATE_FASTPATH
@ STATE_RUNNING
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
Definition: bgworker.c:1282
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
#define NameStr(name)
Definition: c.h:681
unsigned int uint32
Definition: c.h:441
signed int int32
Definition: c.h:429
#define UINT64_FORMAT
Definition: c.h:484
#define lengthof(array)
Definition: c.h:734
#define MemSet(start, val, len)
Definition: c.h:1008
#define OidIsValid(objectId)
Definition: c.h:710
int64 TimestampTz
Definition: timestamp.h:39
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1692
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:631
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:635
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
void SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:299
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:303
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:305
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:301
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:323
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define NI_MAXSERV
Definition: getaddrinfo.h:91
#define NI_NUMERICSERV
Definition: getaddrinfo.h:81
int MyProcPid
Definition: globals.c:44
Oid MyDatabaseId
Definition: globals.c:89
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:290
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition: ip.c:122
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1175
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
@ B_WAL_SENDER
Definition: miscadmin.h:335
@ B_BG_WORKER
Definition: miscadmin.h:330
@ B_BACKEND
Definition: miscadmin.h:329
const char * GetBackendTypeDesc(BackendType backendType)
Definition: miscinit.c:249
void namestrcpy(Name name, const char *str)
Definition: name.c:233
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:2103
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:121
static char * buf
Definition: pg_test_fsync.c:67
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:704
void pgstat_reset_counters(void)
Definition: pgstat.c:685
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:882
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition: pgstat.c:726
void pgstat_force_next_flush(void)
Definition: pgstat.c:664
void pgstat_clear_snapshot(void)
Definition: pgstat.c:751
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition: pgstat.c:868
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1189
PgStat_Kind
Definition: pgstat.h:36
@ PGSTAT_KIND_REPLSLOT
Definition: pgstat.h:44
@ PGSTAT_KIND_ARCHIVER
Definition: pgstat.h:48
@ PGSTAT_KIND_SLRU
Definition: pgstat.h:51
@ PGSTAT_KIND_BGWRITER
Definition: pgstat.h:49
@ PGSTAT_KIND_SUBSCRIPTION
Definition: pgstat.h:45
@ PGSTAT_KIND_CHECKPOINTER
Definition: pgstat.h:50
@ PGSTAT_KIND_FUNCTION
Definition: pgstat.h:43
@ PGSTAT_KIND_WAL
Definition: pgstat.h:52
@ PGSTAT_KIND_RELATION
Definition: pgstat.h:42
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
void pgstat_reset_replslot(const char *name)
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
void pgstat_reset_slru(const char *name)
Definition: pgstat_slru.c:45
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat_slru.c:105
const char * pgstat_get_slru_name(int slru_idx)
Definition: pgstat_slru.c:118
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition: pgstat_wal.c:53
Datum pg_stat_get_db_sessions(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1621
Datum pg_stat_get_function_total_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:390
Datum pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1968
Datum pg_stat_get_progress_info(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:457
Datum pg_stat_get_numscans(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:40
Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:72
Datum pg_stat_get_db_tuples_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1319
Datum pg_stat_get_snapshot_timestamp(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2048
Datum pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1091
Datum pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1905
Datum pg_stat_get_last_autovacuum_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:265
Datum pg_stat_get_db_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1350
#define PG_STAT_GET_WAL_COLS
Datum pg_stat_get_wal(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1746
Datum pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1703
Datum pg_stat_get_db_conflict_tablespace(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1399
Datum pg_stat_reset_replication_slot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2160
Datum pg_stat_get_db_deadlocks(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1493
Datum pg_stat_get_checkpoint_sync_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1711
Datum pg_stat_get_db_idle_in_transaction_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1607
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:35
Datum pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1725
Datum pg_stat_get_activity(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:540
Datum pg_stat_get_slru(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1814
Datum pg_stat_get_db_conflict_snapshot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1429
Datum pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1138
Datum pg_stat_get_backend_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1069
Datum pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1474
Datum pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1679
Datum pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1685
Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:216
Datum pg_stat_get_function_self_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:402
Datum pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2346
Datum pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2024
Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1223
#define PG_STAT_GET_SLRU_COLS
Datum pg_stat_get_last_autoanalyze_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:301
Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:232
Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:168
Datum pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1983
Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:914
Datum pg_stat_get_tuples_returned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:56
Datum pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:136
Datum pg_stat_get_db_conflict_lock(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1414
#define PG_STAT_GET_ACTIVITY_COLS
Datum pg_stat_get_xact_numscans(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1860
Datum pg_stat_get_analyze_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:349
Datum pg_stat_get_db_temp_bytes(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1384
Datum pg_stat_get_db_tuples_inserted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1303
Datum pg_stat_get_vacuum_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:319
Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:953
Datum pg_stat_get_last_analyze_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:283
Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:88
Datum pg_stat_get_db_sessions_fatal(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1647
Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1186
Datum pg_stat_get_db_sessions_abandoned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1634
Datum pg_stat_get_xact_tuples_returned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1875
Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:104
Datum pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1508
Datum pg_stat_reset_subscription_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2177
Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2063
Datum pg_stat_get_db_session_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1579
Datum pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1998
Datum pg_stat_reset_slru(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2143
Datum pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1526
Datum pg_stat_get_ins_since_vacuum(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:200
Datum pg_stat_have_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2409
Datum pg_stat_get_live_tuples(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:152
Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:414
Datum pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:978
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS
Datum pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1697
Datum pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1691
Datum pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1673
Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1207
Datum pg_stat_get_autoanalyze_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:364
Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:940
Datum pg_stat_reset(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2083
Datum pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:999
Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:120
Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:927
Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2013
Datum pg_stat_get_db_blk_read_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1547
#define PG_STAT_GET_PROGRESS_COLS
Datum pg_stat_get_db_temp_files(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1368
Datum pg_stat_get_xact_tuples_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1890
Datum pg_stat_get_autovacuum_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:334
Datum pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2035
Datum pg_stat_get_db_conflict_bufferpin(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1444
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:37
Datum pg_stat_get_buf_fsync_backend(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1731
Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1239
Datum pg_stat_get_db_conflict_startup_deadlock(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1459
Datum pg_stat_get_db_tuples_returned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1271
Datum pg_stat_get_archiver(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2201
Datum pg_stat_reset_shared(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2092
Datum pg_stat_force_next_flush(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2073
Datum pg_stat_reset_single_table_counters(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2122
Datum pg_stat_get_db_tuples_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1287
Datum pg_stat_get_bgwriter_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1719
Datum pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1047
Datum pg_stat_get_db_tuples_deleted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1335
Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:379
Datum pg_stat_get_xact_tuples_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1926
Datum pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2271
Datum pg_stat_get_last_vacuum_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:247
Datum pg_stat_get_mod_since_analyze(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:184
Datum pg_stat_get_db_active_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1593
Datum pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1947
Datum pg_stat_get_db_sessions_killed(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1660
Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1255
Datum pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1563
Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1021
Datum pg_stat_reset_single_function_counters(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2132
Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1737
Datum pg_backend_pid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:907
#define PG_STAT_GET_REPLICATION_SLOT_COLS
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define snprintf
Definition: port.h:225
#define TransactionIdGetDatum(X)
Definition: postgres.h:565
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define BoolGetDatum(X)
Definition: postgres.h:446
#define Int32GetDatum(X)
Definition: postgres.h:523
#define PointerGetDatum(X)
Definition: postgres.h:600
#define UInt64GetDatum(X)
Definition: postgres.h:692
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:3170
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:968
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
TransactionId backend_xid
PgBackendStatus backendStatus
TransactionId backend_xmin
Definition: proc.h:160
uint32 wait_event_info
Definition: proc.h:264
int pid
Definition: proc.h:184
PGPROC * lockGroupLeader
Definition: proc.h:289
char gss_princ[NAMEDATALEN]
char ssl_version[NAMEDATALEN]
char ssl_cipher[NAMEDATALEN]
char ssl_client_dn[NAMEDATALEN]
char ssl_client_serial[NAMEDATALEN]
char ssl_issuer_dn[NAMEDATALEN]
BackendType st_backendType
TimestampTz st_state_start_timestamp
TimestampTz st_proc_start_timestamp
PgBackendGSSStatus * st_gssstatus
BackendState st_state
TimestampTz st_activity_start_timestamp
ProgressCommandType st_progress_command
SockAddr st_clientaddr
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
PgBackendSSLStatus * st_sslstatus
TimestampTz st_xact_start_timestamp
char * st_clienthostname
Oid st_progress_command_target
TimestampTz last_failed_timestamp
Definition: pgstat.h:256
TimestampTz stat_reset_timestamp
Definition: pgstat.h:257
TimestampTz last_archived_timestamp
Definition: pgstat.h:252
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:254
PgStat_Counter failed_count
Definition: pgstat.h:253
PgStat_Counter archived_count
Definition: pgstat.h:249
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:250
PgStat_FunctionCounts f_counts
Definition: pgstat.h:119
instr_time f_total_time
Definition: pgstat.h:109
PgStat_Counter f_numcalls
Definition: pgstat.h:108
instr_time f_self_time
Definition: pgstat.h:110
PgStat_Counter n_sessions_killed
Definition: pgstat.h:309
PgStat_Counter total_session_time
Definition: pgstat.h:304
TimestampTz stat_reset_timestamp
Definition: pgstat.h:311
TimestampTz last_checksum_failure
Definition: pgstat.h:300
PgStat_Counter n_sessions_fatal
Definition: pgstat.h:308
PgStat_Counter total_idle_in_xact_time
Definition: pgstat.h:306
PgStat_Counter n_temp_bytes
Definition: pgstat.h:297
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:289
PgStat_Counter n_xact_commit
Definition: pgstat.h:281
PgStat_Counter n_tuples_updated
Definition: pgstat.h:288
PgStat_Counter n_xact_rollback
Definition: pgstat.h:282
PgStat_Counter n_conflict_lock
Definition: pgstat.h:292
PgStat_Counter total_active_time
Definition: pgstat.h:305
PgStat_Counter n_checksum_failures
Definition: pgstat.h:299
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:283
PgStat_Counter n_deadlocks
Definition: pgstat.h:298
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:286
PgStat_Counter n_block_read_time
Definition: pgstat.h:301
PgStat_Counter n_sessions
Definition: pgstat.h:303
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:291
PgStat_Counter n_sessions_abandoned
Definition: pgstat.h:307
PgStat_Counter n_block_write_time
Definition: pgstat.h:302
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:294
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:287
PgStat_Counter n_tuples_returned
Definition: pgstat.h:285
PgStat_Counter n_blocks_hit
Definition: pgstat.h:284
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:295
PgStat_Counter n_temp_files
Definition: pgstat.h:296
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:293
PgStat_Counter f_self_time
Definition: pgstat.h:319
PgStat_Counter f_total_time
Definition: pgstat.h:318
PgStat_Counter f_numcalls
Definition: pgstat.h:316
TimestampTz stat_reset_timestamp
Definition: pgstat.h:333
PgStat_Counter stream_count
Definition: pgstat.h:329
PgStat_Counter total_txns
Definition: pgstat.h:331
PgStat_Counter total_bytes
Definition: pgstat.h:332
PgStat_Counter spill_txns
Definition: pgstat.h:325
PgStat_Counter stream_txns
Definition: pgstat.h:328
PgStat_Counter spill_count
Definition: pgstat.h:326
PgStat_Counter stream_bytes
Definition: pgstat.h:330
PgStat_Counter spill_bytes
Definition: pgstat.h:327
PgStat_Counter apply_error_count
Definition: pgstat.h:350
PgStat_Counter sync_error_count
Definition: pgstat.h:351
TimestampTz stat_reset_timestamp
Definition: pgstat.h:352
PgStat_Counter vacuum_count
Definition: pgstat.h:376
PgStat_Counter tuples_fetched
Definition: pgstat.h:360
TimestampTz vacuum_timestamp
Definition: pgstat.h:375
PgStat_Counter blocks_hit
Definition: pgstat.h:373
PgStat_Counter analyze_count
Definition: pgstat.h:380
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:381
PgStat_Counter tuples_deleted
Definition: pgstat.h:364
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:382
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:365
PgStat_Counter tuples_updated
Definition: pgstat.h:363
PgStat_Counter changes_since_analyze
Definition: pgstat.h:369
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:370
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:378
PgStat_Counter numscans
Definition: pgstat.h:357
PgStat_Counter blocks_fetched
Definition: pgstat.h:372
PgStat_Counter tuples_returned
Definition: pgstat.h:359
TimestampTz analyze_timestamp
Definition: pgstat.h:379
PgStat_Counter n_live_tuples
Definition: pgstat.h:367
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:377
PgStat_Counter n_dead_tuples
Definition: pgstat.h:368
PgStat_Counter tuples_inserted
Definition: pgstat.h:362
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:178
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:175
PgStat_Counter t_tuples_updated
Definition: pgstat.h:176
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:173
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:177
PgStat_Counter t_numscans
Definition: pgstat.h:170
PgStat_Counter t_blocks_hit
Definition: pgstat.h:186
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:185
PgStat_Counter t_tuples_returned
Definition: pgstat.h:172
PgStat_TableCounts t_counts
Definition: pgstat.h:209
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:208
PgStat_Counter wal_write
Definition: pgstat.h:391
PgStat_Counter wal_buffers_full
Definition: pgstat.h:390
PgStat_Counter wal_write_time
Definition: pgstat.h:393
TimestampTz stat_reset_timestamp
Definition: pgstat.h:395
uint64 wal_bytes
Definition: pgstat.h:389
PgStat_Counter wal_sync_time
Definition: pgstat.h:394
PgStat_Counter wal_fpi
Definition: pgstat.h:388
PgStat_Counter wal_sync
Definition: pgstat.h:392
PgStat_Counter wal_records
Definition: pgstat.h:387
TupleDesc setDesc
Definition: execnodes.h:317
Tuplestorestate * setResult
Definition: execnodes.h:316
struct sockaddr_storage addr
Definition: pqcomm.h:64
socklen_t salen
Definition: pqcomm.h:65
Definition: c.h:676
Definition: c.h:622
#define TransactionIdIsValid(xid)
Definition: transam.h:41
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define PG_RETURN_INET_P(x)
Definition: inet.h:125
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
char * text_to_cstring(const text *t)
Definition: varlena.c:221
text * cstring_to_text(const char *s)
Definition: varlena.c:188
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: wait_event.c:129
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: wait_event.c:74
#define stat
Definition: win32_port.h:283
bool DataChecksumsEnabled(void)
Definition: xlog.c:4226
void XLogPrefetchResetStats(void)
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400