PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgstatfuncs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pgstatfuncs.c
4  * Functions for accessing the statistics collector data
5  *
6  * Portions Copyright (c) 1996-2017, 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 "catalog/pg_type.h"
19 #include "common/ip.h"
20 #include "funcapi.h"
21 #include "miscadmin.h"
22 #include "pgstat.h"
23 #include "postmaster/postmaster.h"
24 #include "storage/proc.h"
25 #include "storage/procarray.h"
26 #include "utils/acl.h"
27 #include "utils/builtins.h"
28 #include "utils/inet.h"
29 #include "utils/timestamp.h"
30 
31 #define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var))))
32 
33 /* Global bgwriter statistics, from bgwriter.c */
35 
36 Datum
38 {
39  Oid relid = PG_GETARG_OID(0);
40  int64 result;
41  PgStat_StatTabEntry *tabentry;
42 
43  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
44  result = 0;
45  else
46  result = (int64) (tabentry->numscans);
47 
48  PG_RETURN_INT64(result);
49 }
50 
51 
52 Datum
54 {
55  Oid relid = PG_GETARG_OID(0);
56  int64 result;
57  PgStat_StatTabEntry *tabentry;
58 
59  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
60  result = 0;
61  else
62  result = (int64) (tabentry->tuples_returned);
63 
64  PG_RETURN_INT64(result);
65 }
66 
67 
68 Datum
70 {
71  Oid relid = PG_GETARG_OID(0);
72  int64 result;
73  PgStat_StatTabEntry *tabentry;
74 
75  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
76  result = 0;
77  else
78  result = (int64) (tabentry->tuples_fetched);
79 
80  PG_RETURN_INT64(result);
81 }
82 
83 
84 Datum
86 {
87  Oid relid = PG_GETARG_OID(0);
88  int64 result;
89  PgStat_StatTabEntry *tabentry;
90 
91  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
92  result = 0;
93  else
94  result = (int64) (tabentry->tuples_inserted);
95 
96  PG_RETURN_INT64(result);
97 }
98 
99 
100 Datum
102 {
103  Oid relid = PG_GETARG_OID(0);
104  int64 result;
105  PgStat_StatTabEntry *tabentry;
106 
107  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
108  result = 0;
109  else
110  result = (int64) (tabentry->tuples_updated);
111 
112  PG_RETURN_INT64(result);
113 }
114 
115 
116 Datum
118 {
119  Oid relid = PG_GETARG_OID(0);
120  int64 result;
121  PgStat_StatTabEntry *tabentry;
122 
123  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
124  result = 0;
125  else
126  result = (int64) (tabentry->tuples_deleted);
127 
128  PG_RETURN_INT64(result);
129 }
130 
131 
132 Datum
134 {
135  Oid relid = PG_GETARG_OID(0);
136  int64 result;
137  PgStat_StatTabEntry *tabentry;
138 
139  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
140  result = 0;
141  else
142  result = (int64) (tabentry->tuples_hot_updated);
143 
144  PG_RETURN_INT64(result);
145 }
146 
147 
148 Datum
150 {
151  Oid relid = PG_GETARG_OID(0);
152  int64 result;
153  PgStat_StatTabEntry *tabentry;
154 
155  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
156  result = 0;
157  else
158  result = (int64) (tabentry->n_live_tuples);
159 
160  PG_RETURN_INT64(result);
161 }
162 
163 
164 Datum
166 {
167  Oid relid = PG_GETARG_OID(0);
168  int64 result;
169  PgStat_StatTabEntry *tabentry;
170 
171  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
172  result = 0;
173  else
174  result = (int64) (tabentry->n_dead_tuples);
175 
176  PG_RETURN_INT64(result);
177 }
178 
179 
180 Datum
182 {
183  Oid relid = PG_GETARG_OID(0);
184  int64 result;
185  PgStat_StatTabEntry *tabentry;
186 
187  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
188  result = 0;
189  else
190  result = (int64) (tabentry->changes_since_analyze);
191 
192  PG_RETURN_INT64(result);
193 }
194 
195 
196 Datum
198 {
199  Oid relid = PG_GETARG_OID(0);
200  int64 result;
201  PgStat_StatTabEntry *tabentry;
202 
203  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
204  result = 0;
205  else
206  result = (int64) (tabentry->blocks_fetched);
207 
208  PG_RETURN_INT64(result);
209 }
210 
211 
212 Datum
214 {
215  Oid relid = PG_GETARG_OID(0);
216  int64 result;
217  PgStat_StatTabEntry *tabentry;
218 
219  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
220  result = 0;
221  else
222  result = (int64) (tabentry->blocks_hit);
223 
224  PG_RETURN_INT64(result);
225 }
226 
227 Datum
229 {
230  Oid relid = PG_GETARG_OID(0);
232  PgStat_StatTabEntry *tabentry;
233 
234  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
235  result = 0;
236  else
237  result = tabentry->vacuum_timestamp;
238 
239  if (result == 0)
240  PG_RETURN_NULL();
241  else
242  PG_RETURN_TIMESTAMPTZ(result);
243 }
244 
245 Datum
247 {
248  Oid relid = PG_GETARG_OID(0);
250  PgStat_StatTabEntry *tabentry;
251 
252  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
253  result = 0;
254  else
255  result = tabentry->autovac_vacuum_timestamp;
256 
257  if (result == 0)
258  PG_RETURN_NULL();
259  else
260  PG_RETURN_TIMESTAMPTZ(result);
261 }
262 
263 Datum
265 {
266  Oid relid = PG_GETARG_OID(0);
268  PgStat_StatTabEntry *tabentry;
269 
270  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
271  result = 0;
272  else
273  result = tabentry->analyze_timestamp;
274 
275  if (result == 0)
276  PG_RETURN_NULL();
277  else
278  PG_RETURN_TIMESTAMPTZ(result);
279 }
280 
281 Datum
283 {
284  Oid relid = PG_GETARG_OID(0);
286  PgStat_StatTabEntry *tabentry;
287 
288  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
289  result = 0;
290  else
291  result = tabentry->autovac_analyze_timestamp;
292 
293  if (result == 0)
294  PG_RETURN_NULL();
295  else
296  PG_RETURN_TIMESTAMPTZ(result);
297 }
298 
299 Datum
301 {
302  Oid relid = PG_GETARG_OID(0);
303  int64 result;
304  PgStat_StatTabEntry *tabentry;
305 
306  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
307  result = 0;
308  else
309  result = (int64) (tabentry->vacuum_count);
310 
311  PG_RETURN_INT64(result);
312 }
313 
314 Datum
316 {
317  Oid relid = PG_GETARG_OID(0);
318  int64 result;
319  PgStat_StatTabEntry *tabentry;
320 
321  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
322  result = 0;
323  else
324  result = (int64) (tabentry->autovac_vacuum_count);
325 
326  PG_RETURN_INT64(result);
327 }
328 
329 Datum
331 {
332  Oid relid = PG_GETARG_OID(0);
333  int64 result;
334  PgStat_StatTabEntry *tabentry;
335 
336  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
337  result = 0;
338  else
339  result = (int64) (tabentry->analyze_count);
340 
341  PG_RETURN_INT64(result);
342 }
343 
344 Datum
346 {
347  Oid relid = PG_GETARG_OID(0);
348  int64 result;
349  PgStat_StatTabEntry *tabentry;
350 
351  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
352  result = 0;
353  else
354  result = (int64) (tabentry->autovac_analyze_count);
355 
356  PG_RETURN_INT64(result);
357 }
358 
359 Datum
361 {
362  Oid funcid = PG_GETARG_OID(0);
363  PgStat_StatFuncEntry *funcentry;
364 
365  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
366  PG_RETURN_NULL();
367  PG_RETURN_INT64(funcentry->f_numcalls);
368 }
369 
370 Datum
372 {
373  Oid funcid = PG_GETARG_OID(0);
374  PgStat_StatFuncEntry *funcentry;
375 
376  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
377  PG_RETURN_NULL();
378  /* convert counter from microsec to millisec for display */
379  PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
380 }
381 
382 Datum
384 {
385  Oid funcid = PG_GETARG_OID(0);
386  PgStat_StatFuncEntry *funcentry;
387 
388  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
389  PG_RETURN_NULL();
390  /* convert counter from microsec to millisec for display */
391  PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
392 }
393 
394 Datum
396 {
397  FuncCallContext *funcctx;
398  int *fctx;
399  int32 result;
400 
401  /* stuff done only on the first call of the function */
402  if (SRF_IS_FIRSTCALL())
403  {
404  /* create a function context for cross-call persistence */
405  funcctx = SRF_FIRSTCALL_INIT();
406 
408  2 * sizeof(int));
409  funcctx->user_fctx = fctx;
410 
411  fctx[0] = 0;
412  fctx[1] = pgstat_fetch_stat_numbackends();
413  }
414 
415  /* stuff done on every call of the function */
416  funcctx = SRF_PERCALL_SETUP();
417  fctx = funcctx->user_fctx;
418 
419  fctx[0] += 1;
420  result = fctx[0];
421 
422  if (result <= fctx[1])
423  {
424  /* do when there is more left to send */
425  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
426  }
427  else
428  {
429  /* do when there is no more left */
430  SRF_RETURN_DONE(funcctx);
431  }
432 }
433 
434 /*
435  * Returns command progress information for the named command.
436  */
437 Datum
439 {
440 #define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
441  int num_backends = pgstat_fetch_stat_numbackends();
442  int curr_backend;
443  char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
444  ProgressCommandType cmdtype;
445  TupleDesc tupdesc;
446  Tuplestorestate *tupstore;
447  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
448  MemoryContext per_query_ctx;
449  MemoryContext oldcontext;
450 
451  /* check to see if caller supports us returning a tuplestore */
452  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
453  ereport(ERROR,
454  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
455  errmsg("set-valued function called in context that cannot accept a set")));
456  if (!(rsinfo->allowedModes & SFRM_Materialize))
457  ereport(ERROR,
458  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
459  errmsg("materialize mode required, but it is not " \
460  "allowed in this context")));
461 
462  /* Build a tuple descriptor for our result type */
463  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
464  elog(ERROR, "return type must be a row type");
465 
466  /* Translate command name into command type code. */
467  if (pg_strcasecmp(cmd, "VACUUM") == 0)
468  cmdtype = PROGRESS_COMMAND_VACUUM;
469  else
470  ereport(ERROR,
471  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
472  errmsg("invalid command name: \"%s\"", cmd)));
473 
474  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
475  oldcontext = MemoryContextSwitchTo(per_query_ctx);
476 
477  tupstore = tuplestore_begin_heap(true, false, work_mem);
478  rsinfo->returnMode = SFRM_Materialize;
479  rsinfo->setResult = tupstore;
480  rsinfo->setDesc = tupdesc;
481  MemoryContextSwitchTo(oldcontext);
482 
483  /* 1-based index */
484  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
485  {
486  LocalPgBackendStatus *local_beentry;
487  PgBackendStatus *beentry;
489  bool nulls[PG_STAT_GET_PROGRESS_COLS];
490  int i;
491 
492  MemSet(values, 0, sizeof(values));
493  MemSet(nulls, 0, sizeof(nulls));
494 
495  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
496 
497  if (!local_beentry)
498  continue;
499 
500  beentry = &local_beentry->backendStatus;
501 
502  /*
503  * Report values for only those backends which are running the given
504  * command.
505  */
506  if (!beentry || beentry->st_progress_command != cmdtype)
507  continue;
508 
509  /* Value available to all callers */
510  values[0] = Int32GetDatum(beentry->st_procpid);
511  values[1] = ObjectIdGetDatum(beentry->st_databaseid);
512 
513  /* show rest of the values including relid only to role members */
514  if (has_privs_of_role(GetUserId(), beentry->st_userid))
515  {
516  values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
517  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
518  values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
519  }
520  else
521  {
522  nulls[2] = true;
523  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
524  nulls[i + 3] = true;
525  }
526 
527  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
528  }
529 
530  /* clean up and return the tuplestore */
531  tuplestore_donestoring(tupstore);
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 24
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  TupleDesc tupdesc;
548  Tuplestorestate *tupstore;
549  MemoryContext per_query_ctx;
550  MemoryContext oldcontext;
551 
552  /* check to see if caller supports us returning a tuplestore */
553  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
554  ereport(ERROR,
555  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
556  errmsg("set-valued function called in context that cannot accept a set")));
557  if (!(rsinfo->allowedModes & SFRM_Materialize))
558  ereport(ERROR,
559  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
560  errmsg("materialize mode required, but it is not " \
561  "allowed in this context")));
562 
563  /* Build a tuple descriptor for our result type */
564  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
565  elog(ERROR, "return type must be a row type");
566 
567  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
568  oldcontext = MemoryContextSwitchTo(per_query_ctx);
569 
570  tupstore = tuplestore_begin_heap(true, false, work_mem);
571  rsinfo->returnMode = SFRM_Materialize;
572  rsinfo->setResult = tupstore;
573  rsinfo->setDesc = tupdesc;
574 
575  MemoryContextSwitchTo(oldcontext);
576 
577  /* 1-based index */
578  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
579  {
580  /* for each row */
582  bool nulls[PG_STAT_GET_ACTIVITY_COLS];
583  LocalPgBackendStatus *local_beentry;
584  PgBackendStatus *beentry;
585  PGPROC *proc;
586  const char *wait_event_type = NULL;
587  const char *wait_event = NULL;
588 
589  MemSet(values, 0, sizeof(values));
590  MemSet(nulls, 0, sizeof(nulls));
591 
592  /* Get the next one in the list */
593  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
594  if (!local_beentry)
595  {
596  int i;
597 
598  /* Ignore missing entries if looking for specific PID */
599  if (pid != -1)
600  continue;
601 
602  for (i = 0; i < lengthof(nulls); i++)
603  nulls[i] = true;
604 
605  nulls[5] = false;
606  values[5] = CStringGetTextDatum("<backend information not available>");
607 
608  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
609  continue;
610  }
611 
612  beentry = &local_beentry->backendStatus;
613 
614  /* If looking for specific PID, ignore all the others */
615  if (pid != -1 && beentry->st_procpid != pid)
616  continue;
617 
618  /* Values available to all callers */
619  if (beentry->st_databaseid != InvalidOid)
620  values[0] = ObjectIdGetDatum(beentry->st_databaseid);
621  else
622  nulls[0] = true;
623 
624  values[1] = Int32GetDatum(beentry->st_procpid);
625 
626  if (beentry->st_userid != InvalidOid)
627  values[2] = ObjectIdGetDatum(beentry->st_userid);
628  else
629  nulls[2] = true;
630 
631  if (beentry->st_appname)
632  values[3] = CStringGetTextDatum(beentry->st_appname);
633  else
634  nulls[3] = true;
635 
636  if (TransactionIdIsValid(local_beentry->backend_xid))
637  values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
638  else
639  nulls[15] = true;
640 
641  if (TransactionIdIsValid(local_beentry->backend_xmin))
642  values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
643  else
644  nulls[16] = true;
645 
646  if (beentry->st_ssl)
647  {
648  values[18] = BoolGetDatum(true); /* ssl */
649  values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version);
650  values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher);
651  values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
652  values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression);
653  values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_clientdn);
654  }
655  else
656  {
657  values[18] = BoolGetDatum(false); /* ssl */
658  nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = true;
659  }
660 
661  /* Values only available to role member */
662  if (has_privs_of_role(GetUserId(), beentry->st_userid))
663  {
664  SockAddr zero_clientaddr;
665 
666  switch (beentry->st_state)
667  {
668  case STATE_IDLE:
669  values[4] = CStringGetTextDatum("idle");
670  break;
671  case STATE_RUNNING:
672  values[4] = CStringGetTextDatum("active");
673  break;
675  values[4] = CStringGetTextDatum("idle in transaction");
676  break;
677  case STATE_FASTPATH:
678  values[4] = CStringGetTextDatum("fastpath function call");
679  break;
681  values[4] = CStringGetTextDatum("idle in transaction (aborted)");
682  break;
683  case STATE_DISABLED:
684  values[4] = CStringGetTextDatum("disabled");
685  break;
686  case STATE_UNDEFINED:
687  nulls[4] = true;
688  break;
689  }
690 
691  values[5] = CStringGetTextDatum(beentry->st_activity);
692 
693  proc = BackendPidGetProc(beentry->st_procpid);
694  if (proc != NULL)
695  {
696  uint32 raw_wait_event;
697 
698  raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
699  wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
700  wait_event = pgstat_get_wait_event(raw_wait_event);
701 
702  }
703  else if (beentry->st_backendType != B_BACKEND)
704  {
705  /*
706  * For an auxiliary process, retrieve process info from
707  * AuxiliaryProcs stored in shared-memory.
708  */
709  proc = AuxiliaryPidGetProc(beentry->st_procpid);
710 
711  if (proc != NULL)
712  {
713  uint32 raw_wait_event;
714 
715  raw_wait_event =
717  wait_event_type =
718  pgstat_get_wait_event_type(raw_wait_event);
719  wait_event = pgstat_get_wait_event(raw_wait_event);
720  }
721  }
722 
723  if (wait_event_type)
724  values[6] = CStringGetTextDatum(wait_event_type);
725  else
726  nulls[6] = true;
727 
728  if (wait_event)
729  values[7] = CStringGetTextDatum(wait_event);
730  else
731  nulls[7] = true;
732 
733  if (beentry->st_xact_start_timestamp != 0)
734  values[8] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
735  else
736  nulls[8] = true;
737 
738  if (beentry->st_activity_start_timestamp != 0)
739  values[9] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
740  else
741  nulls[9] = true;
742 
743  if (beentry->st_proc_start_timestamp != 0)
744  values[10] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
745  else
746  nulls[10] = true;
747 
748  if (beentry->st_state_start_timestamp != 0)
749  values[11] = TimestampTzGetDatum(beentry->st_state_start_timestamp);
750  else
751  nulls[11] = true;
752 
753  /* A zeroed client addr means we don't know */
754  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
755  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
756  sizeof(zero_clientaddr)) == 0)
757  {
758  nulls[12] = true;
759  nulls[13] = true;
760  nulls[14] = true;
761  }
762  else
763  {
764  if (beentry->st_clientaddr.addr.ss_family == AF_INET
765 #ifdef HAVE_IPV6
766  || beentry->st_clientaddr.addr.ss_family == AF_INET6
767 #endif
768  )
769  {
770  char remote_host[NI_MAXHOST];
771  char remote_port[NI_MAXSERV];
772  int ret;
773 
774  remote_host[0] = '\0';
775  remote_port[0] = '\0';
776  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
777  beentry->st_clientaddr.salen,
778  remote_host, sizeof(remote_host),
779  remote_port, sizeof(remote_port),
781  if (ret == 0)
782  {
783  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
784  values[12] = DirectFunctionCall1(inet_in,
785  CStringGetDatum(remote_host));
786  if (beentry->st_clienthostname &&
787  beentry->st_clienthostname[0])
788  values[13] = CStringGetTextDatum(beentry->st_clienthostname);
789  else
790  nulls[13] = true;
791  values[14] = Int32GetDatum(atoi(remote_port));
792  }
793  else
794  {
795  nulls[12] = true;
796  nulls[13] = true;
797  nulls[14] = true;
798  }
799  }
800  else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
801  {
802  /*
803  * Unix sockets always reports NULL for host and -1 for
804  * port, so it's possible to tell the difference to
805  * connections we have no permissions to view, or with
806  * errors.
807  */
808  nulls[12] = true;
809  nulls[13] = true;
810  values[14] = DatumGetInt32(-1);
811  }
812  else
813  {
814  /* Unknown address type, should never happen */
815  nulls[12] = true;
816  nulls[13] = true;
817  nulls[14] = true;
818  }
819  }
820  /* Add backend type */
821  values[17] =
823  }
824  else
825  {
826  /* No permissions to view data about this session */
827  values[5] = CStringGetTextDatum("<insufficient privilege>");
828  nulls[4] = true;
829  nulls[6] = true;
830  nulls[7] = true;
831  nulls[8] = true;
832  nulls[9] = true;
833  nulls[10] = true;
834  nulls[11] = true;
835  nulls[12] = true;
836  nulls[13] = true;
837  nulls[14] = true;
838  nulls[17] = true;
839  }
840 
841  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
842 
843  /* If only a single backend was requested, and we found it, break. */
844  if (pid != -1)
845  break;
846  }
847 
848  /* clean up and return the tuplestore */
849  tuplestore_donestoring(tupstore);
850 
851  return (Datum) 0;
852 }
853 
854 
855 Datum
857 {
859 }
860 
861 
862 Datum
864 {
865  int32 beid = PG_GETARG_INT32(0);
866  PgBackendStatus *beentry;
867 
868  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
869  PG_RETURN_NULL();
870 
871  PG_RETURN_INT32(beentry->st_procpid);
872 }
873 
874 
875 Datum
877 {
878  int32 beid = PG_GETARG_INT32(0);
879  PgBackendStatus *beentry;
880 
881  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
882  PG_RETURN_NULL();
883 
884  PG_RETURN_OID(beentry->st_databaseid);
885 }
886 
887 
888 Datum
890 {
891  int32 beid = PG_GETARG_INT32(0);
892  PgBackendStatus *beentry;
893 
894  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
895  PG_RETURN_NULL();
896 
897  PG_RETURN_OID(beentry->st_userid);
898 }
899 
900 
901 Datum
903 {
904  int32 beid = PG_GETARG_INT32(0);
905  PgBackendStatus *beentry;
906  const char *activity;
907 
908  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
909  activity = "<backend information not available>";
910  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
911  activity = "<insufficient privilege>";
912  else if (*(beentry->st_activity) == '\0')
913  activity = "<command string not enabled>";
914  else
915  activity = beentry->st_activity;
916 
918 }
919 
920 Datum
922 {
923  int32 beid = PG_GETARG_INT32(0);
924  PgBackendStatus *beentry;
925  PGPROC *proc;
926  const char *wait_event_type = NULL;
927 
928  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
929  wait_event_type = "<backend information not available>";
930  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
931  wait_event_type = "<insufficient privilege>";
932  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
933  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
934 
935  if (!wait_event_type)
936  PG_RETURN_NULL();
937 
938  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
939 }
940 
941 Datum
943 {
944  int32 beid = PG_GETARG_INT32(0);
945  PgBackendStatus *beentry;
946  PGPROC *proc;
947  const char *wait_event = NULL;
948 
949  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
950  wait_event = "<backend information not available>";
951  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
952  wait_event = "<insufficient privilege>";
953  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
954  wait_event = pgstat_get_wait_event(proc->wait_event_info);
955 
956  if (!wait_event)
957  PG_RETURN_NULL();
958 
959  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
960 }
961 
962 
963 Datum
965 {
966  int32 beid = PG_GETARG_INT32(0);
968  PgBackendStatus *beentry;
969 
970  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
971  PG_RETURN_NULL();
972 
973  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
974  PG_RETURN_NULL();
975 
976  result = beentry->st_activity_start_timestamp;
977 
978  /*
979  * No time recorded for start of current query -- this is the case if the
980  * user hasn't enabled query-level stats collection.
981  */
982  if (result == 0)
983  PG_RETURN_NULL();
984 
985  PG_RETURN_TIMESTAMPTZ(result);
986 }
987 
988 
989 Datum
991 {
992  int32 beid = PG_GETARG_INT32(0);
994  PgBackendStatus *beentry;
995 
996  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
997  PG_RETURN_NULL();
998 
999  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1000  PG_RETURN_NULL();
1001 
1002  result = beentry->st_xact_start_timestamp;
1003 
1004  if (result == 0) /* not in a transaction */
1005  PG_RETURN_NULL();
1006 
1007  PG_RETURN_TIMESTAMPTZ(result);
1008 }
1009 
1010 
1011 Datum
1013 {
1014  int32 beid = PG_GETARG_INT32(0);
1016  PgBackendStatus *beentry;
1017 
1018  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1019  PG_RETURN_NULL();
1020 
1021  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1022  PG_RETURN_NULL();
1023 
1024  result = beentry->st_proc_start_timestamp;
1025 
1026  if (result == 0) /* probably can't happen? */
1027  PG_RETURN_NULL();
1028 
1029  PG_RETURN_TIMESTAMPTZ(result);
1030 }
1031 
1032 
1033 Datum
1035 {
1036  int32 beid = PG_GETARG_INT32(0);
1037  PgBackendStatus *beentry;
1038  SockAddr zero_clientaddr;
1039  char remote_host[NI_MAXHOST];
1040  int ret;
1041 
1042  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1043  PG_RETURN_NULL();
1044 
1045  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1046  PG_RETURN_NULL();
1047 
1048  /* A zeroed client addr means we don't know */
1049  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1050  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1051  sizeof(zero_clientaddr)) == 0)
1052  PG_RETURN_NULL();
1053 
1054  switch (beentry->st_clientaddr.addr.ss_family)
1055  {
1056  case AF_INET:
1057 #ifdef HAVE_IPV6
1058  case AF_INET6:
1059 #endif
1060  break;
1061  default:
1062  PG_RETURN_NULL();
1063  }
1064 
1065  remote_host[0] = '\0';
1066  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1067  beentry->st_clientaddr.salen,
1068  remote_host, sizeof(remote_host),
1069  NULL, 0,
1071  if (ret != 0)
1072  PG_RETURN_NULL();
1073 
1074  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1075 
1077  CStringGetDatum(remote_host)));
1078 }
1079 
1080 Datum
1082 {
1083  int32 beid = PG_GETARG_INT32(0);
1084  PgBackendStatus *beentry;
1085  SockAddr zero_clientaddr;
1086  char remote_port[NI_MAXSERV];
1087  int ret;
1088 
1089  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1090  PG_RETURN_NULL();
1091 
1092  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1093  PG_RETURN_NULL();
1094 
1095  /* A zeroed client addr means we don't know */
1096  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1097  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1098  sizeof(zero_clientaddr)) == 0)
1099  PG_RETURN_NULL();
1100 
1101  switch (beentry->st_clientaddr.addr.ss_family)
1102  {
1103  case AF_INET:
1104 #ifdef HAVE_IPV6
1105  case AF_INET6:
1106 #endif
1107  break;
1108  case AF_UNIX:
1109  PG_RETURN_INT32(-1);
1110  default:
1111  PG_RETURN_NULL();
1112  }
1113 
1114  remote_port[0] = '\0';
1115  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1116  beentry->st_clientaddr.salen,
1117  NULL, 0,
1118  remote_port, sizeof(remote_port),
1120  if (ret != 0)
1121  PG_RETURN_NULL();
1122 
1124  CStringGetDatum(remote_port)));
1125 }
1126 
1127 
1128 Datum
1130 {
1131  Oid dbid = PG_GETARG_OID(0);
1132  int32 result;
1133  int tot_backends = pgstat_fetch_stat_numbackends();
1134  int beid;
1135 
1136  result = 0;
1137  for (beid = 1; beid <= tot_backends; beid++)
1138  {
1139  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1140 
1141  if (beentry && beentry->st_databaseid == dbid)
1142  result++;
1143  }
1144 
1145  PG_RETURN_INT32(result);
1146 }
1147 
1148 
1149 Datum
1151 {
1152  Oid dbid = PG_GETARG_OID(0);
1153  int64 result;
1154  PgStat_StatDBEntry *dbentry;
1155 
1156  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1157  result = 0;
1158  else
1159  result = (int64) (dbentry->n_xact_commit);
1160 
1161  PG_RETURN_INT64(result);
1162 }
1163 
1164 
1165 Datum
1167 {
1168  Oid dbid = PG_GETARG_OID(0);
1169  int64 result;
1170  PgStat_StatDBEntry *dbentry;
1171 
1172  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1173  result = 0;
1174  else
1175  result = (int64) (dbentry->n_xact_rollback);
1176 
1177  PG_RETURN_INT64(result);
1178 }
1179 
1180 
1181 Datum
1183 {
1184  Oid dbid = PG_GETARG_OID(0);
1185  int64 result;
1186  PgStat_StatDBEntry *dbentry;
1187 
1188  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1189  result = 0;
1190  else
1191  result = (int64) (dbentry->n_blocks_fetched);
1192 
1193  PG_RETURN_INT64(result);
1194 }
1195 
1196 
1197 Datum
1199 {
1200  Oid dbid = PG_GETARG_OID(0);
1201  int64 result;
1202  PgStat_StatDBEntry *dbentry;
1203 
1204  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1205  result = 0;
1206  else
1207  result = (int64) (dbentry->n_blocks_hit);
1208 
1209  PG_RETURN_INT64(result);
1210 }
1211 
1212 
1213 Datum
1215 {
1216  Oid dbid = PG_GETARG_OID(0);
1217  int64 result;
1218  PgStat_StatDBEntry *dbentry;
1219 
1220  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1221  result = 0;
1222  else
1223  result = (int64) (dbentry->n_tuples_returned);
1224 
1225  PG_RETURN_INT64(result);
1226 }
1227 
1228 
1229 Datum
1231 {
1232  Oid dbid = PG_GETARG_OID(0);
1233  int64 result;
1234  PgStat_StatDBEntry *dbentry;
1235 
1236  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1237  result = 0;
1238  else
1239  result = (int64) (dbentry->n_tuples_fetched);
1240 
1241  PG_RETURN_INT64(result);
1242 }
1243 
1244 
1245 Datum
1247 {
1248  Oid dbid = PG_GETARG_OID(0);
1249  int64 result;
1250  PgStat_StatDBEntry *dbentry;
1251 
1252  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1253  result = 0;
1254  else
1255  result = (int64) (dbentry->n_tuples_inserted);
1256 
1257  PG_RETURN_INT64(result);
1258 }
1259 
1260 
1261 Datum
1263 {
1264  Oid dbid = PG_GETARG_OID(0);
1265  int64 result;
1266  PgStat_StatDBEntry *dbentry;
1267 
1268  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1269  result = 0;
1270  else
1271  result = (int64) (dbentry->n_tuples_updated);
1272 
1273  PG_RETURN_INT64(result);
1274 }
1275 
1276 
1277 Datum
1279 {
1280  Oid dbid = PG_GETARG_OID(0);
1281  int64 result;
1282  PgStat_StatDBEntry *dbentry;
1283 
1284  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1285  result = 0;
1286  else
1287  result = (int64) (dbentry->n_tuples_deleted);
1288 
1289  PG_RETURN_INT64(result);
1290 }
1291 
1292 Datum
1294 {
1295  Oid dbid = PG_GETARG_OID(0);
1297  PgStat_StatDBEntry *dbentry;
1298 
1299  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1300  result = 0;
1301  else
1302  result = dbentry->stat_reset_timestamp;
1303 
1304  if (result == 0)
1305  PG_RETURN_NULL();
1306  else
1307  PG_RETURN_TIMESTAMPTZ(result);
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 = dbentry->n_temp_files;
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 = dbentry->n_temp_bytes;
1337 
1338  PG_RETURN_INT64(result);
1339 }
1340 
1341 Datum
1343 {
1344  Oid dbid = PG_GETARG_OID(0);
1345  int64 result;
1346  PgStat_StatDBEntry *dbentry;
1347 
1348  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1349  result = 0;
1350  else
1351  result = (int64) (dbentry->n_conflict_tablespace);
1352 
1353  PG_RETURN_INT64(result);
1354 }
1355 
1356 Datum
1358 {
1359  Oid dbid = PG_GETARG_OID(0);
1360  int64 result;
1361  PgStat_StatDBEntry *dbentry;
1362 
1363  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1364  result = 0;
1365  else
1366  result = (int64) (dbentry->n_conflict_lock);
1367 
1368  PG_RETURN_INT64(result);
1369 }
1370 
1371 Datum
1373 {
1374  Oid dbid = PG_GETARG_OID(0);
1375  int64 result;
1376  PgStat_StatDBEntry *dbentry;
1377 
1378  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1379  result = 0;
1380  else
1381  result = (int64) (dbentry->n_conflict_snapshot);
1382 
1383  PG_RETURN_INT64(result);
1384 }
1385 
1386 Datum
1388 {
1389  Oid dbid = PG_GETARG_OID(0);
1390  int64 result;
1391  PgStat_StatDBEntry *dbentry;
1392 
1393  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1394  result = 0;
1395  else
1396  result = (int64) (dbentry->n_conflict_bufferpin);
1397 
1398  PG_RETURN_INT64(result);
1399 }
1400 
1401 Datum
1403 {
1404  Oid dbid = PG_GETARG_OID(0);
1405  int64 result;
1406  PgStat_StatDBEntry *dbentry;
1407 
1408  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1409  result = 0;
1410  else
1411  result = (int64) (dbentry->n_conflict_startup_deadlock);
1412 
1413  PG_RETURN_INT64(result);
1414 }
1415 
1416 Datum
1418 {
1419  Oid dbid = PG_GETARG_OID(0);
1420  int64 result;
1421  PgStat_StatDBEntry *dbentry;
1422 
1423  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1424  result = 0;
1425  else
1426  result = (int64) (
1427  dbentry->n_conflict_tablespace +
1428  dbentry->n_conflict_lock +
1429  dbentry->n_conflict_snapshot +
1430  dbentry->n_conflict_bufferpin +
1431  dbentry->n_conflict_startup_deadlock);
1432 
1433  PG_RETURN_INT64(result);
1434 }
1435 
1436 Datum
1438 {
1439  Oid dbid = PG_GETARG_OID(0);
1440  int64 result;
1441  PgStat_StatDBEntry *dbentry;
1442 
1443  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1444  result = 0;
1445  else
1446  result = (int64) (dbentry->n_deadlocks);
1447 
1448  PG_RETURN_INT64(result);
1449 }
1450 
1451 Datum
1453 {
1454  Oid dbid = PG_GETARG_OID(0);
1455  double result;
1456  PgStat_StatDBEntry *dbentry;
1457 
1458  /* convert counter from microsec to millisec for display */
1459  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1460  result = 0;
1461  else
1462  result = ((double) dbentry->n_block_read_time) / 1000.0;
1463 
1464  PG_RETURN_FLOAT8(result);
1465 }
1466 
1467 Datum
1469 {
1470  Oid dbid = PG_GETARG_OID(0);
1471  double result;
1472  PgStat_StatDBEntry *dbentry;
1473 
1474  /* convert counter from microsec to millisec for display */
1475  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1476  result = 0;
1477  else
1478  result = ((double) dbentry->n_block_write_time) / 1000.0;
1479 
1480  PG_RETURN_FLOAT8(result);
1481 }
1482 
1483 Datum
1485 {
1486  PG_RETURN_INT64(pgstat_fetch_global()->timed_checkpoints);
1487 }
1488 
1489 Datum
1491 {
1492  PG_RETURN_INT64(pgstat_fetch_global()->requested_checkpoints);
1493 }
1494 
1495 Datum
1497 {
1498  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_checkpoints);
1499 }
1500 
1501 Datum
1503 {
1504  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_clean);
1505 }
1506 
1507 Datum
1509 {
1510  PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_clean);
1511 }
1512 
1513 Datum
1515 {
1516  /* time is already in msec, just convert to double for presentation */
1517  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
1518 }
1519 
1520 Datum
1522 {
1523  /* time is already in msec, just convert to double for presentation */
1524  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
1525 }
1526 
1527 Datum
1529 {
1530  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stat_reset_timestamp);
1531 }
1532 
1533 Datum
1535 {
1536  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_backend);
1537 }
1538 
1539 Datum
1541 {
1542  PG_RETURN_INT64(pgstat_fetch_global()->buf_fsync_backend);
1543 }
1544 
1545 Datum
1547 {
1548  PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
1549 }
1550 
1551 Datum
1553 {
1554  Oid relid = PG_GETARG_OID(0);
1555  int64 result;
1556  PgStat_TableStatus *tabentry;
1557 
1558  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1559  result = 0;
1560  else
1561  result = (int64) (tabentry->t_counts.t_numscans);
1562 
1563  PG_RETURN_INT64(result);
1564 }
1565 
1566 Datum
1568 {
1569  Oid relid = PG_GETARG_OID(0);
1570  int64 result;
1571  PgStat_TableStatus *tabentry;
1572 
1573  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1574  result = 0;
1575  else
1576  result = (int64) (tabentry->t_counts.t_tuples_returned);
1577 
1578  PG_RETURN_INT64(result);
1579 }
1580 
1581 Datum
1583 {
1584  Oid relid = PG_GETARG_OID(0);
1585  int64 result;
1586  PgStat_TableStatus *tabentry;
1587 
1588  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1589  result = 0;
1590  else
1591  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1592 
1593  PG_RETURN_INT64(result);
1594 }
1595 
1596 Datum
1598 {
1599  Oid relid = PG_GETARG_OID(0);
1600  int64 result;
1601  PgStat_TableStatus *tabentry;
1603 
1604  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1605  result = 0;
1606  else
1607  {
1608  result = tabentry->t_counts.t_tuples_inserted;
1609  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1610  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1611  result += trans->tuples_inserted;
1612  }
1613 
1614  PG_RETURN_INT64(result);
1615 }
1616 
1617 Datum
1619 {
1620  Oid relid = PG_GETARG_OID(0);
1621  int64 result;
1622  PgStat_TableStatus *tabentry;
1624 
1625  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1626  result = 0;
1627  else
1628  {
1629  result = tabentry->t_counts.t_tuples_updated;
1630  /* live subtransactions' counts aren't in t_tuples_updated yet */
1631  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1632  result += trans->tuples_updated;
1633  }
1634 
1635  PG_RETURN_INT64(result);
1636 }
1637 
1638 Datum
1640 {
1641  Oid relid = PG_GETARG_OID(0);
1642  int64 result;
1643  PgStat_TableStatus *tabentry;
1645 
1646  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1647  result = 0;
1648  else
1649  {
1650  result = tabentry->t_counts.t_tuples_deleted;
1651  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1652  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1653  result += trans->tuples_deleted;
1654  }
1655 
1656  PG_RETURN_INT64(result);
1657 }
1658 
1659 Datum
1661 {
1662  Oid relid = PG_GETARG_OID(0);
1663  int64 result;
1664  PgStat_TableStatus *tabentry;
1665 
1666  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1667  result = 0;
1668  else
1669  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1670 
1671  PG_RETURN_INT64(result);
1672 }
1673 
1674 Datum
1676 {
1677  Oid relid = PG_GETARG_OID(0);
1678  int64 result;
1679  PgStat_TableStatus *tabentry;
1680 
1681  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1682  result = 0;
1683  else
1684  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1685 
1686  PG_RETURN_INT64(result);
1687 }
1688 
1689 Datum
1691 {
1692  Oid relid = PG_GETARG_OID(0);
1693  int64 result;
1694  PgStat_TableStatus *tabentry;
1695 
1696  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1697  result = 0;
1698  else
1699  result = (int64) (tabentry->t_counts.t_blocks_hit);
1700 
1701  PG_RETURN_INT64(result);
1702 }
1703 
1704 Datum
1706 {
1707  Oid funcid = PG_GETARG_OID(0);
1708  PgStat_BackendFunctionEntry *funcentry;
1709 
1710  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1711  PG_RETURN_NULL();
1712  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
1713 }
1714 
1715 Datum
1717 {
1718  Oid funcid = PG_GETARG_OID(0);
1719  PgStat_BackendFunctionEntry *funcentry;
1720 
1721  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1722  PG_RETURN_NULL();
1724 }
1725 
1726 Datum
1728 {
1729  Oid funcid = PG_GETARG_OID(0);
1730  PgStat_BackendFunctionEntry *funcentry;
1731 
1732  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1733  PG_RETURN_NULL();
1735 }
1736 
1737 
1738 /* Get the timestamp of the current statistics snapshot */
1739 Datum
1741 {
1742  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stats_timestamp);
1743 }
1744 
1745 /* Discard the active statistics snapshot */
1746 Datum
1748 {
1750 
1751  PG_RETURN_VOID();
1752 }
1753 
1754 
1755 /* Reset all counters for the current database */
1756 Datum
1758 {
1760 
1761  PG_RETURN_VOID();
1762 }
1763 
1764 /* Reset some shared cluster-wide counters */
1765 Datum
1767 {
1768  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
1769 
1771 
1772  PG_RETURN_VOID();
1773 }
1774 
1775 /* Reset a single counter in the current database */
1776 Datum
1778 {
1779  Oid taboid = PG_GETARG_OID(0);
1780 
1782 
1783  PG_RETURN_VOID();
1784 }
1785 
1786 Datum
1788 {
1789  Oid funcoid = PG_GETARG_OID(0);
1790 
1792 
1793  PG_RETURN_VOID();
1794 }
1795 
1796 Datum
1798 {
1799  TupleDesc tupdesc;
1800  Datum values[7];
1801  bool nulls[7];
1802  PgStat_ArchiverStats *archiver_stats;
1803 
1804  /* Initialise values and NULL flags arrays */
1805  MemSet(values, 0, sizeof(values));
1806  MemSet(nulls, 0, sizeof(nulls));
1807 
1808  /* Initialise attributes information in the tuple descriptor */
1809  tupdesc = CreateTemplateTupleDesc(7, false);
1810  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
1811  INT8OID, -1, 0);
1812  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
1813  TEXTOID, -1, 0);
1814  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
1815  TIMESTAMPTZOID, -1, 0);
1816  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
1817  INT8OID, -1, 0);
1818  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
1819  TEXTOID, -1, 0);
1820  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
1821  TIMESTAMPTZOID, -1, 0);
1822  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
1823  TIMESTAMPTZOID, -1, 0);
1824 
1825  BlessTupleDesc(tupdesc);
1826 
1827  /* Get statistics about the archiver process */
1828  archiver_stats = pgstat_fetch_stat_archiver();
1829 
1830  /* Fill values and NULLs */
1831  values[0] = Int64GetDatum(archiver_stats->archived_count);
1832  if (*(archiver_stats->last_archived_wal) == '\0')
1833  nulls[1] = true;
1834  else
1835  values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
1836 
1837  if (archiver_stats->last_archived_timestamp == 0)
1838  nulls[2] = true;
1839  else
1840  values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
1841 
1842  values[3] = Int64GetDatum(archiver_stats->failed_count);
1843  if (*(archiver_stats->last_failed_wal) == '\0')
1844  nulls[4] = true;
1845  else
1846  values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
1847 
1848  if (archiver_stats->last_failed_timestamp == 0)
1849  nulls[5] = true;
1850  else
1851  values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
1852 
1853  if (archiver_stats->stat_reset_timestamp == 0)
1854  nulls[6] = true;
1855  else
1856  values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
1857 
1858  /* Returns the record as Datum */
1860  heap_form_tuple(tupdesc, values, nulls)));
1861 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:735
Datum pg_stat_get_db_conflict_snapshot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1372
Datum pg_stat_get_db_tuples_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1262
#define TIMESTAMPTZOID
Definition: pg_type.h:521
Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1150
bool ssl_compression
Definition: pgstat.h:935
Datum pg_stat_get_db_deadlocks(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1437
Datum pg_stat_get_autoanalyze_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:345
Datum pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1417
Datum pg_stat_get_buf_fsync_backend(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1540
Datum pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:921
PgStat_Counter analyze_count
Definition: pgstat.h:641
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:937
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:672
Datum pg_stat_get_progress_info(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:438
instr_time f_self_time
Definition: pgstat.h:463
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
Datum pg_stat_get_mod_since_analyze(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:181
Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1129
PgStat_Counter archived_count
Definition: pgstat.h:667
Datum pg_stat_reset_single_function_counters(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1787
#define IsA(nodeptr, _type_)
Definition: nodes.h:557
Oid st_progress_command_target
Definition: pgstat.h:1014
Datum pg_stat_get_archiver(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1797
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
int MyProcPid
Definition: globals.c:38
#define NI_NUMERICHOST
Definition: getaddrinfo.h:80
Datum pg_stat_get_checkpoint_sync_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1521
PgStat_Counter tuples_updated
Definition: pgstat.h:168
PgStat_Counter tuples_returned
Definition: pgstat.h:621
Datum pg_stat_get_xact_tuples_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1618
Datum pg_stat_get_last_analyze_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:264
Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:117
uint32 wait_event_info
Definition: proc.h:172
Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1705
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3294
#define DatumGetInt32(X)
Definition: postgres.h:478
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:102
Oid GetUserId(void)
Definition: miscinit.c:283
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2433
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:982
#define TEXTOID
Definition: pg_type.h:324
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2330
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_blocks_hit
Definition: pgstat.h:581
int64 TimestampTz
Definition: timestamp.h:39
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:591
#define PG_STAT_GET_ACTIVITY_COLS
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:592
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:3984
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:107
Datum pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1468
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:199
Datum pg_stat_get_analyze_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:330
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:642
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:266
Datum pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1514
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
PgStat_Counter n_temp_files
Definition: pgstat.h:593
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
void pgstat_reset_shared_counters(const char *target)
Definition: pgstat.c:1292
struct sockaddr_storage addr
Definition: pqcomm.h:64
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
Datum pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1716
#define PG_RETURN_INET_P(x)
Definition: inet.h:125
TransactionId backend_xmin
Definition: pgstat.h:1080
Datum pg_stat_reset(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1757
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:936
Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:213
Datum pg_stat_get_tuples_returned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:53
PgStat_Counter n_tuples_returned
Definition: pgstat.h:582
PgStat_Counter vacuum_count
Definition: pgstat.h:637
SockAddr st_clientaddr
Definition: pgstat.h:988
Datum pg_stat_get_backend_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1012
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MemSet(start, val, len)
Definition: c.h:857
Datum pg_stat_get_snapshot_timestamp(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1740
Datum pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1508
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2350
TimestampTz stat_reset_timestamp
Definition: pgstat.h:599
return result
Definition: formatting.c:1618
Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:69
Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:395
Datum pg_stat_get_last_autoanalyze_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:282
instr_time f_total_time
Definition: pgstat.h:462
Datum pg_backend_pid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:856
Datum pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1690
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2539
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
Datum pg_stat_get_db_tuples_returned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1214
Datum pg_stat_get_numscans(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:37
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
ProgressCommandType st_progress_command
Definition: pgstat.h:1013
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
PgStat_Counter numscans
Definition: pgstat.h:619
#define lengthof(array)
Definition: c.h:562
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1546
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:627
PgStat_Counter f_total_time
Definition: pgstat.h:657
Datum pg_stat_get_db_temp_bytes(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1327
BackendState st_state
Definition: pgstat.h:996
PgStat_Counter t_tuples_returned
Definition: pgstat.h:101
Datum pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:942
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
char * st_clienthostname
Definition: pgstat.h:989
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
PgStat_Counter tuples_inserted
Definition: pgstat.h:624
PgStat_Counter f_numcalls
Definition: pgstat.h:461
Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:360
Datum pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1727
Datum pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1496
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2487
Datum pg_stat_get_db_tuples_deleted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1278
signed int int32
Definition: c.h:256
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
PgStat_Counter n_xact_commit
Definition: pgstat.h:578
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2522
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1800
Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:101
Oid st_databaseid
Definition: pgstat.h:986
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:917
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:580
Datum pg_stat_get_db_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1293
PgStat_Counter n_live_tuples
Definition: pgstat.h:629
Datum pg_stat_get_db_blk_read_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1452
Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:876
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define NI_MAXHOST
Definition: getaddrinfo.h:90
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:588
Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1166
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
Datum pg_stat_get_last_vacuum_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:228
TransactionId backend_xid
Definition: pgstat.h:1074
TimestampTz vacuum_timestamp
Definition: pgstat.h:636
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
Datum pg_stat_get_db_temp_files(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1311
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
PgStat_Counter n_dead_tuples
Definition: pgstat.h:630
Datum pg_stat_get_last_autovacuum_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:246
Datum pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1081
Datum pg_stat_get_xact_tuples_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1582
Datum pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1534
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
PgStat_Counter f_numcalls
Definition: pgstat.h:655
Datum pg_stat_get_xact_tuples_returned(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1567
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2377
Datum pg_stat_get_live_tuples(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:149
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:951
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:584
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1747
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_conflict_bufferpin(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1387
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3349
Datum pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1490
#define CStringGetDatum(X)
Definition: postgres.h:584
Datum pg_stat_get_db_conflict_lock(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1357
#define NI_MAXSERV
Definition: getaddrinfo.h:93
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1597
PgStat_Counter tuples_fetched
Definition: pgstat.h:622
unsigned int uint32
Definition: c.h:268
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:590
Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:964
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:902
TimestampTz st_state_start_timestamp
Definition: pgstat.h:983
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:586
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:2152
PgStat_Counter n_conflict_lock
Definition: pgstat.h:589
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:493
char * st_appname
Definition: pgstat.h:999
#define ereport(elevel, rest)
Definition: elog.h:122
PgStat_Counter t_blocks_hit
Definition: pgstat.h:115
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1323
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter n_xact_rollback
Definition: pgstat.h:579
Datum pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1660
Datum pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:990
Datum pg_stat_get_vacuum_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:300
Datum pg_stat_get_autovacuum_count(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:315
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:316
#define TransactionIdGetDatum(X)
Definition: postgres.h:527
Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:85
Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1182
PgBackendStatus backendStatus
Definition: pgstat.h:1068
uintptr_t Datum
Definition: postgres.h:372
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
Datum pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:133
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Datum pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1675
BackendType st_backendType
Definition: pgstat.h:977
PgStat_Counter blocks_hit
Definition: pgstat.h:634
int work_mem
Definition: globals.c:112
TimestampTz analyze_timestamp
Definition: pgstat.h:640
Datum pg_stat_get_function_self_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:383
TimestampTz last_failed_timestamp
Definition: pgstat.h:674
PgStat_Counter changes_since_analyze
Definition: pgstat.h:631
PgStat_Counter t_numscans
Definition: pgstat.h:99
#define BoolGetDatum(X)
Definition: postgres.h:408
#define NI_NUMERICSERV
Definition: getaddrinfo.h:83
PgStat_MsgBgWriter bgwriterStats
#define InvalidOid
Definition: postgres_ext.h:36
int allowedModes
Definition: execnodes.h:267
PgStat_Counter n_tuples_updated
Definition: pgstat.h:585
#define INT8OID
Definition: pg_type.h:304
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
Datum pg_stat_get_db_tuples_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1230
SetFunctionReturnMode returnMode
Definition: execnodes.h:269
text * cstring_to_text(const char *s)
Definition: varlena.c:149
Datum pg_stat_get_bgwriter_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1528
#define PG_ARGISNULL(n)
Definition: fmgr.h:174
#define NULL
Definition: c.h:229
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2506
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
ProgressCommandType
Definition: pgstat.h:911
char * st_activity
Definition: pgstat.h:1002
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2465
Datum pg_stat_reset_shared(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1766
PgStat_Counter failed_count
Definition: pgstat.h:671
PgStat_Counter n_block_write_time
Definition: pgstat.h:597
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1015
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:80
PgStat_Counter tuples_deleted
Definition: pgstat.h:626
Datum pg_stat_get_function_total_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:371
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5478
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
PgStat_Counter tuples_updated
Definition: pgstat.h:625
Datum pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1034
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:1504
Datum pg_stat_get_db_tuples_inserted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1246
Datum pg_stat_reset_single_table_counters(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1777
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:201
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:638
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:41
PgStat_Counter n_block_read_time
Definition: pgstat.h:596
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1198
int st_procpid
Definition: pgstat.h:974
Tuplestorestate * setResult
Definition: execnodes.h:272
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:643
Datum pg_stat_get_activity(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:540
static Datum values[MAXATTR]
Definition: bootstrap.c:162
char * text_to_cstring(const text *t)
Definition: varlena.c:182
ExprContext * econtext
Definition: execnodes.h:265
#define Int32GetDatum(X)
Definition: postgres.h:485
TimestampTz stat_reset_timestamp
Definition: pgstat.h:675
TimestampTz last_archived_timestamp
Definition: pgstat.h:670
Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:863
void * user_fctx
Definition: funcapi.h:90
TupleDesc setDesc
Definition: execnodes.h:273
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:382
int errmsg(const char *fmt,...)
Definition: elog.c:797
PgStat_Counter n_deadlocks
Definition: pgstat.h:595
Datum pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1484
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:981
#define PG_STAT_GET_PROGRESS_COLS
int i
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:31
Datum pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1597
Datum pg_stat_get_xact_numscans(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1552
#define CStringGetTextDatum(s)
Definition: builtins.h:91
Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:197
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
Datum pg_stat_get_db_conflict_startup_deadlock(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1402
#define elog
Definition: elog.h:219
Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:889
#define TransactionIdIsValid(xid)
Definition: transam.h:41
PgStat_Counter f_self_time
Definition: pgstat.h:658
Definition: proc.h:94
PgStat_Counter blocks_fetched
Definition: pgstat.h:633
Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:165
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:980
Datum pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1639
Datum pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1502
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:993
int16 AttrNumber
Definition: attnum.h:21
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
void pgstat_reset_counters(void)
Definition: pgstat.c:1270
#define PG_RETURN_NULL()
Definition: fmgr.h:305
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:114
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:583
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:668
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:639
char ssl_clientdn[NAMEDATALEN]
Definition: pgstat.h:938
Datum pg_stat_get_db_conflict_tablespace(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1342
PgStat_Counter n_temp_bytes
Definition: pgstat.h:594
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287