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