PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgstatfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_type.h"
#include "common/ip.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/postmaster.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/inet.h"
#include "utils/timestamp.h"
Include dependency graph for pgstatfuncs.c:

Go to the source code of this file.

Macros

#define UINT32_ACCESS_ONCE(var)   ((uint32)(*((volatile uint32 *)&(var))))
 
#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3
 
#define PG_STAT_GET_ACTIVITY_COLS   24
 

Functions

Datum pg_stat_get_numscans (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_returned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_inserted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_deleted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_hot_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_live_tuples (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_dead_tuples (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_mod_since_analyze (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_blocks_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_blocks_hit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_vacuum_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_autovacuum_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_analyze_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_autoanalyze_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_vacuum_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_autovacuum_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_analyze_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_autoanalyze_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_calls (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_total_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_self_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_idset (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_progress_info (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_activity (PG_FUNCTION_ARGS)
 
Datum pg_backend_pid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_pid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_dbid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_userid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_activity (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_wait_event_type (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_wait_event (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_activity_start (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_xact_start (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_start (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_client_addr (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_client_port (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_numbackends (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_xact_commit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_xact_rollback (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blocks_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blocks_hit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_returned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_inserted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_deleted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_stat_reset_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_temp_files (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_temp_bytes (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_tablespace (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_lock (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_snapshot (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_bufferpin (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_startup_deadlock (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_all (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_deadlocks (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blk_read_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blk_write_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_timed_checkpoints (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_requested_checkpoints (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_buf_written_checkpoints (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_buf_written_clean (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_maxwritten_clean (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpoint_write_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpoint_sync_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_stat_reset_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_buf_written_backend (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_buf_fsync_backend (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_buf_alloc (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_numscans (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_returned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_inserted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_deleted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_hot_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_blocks_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_blocks_hit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_calls (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_total_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_self_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_snapshot_timestamp (PG_FUNCTION_ARGS)
 
Datum pg_stat_clear_snapshot (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_shared (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_single_table_counters (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_single_function_counters (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_archiver (PG_FUNCTION_ARGS)
 

Variables

PgStat_MsgBgWriter bgwriterStats
 

Macro Definition Documentation

#define PG_STAT_GET_ACTIVITY_COLS   24

Referenced by pg_stat_get_activity().

#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3
#define UINT32_ACCESS_ONCE (   var)    ((uint32)(*((volatile uint32 *)&(var))))

Definition at line 32 of file pgstatfuncs.c.

Referenced by pg_stat_get_activity().

Function Documentation

Datum pg_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 861 of file pgstatfuncs.c.

References MyProcPid, and PG_RETURN_INT32.

862 {
864 }
int MyProcPid
Definition: globals.c:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1758 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_clear_snapshot().

1759 {
1761 
1762  PG_RETURN_VOID();
1763 }
#define PG_RETURN_VOID()
Definition: fmgr.h:309
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5560
Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 541 of file pgstatfuncs.c.

References SockAddr::addr, ReturnSetInfo::allowedModes, AuxiliaryPidGetProc(), B_BACKEND, LocalPgBackendStatus::backend_xid, LocalPgBackendStatus::backend_xmin, BackendPidGetProc(), LocalPgBackendStatus::backendStatus, BoolGetDatum, clean_ipv6_addr(), CStringGetDatum, CStringGetTextDatum, DatumGetInt32, DEFAULT_ROLE_READ_ALL_STATS, DirectFunctionCall1, ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), GetUserId(), has_privs_of_role(), i, inet_in(), Int32GetDatum, InvalidOid, is_member_of_role(), IsA, lengthof, MemoryContextSwitchTo(), MemSet, NI_MAXHOST, NI_MAXSERV, NI_NUMERICHOST, NI_NUMERICSERV, ObjectIdGetDatum, pfree(), PG_ARGISNULL, PG_GETARG_INT32, pg_getnameinfo_all(), PG_STAT_GET_ACTIVITY_COLS, pgstat_clip_activity(), pgstat_fetch_stat_local_beentry(), pgstat_fetch_stat_numbackends(), pgstat_get_backend_desc(), pgstat_get_wait_event(), pgstat_get_wait_event_type(), ReturnSetInfo::returnMode, SockAddr::salen, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, PgBackendSSLStatus::ssl_bits, PgBackendSSLStatus::ssl_cipher, PgBackendSSLStatus::ssl_clientdn, PgBackendSSLStatus::ssl_compression, PgBackendSSLStatus::ssl_version, PgBackendStatus::st_activity_raw, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_appname, PgBackendStatus::st_backendType, PgBackendStatus::st_clientaddr, PgBackendStatus::st_clienthostname, PgBackendStatus::st_databaseid, PgBackendStatus::st_proc_start_timestamp, PgBackendStatus::st_procpid, PgBackendStatus::st_ssl, PgBackendStatus::st_sslstatus, PgBackendStatus::st_state, PgBackendStatus::st_state_start_timestamp, PgBackendStatus::st_userid, PgBackendStatus::st_xact_start_timestamp, STATE_DISABLED, STATE_FASTPATH, STATE_IDLE, STATE_IDLEINTRANSACTION, STATE_IDLEINTRANSACTION_ABORTED, STATE_RUNNING, STATE_UNDEFINED, TimestampTzGetDatum, TransactionIdGetDatum, TransactionIdIsValid, tuplestore_begin_heap(), tuplestore_donestoring, tuplestore_putvalues(), TYPEFUNC_COMPOSITE, UINT32_ACCESS_ONCE, values, PGPROC::wait_event_info, and work_mem.

542 {
543 #define PG_STAT_GET_ACTIVITY_COLS 24
544  int num_backends = pgstat_fetch_stat_numbackends();
545  int curr_backend;
546  int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
547  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
548  TupleDesc tupdesc;
549  Tuplestorestate *tupstore;
550  MemoryContext per_query_ctx;
551  MemoryContext oldcontext;
552 
553  /* check to see if caller supports us returning a tuplestore */
554  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
555  ereport(ERROR,
556  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
557  errmsg("set-valued function called in context that cannot accept a set")));
558  if (!(rsinfo->allowedModes & SFRM_Materialize))
559  ereport(ERROR,
560  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
561  errmsg("materialize mode required, but it is not " \
562  "allowed in this context")));
563 
564  /* Build a tuple descriptor for our result type */
565  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
566  elog(ERROR, "return type must be a row type");
567 
568  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
569  oldcontext = MemoryContextSwitchTo(per_query_ctx);
570 
571  tupstore = tuplestore_begin_heap(true, false, work_mem);
572  rsinfo->returnMode = SFRM_Materialize;
573  rsinfo->setResult = tupstore;
574  rsinfo->setDesc = tupdesc;
575 
576  MemoryContextSwitchTo(oldcontext);
577 
578  /* 1-based index */
579  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
580  {
581  /* for each row */
583  bool nulls[PG_STAT_GET_ACTIVITY_COLS];
584  LocalPgBackendStatus *local_beentry;
585  PgBackendStatus *beentry;
586  PGPROC *proc;
587  const char *wait_event_type = NULL;
588  const char *wait_event = NULL;
589 
590  MemSet(values, 0, sizeof(values));
591  MemSet(nulls, 0, sizeof(nulls));
592 
593  /* Get the next one in the list */
594  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
595  if (!local_beentry)
596  {
597  int i;
598 
599  /* Ignore missing entries if looking for specific PID */
600  if (pid != -1)
601  continue;
602 
603  for (i = 0; i < lengthof(nulls); i++)
604  nulls[i] = true;
605 
606  nulls[5] = false;
607  values[5] = CStringGetTextDatum("<backend information not available>");
608 
609  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
610  continue;
611  }
612 
613  beentry = &local_beentry->backendStatus;
614 
615  /* If looking for specific PID, ignore all the others */
616  if (pid != -1 && beentry->st_procpid != pid)
617  continue;
618 
619  /* Values available to all callers */
620  if (beentry->st_databaseid != InvalidOid)
621  values[0] = ObjectIdGetDatum(beentry->st_databaseid);
622  else
623  nulls[0] = true;
624 
625  values[1] = Int32GetDatum(beentry->st_procpid);
626 
627  if (beentry->st_userid != InvalidOid)
628  values[2] = ObjectIdGetDatum(beentry->st_userid);
629  else
630  nulls[2] = true;
631 
632  if (beentry->st_appname)
633  values[3] = CStringGetTextDatum(beentry->st_appname);
634  else
635  nulls[3] = true;
636 
637  if (TransactionIdIsValid(local_beentry->backend_xid))
638  values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
639  else
640  nulls[15] = true;
641 
642  if (TransactionIdIsValid(local_beentry->backend_xmin))
643  values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
644  else
645  nulls[16] = true;
646 
647  if (beentry->st_ssl)
648  {
649  values[18] = BoolGetDatum(true); /* ssl */
650  values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version);
651  values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher);
652  values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
653  values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression);
654  values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_clientdn);
655  }
656  else
657  {
658  values[18] = BoolGetDatum(false); /* ssl */
659  nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = true;
660  }
661 
662  /* Values only available to role member or pg_read_all_stats */
663  if (has_privs_of_role(GetUserId(), beentry->st_userid) ||
665  {
666  SockAddr zero_clientaddr;
667  char *clipped_activity;
668 
669  switch (beentry->st_state)
670  {
671  case STATE_IDLE:
672  values[4] = CStringGetTextDatum("idle");
673  break;
674  case STATE_RUNNING:
675  values[4] = CStringGetTextDatum("active");
676  break;
678  values[4] = CStringGetTextDatum("idle in transaction");
679  break;
680  case STATE_FASTPATH:
681  values[4] = CStringGetTextDatum("fastpath function call");
682  break;
684  values[4] = CStringGetTextDatum("idle in transaction (aborted)");
685  break;
686  case STATE_DISABLED:
687  values[4] = CStringGetTextDatum("disabled");
688  break;
689  case STATE_UNDEFINED:
690  nulls[4] = true;
691  break;
692  }
693 
694  clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
695  values[5] = CStringGetTextDatum(clipped_activity);
696  pfree(clipped_activity);
697 
698  proc = BackendPidGetProc(beentry->st_procpid);
699  if (proc != NULL)
700  {
701  uint32 raw_wait_event;
702 
703  raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
704  wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
705  wait_event = pgstat_get_wait_event(raw_wait_event);
706 
707  }
708  else if (beentry->st_backendType != B_BACKEND)
709  {
710  /*
711  * For an auxiliary process, retrieve process info from
712  * AuxiliaryProcs stored in shared-memory.
713  */
714  proc = AuxiliaryPidGetProc(beentry->st_procpid);
715 
716  if (proc != NULL)
717  {
718  uint32 raw_wait_event;
719 
720  raw_wait_event =
722  wait_event_type =
723  pgstat_get_wait_event_type(raw_wait_event);
724  wait_event = pgstat_get_wait_event(raw_wait_event);
725  }
726  }
727 
728  if (wait_event_type)
729  values[6] = CStringGetTextDatum(wait_event_type);
730  else
731  nulls[6] = true;
732 
733  if (wait_event)
734  values[7] = CStringGetTextDatum(wait_event);
735  else
736  nulls[7] = true;
737 
738  if (beentry->st_xact_start_timestamp != 0)
739  values[8] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
740  else
741  nulls[8] = true;
742 
743  if (beentry->st_activity_start_timestamp != 0)
744  values[9] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
745  else
746  nulls[9] = true;
747 
748  if (beentry->st_proc_start_timestamp != 0)
749  values[10] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
750  else
751  nulls[10] = true;
752 
753  if (beentry->st_state_start_timestamp != 0)
754  values[11] = TimestampTzGetDatum(beentry->st_state_start_timestamp);
755  else
756  nulls[11] = true;
757 
758  /* A zeroed client addr means we don't know */
759  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
760  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
761  sizeof(zero_clientaddr)) == 0)
762  {
763  nulls[12] = true;
764  nulls[13] = true;
765  nulls[14] = true;
766  }
767  else
768  {
769  if (beentry->st_clientaddr.addr.ss_family == AF_INET
770 #ifdef HAVE_IPV6
771  || beentry->st_clientaddr.addr.ss_family == AF_INET6
772 #endif
773  )
774  {
775  char remote_host[NI_MAXHOST];
776  char remote_port[NI_MAXSERV];
777  int ret;
778 
779  remote_host[0] = '\0';
780  remote_port[0] = '\0';
781  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
782  beentry->st_clientaddr.salen,
783  remote_host, sizeof(remote_host),
784  remote_port, sizeof(remote_port),
786  if (ret == 0)
787  {
788  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
789  values[12] = DirectFunctionCall1(inet_in,
790  CStringGetDatum(remote_host));
791  if (beentry->st_clienthostname &&
792  beentry->st_clienthostname[0])
793  values[13] = CStringGetTextDatum(beentry->st_clienthostname);
794  else
795  nulls[13] = true;
796  values[14] = Int32GetDatum(atoi(remote_port));
797  }
798  else
799  {
800  nulls[12] = true;
801  nulls[13] = true;
802  nulls[14] = true;
803  }
804  }
805  else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
806  {
807  /*
808  * Unix sockets always reports NULL for host and -1 for
809  * port, so it's possible to tell the difference to
810  * connections we have no permissions to view, or with
811  * errors.
812  */
813  nulls[12] = true;
814  nulls[13] = true;
815  values[14] = DatumGetInt32(-1);
816  }
817  else
818  {
819  /* Unknown address type, should never happen */
820  nulls[12] = true;
821  nulls[13] = true;
822  nulls[14] = true;
823  }
824  }
825  /* Add backend type */
826  values[17] =
828  }
829  else
830  {
831  /* No permissions to view data about this session */
832  values[5] = CStringGetTextDatum("<insufficient privilege>");
833  nulls[4] = true;
834  nulls[6] = true;
835  nulls[7] = true;
836  nulls[8] = true;
837  nulls[9] = true;
838  nulls[10] = true;
839  nulls[11] = true;
840  nulls[12] = true;
841  nulls[13] = true;
842  nulls[14] = true;
843  nulls[17] = true;
844  }
845 
846  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
847 
848  /* If only a single backend was requested, and we found it, break. */
849  if (pid != -1)
850  break;
851  }
852 
853  /* clean up and return the tuplestore */
854  tuplestore_donestoring(tupstore);
855 
856  return (Datum) 0;
857 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
bool ssl_compression
Definition: pgstat.h:940
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:942
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
uint32 wait_event_info
Definition: proc.h:173
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3335
#define DatumGetInt32(X)
Definition: postgres.h:478
Oid GetUserId(void)
Definition: miscinit.c:284
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:987
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2346
#define PG_STAT_GET_ACTIVITY_COLS
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4044
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
struct sockaddr_storage addr
Definition: pqcomm.h:64
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
TransactionId backend_xmin
Definition: pgstat.h:1091
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:941
SockAddr st_clientaddr
Definition: pgstat.h:993
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MemSet(start, val, len)
Definition: c.h:846
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
#define lengthof(array)
Definition: c.h:556
BackendState st_state
Definition: pgstat.h:1001
char * st_clienthostname
Definition: pgstat.h:994
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2524
Oid st_databaseid
Definition: pgstat.h:991
void pfree(void *pointer)
Definition: mcxt.c:949
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
TransactionId backend_xid
Definition: pgstat.h:1085
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:960
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3390
char * st_activity_raw
Definition: pgstat.h:1013
#define CStringGetDatum(X)
Definition: postgres.h:584
#define NI_MAXSERV
Definition: getaddrinfo.h:91
unsigned int uint32
Definition: c.h:258
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
TimestampTz st_state_start_timestamp
Definition: pgstat.h:988
char * st_appname
Definition: pgstat.h:1004
#define ereport(elevel, rest)
Definition: elog.h:122
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
#define TransactionIdGetDatum(X)
Definition: postgres.h:527
PgBackendStatus backendStatus
Definition: pgstat.h:1079
uintptr_t Datum
Definition: postgres.h:372
BackendType st_backendType
Definition: pgstat.h:982
int work_mem
Definition: globals.c:113
#define DEFAULT_ROLE_READ_ALL_STATS
Definition: pg_authid.h:108
#define BoolGetDatum(X)
Definition: postgres.h:408
#define NI_NUMERICSERV
Definition: getaddrinfo.h:81
#define InvalidOid
Definition: postgres_ext.h:36
int allowedModes
Definition: execnodes.h:268
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4852
SetFunctionReturnMode returnMode
Definition: execnodes.h:270
#define PG_ARGISNULL(n)
Definition: fmgr.h:174
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2543
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
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:80
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:1514
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:202
int st_procpid
Definition: pgstat.h:979
Tuplestorestate * setResult
Definition: execnodes.h:273
static Datum values[MAXATTR]
Definition: bootstrap.c:164
ExprContext * econtext
Definition: execnodes.h:266
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6291
#define Int32GetDatum(X)
Definition: postgres.h:485
TupleDesc setDesc
Definition: execnodes.h:274
int errmsg(const char *fmt,...)
Definition: elog.c:797
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:986
int i
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:32
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define elog
Definition: elog.h:219
#define TransactionIdIsValid(xid)
Definition: transam.h:41
Definition: proc.h:95
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:985
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:998
char ssl_clientdn[NAMEDATALEN]
Definition: pgstat.h:943
Datum pg_stat_get_analyze_count ( PG_FUNCTION_ARGS  )

Definition at line 331 of file pgstatfuncs.c.

References PgStat_StatTabEntry::analyze_count, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

332 {
333  Oid relid = PG_GETARG_OID(0);
334  int64 result;
335  PgStat_StatTabEntry *tabentry;
336 
337  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
338  result = 0;
339  else
340  result = (int64) (tabentry->analyze_count);
341 
342  PG_RETURN_INT64(result);
343 }
PgStat_Counter analyze_count
Definition: pgstat.h:641
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_archiver ( PG_FUNCTION_ARGS  )

Definition at line 1808 of file pgstatfuncs.c.

References PgStat_ArchiverStats::archived_count, BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, PgStat_ArchiverStats::failed_count, heap_form_tuple(), HeapTupleGetDatum, Int64GetDatum(), INT8OID, PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, MemSet, PG_RETURN_DATUM, pgstat_fetch_stat_archiver(), PgStat_ArchiverStats::stat_reset_timestamp, TEXTOID, TimestampTzGetDatum, TIMESTAMPTZOID, TupleDescInitEntry(), and values.

1809 {
1810  TupleDesc tupdesc;
1811  Datum values[7];
1812  bool nulls[7];
1813  PgStat_ArchiverStats *archiver_stats;
1814 
1815  /* Initialise values and NULL flags arrays */
1816  MemSet(values, 0, sizeof(values));
1817  MemSet(nulls, 0, sizeof(nulls));
1818 
1819  /* Initialise attributes information in the tuple descriptor */
1820  tupdesc = CreateTemplateTupleDesc(7, false);
1821  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
1822  INT8OID, -1, 0);
1823  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
1824  TEXTOID, -1, 0);
1825  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
1826  TIMESTAMPTZOID, -1, 0);
1827  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
1828  INT8OID, -1, 0);
1829  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
1830  TEXTOID, -1, 0);
1831  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
1832  TIMESTAMPTZOID, -1, 0);
1833  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
1834  TIMESTAMPTZOID, -1, 0);
1835 
1836  BlessTupleDesc(tupdesc);
1837 
1838  /* Get statistics about the archiver process */
1839  archiver_stats = pgstat_fetch_stat_archiver();
1840 
1841  /* Fill values and NULLs */
1842  values[0] = Int64GetDatum(archiver_stats->archived_count);
1843  if (*(archiver_stats->last_archived_wal) == '\0')
1844  nulls[1] = true;
1845  else
1846  values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
1847 
1848  if (archiver_stats->last_archived_timestamp == 0)
1849  nulls[2] = true;
1850  else
1851  values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
1852 
1853  values[3] = Int64GetDatum(archiver_stats->failed_count);
1854  if (*(archiver_stats->last_failed_wal) == '\0')
1855  nulls[4] = true;
1856  else
1857  values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
1858 
1859  if (archiver_stats->last_failed_timestamp == 0)
1860  nulls[5] = true;
1861  else
1862  values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
1863 
1864  if (archiver_stats->stat_reset_timestamp == 0)
1865  nulls[6] = true;
1866  else
1867  values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
1868 
1869  /* Returns the record as Datum */
1871  heap_form_tuple(tupdesc, values, nulls)));
1872 }
#define TIMESTAMPTZOID
Definition: pg_type.h:525
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:672
PgStat_Counter archived_count
Definition: pgstat.h:667
#define TEXTOID
Definition: pg_type.h:324
#define MemSet(start, val, len)
Definition: c.h:846
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2559
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1791
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
TimestampTz last_failed_timestamp
Definition: pgstat.h:674
#define INT8OID
Definition: pg_type.h:304
PgStat_Counter failed_count
Definition: pgstat.h:671
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
static Datum values[MAXATTR]
Definition: bootstrap.c:164
TimestampTz stat_reset_timestamp
Definition: pgstat.h:675
TimestampTz last_archived_timestamp
Definition: pgstat.h:670
#define CStringGetTextDatum(s)
Definition: builtins.h:91
int16 AttrNumber
Definition: attnum.h:21
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:668
Datum pg_stat_get_autoanalyze_count ( PG_FUNCTION_ARGS  )

Definition at line 346 of file pgstatfuncs.c.

References PgStat_StatTabEntry::autovac_analyze_count, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

347 {
348  Oid relid = PG_GETARG_OID(0);
349  int64 result;
350  PgStat_StatTabEntry *tabentry;
351 
352  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
353  result = 0;
354  else
355  result = (int64) (tabentry->autovac_analyze_count);
356 
357  PG_RETURN_INT64(result);
358 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:643
Datum pg_stat_get_autovacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 316 of file pgstatfuncs.c.

References PgStat_StatTabEntry::autovac_vacuum_count, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

317 {
318  Oid relid = PG_GETARG_OID(0);
319  int64 result;
320  PgStat_StatTabEntry *tabentry;
321 
322  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
323  result = 0;
324  else
325  result = (int64) (tabentry->autovac_vacuum_count);
326 
327  PG_RETURN_INT64(result);
328 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:639
Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 907 of file pgstatfuncs.c.

References cstring_to_text(), GetUserId(), has_privs_of_role(), pfree(), PG_GETARG_INT32, PG_RETURN_TEXT_P, pgstat_clip_activity(), pgstat_fetch_stat_beentry(), PgBackendStatus::st_activity_raw, and PgBackendStatus::st_userid.

908 {
909  int32 beid = PG_GETARG_INT32(0);
910  PgBackendStatus *beentry;
911  const char *activity;
912  char *clipped_activity;
913  text *ret;
914 
915  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
916  activity = "<backend information not available>";
917  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
918  activity = "<insufficient privilege>";
919  else if (*(beentry->st_activity_raw) == '\0')
920  activity = "<command string not enabled>";
921  else
922  activity = beentry->st_activity_raw;
923 
924  clipped_activity = pgstat_clip_activity(activity);
925  ret = cstring_to_text(activity);
926  pfree(clipped_activity);
927 
928  PG_RETURN_TEXT_P(ret);
929 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
Oid GetUserId(void)
Definition: miscinit.c:284
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
signed int int32
Definition: c.h:246
void pfree(void *pointer)
Definition: mcxt.c:949
char * st_activity_raw
Definition: pgstat.h:1013
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:331
text * cstring_to_text(const char *s)
Definition: varlena.c:149
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6291
Definition: c.h:433
Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 975 of file pgstatfuncs.c.

References GetUserId(), has_privs_of_role(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_fetch_stat_beentry(), PgBackendStatus::st_activity_start_timestamp, and PgBackendStatus::st_userid.

976 {
977  int32 beid = PG_GETARG_INT32(0);
978  TimestampTz result;
979  PgBackendStatus *beentry;
980 
981  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
982  PG_RETURN_NULL();
983 
984  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
985  PG_RETURN_NULL();
986 
987  result = beentry->st_activity_start_timestamp;
988 
989  /*
990  * No time recorded for start of current query -- this is the case if the
991  * user hasn't enabled query-level stats collection.
992  */
993  if (result == 0)
994  PG_RETURN_NULL();
995 
996  PG_RETURN_TIMESTAMPTZ(result);
997 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
Oid GetUserId(void)
Definition: miscinit.c:284
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:987
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:246
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 1045 of file pgstatfuncs.c.

References SockAddr::addr, clean_ipv6_addr(), CStringGetDatum, DirectFunctionCall1, GetUserId(), has_privs_of_role(), inet_in(), NI_MAXHOST, NI_NUMERICHOST, NI_NUMERICSERV, PG_GETARG_INT32, pg_getnameinfo_all(), PG_RETURN_INET_P, PG_RETURN_NULL, pgstat_fetch_stat_beentry(), SockAddr::salen, PgBackendStatus::st_clientaddr, and PgBackendStatus::st_userid.

1046 {
1047  int32 beid = PG_GETARG_INT32(0);
1048  PgBackendStatus *beentry;
1049  SockAddr zero_clientaddr;
1050  char remote_host[NI_MAXHOST];
1051  int ret;
1052 
1053  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1054  PG_RETURN_NULL();
1055 
1056  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1057  PG_RETURN_NULL();
1058 
1059  /* A zeroed client addr means we don't know */
1060  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1061  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1062  sizeof(zero_clientaddr)) == 0)
1063  PG_RETURN_NULL();
1064 
1065  switch (beentry->st_clientaddr.addr.ss_family)
1066  {
1067  case AF_INET:
1068 #ifdef HAVE_IPV6
1069  case AF_INET6:
1070 #endif
1071  break;
1072  default:
1073  PG_RETURN_NULL();
1074  }
1075 
1076  remote_host[0] = '\0';
1077  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1078  beentry->st_clientaddr.salen,
1079  remote_host, sizeof(remote_host),
1080  NULL, 0,
1082  if (ret != 0)
1083  PG_RETURN_NULL();
1084 
1085  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1086 
1088  CStringGetDatum(remote_host)));
1089 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Oid GetUserId(void)
Definition: miscinit.c:284
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INET_P(x)
Definition: inet.h:125
SockAddr st_clientaddr
Definition: pgstat.h:993
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
signed int int32
Definition: c.h:246
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define CStringGetDatum(X)
Definition: postgres.h:584
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
#define NI_NUMERICSERV
Definition: getaddrinfo.h:81
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
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:80
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:1514
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 1092 of file pgstatfuncs.c.

References SockAddr::addr, CStringGetDatum, DirectFunctionCall1, GetUserId(), has_privs_of_role(), int4in(), NI_MAXSERV, NI_NUMERICHOST, NI_NUMERICSERV, PG_GETARG_INT32, pg_getnameinfo_all(), PG_RETURN_DATUM, PG_RETURN_INT32, PG_RETURN_NULL, pgstat_fetch_stat_beentry(), SockAddr::salen, PgBackendStatus::st_clientaddr, and PgBackendStatus::st_userid.

1093 {
1094  int32 beid = PG_GETARG_INT32(0);
1095  PgBackendStatus *beentry;
1096  SockAddr zero_clientaddr;
1097  char remote_port[NI_MAXSERV];
1098  int ret;
1099 
1100  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1101  PG_RETURN_NULL();
1102 
1103  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1104  PG_RETURN_NULL();
1105 
1106  /* A zeroed client addr means we don't know */
1107  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1108  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1109  sizeof(zero_clientaddr)) == 0)
1110  PG_RETURN_NULL();
1111 
1112  switch (beentry->st_clientaddr.addr.ss_family)
1113  {
1114  case AF_INET:
1115 #ifdef HAVE_IPV6
1116  case AF_INET6:
1117 #endif
1118  break;
1119  case AF_UNIX:
1120  PG_RETURN_INT32(-1);
1121  default:
1122  PG_RETURN_NULL();
1123  }
1124 
1125  remote_port[0] = '\0';
1126  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1127  beentry->st_clientaddr.salen,
1128  NULL, 0,
1129  remote_port, sizeof(remote_port),
1131  if (ret != 0)
1132  PG_RETURN_NULL();
1133 
1135  CStringGetDatum(remote_port)));
1136 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Oid GetUserId(void)
Definition: miscinit.c:284
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:266
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
SockAddr st_clientaddr
Definition: pgstat.h:993
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
signed int int32
Definition: c.h:246
#define CStringGetDatum(X)
Definition: postgres.h:584
#define NI_MAXSERV
Definition: getaddrinfo.h:91
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define NI_NUMERICSERV
Definition: getaddrinfo.h:81
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
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 881 of file pgstatfuncs.c.

References PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_OID, pgstat_fetch_stat_beentry(), and PgBackendStatus::st_databaseid.

882 {
883  int32 beid = PG_GETARG_INT32(0);
884  PgBackendStatus *beentry;
885 
886  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
887  PG_RETURN_NULL();
888 
889  PG_RETURN_OID(beentry->st_databaseid);
890 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
signed int int32
Definition: c.h:246
Oid st_databaseid
Definition: pgstat.h:991
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

Definition at line 396 of file pgstatfuncs.c.

References Int32GetDatum, MemoryContextAlloc(), FuncCallContext::multi_call_memory_ctx, pgstat_fetch_stat_numbackends(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, and FuncCallContext::user_fctx.

397 {
398  FuncCallContext *funcctx;
399  int *fctx;
400  int32 result;
401 
402  /* stuff done only on the first call of the function */
403  if (SRF_IS_FIRSTCALL())
404  {
405  /* create a function context for cross-call persistence */
406  funcctx = SRF_FIRSTCALL_INIT();
407 
409  2 * sizeof(int));
410  funcctx->user_fctx = fctx;
411 
412  fctx[0] = 0;
413  fctx[1] = pgstat_fetch_stat_numbackends();
414  }
415 
416  /* stuff done on every call of the function */
417  funcctx = SRF_PERCALL_SETUP();
418  fctx = funcctx->user_fctx;
419 
420  fctx[0] += 1;
421  result = fctx[0];
422 
423  if (result <= fctx[1])
424  {
425  /* do when there is more left to send */
426  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
427  }
428  else
429  {
430  /* do when there is no more left */
431  SRF_RETURN_DONE(funcctx);
432  }
433 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
signed int int32
Definition: c.h:246
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2543
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
#define Int32GetDatum(X)
Definition: postgres.h:485
void * user_fctx
Definition: funcapi.h:90
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:706
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
Datum pg_stat_get_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 868 of file pgstatfuncs.c.

References PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, pgstat_fetch_stat_beentry(), and PgBackendStatus::st_procpid.

869 {
870  int32 beid = PG_GETARG_INT32(0);
871  PgBackendStatus *beentry;
872 
873  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
874  PG_RETURN_NULL();
875 
876  PG_RETURN_INT32(beentry->st_procpid);
877 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:246
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
int st_procpid
Definition: pgstat.h:979
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 1023 of file pgstatfuncs.c.

References GetUserId(), has_privs_of_role(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_fetch_stat_beentry(), PgBackendStatus::st_proc_start_timestamp, and PgBackendStatus::st_userid.

1024 {
1025  int32 beid = PG_GETARG_INT32(0);
1026  TimestampTz result;
1027  PgBackendStatus *beentry;
1028 
1029  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1030  PG_RETURN_NULL();
1031 
1032  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1033  PG_RETURN_NULL();
1034 
1035  result = beentry->st_proc_start_timestamp;
1036 
1037  if (result == 0) /* probably can't happen? */
1038  PG_RETURN_NULL();
1039 
1040  PG_RETURN_TIMESTAMPTZ(result);
1041 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
Oid GetUserId(void)
Definition: miscinit.c:284
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:246
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:985
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 894 of file pgstatfuncs.c.

References PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_OID, pgstat_fetch_stat_beentry(), and PgBackendStatus::st_userid.

895 {
896  int32 beid = PG_GETARG_INT32(0);
897  PgBackendStatus *beentry;
898 
899  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
900  PG_RETURN_NULL();
901 
902  PG_RETURN_OID(beentry->st_userid);
903 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
signed int int32
Definition: c.h:246
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 953 of file pgstatfuncs.c.

References BackendPidGetProc(), cstring_to_text(), GetUserId(), has_privs_of_role(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TEXT_P, pgstat_fetch_stat_beentry(), pgstat_get_wait_event(), PgBackendStatus::st_procpid, PgBackendStatus::st_userid, and PGPROC::wait_event_info.

954 {
955  int32 beid = PG_GETARG_INT32(0);
956  PgBackendStatus *beentry;
957  PGPROC *proc;
958  const char *wait_event = NULL;
959 
960  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
961  wait_event = "<backend information not available>";
962  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
963  wait_event = "<insufficient privilege>";
964  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
965  wait_event = pgstat_get_wait_event(proc->wait_event_info);
966 
967  if (!wait_event)
968  PG_RETURN_NULL();
969 
970  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
971 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
uint32 wait_event_info
Definition: proc.h:173
Oid GetUserId(void)
Definition: miscinit.c:284
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2346
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
signed int int32
Definition: c.h:246
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3390
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:331
text * cstring_to_text(const char *s)
Definition: varlena.c:149
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
int st_procpid
Definition: pgstat.h:979
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_wait_event_type ( PG_FUNCTION_ARGS  )

Definition at line 932 of file pgstatfuncs.c.

References BackendPidGetProc(), cstring_to_text(), GetUserId(), has_privs_of_role(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TEXT_P, pgstat_fetch_stat_beentry(), pgstat_get_wait_event_type(), PgBackendStatus::st_procpid, PgBackendStatus::st_userid, and PGPROC::wait_event_info.

933 {
934  int32 beid = PG_GETARG_INT32(0);
935  PgBackendStatus *beentry;
936  PGPROC *proc;
937  const char *wait_event_type = NULL;
938 
939  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
940  wait_event_type = "<backend information not available>";
941  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
942  wait_event_type = "<insufficient privilege>";
943  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
944  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
945 
946  if (!wait_event_type)
947  PG_RETURN_NULL();
948 
949  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
950 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
uint32 wait_event_info
Definition: proc.h:173
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3335
Oid GetUserId(void)
Definition: miscinit.c:284
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2346
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
signed int int32
Definition: c.h:246
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:331
text * cstring_to_text(const char *s)
Definition: varlena.c:149
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
int st_procpid
Definition: pgstat.h:979
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 1001 of file pgstatfuncs.c.

References GetUserId(), has_privs_of_role(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_fetch_stat_beentry(), PgBackendStatus::st_userid, and PgBackendStatus::st_xact_start_timestamp.

1002 {
1003  int32 beid = PG_GETARG_INT32(0);
1004  TimestampTz result;
1005  PgBackendStatus *beentry;
1006 
1007  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1008  PG_RETURN_NULL();
1009 
1010  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1011  PG_RETURN_NULL();
1012 
1013  result = beentry->st_xact_start_timestamp;
1014 
1015  if (result == 0) /* not in a transaction */
1016  PG_RETURN_NULL();
1017 
1018  PG_RETURN_TIMESTAMPTZ(result);
1019 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
Oid GetUserId(void)
Definition: miscinit.c:284
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:246
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:986
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_bgwriter_buf_written_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1507 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1508 {
1509  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_checkpoints);
1510 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1513 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1514 {
1515  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_clean);
1516 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_bgwriter_maxwritten_clean ( PG_FUNCTION_ARGS  )

Definition at line 1519 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1520 {
1521  PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_clean);
1522 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_bgwriter_requested_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1501 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1502 {
1503  PG_RETURN_INT64(pgstat_fetch_global()->requested_checkpoints);
1504 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_bgwriter_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1539 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1540 {
1541  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stat_reset_timestamp);
1542 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
Datum pg_stat_get_bgwriter_timed_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1495 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1496 {
1497  PG_RETURN_INT64(pgstat_fetch_global()->timed_checkpoints);
1498 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 198 of file pgstatfuncs.c.

References PgStat_StatTabEntry::blocks_fetched, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

199 {
200  Oid relid = PG_GETARG_OID(0);
201  int64 result;
202  PgStat_StatTabEntry *tabentry;
203 
204  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
205  result = 0;
206  else
207  result = (int64) (tabentry->blocks_fetched);
208 
209  PG_RETURN_INT64(result);
210 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter blocks_fetched
Definition: pgstat.h:633
Datum pg_stat_get_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 214 of file pgstatfuncs.c.

References PgStat_StatTabEntry::blocks_hit, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

215 {
216  Oid relid = PG_GETARG_OID(0);
217  int64 result;
218  PgStat_StatTabEntry *tabentry;
219 
220  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
221  result = 0;
222  else
223  result = (int64) (tabentry->blocks_hit);
224 
225  PG_RETURN_INT64(result);
226 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter blocks_hit
Definition: pgstat.h:634
Datum pg_stat_get_buf_alloc ( PG_FUNCTION_ARGS  )

Definition at line 1557 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1558 {
1559  PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
1560 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_buf_fsync_backend ( PG_FUNCTION_ARGS  )

Definition at line 1551 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1552 {
1553  PG_RETURN_INT64(pgstat_fetch_global()->buf_fsync_backend);
1554 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_buf_written_backend ( PG_FUNCTION_ARGS  )

Definition at line 1545 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1546 {
1547  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_backend);
1548 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_checkpoint_sync_time ( PG_FUNCTION_ARGS  )

Definition at line 1532 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1533 {
1534  /* time is already in msec, just convert to double for presentation */
1535  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
1536 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_checkpoint_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1525 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1526 {
1527  /* time is already in msec, just convert to double for presentation */
1528  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
1529 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
Datum pg_stat_get_db_blk_read_time ( PG_FUNCTION_ARGS  )

Definition at line 1463 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_block_read_time, PG_GETARG_OID, PG_RETURN_FLOAT8, and pgstat_fetch_stat_dbentry().

1464 {
1465  Oid dbid = PG_GETARG_OID(0);
1466  double result;
1467  PgStat_StatDBEntry *dbentry;
1468 
1469  /* convert counter from microsec to millisec for display */
1470  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1471  result = 0;
1472  else
1473  result = ((double) dbentry->n_block_read_time) / 1000.0;
1474 
1475  PG_RETURN_FLOAT8(result);
1476 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_block_read_time
Definition: pgstat.h:596
Datum pg_stat_get_db_blk_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1479 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_block_write_time, PG_GETARG_OID, PG_RETURN_FLOAT8, and pgstat_fetch_stat_dbentry().

1480 {
1481  Oid dbid = PG_GETARG_OID(0);
1482  double result;
1483  PgStat_StatDBEntry *dbentry;
1484 
1485  /* convert counter from microsec to millisec for display */
1486  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1487  result = 0;
1488  else
1489  result = ((double) dbentry->n_block_write_time) / 1000.0;
1490 
1491  PG_RETURN_FLOAT8(result);
1492 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_block_write_time
Definition: pgstat.h:597
Datum pg_stat_get_db_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1193 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_blocks_fetched, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1194 {
1195  Oid dbid = PG_GETARG_OID(0);
1196  int64 result;
1197  PgStat_StatDBEntry *dbentry;
1198 
1199  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1200  result = 0;
1201  else
1202  result = (int64) (dbentry->n_blocks_fetched);
1203 
1204  PG_RETURN_INT64(result);
1205 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:580
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1209 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_blocks_hit, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1210 {
1211  Oid dbid = PG_GETARG_OID(0);
1212  int64 result;
1213  PgStat_StatDBEntry *dbentry;
1214 
1215  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1216  result = 0;
1217  else
1218  result = (int64) (dbentry->n_blocks_hit);
1219 
1220  PG_RETURN_INT64(result);
1221 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_blocks_hit
Definition: pgstat.h:581
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

Definition at line 1428 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_conflict_bufferpin, PgStat_StatDBEntry::n_conflict_lock, PgStat_StatDBEntry::n_conflict_snapshot, PgStat_StatDBEntry::n_conflict_startup_deadlock, PgStat_StatDBEntry::n_conflict_tablespace, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1429 {
1430  Oid dbid = PG_GETARG_OID(0);
1431  int64 result;
1432  PgStat_StatDBEntry *dbentry;
1433 
1434  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1435  result = 0;
1436  else
1437  result = (int64) (
1438  dbentry->n_conflict_tablespace +
1439  dbentry->n_conflict_lock +
1440  dbentry->n_conflict_snapshot +
1441  dbentry->n_conflict_bufferpin +
1442  dbentry->n_conflict_startup_deadlock);
1443 
1444  PG_RETURN_INT64(result);
1445 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:591
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:592
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:588
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:590
PgStat_Counter n_conflict_lock
Definition: pgstat.h:589
Datum pg_stat_get_db_conflict_bufferpin ( PG_FUNCTION_ARGS  )

Definition at line 1398 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_conflict_bufferpin, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1399 {
1400  Oid dbid = PG_GETARG_OID(0);
1401  int64 result;
1402  PgStat_StatDBEntry *dbentry;
1403 
1404  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1405  result = 0;
1406  else
1407  result = (int64) (dbentry->n_conflict_bufferpin);
1408 
1409  PG_RETURN_INT64(result);
1410 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:591
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_conflict_lock ( PG_FUNCTION_ARGS  )

Definition at line 1368 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_conflict_lock, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1369 {
1370  Oid dbid = PG_GETARG_OID(0);
1371  int64 result;
1372  PgStat_StatDBEntry *dbentry;
1373 
1374  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1375  result = 0;
1376  else
1377  result = (int64) (dbentry->n_conflict_lock);
1378 
1379  PG_RETURN_INT64(result);
1380 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_conflict_lock
Definition: pgstat.h:589
Datum pg_stat_get_db_conflict_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1383 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_conflict_snapshot, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1384 {
1385  Oid dbid = PG_GETARG_OID(0);
1386  int64 result;
1387  PgStat_StatDBEntry *dbentry;
1388 
1389  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1390  result = 0;
1391  else
1392  result = (int64) (dbentry->n_conflict_snapshot);
1393 
1394  PG_RETURN_INT64(result);
1395 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:590
Datum pg_stat_get_db_conflict_startup_deadlock ( PG_FUNCTION_ARGS  )

Definition at line 1413 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_conflict_startup_deadlock, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1414 {
1415  Oid dbid = PG_GETARG_OID(0);
1416  int64 result;
1417  PgStat_StatDBEntry *dbentry;
1418 
1419  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1420  result = 0;
1421  else
1422  result = (int64) (dbentry->n_conflict_startup_deadlock);
1423 
1424  PG_RETURN_INT64(result);
1425 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:592
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_conflict_tablespace ( PG_FUNCTION_ARGS  )

Definition at line 1353 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_conflict_tablespace, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1354 {
1355  Oid dbid = PG_GETARG_OID(0);
1356  int64 result;
1357  PgStat_StatDBEntry *dbentry;
1358 
1359  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1360  result = 0;
1361  else
1362  result = (int64) (dbentry->n_conflict_tablespace);
1363 
1364  PG_RETURN_INT64(result);
1365 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:588
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_deadlocks ( PG_FUNCTION_ARGS  )

Definition at line 1448 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_deadlocks, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1449 {
1450  Oid dbid = PG_GETARG_OID(0);
1451  int64 result;
1452  PgStat_StatDBEntry *dbentry;
1453 
1454  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1455  result = 0;
1456  else
1457  result = (int64) (dbentry->n_deadlocks);
1458 
1459  PG_RETURN_INT64(result);
1460 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_deadlocks
Definition: pgstat.h:595
Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1140 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT32, pgstat_fetch_stat_beentry(), pgstat_fetch_stat_numbackends(), and PgBackendStatus::st_databaseid.

1141 {
1142  Oid dbid = PG_GETARG_OID(0);
1143  int32 result;
1144  int tot_backends = pgstat_fetch_stat_numbackends();
1145  int beid;
1146 
1147  result = 0;
1148  for (beid = 1; beid <= tot_backends; beid++)
1149  {
1150  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1151 
1152  if (beentry && beentry->st_databaseid == dbid)
1153  result++;
1154  }
1155 
1156  PG_RETURN_INT32(result);
1157 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:246
Oid st_databaseid
Definition: pgstat.h:991
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2543
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2502
Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1304 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_fetch_stat_dbentry(), and PgStat_StatDBEntry::stat_reset_timestamp.

1305 {
1306  Oid dbid = PG_GETARG_OID(0);
1307  TimestampTz result;
1308  PgStat_StatDBEntry *dbentry;
1309 
1310  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1311  result = 0;
1312  else
1313  result = dbentry->stat_reset_timestamp;
1314 
1315  if (result == 0)
1316  PG_RETURN_NULL();
1317  else
1318  PG_RETURN_TIMESTAMPTZ(result);
1319 }
int64 TimestampTz
Definition: timestamp.h:39
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
TimestampTz stat_reset_timestamp
Definition: pgstat.h:599
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_db_temp_bytes ( PG_FUNCTION_ARGS  )

Definition at line 1338 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_temp_bytes, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1339 {
1340  Oid dbid = PG_GETARG_OID(0);
1341  int64 result;
1342  PgStat_StatDBEntry *dbentry;
1343 
1344  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1345  result = 0;
1346  else
1347  result = dbentry->n_temp_bytes;
1348 
1349  PG_RETURN_INT64(result);
1350 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_temp_bytes
Definition: pgstat.h:594
Datum pg_stat_get_db_temp_files ( PG_FUNCTION_ARGS  )

Definition at line 1322 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_temp_files, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1323 {
1324  Oid dbid = PG_GETARG_OID(0);
1325  int64 result;
1326  PgStat_StatDBEntry *dbentry;
1327 
1328  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1329  result = 0;
1330  else
1331  result = dbentry->n_temp_files;
1332 
1333  PG_RETURN_INT64(result);
1334 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_temp_files
Definition: pgstat.h:593
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1289 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_tuples_deleted, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1290 {
1291  Oid dbid = PG_GETARG_OID(0);
1292  int64 result;
1293  PgStat_StatDBEntry *dbentry;
1294 
1295  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1296  result = 0;
1297  else
1298  result = (int64) (dbentry->n_tuples_deleted);
1299 
1300  PG_RETURN_INT64(result);
1301 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:586
Datum pg_stat_get_db_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1241 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_tuples_fetched, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1242 {
1243  Oid dbid = PG_GETARG_OID(0);
1244  int64 result;
1245  PgStat_StatDBEntry *dbentry;
1246 
1247  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1248  result = 0;
1249  else
1250  result = (int64) (dbentry->n_tuples_fetched);
1251 
1252  PG_RETURN_INT64(result);
1253 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:583
Datum pg_stat_get_db_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1257 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_tuples_inserted, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1258 {
1259  Oid dbid = PG_GETARG_OID(0);
1260  int64 result;
1261  PgStat_StatDBEntry *dbentry;
1262 
1263  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1264  result = 0;
1265  else
1266  result = (int64) (dbentry->n_tuples_inserted);
1267 
1268  PG_RETURN_INT64(result);
1269 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:584
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1225 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_tuples_returned, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1226 {
1227  Oid dbid = PG_GETARG_OID(0);
1228  int64 result;
1229  PgStat_StatDBEntry *dbentry;
1230 
1231  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1232  result = 0;
1233  else
1234  result = (int64) (dbentry->n_tuples_returned);
1235 
1236  PG_RETURN_INT64(result);
1237 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter n_tuples_returned
Definition: pgstat.h:582
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1273 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_tuples_updated, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1274 {
1275  Oid dbid = PG_GETARG_OID(0);
1276  int64 result;
1277  PgStat_StatDBEntry *dbentry;
1278 
1279  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1280  result = 0;
1281  else
1282  result = (int64) (dbentry->n_tuples_updated);
1283 
1284  PG_RETURN_INT64(result);
1285 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_tuples_updated
Definition: pgstat.h:585
Datum pg_stat_get_db_xact_commit ( PG_FUNCTION_ARGS  )

Definition at line 1161 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_xact_commit, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1162 {
1163  Oid dbid = PG_GETARG_OID(0);
1164  int64 result;
1165  PgStat_StatDBEntry *dbentry;
1166 
1167  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1168  result = 0;
1169  else
1170  result = (int64) (dbentry->n_xact_commit);
1171 
1172  PG_RETURN_INT64(result);
1173 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_xact_commit
Definition: pgstat.h:578
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_db_xact_rollback ( PG_FUNCTION_ARGS  )

Definition at line 1177 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_xact_rollback, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_dbentry().

1178 {
1179  Oid dbid = PG_GETARG_OID(0);
1180  int64 result;
1181  PgStat_StatDBEntry *dbentry;
1182 
1183  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1184  result = 0;
1185  else
1186  result = (int64) (dbentry->n_xact_rollback);
1187 
1188  PG_RETURN_INT64(result);
1189 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter n_xact_rollback
Definition: pgstat.h:579
Datum pg_stat_get_dead_tuples ( PG_FUNCTION_ARGS  )

Definition at line 166 of file pgstatfuncs.c.

References PgStat_StatTabEntry::n_dead_tuples, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

167 {
168  Oid relid = PG_GETARG_OID(0);
169  int64 result;
170  PgStat_StatTabEntry *tabentry;
171 
172  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
173  result = 0;
174  else
175  result = (int64) (tabentry->n_dead_tuples);
176 
177  PG_RETURN_INT64(result);
178 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_dead_tuples
Definition: pgstat.h:630
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 361 of file pgstatfuncs.c.

References PgStat_StatFuncEntry::f_numcalls, PG_GETARG_OID, PG_RETURN_INT64, PG_RETURN_NULL, and pgstat_fetch_stat_funcentry().

362 {
363  Oid funcid = PG_GETARG_OID(0);
364  PgStat_StatFuncEntry *funcentry;
365 
366  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
367  PG_RETURN_NULL();
368  PG_RETURN_INT64(funcentry->f_numcalls);
369 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2470
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_numcalls
Definition: pgstat.h:655
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 384 of file pgstatfuncs.c.

References PgStat_StatFuncEntry::f_self_time, PG_GETARG_OID, PG_RETURN_FLOAT8, PG_RETURN_NULL, and pgstat_fetch_stat_funcentry().

385 {
386  Oid funcid = PG_GETARG_OID(0);
387  PgStat_StatFuncEntry *funcentry;
388 
389  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
390  PG_RETURN_NULL();
391  /* convert counter from microsec to millisec for display */
392  PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
393 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2470
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter f_self_time
Definition: pgstat.h:658
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 372 of file pgstatfuncs.c.

References PgStat_StatFuncEntry::f_total_time, PG_GETARG_OID, PG_RETURN_FLOAT8, PG_RETURN_NULL, and pgstat_fetch_stat_funcentry().

373 {
374  Oid funcid = PG_GETARG_OID(0);
375  PgStat_StatFuncEntry *funcentry;
376 
377  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
378  PG_RETURN_NULL();
379  /* convert counter from microsec to millisec for display */
380  PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
381 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2470
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_total_time
Definition: pgstat.h:657
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_last_analyze_time ( PG_FUNCTION_ARGS  )

Definition at line 265 of file pgstatfuncs.c.

References PgStat_StatTabEntry::analyze_timestamp, PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_stat_tabentry().

266 {
267  Oid relid = PG_GETARG_OID(0);
268  TimestampTz result;
269  PgStat_StatTabEntry *tabentry;
270 
271  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
272  result = 0;
273  else
274  result = tabentry->analyze_timestamp;
275 
276  if (result == 0)
277  PG_RETURN_NULL();
278  else
279  PG_RETURN_TIMESTAMPTZ(result);
280 }
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
TimestampTz analyze_timestamp
Definition: pgstat.h:640
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_last_autoanalyze_time ( PG_FUNCTION_ARGS  )

Definition at line 283 of file pgstatfuncs.c.

References PgStat_StatTabEntry::autovac_analyze_timestamp, PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_stat_tabentry().

284 {
285  Oid relid = PG_GETARG_OID(0);
286  TimestampTz result;
287  PgStat_StatTabEntry *tabentry;
288 
289  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
290  result = 0;
291  else
292  result = tabentry->autovac_analyze_timestamp;
293 
294  if (result == 0)
295  PG_RETURN_NULL();
296  else
297  PG_RETURN_TIMESTAMPTZ(result);
298 }
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:642
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_last_autovacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 247 of file pgstatfuncs.c.

References PgStat_StatTabEntry::autovac_vacuum_timestamp, PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_stat_tabentry().

248 {
249  Oid relid = PG_GETARG_OID(0);
250  TimestampTz result;
251  PgStat_StatTabEntry *tabentry;
252 
253  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
254  result = 0;
255  else
256  result = tabentry->autovac_vacuum_timestamp;
257 
258  if (result == 0)
259  PG_RETURN_NULL();
260  else
261  PG_RETURN_TIMESTAMPTZ(result);
262 }
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:638
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_last_vacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 229 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::vacuum_timestamp.

230 {
231  Oid relid = PG_GETARG_OID(0);
232  TimestampTz result;
233  PgStat_StatTabEntry *tabentry;
234 
235  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
236  result = 0;
237  else
238  result = tabentry->vacuum_timestamp;
239 
240  if (result == 0)
241  PG_RETURN_NULL();
242  else
243  PG_RETURN_TIMESTAMPTZ(result);
244 }
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
TimestampTz vacuum_timestamp
Definition: pgstat.h:636
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_live_tuples ( PG_FUNCTION_ARGS  )

Definition at line 150 of file pgstatfuncs.c.

References PgStat_StatTabEntry::n_live_tuples, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

151 {
152  Oid relid = PG_GETARG_OID(0);
153  int64 result;
154  PgStat_StatTabEntry *tabentry;
155 
156  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
157  result = 0;
158  else
159  result = (int64) (tabentry->n_live_tuples);
160 
161  PG_RETURN_INT64(result);
162 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_live_tuples
Definition: pgstat.h:629
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_mod_since_analyze ( PG_FUNCTION_ARGS  )

Definition at line 182 of file pgstatfuncs.c.

References PgStat_StatTabEntry::changes_since_analyze, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

183 {
184  Oid relid = PG_GETARG_OID(0);
185  int64 result;
186  PgStat_StatTabEntry *tabentry;
187 
188  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
189  result = 0;
190  else
191  result = (int64) (tabentry->changes_since_analyze);
192 
193  PG_RETURN_INT64(result);
194 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter changes_since_analyze
Definition: pgstat.h:631
Datum pg_stat_get_numscans ( PG_FUNCTION_ARGS  )

Definition at line 38 of file pgstatfuncs.c.

References PgStat_StatTabEntry::numscans, PG_GETARG_OID, PG_RETURN_INT64, and pgstat_fetch_stat_tabentry().

39 {
40  Oid relid = PG_GETARG_OID(0);
41  int64 result;
42  PgStat_StatTabEntry *tabentry;
43 
44  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
45  result = 0;
46  else
47  result = (int64) (tabentry->numscans);
48 
49  PG_RETURN_INT64(result);
50 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter numscans
Definition: pgstat.h:619
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 439 of file pgstatfuncs.c.

References ReturnSetInfo::allowedModes, LocalPgBackendStatus::backendStatus, ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), GetUserId(), has_privs_of_role(), i, Int32GetDatum, Int64GetDatum(), IsA, MemoryContextSwitchTo(), MemSet, ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_STAT_GET_PROGRESS_COLS, pg_strcasecmp(), pgstat_fetch_stat_local_beentry(), pgstat_fetch_stat_numbackends(), PGSTAT_NUM_PROGRESS_PARAM, PROGRESS_COMMAND_VACUUM, ReturnSetInfo::returnMode, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, PgBackendStatus::st_databaseid, PgBackendStatus::st_procpid, PgBackendStatus::st_progress_command, PgBackendStatus::st_progress_command_target, PgBackendStatus::st_progress_param, PgBackendStatus::st_userid, text_to_cstring(), tuplestore_begin_heap(), tuplestore_donestoring, tuplestore_putvalues(), TYPEFUNC_COMPOSITE, values, and work_mem.

440 {
441 #define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
442  int num_backends = pgstat_fetch_stat_numbackends();
443  int curr_backend;
444  char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
445  ProgressCommandType cmdtype;
446  TupleDesc tupdesc;
447  Tuplestorestate *tupstore;
448  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
449  MemoryContext per_query_ctx;
450  MemoryContext oldcontext;
451 
452  /* check to see if caller supports us returning a tuplestore */
453  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
454  ereport(ERROR,
455  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
456  errmsg("set-valued function called in context that cannot accept a set")));
457  if (!(rsinfo->allowedModes & SFRM_Materialize))
458  ereport(ERROR,
459  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
460  errmsg("materialize mode required, but it is not " \
461  "allowed in this context")));
462 
463  /* Build a tuple descriptor for our result type */
464  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
465  elog(ERROR, "return type must be a row type");
466 
467  /* Translate command name into command type code. */
468  if (pg_strcasecmp(cmd, "VACUUM") == 0)
469  cmdtype = PROGRESS_COMMAND_VACUUM;
470  else
471  ereport(ERROR,
472  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
473  errmsg("invalid command name: \"%s\"", cmd)));
474 
475  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
476  oldcontext = MemoryContextSwitchTo(per_query_ctx);
477 
478  tupstore = tuplestore_begin_heap(true, false, work_mem);
479  rsinfo->returnMode = SFRM_Materialize;
480  rsinfo->setResult = tupstore;
481  rsinfo->setDesc = tupdesc;
482  MemoryContextSwitchTo(oldcontext);
483 
484  /* 1-based index */
485  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
486  {
487  LocalPgBackendStatus *local_beentry;
488  PgBackendStatus *beentry;
490  bool nulls[PG_STAT_GET_PROGRESS_COLS];
491  int i;
492 
493  MemSet(values, 0, sizeof(values));
494  MemSet(nulls, 0, sizeof(nulls));
495 
496  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
497 
498  if (!local_beentry)
499  continue;
500 
501  beentry = &local_beentry->backendStatus;
502 
503  /*
504  * Report values for only those backends which are running the given
505  * command.
506  */
507  if (!beentry || beentry->st_progress_command != cmdtype)
508  continue;
509 
510  /* Value available to all callers */
511  values[0] = Int32GetDatum(beentry->st_procpid);
512  values[1] = ObjectIdGetDatum(beentry->st_databaseid);
513 
514  /* show rest of the values including relid only to role members */
515  if (has_privs_of_role(GetUserId(), beentry->st_userid))
516  {
517  values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
518  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
519  values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
520  }
521  else
522  {
523  nulls[2] = true;
524  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
525  nulls[i + 3] = true;
526  }
527 
528  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
529  }
530 
531  /* clean up and return the tuplestore */
532  tuplestore_donestoring(tupstore);
533 
534  return (Datum) 0;
535 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Oid st_progress_command_target
Definition: pgstat.h:1025
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
Oid GetUserId(void)
Definition: miscinit.c:284
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4828
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MemSet(start, val, len)
Definition: c.h:846
ProgressCommandType st_progress_command
Definition: pgstat.h:1024
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2524
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
Oid st_databaseid
Definition: pgstat.h:991
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:922
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1791
#define ereport(elevel, rest)
Definition: elog.h:122
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
PgBackendStatus backendStatus
Definition: pgstat.h:1079
uintptr_t Datum
Definition: postgres.h:372
int work_mem
Definition: globals.c:113
int allowedModes
Definition: execnodes.h:268
SetFunctionReturnMode returnMode
Definition: execnodes.h:270
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2543
ProgressCommandType
Definition: pgstat.h:916
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1026
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:202
int st_procpid
Definition: pgstat.h:979
Tuplestorestate * setResult
Definition: execnodes.h:273
static Datum values[MAXATTR]
Definition: bootstrap.c:164
char * text_to_cstring(const text *t)
Definition: varlena.c:182
ExprContext * econtext
Definition: execnodes.h:266
#define Int32GetDatum(X)
Definition: postgres.h:485
TupleDesc setDesc
Definition: execnodes.h:274
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_STAT_GET_PROGRESS_COLS
int i
#define elog
Definition: elog.h:219
Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1751 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1752 {
1753  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stats_timestamp);
1754 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2576
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
Datum pg_stat_get_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 118 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::tuples_deleted.

119 {
120  Oid relid = PG_GETARG_OID(0);
121  int64 result;
122  PgStat_StatTabEntry *tabentry;
123 
124  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
125  result = 0;
126  else
127  result = (int64) (tabentry->tuples_deleted);
128 
129  PG_RETURN_INT64(result);
130 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter tuples_deleted
Definition: pgstat.h:626
Datum pg_stat_get_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 70 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::tuples_fetched.

71 {
72  Oid relid = PG_GETARG_OID(0);
73  int64 result;
74  PgStat_StatTabEntry *tabentry;
75 
76  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
77  result = 0;
78  else
79  result = (int64) (tabentry->tuples_fetched);
80 
81  PG_RETURN_INT64(result);
82 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter tuples_fetched
Definition: pgstat.h:622
Datum pg_stat_get_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 134 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::tuples_hot_updated.

135 {
136  Oid relid = PG_GETARG_OID(0);
137  int64 result;
138  PgStat_StatTabEntry *tabentry;
139 
140  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
141  result = 0;
142  else
143  result = (int64) (tabentry->tuples_hot_updated);
144 
145  PG_RETURN_INT64(result);
146 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:627
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 86 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::tuples_inserted.

87 {
88  Oid relid = PG_GETARG_OID(0);
89  int64 result;
90  PgStat_StatTabEntry *tabentry;
91 
92  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
93  result = 0;
94  else
95  result = (int64) (tabentry->tuples_inserted);
96 
97  PG_RETURN_INT64(result);
98 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter tuples_inserted
Definition: pgstat.h:624
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 54 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::tuples_returned.

55 {
56  Oid relid = PG_GETARG_OID(0);
57  int64 result;
58  PgStat_StatTabEntry *tabentry;
59 
60  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
61  result = 0;
62  else
63  result = (int64) (tabentry->tuples_returned);
64 
65  PG_RETURN_INT64(result);
66 }
PgStat_Counter tuples_returned
Definition: pgstat.h:621
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 102 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::tuples_updated.

103 {
104  Oid relid = PG_GETARG_OID(0);
105  int64 result;
106  PgStat_StatTabEntry *tabentry;
107 
108  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
109  result = 0;
110  else
111  result = (int64) (tabentry->tuples_updated);
112 
113  PG_RETURN_INT64(result);
114 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter tuples_updated
Definition: pgstat.h:625
Datum pg_stat_get_vacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 301 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_tabentry(), and PgStat_StatTabEntry::vacuum_count.

302 {
303  Oid relid = PG_GETARG_OID(0);
304  int64 result;
305  PgStat_StatTabEntry *tabentry;
306 
307  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
308  result = 0;
309  else
310  result = (int64) (tabentry->vacuum_count);
311 
312  PG_RETURN_INT64(result);
313 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter vacuum_count
Definition: pgstat.h:637
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2414
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_xact_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1686 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableCounts::t_blocks_fetched, and PgStat_TableStatus::t_counts.

1687 {
1688  Oid relid = PG_GETARG_OID(0);
1689  int64 result;
1690  PgStat_TableStatus *tabentry;
1691 
1692  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1693  result = 0;
1694  else
1695  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1696 
1697  PG_RETURN_INT64(result);
1698 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:114
Datum pg_stat_get_xact_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1701 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableCounts::t_blocks_hit, and PgStat_TableStatus::t_counts.

1702 {
1703  Oid relid = PG_GETARG_OID(0);
1704  int64 result;
1705  PgStat_TableStatus *tabentry;
1706 
1707  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1708  result = 0;
1709  else
1710  result = (int64) (tabentry->t_counts.t_blocks_hit);
1711 
1712  PG_RETURN_INT64(result);
1713 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter t_blocks_hit
Definition: pgstat.h:115
Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 1716 of file pgstatfuncs.c.

References PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCounts::f_numcalls, find_funcstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, and PG_RETURN_NULL.

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();
1723  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
1724 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_numcalls
Definition: pgstat.h:461
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1633
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_xact_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 1738 of file pgstatfuncs.c.

References PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCounts::f_self_time, find_funcstat_entry(), INSTR_TIME_GET_MILLISEC, PG_GETARG_OID, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

1739 {
1740  Oid funcid = PG_GETARG_OID(0);
1741  PgStat_BackendFunctionEntry *funcentry;
1742 
1743  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1744  PG_RETURN_NULL();
1746 }
instr_time f_self_time
Definition: pgstat.h:463
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1633
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_xact_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 1727 of file pgstatfuncs.c.

References PgStat_BackendFunctionEntry::f_counts, PgStat_FunctionCounts::f_total_time, find_funcstat_entry(), INSTR_TIME_GET_MILLISEC, PG_GETARG_OID, PG_RETURN_FLOAT8, and PG_RETURN_NULL.

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 }
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
instr_time f_total_time
Definition: pgstat.h:462
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1633
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum pg_stat_get_xact_numscans ( PG_FUNCTION_ARGS  )

Definition at line 1563 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, and PgStat_TableCounts::t_numscans.

1564 {
1565  Oid relid = PG_GETARG_OID(0);
1566  int64 result;
1567  PgStat_TableStatus *tabentry;
1568 
1569  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1570  result = 0;
1571  else
1572  result = (int64) (tabentry->t_counts.t_numscans);
1573 
1574  PG_RETURN_INT64(result);
1575 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
PgStat_Counter t_numscans
Definition: pgstat.h:99
Datum pg_stat_get_xact_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1650 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_tuples_deleted, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::tuples_deleted, and PgStat_TableXactStatus::upper.

1651 {
1652  Oid relid = PG_GETARG_OID(0);
1653  int64 result;
1654  PgStat_TableStatus *tabentry;
1656 
1657  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1658  result = 0;
1659  else
1660  {
1661  result = tabentry->t_counts.t_tuples_deleted;
1662  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1663  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1664  result += trans->tuples_deleted;
1665  }
1666 
1667  PG_RETURN_INT64(result);
1668 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:387
Datum pg_stat_get_xact_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1593 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, and PgStat_TableCounts::t_tuples_fetched.

1594 {
1595  Oid relid = PG_GETARG_OID(0);
1596  int64 result;
1597  PgStat_TableStatus *tabentry;
1598 
1599  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1600  result = 0;
1601  else
1602  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1603 
1604  PG_RETURN_INT64(result);
1605 }
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:102
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_xact_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 1671 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, and PgStat_TableCounts::t_tuples_hot_updated.

1672 {
1673  Oid relid = PG_GETARG_OID(0);
1674  int64 result;
1675  PgStat_TableStatus *tabentry;
1676 
1677  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1678  result = 0;
1679  else
1680  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1681 
1682  PG_RETURN_INT64(result);
1683 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:107
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_xact_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1608 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_tuples_inserted, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::upper.

1609 {
1610  Oid relid = PG_GETARG_OID(0);
1611  int64 result;
1612  PgStat_TableStatus *tabentry;
1614 
1615  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1616  result = 0;
1617  else
1618  {
1619  result = tabentry->t_counts.t_tuples_inserted;
1620  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1621  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1622  result += trans->tuples_inserted;
1623  }
1624 
1625  PG_RETURN_INT64(result);
1626 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:387
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104
Datum pg_stat_get_xact_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1578 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, and PgStat_TableCounts::t_tuples_returned.

1579 {
1580  Oid relid = PG_GETARG_OID(0);
1581  int64 result;
1582  PgStat_TableStatus *tabentry;
1583 
1584  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1585  result = 0;
1586  else
1587  result = (int64) (tabentry->t_counts.t_tuples_returned);
1588 
1589  PG_RETURN_INT64(result);
1590 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter t_tuples_returned
Definition: pgstat.h:101
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum pg_stat_get_xact_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1629 of file pgstatfuncs.c.

References find_tabstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, PgStat_TableStatus::t_counts, PgStat_TableCounts::t_tuples_updated, PgStat_TableStatus::trans, trans, PgStat_TableXactStatus::tuples_updated, and PgStat_TableXactStatus::upper.

1630 {
1631  Oid relid = PG_GETARG_OID(0);
1632  int64 result;
1633  PgStat_TableStatus *tabentry;
1635 
1636  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1637  result = 0;
1638  else
1639  {
1640  result = tabentry->t_counts.t_tuples_updated;
1641  /* live subtransactions' counts aren't in t_tuples_updated yet */
1642  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1643  result += trans->tuples_updated;
1644  }
1645 
1646  PG_RETURN_INT64(result);
1647 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1838
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:387
Datum pg_stat_reset ( PG_FUNCTION_ARGS  )

Definition at line 1768 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_reset_counters().

1769 {
1771 
1772  PG_RETURN_VOID();
1773 }
#define PG_RETURN_VOID()
Definition: fmgr.h:309
void pgstat_reset_counters(void)
Definition: pgstat.c:1306
Datum pg_stat_reset_shared ( PG_FUNCTION_ARGS  )

Definition at line 1777 of file pgstatfuncs.c.

References PG_GETARG_TEXT_PP, PG_RETURN_VOID, pgstat_reset_shared_counters(), and text_to_cstring().

1778 {
1779  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
1780 
1782 
1783  PG_RETURN_VOID();
1784 }
void pgstat_reset_shared_counters(const char *target)
Definition: pgstat.c:1328
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_RETURN_VOID()
Definition: fmgr.h:309
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Datum pg_stat_reset_single_function_counters ( PG_FUNCTION_ARGS  )

Definition at line 1798 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_VOID, pgstat_reset_single_counter(), and RESET_FUNCTION.

1799 {
1800  Oid funcoid = PG_GETARG_OID(0);
1801 
1803 
1804  PG_RETURN_VOID();
1805 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1359
#define PG_RETURN_VOID()
Definition: fmgr.h:309
Datum pg_stat_reset_single_table_counters ( PG_FUNCTION_ARGS  )

Definition at line 1788 of file pgstatfuncs.c.

References PG_GETARG_OID, PG_RETURN_VOID, pgstat_reset_single_counter(), and RESET_TABLE.

1789 {
1790  Oid taboid = PG_GETARG_OID(0);
1791 
1793 
1794  PG_RETURN_VOID();
1795 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1359
#define PG_RETURN_VOID()
Definition: fmgr.h:309

Variable Documentation

PgStat_MsgBgWriter bgwriterStats