PostgreSQL Source Code  git master
pgstatfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xlog.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/bgworker_internals.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   29
 

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_checksum_failures (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_checksum_last_failure (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

◆ PG_STAT_GET_ACTIVITY_COLS

#define PG_STAT_GET_ACTIVITY_COLS   29

Referenced by pg_stat_get_activity().

◆ PG_STAT_GET_PROGRESS_COLS

#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3

◆ UINT32_ACCESS_ONCE

#define UINT32_ACCESS_ONCE (   var)    ((uint32)(*((volatile uint32 *)&(var))))

Definition at line 34 of file pgstatfuncs.c.

Referenced by pg_stat_get_activity().

Function Documentation

◆ pg_backend_pid()

Datum pg_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 922 of file pgstatfuncs.c.

References MyProcPid, and PG_RETURN_INT32.

923 {
925 }
int MyProcPid
Definition: globals.c:40
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344

◆ pg_stat_clear_snapshot()

Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1858 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_clear_snapshot().

1859 {
1861 
1862  PG_RETURN_VOID();
1863 }
#define PG_RETURN_VOID()
Definition: fmgr.h:339
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5796

◆ pg_stat_get_activity()

Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 547 of file pgstatfuncs.c.

References SockAddr::addr, ReturnSetInfo::allowedModes, AuxiliaryPidGetProc(), B_BACKEND, B_BG_WORKER, LocalPgBackendStatus::backend_xid, LocalPgBackendStatus::backend_xmin, BackendPidGetProc(), LocalPgBackendStatus::backendStatus, BoolGetDatum, clean_ipv6_addr(), CStringGetDatum, CStringGetTextDatum, DirectFunctionCall1, DirectFunctionCall3, ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), GetBackgroundWorkerTypeByPid(), GetUserId(), PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, 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, numeric_in(), 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_client_dn, PgBackendSSLStatus::ssl_client_serial, PgBackendSSLStatus::ssl_compression, PgBackendSSLStatus::ssl_issuer_dn, 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_gss, PgBackendStatus::st_gssstatus, 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.

548 {
549 #define PG_STAT_GET_ACTIVITY_COLS 29
550  int num_backends = pgstat_fetch_stat_numbackends();
551  int curr_backend;
552  int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
553  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
554  TupleDesc tupdesc;
555  Tuplestorestate *tupstore;
556  MemoryContext per_query_ctx;
557  MemoryContext oldcontext;
558 
559  /* check to see if caller supports us returning a tuplestore */
560  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
561  ereport(ERROR,
562  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
563  errmsg("set-valued function called in context that cannot accept a set")));
564  if (!(rsinfo->allowedModes & SFRM_Materialize))
565  ereport(ERROR,
566  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
567  errmsg("materialize mode required, but it is not " \
568  "allowed in this context")));
569 
570  /* Build a tuple descriptor for our result type */
571  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
572  elog(ERROR, "return type must be a row type");
573 
574  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
575  oldcontext = MemoryContextSwitchTo(per_query_ctx);
576 
577  tupstore = tuplestore_begin_heap(true, false, work_mem);
578  rsinfo->returnMode = SFRM_Materialize;
579  rsinfo->setResult = tupstore;
580  rsinfo->setDesc = tupdesc;
581 
582  MemoryContextSwitchTo(oldcontext);
583 
584  /* 1-based index */
585  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
586  {
587  /* for each row */
589  bool nulls[PG_STAT_GET_ACTIVITY_COLS];
590  LocalPgBackendStatus *local_beentry;
591  PgBackendStatus *beentry;
592  PGPROC *proc;
593  const char *wait_event_type = NULL;
594  const char *wait_event = NULL;
595 
596  MemSet(values, 0, sizeof(values));
597  MemSet(nulls, 0, sizeof(nulls));
598 
599  /* Get the next one in the list */
600  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
601  if (!local_beentry)
602  {
603  int i;
604 
605  /* Ignore missing entries if looking for specific PID */
606  if (pid != -1)
607  continue;
608 
609  for (i = 0; i < lengthof(nulls); i++)
610  nulls[i] = true;
611 
612  nulls[5] = false;
613  values[5] = CStringGetTextDatum("<backend information not available>");
614 
615  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
616  continue;
617  }
618 
619  beentry = &local_beentry->backendStatus;
620 
621  /* If looking for specific PID, ignore all the others */
622  if (pid != -1 && beentry->st_procpid != pid)
623  continue;
624 
625  /* Values available to all callers */
626  if (beentry->st_databaseid != InvalidOid)
627  values[0] = ObjectIdGetDatum(beentry->st_databaseid);
628  else
629  nulls[0] = true;
630 
631  values[1] = Int32GetDatum(beentry->st_procpid);
632 
633  if (beentry->st_userid != InvalidOid)
634  values[2] = ObjectIdGetDatum(beentry->st_userid);
635  else
636  nulls[2] = true;
637 
638  if (beentry->st_appname)
639  values[3] = CStringGetTextDatum(beentry->st_appname);
640  else
641  nulls[3] = true;
642 
643  if (TransactionIdIsValid(local_beentry->backend_xid))
644  values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
645  else
646  nulls[15] = true;
647 
648  if (TransactionIdIsValid(local_beentry->backend_xmin))
649  values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
650  else
651  nulls[16] = true;
652 
653  /* Values only available to role member or pg_read_all_stats */
654  if (has_privs_of_role(GetUserId(), beentry->st_userid) ||
655  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS))
656  {
657  SockAddr zero_clientaddr;
658  char *clipped_activity;
659 
660  switch (beentry->st_state)
661  {
662  case STATE_IDLE:
663  values[4] = CStringGetTextDatum("idle");
664  break;
665  case STATE_RUNNING:
666  values[4] = CStringGetTextDatum("active");
667  break;
669  values[4] = CStringGetTextDatum("idle in transaction");
670  break;
671  case STATE_FASTPATH:
672  values[4] = CStringGetTextDatum("fastpath function call");
673  break;
675  values[4] = CStringGetTextDatum("idle in transaction (aborted)");
676  break;
677  case STATE_DISABLED:
678  values[4] = CStringGetTextDatum("disabled");
679  break;
680  case STATE_UNDEFINED:
681  nulls[4] = true;
682  break;
683  }
684 
685  clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
686  values[5] = CStringGetTextDatum(clipped_activity);
687  pfree(clipped_activity);
688 
689  proc = BackendPidGetProc(beentry->st_procpid);
690  if (proc != NULL)
691  {
692  uint32 raw_wait_event;
693 
694  raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
695  wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
696  wait_event = pgstat_get_wait_event(raw_wait_event);
697 
698  }
699  else if (beentry->st_backendType != B_BACKEND)
700  {
701  /*
702  * For an auxiliary process, retrieve process info from
703  * AuxiliaryProcs stored in shared-memory.
704  */
705  proc = AuxiliaryPidGetProc(beentry->st_procpid);
706 
707  if (proc != NULL)
708  {
709  uint32 raw_wait_event;
710 
711  raw_wait_event =
713  wait_event_type =
714  pgstat_get_wait_event_type(raw_wait_event);
715  wait_event = pgstat_get_wait_event(raw_wait_event);
716  }
717  }
718 
719  if (wait_event_type)
720  values[6] = CStringGetTextDatum(wait_event_type);
721  else
722  nulls[6] = true;
723 
724  if (wait_event)
725  values[7] = CStringGetTextDatum(wait_event);
726  else
727  nulls[7] = true;
728 
729  if (beentry->st_xact_start_timestamp != 0)
730  values[8] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
731  else
732  nulls[8] = true;
733 
734  if (beentry->st_activity_start_timestamp != 0)
735  values[9] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
736  else
737  nulls[9] = true;
738 
739  if (beentry->st_proc_start_timestamp != 0)
740  values[10] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
741  else
742  nulls[10] = true;
743 
744  if (beentry->st_state_start_timestamp != 0)
745  values[11] = TimestampTzGetDatum(beentry->st_state_start_timestamp);
746  else
747  nulls[11] = true;
748 
749  /* A zeroed client addr means we don't know */
750  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
751  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
752  sizeof(zero_clientaddr)) == 0)
753  {
754  nulls[12] = true;
755  nulls[13] = true;
756  nulls[14] = true;
757  }
758  else
759  {
760  if (beentry->st_clientaddr.addr.ss_family == AF_INET
761 #ifdef HAVE_IPV6
762  || beentry->st_clientaddr.addr.ss_family == AF_INET6
763 #endif
764  )
765  {
766  char remote_host[NI_MAXHOST];
767  char remote_port[NI_MAXSERV];
768  int ret;
769 
770  remote_host[0] = '\0';
771  remote_port[0] = '\0';
772  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
773  beentry->st_clientaddr.salen,
774  remote_host, sizeof(remote_host),
775  remote_port, sizeof(remote_port),
777  if (ret == 0)
778  {
779  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
780  values[12] = DirectFunctionCall1(inet_in,
781  CStringGetDatum(remote_host));
782  if (beentry->st_clienthostname &&
783  beentry->st_clienthostname[0])
784  values[13] = CStringGetTextDatum(beentry->st_clienthostname);
785  else
786  nulls[13] = true;
787  values[14] = Int32GetDatum(atoi(remote_port));
788  }
789  else
790  {
791  nulls[12] = true;
792  nulls[13] = true;
793  nulls[14] = true;
794  }
795  }
796  else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
797  {
798  /*
799  * Unix sockets always reports NULL for host and -1 for
800  * port, so it's possible to tell the difference to
801  * connections we have no permissions to view, or with
802  * errors.
803  */
804  nulls[12] = true;
805  nulls[13] = true;
806  values[14] = Int32GetDatum(-1);
807  }
808  else
809  {
810  /* Unknown address type, should never happen */
811  nulls[12] = true;
812  nulls[13] = true;
813  nulls[14] = true;
814  }
815  }
816  /* Add backend type */
817  if (beentry->st_backendType == B_BG_WORKER)
818  {
819  const char *bgw_type;
820 
821  bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
822  if (bgw_type)
823  values[17] = CStringGetTextDatum(bgw_type);
824  else
825  nulls[17] = true;
826  }
827  else
828  values[17] =
830 
831  /* SSL information */
832  if (beentry->st_ssl)
833  {
834  values[18] = BoolGetDatum(true); /* ssl */
835  values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version);
836  values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher);
837  values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
838  values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression);
839 
840  if (beentry->st_sslstatus->ssl_client_dn[0])
841  values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_client_dn);
842  else
843  nulls[23] = true;
844 
845  if (beentry->st_sslstatus->ssl_client_serial[0])
846  values[24] = DirectFunctionCall3(numeric_in,
849  Int32GetDatum(-1));
850  else
851  nulls[24] = true;
852 
853  if (beentry->st_sslstatus->ssl_issuer_dn[0])
854  values[25] = CStringGetTextDatum(beentry->st_sslstatus->ssl_issuer_dn);
855  else
856  nulls[25] = true;
857  }
858  else
859  {
860  values[18] = BoolGetDatum(false); /* ssl */
861  nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = nulls[25] = true;
862  }
863 
864  /* GSSAPI information */
865  if (beentry->st_gss)
866  {
867  values[26] = BoolGetDatum(beentry->st_gssstatus->gss_auth); /* gss_auth */
868  values[27] = CStringGetTextDatum(beentry->st_gssstatus->gss_princ);
869  values[28] = BoolGetDatum(beentry->st_gssstatus->gss_enc); /* GSS Encryption in use */
870  }
871  else
872  {
873  values[26] = BoolGetDatum(false); /* gss_auth */
874  nulls[27] = true; /* No GSS principal */
875  values[28] = BoolGetDatum(false); /* GSS Encryption not in
876  * use */
877  }
878  }
879  else
880  {
881  /* No permissions to view data about this session */
882  values[5] = CStringGetTextDatum("<insufficient privilege>");
883  nulls[4] = true;
884  nulls[6] = true;
885  nulls[7] = true;
886  nulls[8] = true;
887  nulls[9] = true;
888  nulls[10] = true;
889  nulls[11] = true;
890  nulls[12] = true;
891  nulls[13] = true;
892  nulls[14] = true;
893  nulls[17] = true;
894  nulls[18] = true;
895  nulls[19] = true;
896  nulls[20] = true;
897  nulls[21] = true;
898  nulls[22] = true;
899  nulls[23] = true;
900  nulls[24] = true;
901  nulls[25] = true;
902  nulls[26] = true;
903  nulls[27] = true;
904  nulls[28] = true;
905  }
906 
907  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
908 
909  /* If only a single backend was requested, and we found it, break. */
910  if (pid != -1)
911  break;
912  }
913 
914  /* clean up and return the tuplestore */
915  tuplestore_donestoring(tupstore);
916 
917  return (Datum) 0;
918 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
char ssl_issuer_dn[NAMEDATALEN]
Definition: pgstat.h:993
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
Definition: bgworker.c:1252
char gss_princ[NAMEDATALEN]
Definition: pgstat.h:1007
bool ssl_compression
Definition: pgstat.h:982
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:984
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:196
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
uint32 wait_event_info
Definition: proc.h:176
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3502
Oid GetUserId(void)
Definition: miscinit.c:380
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1055
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2363
#define PG_STAT_GET_ACTIVITY_COLS
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4274
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
char ssl_client_dn[NAMEDATALEN]
Definition: pgstat.h:985
#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:1187
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:983
SockAddr st_clientaddr
Definition: pgstat.h:1061
int errcode(int sqlerrcode)
Definition: elog.c:570
#define MemSet(start, val, len)
Definition: c.h:955
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:617
#define lengthof(array)
Definition: c.h:662
char ssl_client_serial[NAMEDATALEN]
Definition: pgstat.h:991
BackendState st_state
Definition: pgstat.h:1073
char * st_clienthostname
Definition: pgstat.h:1062
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2569
Oid st_databaseid
Definition: pgstat.h:1059
void pfree(void *pointer)
Definition: mcxt.c:1056
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
TransactionId backend_xid
Definition: pgstat.h:1181
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:986
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3557
char * st_activity_raw
Definition: pgstat.h:1085
#define CStringGetDatum(X)
Definition: postgres.h:578
#define NI_MAXSERV
Definition: getaddrinfo.h:91
unsigned int uint32
Definition: c.h:358
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:573
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1056
char * st_appname
Definition: pgstat.h:1076
#define ereport(elevel, rest)
Definition: elog.h:141
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:621
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
#define TransactionIdGetDatum(X)
Definition: postgres.h:521
PgBackendStatus backendStatus
Definition: pgstat.h:1175
uintptr_t Datum
Definition: postgres.h:367
BackendType st_backendType
Definition: pgstat.h:1050
int work_mem
Definition: globals.c:121
#define BoolGetDatum(X)
Definition: postgres.h:402
#define NI_NUMERICSERV
Definition: getaddrinfo.h:81
#define InvalidOid
Definition: postgres_ext.h:36
int allowedModes
Definition: execnodes.h:303
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4932
SetFunctionReturnMode returnMode
Definition: execnodes.h:305
#define PG_ARGISNULL(n)
Definition: fmgr.h:204
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2588
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:122
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:2118
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
Tuplestorestate * setResult
Definition: execnodes.h:308
static Datum values[MAXATTR]
Definition: bootstrap.c:167
ExprContext * econtext
Definition: execnodes.h:301
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6544
#define Int32GetDatum(X)
Definition: postgres.h:479
TupleDesc setDesc
Definition: execnodes.h:309
int errmsg(const char *fmt,...)
Definition: elog.c:784
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1054
#define elog(elevel,...)
Definition: elog.h:226
int i
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:34
#define CStringGetTextDatum(s)
Definition: builtins.h:83
#define TransactionIdIsValid(xid)
Definition: transam.h:41
Definition: proc.h:95
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1053
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1066
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1070

◆ pg_stat_get_analyze_count()

Datum pg_stat_get_analyze_count ( PG_FUNCTION_ARGS  )

Definition at line 333 of file pgstatfuncs.c.

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

334 {
335  Oid relid = PG_GETARG_OID(0);
336  int64 result;
337  PgStat_StatTabEntry *tabentry;
338 
339  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
340  result = 0;
341  else
342  result = (int64) (tabentry->analyze_count);
343 
344  PG_RETURN_INT64(result);
345 }
PgStat_Counter analyze_count
Definition: pgstat.h:658
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_archiver()

Datum pg_stat_get_archiver ( PG_FUNCTION_ARGS  )

Definition at line 1908 of file pgstatfuncs.c.

References PgStat_ArchiverStats::archived_count, BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, PgStat_ArchiverStats::failed_count, heap_form_tuple(), HeapTupleGetDatum, Int64GetDatum(), 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, TimestampTzGetDatum, TupleDescInitEntry(), and values.

1909 {
1910  TupleDesc tupdesc;
1911  Datum values[7];
1912  bool nulls[7];
1913  PgStat_ArchiverStats *archiver_stats;
1914 
1915  /* Initialise values and NULL flags arrays */
1916  MemSet(values, 0, sizeof(values));
1917  MemSet(nulls, 0, sizeof(nulls));
1918 
1919  /* Initialise attributes information in the tuple descriptor */
1920  tupdesc = CreateTemplateTupleDesc(7);
1921  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
1922  INT8OID, -1, 0);
1923  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
1924  TEXTOID, -1, 0);
1925  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
1926  TIMESTAMPTZOID, -1, 0);
1927  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
1928  INT8OID, -1, 0);
1929  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
1930  TEXTOID, -1, 0);
1931  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
1932  TIMESTAMPTZOID, -1, 0);
1933  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
1934  TIMESTAMPTZOID, -1, 0);
1935 
1936  BlessTupleDesc(tupdesc);
1937 
1938  /* Get statistics about the archiver process */
1939  archiver_stats = pgstat_fetch_stat_archiver();
1940 
1941  /* Fill values and NULLs */
1942  values[0] = Int64GetDatum(archiver_stats->archived_count);
1943  if (*(archiver_stats->last_archived_wal) == '\0')
1944  nulls[1] = true;
1945  else
1946  values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
1947 
1948  if (archiver_stats->last_archived_timestamp == 0)
1949  nulls[2] = true;
1950  else
1951  values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
1952 
1953  values[3] = Int64GetDatum(archiver_stats->failed_count);
1954  if (*(archiver_stats->last_failed_wal) == '\0')
1955  nulls[4] = true;
1956  else
1957  values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
1958 
1959  if (archiver_stats->last_failed_timestamp == 0)
1960  nulls[5] = true;
1961  else
1962  values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
1963 
1964  if (archiver_stats->stat_reset_timestamp == 0)
1965  nulls[6] = true;
1966  else
1967  values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
1968 
1969  /* Returns the record as Datum */
1971  heap_form_tuple(tupdesc, values, nulls)));
1972 }
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:689
PgStat_Counter archived_count
Definition: pgstat.h:684
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
#define MemSet(start, val, len)
Definition: c.h:955
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2604
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2048
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1699
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
TimestampTz last_failed_timestamp
Definition: pgstat.h:691
PgStat_Counter failed_count
Definition: pgstat.h:688
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
static Datum values[MAXATTR]
Definition: bootstrap.c:167
TimestampTz stat_reset_timestamp
Definition: pgstat.h:692
TimestampTz last_archived_timestamp
Definition: pgstat.h:687
#define CStringGetTextDatum(s)
Definition: builtins.h:83
int16 AttrNumber
Definition: attnum.h:21
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:685

◆ pg_stat_get_autoanalyze_count()

Datum pg_stat_get_autoanalyze_count ( PG_FUNCTION_ARGS  )

Definition at line 348 of file pgstatfuncs.c.

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

349 {
350  Oid relid = PG_GETARG_OID(0);
351  int64 result;
352  PgStat_StatTabEntry *tabentry;
353 
354  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
355  result = 0;
356  else
357  result = (int64) (tabentry->autovac_analyze_count);
358 
359  PG_RETURN_INT64(result);
360 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:660

◆ pg_stat_get_autovacuum_count()

Datum pg_stat_get_autovacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 318 of file pgstatfuncs.c.

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

319 {
320  Oid relid = PG_GETARG_OID(0);
321  int64 result;
322  PgStat_StatTabEntry *tabentry;
323 
324  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
325  result = 0;
326  else
327  result = (int64) (tabentry->autovac_vacuum_count);
328 
329  PG_RETURN_INT64(result);
330 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:656

◆ pg_stat_get_backend_activity()

Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 968 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.

969 {
970  int32 beid = PG_GETARG_INT32(0);
971  PgBackendStatus *beentry;
972  const char *activity;
973  char *clipped_activity;
974  text *ret;
975 
976  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
977  activity = "<backend information not available>";
978  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
979  activity = "<insufficient privilege>";
980  else if (*(beentry->st_activity_raw) == '\0')
981  activity = "<command string not enabled>";
982  else
983  activity = beentry->st_activity_raw;
984 
985  clipped_activity = pgstat_clip_activity(activity);
986  ret = cstring_to_text(activity);
987  pfree(clipped_activity);
988 
989  PG_RETURN_TEXT_P(ret);
990 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:380
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
signed int int32
Definition: c.h:346
void pfree(void *pointer)
Definition: mcxt.c:1056
char * st_activity_raw
Definition: pgstat.h:1085
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6544
Definition: c.h:549

◆ pg_stat_get_backend_activity_start()

Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 1036 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.

1037 {
1038  int32 beid = PG_GETARG_INT32(0);
1039  TimestampTz result;
1040  PgBackendStatus *beentry;
1041 
1042  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1043  PG_RETURN_NULL();
1044 
1045  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1046  PG_RETURN_NULL();
1047 
1048  result = beentry->st_activity_start_timestamp;
1049 
1050  /*
1051  * No time recorded for start of current query -- this is the case if the
1052  * user hasn't enabled query-level stats collection.
1053  */
1054  if (result == 0)
1055  PG_RETURN_NULL();
1056 
1057  PG_RETURN_TIMESTAMPTZ(result);
1058 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:380
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1055
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:346
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 1106 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.

1107 {
1108  int32 beid = PG_GETARG_INT32(0);
1109  PgBackendStatus *beentry;
1110  SockAddr zero_clientaddr;
1111  char remote_host[NI_MAXHOST];
1112  int ret;
1113 
1114  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1115  PG_RETURN_NULL();
1116 
1117  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1118  PG_RETURN_NULL();
1119 
1120  /* A zeroed client addr means we don't know */
1121  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1122  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1123  sizeof(zero_clientaddr)) == 0)
1124  PG_RETURN_NULL();
1125 
1126  switch (beentry->st_clientaddr.addr.ss_family)
1127  {
1128  case AF_INET:
1129 #ifdef HAVE_IPV6
1130  case AF_INET6:
1131 #endif
1132  break;
1133  default:
1134  PG_RETURN_NULL();
1135  }
1136 
1137  remote_host[0] = '\0';
1138  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1139  beentry->st_clientaddr.salen,
1140  remote_host, sizeof(remote_host),
1141  NULL, 0,
1143  if (ret != 0)
1144  PG_RETURN_NULL();
1145 
1146  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1147 
1149  CStringGetDatum(remote_host)));
1150 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Oid GetUserId(void)
Definition: miscinit.c:380
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INET_P(x)
Definition: inet.h:125
SockAddr st_clientaddr
Definition: pgstat.h:1061
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:617
signed int int32
Definition: c.h:346
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define CStringGetDatum(X)
Definition: postgres.h:578
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:2547
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:122
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:2118
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_client_port()

Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 1153 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.

1154 {
1155  int32 beid = PG_GETARG_INT32(0);
1156  PgBackendStatus *beentry;
1157  SockAddr zero_clientaddr;
1158  char remote_port[NI_MAXSERV];
1159  int ret;
1160 
1161  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1162  PG_RETURN_NULL();
1163 
1164  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1165  PG_RETURN_NULL();
1166 
1167  /* A zeroed client addr means we don't know */
1168  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1169  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1170  sizeof(zero_clientaddr)) == 0)
1171  PG_RETURN_NULL();
1172 
1173  switch (beentry->st_clientaddr.addr.ss_family)
1174  {
1175  case AF_INET:
1176 #ifdef HAVE_IPV6
1177  case AF_INET6:
1178 #endif
1179  break;
1180  case AF_UNIX:
1181  PG_RETURN_INT32(-1);
1182  default:
1183  PG_RETURN_NULL();
1184  }
1185 
1186  remote_port[0] = '\0';
1187  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1188  beentry->st_clientaddr.salen,
1189  NULL, 0,
1190  remote_port, sizeof(remote_port),
1192  if (ret != 0)
1193  PG_RETURN_NULL();
1194 
1196  CStringGetDatum(remote_port)));
1197 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Oid GetUserId(void)
Definition: miscinit.c:380
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:268
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
SockAddr st_clientaddr
Definition: pgstat.h:1061
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:617
signed int int32
Definition: c.h:346
#define CStringGetDatum(X)
Definition: postgres.h:578
#define NI_MAXSERV
Definition: getaddrinfo.h:91
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#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:2547
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_dbid()

Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 942 of file pgstatfuncs.c.

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

943 {
944  int32 beid = PG_GETARG_INT32(0);
945  PgBackendStatus *beentry;
946 
947  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
948  PG_RETURN_NULL();
949 
950  PG_RETURN_OID(beentry->st_databaseid);
951 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
Oid st_databaseid
Definition: pgstat.h:1059
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
#define PG_RETURN_OID(x)
Definition: fmgr.h:350
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_idset()

Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

Definition at line 398 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.

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

◆ pg_stat_get_backend_pid()

Datum pg_stat_get_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 929 of file pgstatfuncs.c.

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

930 {
931  int32 beid = PG_GETARG_INT32(0);
932  PgBackendStatus *beentry;
933 
934  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
935  PG_RETURN_NULL();
936 
937  PG_RETURN_INT32(beentry->st_procpid);
938 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:346
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_start()

Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 1084 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.

1085 {
1086  int32 beid = PG_GETARG_INT32(0);
1087  TimestampTz result;
1088  PgBackendStatus *beentry;
1089 
1090  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1091  PG_RETURN_NULL();
1092 
1093  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1094  PG_RETURN_NULL();
1095 
1096  result = beentry->st_proc_start_timestamp;
1097 
1098  if (result == 0) /* probably can't happen? */
1099  PG_RETURN_NULL();
1100 
1101  PG_RETURN_TIMESTAMPTZ(result);
1102 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:380
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:346
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1053
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_userid()

Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 955 of file pgstatfuncs.c.

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

956 {
957  int32 beid = PG_GETARG_INT32(0);
958  PgBackendStatus *beentry;
959 
960  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
961  PG_RETURN_NULL();
962 
963  PG_RETURN_OID(beentry->st_userid);
964 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
#define PG_RETURN_OID(x)
Definition: fmgr.h:350
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_wait_event()

Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 1014 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.

1015 {
1016  int32 beid = PG_GETARG_INT32(0);
1017  PgBackendStatus *beentry;
1018  PGPROC *proc;
1019  const char *wait_event = NULL;
1020 
1021  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1022  wait_event = "<backend information not available>";
1023  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1024  wait_event = "<insufficient privilege>";
1025  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1026  wait_event = pgstat_get_wait_event(proc->wait_event_info);
1027 
1028  if (!wait_event)
1029  PG_RETURN_NULL();
1030 
1031  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
1032 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
uint32 wait_event_info
Definition: proc.h:176
Oid GetUserId(void)
Definition: miscinit.c:380
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2363
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
signed int int32
Definition: c.h:346
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3557
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_wait_event_type()

Datum pg_stat_get_backend_wait_event_type ( PG_FUNCTION_ARGS  )

Definition at line 993 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.

994 {
995  int32 beid = PG_GETARG_INT32(0);
996  PgBackendStatus *beentry;
997  PGPROC *proc;
998  const char *wait_event_type = NULL;
999 
1000  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1001  wait_event_type = "<backend information not available>";
1002  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1003  wait_event_type = "<insufficient privilege>";
1004  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1005  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
1006 
1007  if (!wait_event_type)
1008  PG_RETURN_NULL();
1009 
1010  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
1011 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
uint32 wait_event_info
Definition: proc.h:176
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3502
Oid GetUserId(void)
Definition: miscinit.c:380
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2363
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
signed int int32
Definition: c.h:346
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_xact_start()

Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 1062 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.

1063 {
1064  int32 beid = PG_GETARG_INT32(0);
1065  TimestampTz result;
1066  PgBackendStatus *beentry;
1067 
1068  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1069  PG_RETURN_NULL();
1070 
1071  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1072  PG_RETURN_NULL();
1073 
1074  result = beentry->st_xact_start_timestamp;
1075 
1076  if (result == 0) /* not in a transaction */
1077  PG_RETURN_NULL();
1078 
1079  PG_RETURN_TIMESTAMPTZ(result);
1080 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:380
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:346
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1054
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_bgwriter_buf_written_checkpoints()

Datum pg_stat_get_bgwriter_buf_written_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1607 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1608 {
1609  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_checkpoints);
1610 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1613 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1614 {
1615  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_clean);
1616 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_bgwriter_maxwritten_clean()

Datum pg_stat_get_bgwriter_maxwritten_clean ( PG_FUNCTION_ARGS  )

Definition at line 1619 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1620 {
1621  PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_clean);
1622 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_bgwriter_requested_checkpoints()

Datum pg_stat_get_bgwriter_requested_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1601 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1602 {
1603  PG_RETURN_INT64(pgstat_fetch_global()->requested_checkpoints);
1604 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_bgwriter_stat_reset_time()

Datum pg_stat_get_bgwriter_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1639 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1640 {
1641  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stat_reset_timestamp);
1642 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40

◆ pg_stat_get_bgwriter_timed_checkpoints()

Datum pg_stat_get_bgwriter_timed_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1595 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1596 {
1597  PG_RETURN_INT64(pgstat_fetch_global()->timed_checkpoints);
1598 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_blocks_fetched()

Datum pg_stat_get_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 200 of file pgstatfuncs.c.

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

201 {
202  Oid relid = PG_GETARG_OID(0);
203  int64 result;
204  PgStat_StatTabEntry *tabentry;
205 
206  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
207  result = 0;
208  else
209  result = (int64) (tabentry->blocks_fetched);
210 
211  PG_RETURN_INT64(result);
212 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter blocks_fetched
Definition: pgstat.h:650

◆ pg_stat_get_blocks_hit()

Datum pg_stat_get_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 216 of file pgstatfuncs.c.

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

217 {
218  Oid relid = PG_GETARG_OID(0);
219  int64 result;
220  PgStat_StatTabEntry *tabentry;
221 
222  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
223  result = 0;
224  else
225  result = (int64) (tabentry->blocks_hit);
226 
227  PG_RETURN_INT64(result);
228 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter blocks_hit
Definition: pgstat.h:651

◆ pg_stat_get_buf_alloc()

Datum pg_stat_get_buf_alloc ( PG_FUNCTION_ARGS  )

Definition at line 1657 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1658 {
1659  PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
1660 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_buf_fsync_backend()

Datum pg_stat_get_buf_fsync_backend ( PG_FUNCTION_ARGS  )

Definition at line 1651 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1652 {
1653  PG_RETURN_INT64(pgstat_fetch_global()->buf_fsync_backend);
1654 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_buf_written_backend()

Datum pg_stat_get_buf_written_backend ( PG_FUNCTION_ARGS  )

Definition at line 1645 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1646 {
1647  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_backend);
1648 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_checkpoint_sync_time()

Datum pg_stat_get_checkpoint_sync_time ( PG_FUNCTION_ARGS  )

Definition at line 1632 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1633 {
1634  /* time is already in msec, just convert to double for presentation */
1635  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
1636 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_checkpoint_write_time()

Datum pg_stat_get_checkpoint_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1625 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1626 {
1627  /* time is already in msec, just convert to double for presentation */
1628  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
1629 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621

◆ pg_stat_get_db_blk_read_time()

Datum pg_stat_get_db_blk_read_time ( PG_FUNCTION_ARGS  )

Definition at line 1563 of file pgstatfuncs.c.

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

1564 {
1565  Oid dbid = PG_GETARG_OID(0);
1566  double result;
1567  PgStat_StatDBEntry *dbentry;
1568 
1569  /* convert counter from microsec to millisec for display */
1570  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1571  result = 0;
1572  else
1573  result = ((double) dbentry->n_block_read_time) / 1000.0;
1574 
1575  PG_RETURN_FLOAT8(result);
1576 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_block_read_time
Definition: pgstat.h:613

◆ pg_stat_get_db_blk_write_time()

Datum pg_stat_get_db_blk_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1579 of file pgstatfuncs.c.

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

1580 {
1581  Oid dbid = PG_GETARG_OID(0);
1582  double result;
1583  PgStat_StatDBEntry *dbentry;
1584 
1585  /* convert counter from microsec to millisec for display */
1586  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1587  result = 0;
1588  else
1589  result = ((double) dbentry->n_block_write_time) / 1000.0;
1590 
1591  PG_RETURN_FLOAT8(result);
1592 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_block_write_time
Definition: pgstat.h:614

◆ pg_stat_get_db_blocks_fetched()

Datum pg_stat_get_db_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1254 of file pgstatfuncs.c.

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

1255 {
1256  Oid dbid = PG_GETARG_OID(0);
1257  int64 result;
1258  PgStat_StatDBEntry *dbentry;
1259 
1260  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1261  result = 0;
1262  else
1263  result = (int64) (dbentry->n_blocks_fetched);
1264 
1265  PG_RETURN_INT64(result);
1266 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:595
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_blocks_hit()

Datum pg_stat_get_db_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1270 of file pgstatfuncs.c.

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

1271 {
1272  Oid dbid = PG_GETARG_OID(0);
1273  int64 result;
1274  PgStat_StatDBEntry *dbentry;
1275 
1276  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1277  result = 0;
1278  else
1279  result = (int64) (dbentry->n_blocks_hit);
1280 
1281  PG_RETURN_INT64(result);
1282 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_blocks_hit
Definition: pgstat.h:596
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_checksum_failures()

Datum pg_stat_get_db_checksum_failures ( PG_FUNCTION_ARGS  )

Definition at line 1524 of file pgstatfuncs.c.

References DataChecksumsEnabled(), PgStat_StatDBEntry::n_checksum_failures, PG_GETARG_OID, PG_RETURN_INT64, PG_RETURN_NULL, and pgstat_fetch_stat_dbentry().

1525 {
1526  Oid dbid = PG_GETARG_OID(0);
1527  int64 result;
1528  PgStat_StatDBEntry *dbentry;
1529 
1530  if (!DataChecksumsEnabled())
1531  PG_RETURN_NULL();
1532 
1533  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1534  result = 0;
1535  else
1536  result = (int64) (dbentry->n_checksum_failures);
1537 
1538  PG_RETURN_INT64(result);
1539 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
bool DataChecksumsEnabled(void)
Definition: xlog.c:4822
PgStat_Counter n_checksum_failures
Definition: pgstat.h:611
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_db_checksum_last_failure()

Datum pg_stat_get_db_checksum_last_failure ( PG_FUNCTION_ARGS  )

Definition at line 1542 of file pgstatfuncs.c.

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

1543 {
1544  Oid dbid = PG_GETARG_OID(0);
1545  TimestampTz result;
1546  PgStat_StatDBEntry *dbentry;
1547 
1548  if (!DataChecksumsEnabled())
1549  PG_RETURN_NULL();
1550 
1551  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1552  result = 0;
1553  else
1554  result = dbentry->last_checksum_failure;
1555 
1556  if (result == 0)
1557  PG_RETURN_NULL();
1558  else
1559  PG_RETURN_TIMESTAMPTZ(result);
1560 }
bool DataChecksumsEnabled(void)
Definition: xlog.c:4822
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz last_checksum_failure
Definition: pgstat.h:612
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
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:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_db_conflict_all()

Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

Definition at line 1489 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().

1490 {
1491  Oid dbid = PG_GETARG_OID(0);
1492  int64 result;
1493  PgStat_StatDBEntry *dbentry;
1494 
1495  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1496  result = 0;
1497  else
1498  result = (int64) (
1499  dbentry->n_conflict_tablespace +
1500  dbentry->n_conflict_lock +
1501  dbentry->n_conflict_snapshot +
1502  dbentry->n_conflict_bufferpin +
1503  dbentry->n_conflict_startup_deadlock);
1504 
1505  PG_RETURN_INT64(result);
1506 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:606
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:607
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:605
PgStat_Counter n_conflict_lock
Definition: pgstat.h:604

◆ pg_stat_get_db_conflict_bufferpin()

Datum pg_stat_get_db_conflict_bufferpin ( PG_FUNCTION_ARGS  )

Definition at line 1459 of file pgstatfuncs.c.

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

1460 {
1461  Oid dbid = PG_GETARG_OID(0);
1462  int64 result;
1463  PgStat_StatDBEntry *dbentry;
1464 
1465  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1466  result = 0;
1467  else
1468  result = (int64) (dbentry->n_conflict_bufferpin);
1469 
1470  PG_RETURN_INT64(result);
1471 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:606
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_conflict_lock()

Datum pg_stat_get_db_conflict_lock ( PG_FUNCTION_ARGS  )

Definition at line 1429 of file pgstatfuncs.c.

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

1430 {
1431  Oid dbid = PG_GETARG_OID(0);
1432  int64 result;
1433  PgStat_StatDBEntry *dbentry;
1434 
1435  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1436  result = 0;
1437  else
1438  result = (int64) (dbentry->n_conflict_lock);
1439 
1440  PG_RETURN_INT64(result);
1441 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_conflict_lock
Definition: pgstat.h:604

◆ pg_stat_get_db_conflict_snapshot()

Datum pg_stat_get_db_conflict_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1444 of file pgstatfuncs.c.

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

1445 {
1446  Oid dbid = PG_GETARG_OID(0);
1447  int64 result;
1448  PgStat_StatDBEntry *dbentry;
1449 
1450  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1451  result = 0;
1452  else
1453  result = (int64) (dbentry->n_conflict_snapshot);
1454 
1455  PG_RETURN_INT64(result);
1456 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:605

◆ pg_stat_get_db_conflict_startup_deadlock()

Datum pg_stat_get_db_conflict_startup_deadlock ( PG_FUNCTION_ARGS  )

Definition at line 1474 of file pgstatfuncs.c.

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

1475 {
1476  Oid dbid = PG_GETARG_OID(0);
1477  int64 result;
1478  PgStat_StatDBEntry *dbentry;
1479 
1480  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1481  result = 0;
1482  else
1483  result = (int64) (dbentry->n_conflict_startup_deadlock);
1484 
1485  PG_RETURN_INT64(result);
1486 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:607
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_conflict_tablespace()

Datum pg_stat_get_db_conflict_tablespace ( PG_FUNCTION_ARGS  )

Definition at line 1414 of file pgstatfuncs.c.

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

1415 {
1416  Oid dbid = PG_GETARG_OID(0);
1417  int64 result;
1418  PgStat_StatDBEntry *dbentry;
1419 
1420  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1421  result = 0;
1422  else
1423  result = (int64) (dbentry->n_conflict_tablespace);
1424 
1425  PG_RETURN_INT64(result);
1426 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_deadlocks()

Datum pg_stat_get_db_deadlocks ( PG_FUNCTION_ARGS  )

Definition at line 1509 of file pgstatfuncs.c.

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

1510 {
1511  Oid dbid = PG_GETARG_OID(0);
1512  int64 result;
1513  PgStat_StatDBEntry *dbentry;
1514 
1515  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1516  result = 0;
1517  else
1518  result = (int64) (dbentry->n_deadlocks);
1519 
1520  PG_RETURN_INT64(result);
1521 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_deadlocks
Definition: pgstat.h:610

◆ pg_stat_get_db_numbackends()

Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1201 of file pgstatfuncs.c.

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

1202 {
1203  Oid dbid = PG_GETARG_OID(0);
1204  int32 result;
1205  int tot_backends = pgstat_fetch_stat_numbackends();
1206  int beid;
1207 
1208  result = 0;
1209  for (beid = 1; beid <= tot_backends; beid++)
1210  {
1211  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1212 
1213  if (beentry && beentry->st_databaseid == dbid)
1214  result++;
1215  }
1216 
1217  PG_RETURN_INT32(result);
1218 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:346
Oid st_databaseid
Definition: pgstat.h:1059
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2588
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2547

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1365 of file pgstatfuncs.c.

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

1366 {
1367  Oid dbid = PG_GETARG_OID(0);
1368  TimestampTz result;
1369  PgStat_StatDBEntry *dbentry;
1370 
1371  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1372  result = 0;
1373  else
1374  result = dbentry->stat_reset_timestamp;
1375 
1376  if (result == 0)
1377  PG_RETURN_NULL();
1378  else
1379  PG_RETURN_TIMESTAMPTZ(result);
1380 }
int64 TimestampTz
Definition: timestamp.h:39
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
TimestampTz stat_reset_timestamp
Definition: pgstat.h:616
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:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_db_temp_bytes()

Datum pg_stat_get_db_temp_bytes ( PG_FUNCTION_ARGS  )

Definition at line 1399 of file pgstatfuncs.c.

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

1400 {
1401  Oid dbid = PG_GETARG_OID(0);
1402  int64 result;
1403  PgStat_StatDBEntry *dbentry;
1404 
1405  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1406  result = 0;
1407  else
1408  result = dbentry->n_temp_bytes;
1409 
1410  PG_RETURN_INT64(result);
1411 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_temp_bytes
Definition: pgstat.h:609

◆ pg_stat_get_db_temp_files()

Datum pg_stat_get_db_temp_files ( PG_FUNCTION_ARGS  )

Definition at line 1383 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_temp_files, 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 = dbentry->n_temp_files;
1393 
1394  PG_RETURN_INT64(result);
1395 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_temp_files
Definition: pgstat.h:608
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_tuples_deleted()

Datum pg_stat_get_db_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1350 of file pgstatfuncs.c.

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

1351 {
1352  Oid dbid = PG_GETARG_OID(0);
1353  int64 result;
1354  PgStat_StatDBEntry *dbentry;
1355 
1356  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1357  result = 0;
1358  else
1359  result = (int64) (dbentry->n_tuples_deleted);
1360 
1361  PG_RETURN_INT64(result);
1362 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:601

◆ pg_stat_get_db_tuples_fetched()

Datum pg_stat_get_db_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1302 of file pgstatfuncs.c.

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

1303 {
1304  Oid dbid = PG_GETARG_OID(0);
1305  int64 result;
1306  PgStat_StatDBEntry *dbentry;
1307 
1308  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1309  result = 0;
1310  else
1311  result = (int64) (dbentry->n_tuples_fetched);
1312 
1313  PG_RETURN_INT64(result);
1314 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:598

◆ pg_stat_get_db_tuples_inserted()

Datum pg_stat_get_db_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1318 of file pgstatfuncs.c.

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

1319 {
1320  Oid dbid = PG_GETARG_OID(0);
1321  int64 result;
1322  PgStat_StatDBEntry *dbentry;
1323 
1324  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1325  result = 0;
1326  else
1327  result = (int64) (dbentry->n_tuples_inserted);
1328 
1329  PG_RETURN_INT64(result);
1330 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:599
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_tuples_returned()

Datum pg_stat_get_db_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1286 of file pgstatfuncs.c.

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

1287 {
1288  Oid dbid = PG_GETARG_OID(0);
1289  int64 result;
1290  PgStat_StatDBEntry *dbentry;
1291 
1292  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1293  result = 0;
1294  else
1295  result = (int64) (dbentry->n_tuples_returned);
1296 
1297  PG_RETURN_INT64(result);
1298 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_tuples_returned
Definition: pgstat.h:597
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_tuples_updated()

Datum pg_stat_get_db_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1334 of file pgstatfuncs.c.

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

1335 {
1336  Oid dbid = PG_GETARG_OID(0);
1337  int64 result;
1338  PgStat_StatDBEntry *dbentry;
1339 
1340  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1341  result = 0;
1342  else
1343  result = (int64) (dbentry->n_tuples_updated);
1344 
1345  PG_RETURN_INT64(result);
1346 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_tuples_updated
Definition: pgstat.h:600

◆ pg_stat_get_db_xact_commit()

Datum pg_stat_get_db_xact_commit ( PG_FUNCTION_ARGS  )

Definition at line 1222 of file pgstatfuncs.c.

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

1223 {
1224  Oid dbid = PG_GETARG_OID(0);
1225  int64 result;
1226  PgStat_StatDBEntry *dbentry;
1227 
1228  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1229  result = 0;
1230  else
1231  result = (int64) (dbentry->n_xact_commit);
1232 
1233  PG_RETURN_INT64(result);
1234 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_xact_commit
Definition: pgstat.h:593
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_xact_rollback()

Datum pg_stat_get_db_xact_rollback ( PG_FUNCTION_ARGS  )

Definition at line 1238 of file pgstatfuncs.c.

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

1239 {
1240  Oid dbid = PG_GETARG_OID(0);
1241  int64 result;
1242  PgStat_StatDBEntry *dbentry;
1243 
1244  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1245  result = 0;
1246  else
1247  result = (int64) (dbentry->n_xact_rollback);
1248 
1249  PG_RETURN_INT64(result);
1250 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2432
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_xact_rollback
Definition: pgstat.h:594

◆ pg_stat_get_dead_tuples()

Datum pg_stat_get_dead_tuples ( PG_FUNCTION_ARGS  )

Definition at line 168 of file pgstatfuncs.c.

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

169 {
170  Oid relid = PG_GETARG_OID(0);
171  int64 result;
172  PgStat_StatTabEntry *tabentry;
173 
174  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
175  result = 0;
176  else
177  result = (int64) (tabentry->n_dead_tuples);
178 
179  PG_RETURN_INT64(result);
180 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_dead_tuples
Definition: pgstat.h:647
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_function_calls()

Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 363 of file pgstatfuncs.c.

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

364 {
365  Oid funcid = PG_GETARG_OID(0);
366  PgStat_StatFuncEntry *funcentry;
367 
368  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
369  PG_RETURN_NULL();
370  PG_RETURN_INT64(funcentry->f_numcalls);
371 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2515
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_numcalls
Definition: pgstat.h:672
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_function_self_time()

Datum pg_stat_get_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 386 of file pgstatfuncs.c.

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

387 {
388  Oid funcid = PG_GETARG_OID(0);
389  PgStat_StatFuncEntry *funcentry;
390 
391  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
392  PG_RETURN_NULL();
393  /* convert counter from microsec to millisec for display */
394  PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
395 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2515
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter f_self_time
Definition: pgstat.h:675
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_function_total_time()

Datum pg_stat_get_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 374 of file pgstatfuncs.c.

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

375 {
376  Oid funcid = PG_GETARG_OID(0);
377  PgStat_StatFuncEntry *funcentry;
378 
379  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
380  PG_RETURN_NULL();
381  /* convert counter from microsec to millisec for display */
382  PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
383 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2515
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_total_time
Definition: pgstat.h:674
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_last_analyze_time()

Datum pg_stat_get_last_analyze_time ( PG_FUNCTION_ARGS  )

Definition at line 267 of file pgstatfuncs.c.

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

268 {
269  Oid relid = PG_GETARG_OID(0);
270  TimestampTz result;
271  PgStat_StatTabEntry *tabentry;
272 
273  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
274  result = 0;
275  else
276  result = tabentry->analyze_timestamp;
277 
278  if (result == 0)
279  PG_RETURN_NULL();
280  else
281  PG_RETURN_TIMESTAMPTZ(result);
282 }
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:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
TimestampTz analyze_timestamp
Definition: pgstat.h:657
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_last_autoanalyze_time()

Datum pg_stat_get_last_autoanalyze_time ( PG_FUNCTION_ARGS  )

Definition at line 285 of file pgstatfuncs.c.

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

286 {
287  Oid relid = PG_GETARG_OID(0);
288  TimestampTz result;
289  PgStat_StatTabEntry *tabentry;
290 
291  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
292  result = 0;
293  else
294  result = tabentry->autovac_analyze_timestamp;
295 
296  if (result == 0)
297  PG_RETURN_NULL();
298  else
299  PG_RETURN_TIMESTAMPTZ(result);
300 }
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:659
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:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_last_autovacuum_time()

Datum pg_stat_get_last_autovacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 249 of file pgstatfuncs.c.

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

250 {
251  Oid relid = PG_GETARG_OID(0);
252  TimestampTz result;
253  PgStat_StatTabEntry *tabentry;
254 
255  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
256  result = 0;
257  else
258  result = tabentry->autovac_vacuum_timestamp;
259 
260  if (result == 0)
261  PG_RETURN_NULL();
262  else
263  PG_RETURN_TIMESTAMPTZ(result);
264 }
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:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:655
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_last_vacuum_time()

Datum pg_stat_get_last_vacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 231 of file pgstatfuncs.c.

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

232 {
233  Oid relid = PG_GETARG_OID(0);
234  TimestampTz result;
235  PgStat_StatTabEntry *tabentry;
236 
237  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
238  result = 0;
239  else
240  result = tabentry->vacuum_timestamp;
241 
242  if (result == 0)
243  PG_RETURN_NULL();
244  else
245  PG_RETURN_TIMESTAMPTZ(result);
246 }
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:653
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_live_tuples()

Datum pg_stat_get_live_tuples ( PG_FUNCTION_ARGS  )

Definition at line 152 of file pgstatfuncs.c.

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

153 {
154  Oid relid = PG_GETARG_OID(0);
155  int64 result;
156  PgStat_StatTabEntry *tabentry;
157 
158  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
159  result = 0;
160  else
161  result = (int64) (tabentry->n_live_tuples);
162 
163  PG_RETURN_INT64(result);
164 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_live_tuples
Definition: pgstat.h:646
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_mod_since_analyze()

Datum pg_stat_get_mod_since_analyze ( PG_FUNCTION_ARGS  )

Definition at line 184 of file pgstatfuncs.c.

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

185 {
186  Oid relid = PG_GETARG_OID(0);
187  int64 result;
188  PgStat_StatTabEntry *tabentry;
189 
190  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
191  result = 0;
192  else
193  result = (int64) (tabentry->changes_since_analyze);
194 
195  PG_RETURN_INT64(result);
196 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter changes_since_analyze
Definition: pgstat.h:648

◆ pg_stat_get_numscans()

Datum pg_stat_get_numscans ( PG_FUNCTION_ARGS  )

Definition at line 40 of file pgstatfuncs.c.

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

41 {
42  Oid relid = PG_GETARG_OID(0);
43  int64 result;
44  PgStat_StatTabEntry *tabentry;
45 
46  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
47  result = 0;
48  else
49  result = (int64) (tabentry->numscans);
50 
51  PG_RETURN_INT64(result);
52 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter numscans
Definition: pgstat.h:636
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_progress_info()

Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 441 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_CLUSTER, PROGRESS_COMMAND_CREATE_INDEX, 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.

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

◆ pg_stat_get_snapshot_timestamp()

Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1851 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1852 {
1853  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stats_timestamp);
1854 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2621
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40

◆ pg_stat_get_tuples_deleted()

Datum pg_stat_get_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 120 of file pgstatfuncs.c.

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

121 {
122  Oid relid = PG_GETARG_OID(0);
123  int64 result;
124  PgStat_StatTabEntry *tabentry;
125 
126  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
127  result = 0;
128  else
129  result = (int64) (tabentry->tuples_deleted);
130 
131  PG_RETURN_INT64(result);
132 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter tuples_deleted
Definition: pgstat.h:643

◆ pg_stat_get_tuples_fetched()

Datum pg_stat_get_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 72 of file pgstatfuncs.c.

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

73 {
74  Oid relid = PG_GETARG_OID(0);
75  int64 result;
76  PgStat_StatTabEntry *tabentry;
77 
78  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
79  result = 0;
80  else
81  result = (int64) (tabentry->tuples_fetched);
82 
83  PG_RETURN_INT64(result);
84 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter tuples_fetched
Definition: pgstat.h:639

◆ pg_stat_get_tuples_hot_updated()

Datum pg_stat_get_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 136 of file pgstatfuncs.c.

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

137 {
138  Oid relid = PG_GETARG_OID(0);
139  int64 result;
140  PgStat_StatTabEntry *tabentry;
141 
142  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
143  result = 0;
144  else
145  result = (int64) (tabentry->tuples_hot_updated);
146 
147  PG_RETURN_INT64(result);
148 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:644
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_tuples_inserted()

Datum pg_stat_get_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 88 of file pgstatfuncs.c.

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

89 {
90  Oid relid = PG_GETARG_OID(0);
91  int64 result;
92  PgStat_StatTabEntry *tabentry;
93 
94  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
95  result = 0;
96  else
97  result = (int64) (tabentry->tuples_inserted);
98 
99  PG_RETURN_INT64(result);
100 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter tuples_inserted
Definition: pgstat.h:641
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_tuples_returned()

Datum pg_stat_get_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 56 of file pgstatfuncs.c.

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

57 {
58  Oid relid = PG_GETARG_OID(0);
59  int64 result;
60  PgStat_StatTabEntry *tabentry;
61 
62  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
63  result = 0;
64  else
65  result = (int64) (tabentry->tuples_returned);
66 
67  PG_RETURN_INT64(result);
68 }
PgStat_Counter tuples_returned
Definition: pgstat.h:638
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_tuples_updated()

Datum pg_stat_get_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 104 of file pgstatfuncs.c.

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

105 {
106  Oid relid = PG_GETARG_OID(0);
107  int64 result;
108  PgStat_StatTabEntry *tabentry;
109 
110  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
111  result = 0;
112  else
113  result = (int64) (tabentry->tuples_updated);
114 
115  PG_RETURN_INT64(result);
116 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter tuples_updated
Definition: pgstat.h:642

◆ pg_stat_get_vacuum_count()

Datum pg_stat_get_vacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 303 of file pgstatfuncs.c.

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

304 {
305  Oid relid = PG_GETARG_OID(0);
306  int64 result;
307  PgStat_StatTabEntry *tabentry;
308 
309  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
310  result = 0;
311  else
312  result = (int64) (tabentry->vacuum_count);
313 
314  PG_RETURN_INT64(result);
315 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter vacuum_count
Definition: pgstat.h:654
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2459
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_blocks_fetched()

Datum pg_stat_get_xact_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1786 of file pgstatfuncs.c.

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

1787 {
1788  Oid relid = PG_GETARG_OID(0);
1789  int64 result;
1790  PgStat_TableStatus *tabentry;
1791 
1792  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1793  result = 0;
1794  else
1795  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1796 
1797  PG_RETURN_INT64(result);
1798 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:114

◆ pg_stat_get_xact_blocks_hit()

Datum pg_stat_get_xact_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1801 of file pgstatfuncs.c.

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

1802 {
1803  Oid relid = PG_GETARG_OID(0);
1804  int64 result;
1805  PgStat_TableStatus *tabentry;
1806 
1807  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1808  result = 0;
1809  else
1810  result = (int64) (tabentry->t_counts.t_blocks_hit);
1811 
1812  PG_RETURN_INT64(result);
1813 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter t_blocks_hit
Definition: pgstat.h:115

◆ pg_stat_get_xact_function_calls()

Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 1816 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.

1817 {
1818  Oid funcid = PG_GETARG_OID(0);
1819  PgStat_BackendFunctionEntry *funcentry;
1820 
1821  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1822  PG_RETURN_NULL();
1823  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
1824 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:270
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1674
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_xact_function_self_time()

Datum pg_stat_get_xact_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 1838 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.

1839 {
1840  Oid funcid = PG_GETARG_OID(0);
1841  PgStat_BackendFunctionEntry *funcentry;
1842 
1843  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1844  PG_RETURN_NULL();
1846 }
instr_time f_self_time
Definition: pgstat.h:463
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1674
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_xact_function_total_time()

Datum pg_stat_get_xact_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 1827 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.

1828 {
1829  Oid funcid = PG_GETARG_OID(0);
1830  PgStat_BackendFunctionEntry *funcentry;
1831 
1832  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1833  PG_RETURN_NULL();
1835 }
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
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:270
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1674
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_xact_numscans()

Datum pg_stat_get_xact_numscans ( PG_FUNCTION_ARGS  )

Definition at line 1663 of file pgstatfuncs.c.

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

1664 {
1665  Oid relid = PG_GETARG_OID(0);
1666  int64 result;
1667  PgStat_TableStatus *tabentry;
1668 
1669  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1670  result = 0;
1671  else
1672  result = (int64) (tabentry->t_counts.t_numscans);
1673 
1674  PG_RETURN_INT64(result);
1675 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter t_numscans
Definition: pgstat.h:99

◆ pg_stat_get_xact_tuples_deleted()

Datum pg_stat_get_xact_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1750 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.

1751 {
1752  Oid relid = PG_GETARG_OID(0);
1753  int64 result;
1754  PgStat_TableStatus *tabentry;
1756 
1757  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1758  result = 0;
1759  else
1760  {
1761  result = tabentry->t_counts.t_tuples_deleted;
1762  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1763  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1764  result += trans->tuples_deleted;
1765  }
1766 
1767  PG_RETURN_INT64(result);
1768 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
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:396

◆ pg_stat_get_xact_tuples_fetched()

Datum pg_stat_get_xact_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1693 of file pgstatfuncs.c.

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

1694 {
1695  Oid relid = PG_GETARG_OID(0);
1696  int64 result;
1697  PgStat_TableStatus *tabentry;
1698 
1699  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1700  result = 0;
1701  else
1702  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1703 
1704  PG_RETURN_INT64(result);
1705 }
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:102
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_tuples_hot_updated()

Datum pg_stat_get_xact_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 1771 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.

1772 {
1773  Oid relid = PG_GETARG_OID(0);
1774  int64 result;
1775  PgStat_TableStatus *tabentry;
1776 
1777  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1778  result = 0;
1779  else
1780  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1781 
1782  PG_RETURN_INT64(result);
1783 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_tuples_inserted()

Datum pg_stat_get_xact_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1708 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.

1709 {
1710  Oid relid = PG_GETARG_OID(0);
1711  int64 result;
1712  PgStat_TableStatus *tabentry;
1714 
1715  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1716  result = 0;
1717  else
1718  {
1719  result = tabentry->t_counts.t_tuples_inserted;
1720  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1721  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1722  result += trans->tuples_inserted;
1723  }
1724 
1725  PG_RETURN_INT64(result);
1726 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
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:396
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104

◆ pg_stat_get_xact_tuples_returned()

Datum pg_stat_get_xact_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1678 of file pgstatfuncs.c.

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

1679 {
1680  Oid relid = PG_GETARG_OID(0);
1681  int64 result;
1682  PgStat_TableStatus *tabentry;
1683 
1684  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1685  result = 0;
1686  else
1687  result = (int64) (tabentry->t_counts.t_tuples_returned);
1688 
1689  PG_RETURN_INT64(result);
1690 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_tuples_updated()

Datum pg_stat_get_xact_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1729 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.

1730 {
1731  Oid relid = PG_GETARG_OID(0);
1732  int64 result;
1733  PgStat_TableStatus *tabentry;
1735 
1736  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1737  result = 0;
1738  else
1739  {
1740  result = tabentry->t_counts.t_tuples_updated;
1741  /* live subtransactions' counts aren't in t_tuples_updated yet */
1742  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1743  result += trans->tuples_updated;
1744  }
1745 
1746  PG_RETURN_INT64(result);
1747 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
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:1879
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
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:396

◆ pg_stat_reset()

Datum pg_stat_reset ( PG_FUNCTION_ARGS  )

Definition at line 1868 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_reset_counters().

1869 {
1871 
1872  PG_RETURN_VOID();
1873 }
#define PG_RETURN_VOID()
Definition: fmgr.h:339
void pgstat_reset_counters(void)
Definition: pgstat.c:1311

◆ pg_stat_reset_shared()

Datum pg_stat_reset_shared ( PG_FUNCTION_ARGS  )

Definition at line 1877 of file pgstatfuncs.c.

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

1878 {
1879  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
1880 
1882 
1883  PG_RETURN_VOID();
1884 }
void pgstat_reset_shared_counters(const char *target)
Definition: pgstat.c:1333
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_VOID()
Definition: fmgr.h:339
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ pg_stat_reset_single_function_counters()

Datum pg_stat_reset_single_function_counters ( PG_FUNCTION_ARGS  )

Definition at line 1898 of file pgstatfuncs.c.

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

1899 {
1900  Oid funcoid = PG_GETARG_OID(0);
1901 
1903 
1904  PG_RETURN_VOID();
1905 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1364
#define PG_RETURN_VOID()
Definition: fmgr.h:339

◆ pg_stat_reset_single_table_counters()

Datum pg_stat_reset_single_table_counters ( PG_FUNCTION_ARGS  )

Definition at line 1888 of file pgstatfuncs.c.

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

1889 {
1890  Oid taboid = PG_GETARG_OID(0);
1891 
1893 
1894  PG_RETURN_VOID();
1895 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1364
#define PG_RETURN_VOID()
Definition: fmgr.h:339

Variable Documentation

◆ bgwriterStats

PgStat_MsgBgWriter bgwriterStats