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 HAS_PGSTAT_PERMISSIONS(role)   (is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
 
#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3
 
#define PG_STAT_GET_ACTIVITY_COLS   30
 
#define PG_STAT_GET_SLRU_COLS   9
 

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_ins_since_vacuum (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_slru (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_reset_slru (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_archiver (PG_FUNCTION_ARGS)
 

Variables

PgStat_MsgBgWriter bgwriterStats
 

Macro Definition Documentation

◆ HAS_PGSTAT_PERMISSIONS

◆ PG_STAT_GET_ACTIVITY_COLS

#define PG_STAT_GET_ACTIVITY_COLS   30

Referenced by pg_stat_get_activity().

◆ PG_STAT_GET_PROGRESS_COLS

#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3

◆ PG_STAT_GET_SLRU_COLS

#define PG_STAT_GET_SLRU_COLS   9

Referenced by pg_stat_get_slru().

◆ 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 955 of file pgstatfuncs.c.

References MyProcPid, and PG_RETURN_INT32.

956 {
958 }
int MyProcPid
Definition: globals.c:40
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353

◆ pg_stat_clear_snapshot()

Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1967 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_clear_snapshot().

1968 {
1970 
1971  PG_RETURN_VOID();
1972 }
#define PG_RETURN_VOID()
Definition: fmgr.h:348
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5841

◆ pg_stat_get_activity()

Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 568 of file pgstatfuncs.c.

References SockAddr::addr, ReturnSetInfo::allowedModes, AuxiliaryPidGetProc(), B_BACKEND, B_BG_WORKER, B_WAL_SENDER, 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(), GetBackendTypeDesc(), GetBackgroundWorkerTypeByPid(), PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, HAS_PGSTAT_PERMISSIONS, i, inet_in(), Int32GetDatum, InvalidOid, IsA, lengthof, PGPROC::lockGroupLeader, 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_wait_event(), pgstat_get_wait_event_type(), PGPROC::pid, 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.

569 {
570 #define PG_STAT_GET_ACTIVITY_COLS 30
571  int num_backends = pgstat_fetch_stat_numbackends();
572  int curr_backend;
573  int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
574  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
575  TupleDesc tupdesc;
576  Tuplestorestate *tupstore;
577  MemoryContext per_query_ctx;
578  MemoryContext oldcontext;
579 
580  /* check to see if caller supports us returning a tuplestore */
581  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
582  ereport(ERROR,
583  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
584  errmsg("set-valued function called in context that cannot accept a set")));
585  if (!(rsinfo->allowedModes & SFRM_Materialize))
586  ereport(ERROR,
587  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
588  errmsg("materialize mode required, but it is not allowed in this context")));
589 
590  /* Build a tuple descriptor for our result type */
591  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
592  elog(ERROR, "return type must be a row type");
593 
594  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
595  oldcontext = MemoryContextSwitchTo(per_query_ctx);
596 
597  tupstore = tuplestore_begin_heap(true, false, work_mem);
598  rsinfo->returnMode = SFRM_Materialize;
599  rsinfo->setResult = tupstore;
600  rsinfo->setDesc = tupdesc;
601 
602  MemoryContextSwitchTo(oldcontext);
603 
604  /* 1-based index */
605  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
606  {
607  /* for each row */
609  bool nulls[PG_STAT_GET_ACTIVITY_COLS];
610  LocalPgBackendStatus *local_beentry;
611  PgBackendStatus *beentry;
612  PGPROC *proc;
613  const char *wait_event_type = NULL;
614  const char *wait_event = NULL;
615 
616  MemSet(values, 0, sizeof(values));
617  MemSet(nulls, 0, sizeof(nulls));
618 
619  /* Get the next one in the list */
620  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
621  if (!local_beentry)
622  {
623  int i;
624 
625  /* Ignore missing entries if looking for specific PID */
626  if (pid != -1)
627  continue;
628 
629  for (i = 0; i < lengthof(nulls); i++)
630  nulls[i] = true;
631 
632  nulls[5] = false;
633  values[5] = CStringGetTextDatum("<backend information not available>");
634 
635  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
636  continue;
637  }
638 
639  beentry = &local_beentry->backendStatus;
640 
641  /* If looking for specific PID, ignore all the others */
642  if (pid != -1 && beentry->st_procpid != pid)
643  continue;
644 
645  /* Values available to all callers */
646  if (beentry->st_databaseid != InvalidOid)
647  values[0] = ObjectIdGetDatum(beentry->st_databaseid);
648  else
649  nulls[0] = true;
650 
651  values[1] = Int32GetDatum(beentry->st_procpid);
652 
653  if (beentry->st_userid != InvalidOid)
654  values[2] = ObjectIdGetDatum(beentry->st_userid);
655  else
656  nulls[2] = true;
657 
658  if (beentry->st_appname)
659  values[3] = CStringGetTextDatum(beentry->st_appname);
660  else
661  nulls[3] = true;
662 
663  if (TransactionIdIsValid(local_beentry->backend_xid))
664  values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
665  else
666  nulls[15] = true;
667 
668  if (TransactionIdIsValid(local_beentry->backend_xmin))
669  values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
670  else
671  nulls[16] = true;
672 
673  /* Values only available to role member or pg_read_all_stats */
674  if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
675  {
676  SockAddr zero_clientaddr;
677  char *clipped_activity;
678 
679  switch (beentry->st_state)
680  {
681  case STATE_IDLE:
682  values[4] = CStringGetTextDatum("idle");
683  break;
684  case STATE_RUNNING:
685  values[4] = CStringGetTextDatum("active");
686  break;
688  values[4] = CStringGetTextDatum("idle in transaction");
689  break;
690  case STATE_FASTPATH:
691  values[4] = CStringGetTextDatum("fastpath function call");
692  break;
694  values[4] = CStringGetTextDatum("idle in transaction (aborted)");
695  break;
696  case STATE_DISABLED:
697  values[4] = CStringGetTextDatum("disabled");
698  break;
699  case STATE_UNDEFINED:
700  nulls[4] = true;
701  break;
702  }
703 
704  clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
705  values[5] = CStringGetTextDatum(clipped_activity);
706  pfree(clipped_activity);
707 
708  /* leader_pid */
709  nulls[29] = true;
710 
711  proc = BackendPidGetProc(beentry->st_procpid);
712 
713  if (proc == NULL && (beentry->st_backendType != B_BACKEND))
714  {
715  /*
716  * For an auxiliary process, retrieve process info from
717  * AuxiliaryProcs stored in shared-memory.
718  */
719  proc = AuxiliaryPidGetProc(beentry->st_procpid);
720  }
721 
722  /*
723  * If a PGPROC entry was retrieved, display wait events and lock
724  * group leader information if any. To avoid extra overhead, no
725  * extra lock is being held, so there is no guarantee of
726  * consistency across multiple rows.
727  */
728  if (proc != NULL)
729  {
730  uint32 raw_wait_event;
731  PGPROC *leader;
732 
733  raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
734  wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
735  wait_event = pgstat_get_wait_event(raw_wait_event);
736 
737  leader = proc->lockGroupLeader;
738  if (leader)
739  {
740  values[29] = Int32GetDatum(leader->pid);
741  nulls[29] = false;
742  }
743  }
744 
745  if (wait_event_type)
746  values[6] = CStringGetTextDatum(wait_event_type);
747  else
748  nulls[6] = true;
749 
750  if (wait_event)
751  values[7] = CStringGetTextDatum(wait_event);
752  else
753  nulls[7] = true;
754 
755  /*
756  * Don't expose transaction time for walsenders; it confuses
757  * monitoring, particularly because we don't keep the time up-to-
758  * date.
759  */
760  if (beentry->st_xact_start_timestamp != 0 &&
761  beentry->st_backendType != B_WAL_SENDER)
762  values[8] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
763  else
764  nulls[8] = true;
765 
766  if (beentry->st_activity_start_timestamp != 0)
767  values[9] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
768  else
769  nulls[9] = true;
770 
771  if (beentry->st_proc_start_timestamp != 0)
772  values[10] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
773  else
774  nulls[10] = true;
775 
776  if (beentry->st_state_start_timestamp != 0)
777  values[11] = TimestampTzGetDatum(beentry->st_state_start_timestamp);
778  else
779  nulls[11] = true;
780 
781  /* A zeroed client addr means we don't know */
782  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
783  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
784  sizeof(zero_clientaddr)) == 0)
785  {
786  nulls[12] = true;
787  nulls[13] = true;
788  nulls[14] = true;
789  }
790  else
791  {
792  if (beentry->st_clientaddr.addr.ss_family == AF_INET
793 #ifdef HAVE_IPV6
794  || beentry->st_clientaddr.addr.ss_family == AF_INET6
795 #endif
796  )
797  {
798  char remote_host[NI_MAXHOST];
799  char remote_port[NI_MAXSERV];
800  int ret;
801 
802  remote_host[0] = '\0';
803  remote_port[0] = '\0';
804  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
805  beentry->st_clientaddr.salen,
806  remote_host, sizeof(remote_host),
807  remote_port, sizeof(remote_port),
809  if (ret == 0)
810  {
811  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
812  values[12] = DirectFunctionCall1(inet_in,
813  CStringGetDatum(remote_host));
814  if (beentry->st_clienthostname &&
815  beentry->st_clienthostname[0])
816  values[13] = CStringGetTextDatum(beentry->st_clienthostname);
817  else
818  nulls[13] = true;
819  values[14] = Int32GetDatum(atoi(remote_port));
820  }
821  else
822  {
823  nulls[12] = true;
824  nulls[13] = true;
825  nulls[14] = true;
826  }
827  }
828  else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
829  {
830  /*
831  * Unix sockets always reports NULL for host and -1 for
832  * port, so it's possible to tell the difference to
833  * connections we have no permissions to view, or with
834  * errors.
835  */
836  nulls[12] = true;
837  nulls[13] = true;
838  values[14] = Int32GetDatum(-1);
839  }
840  else
841  {
842  /* Unknown address type, should never happen */
843  nulls[12] = true;
844  nulls[13] = true;
845  nulls[14] = true;
846  }
847  }
848  /* Add backend type */
849  if (beentry->st_backendType == B_BG_WORKER)
850  {
851  const char *bgw_type;
852 
853  bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
854  if (bgw_type)
855  values[17] = CStringGetTextDatum(bgw_type);
856  else
857  nulls[17] = true;
858  }
859  else
860  values[17] =
862 
863  /* SSL information */
864  if (beentry->st_ssl)
865  {
866  values[18] = BoolGetDatum(true); /* ssl */
867  values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version);
868  values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher);
869  values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
870  values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression);
871 
872  if (beentry->st_sslstatus->ssl_client_dn[0])
873  values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_client_dn);
874  else
875  nulls[23] = true;
876 
877  if (beentry->st_sslstatus->ssl_client_serial[0])
878  values[24] = DirectFunctionCall3(numeric_in,
881  Int32GetDatum(-1));
882  else
883  nulls[24] = true;
884 
885  if (beentry->st_sslstatus->ssl_issuer_dn[0])
886  values[25] = CStringGetTextDatum(beentry->st_sslstatus->ssl_issuer_dn);
887  else
888  nulls[25] = true;
889  }
890  else
891  {
892  values[18] = BoolGetDatum(false); /* ssl */
893  nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = nulls[25] = true;
894  }
895 
896  /* GSSAPI information */
897  if (beentry->st_gss)
898  {
899  values[26] = BoolGetDatum(beentry->st_gssstatus->gss_auth); /* gss_auth */
900  values[27] = CStringGetTextDatum(beentry->st_gssstatus->gss_princ);
901  values[28] = BoolGetDatum(beentry->st_gssstatus->gss_enc); /* GSS Encryption in use */
902  }
903  else
904  {
905  values[26] = BoolGetDatum(false); /* gss_auth */
906  nulls[27] = true; /* No GSS principal */
907  values[28] = BoolGetDatum(false); /* GSS Encryption not in
908  * use */
909  }
910  }
911  else
912  {
913  /* No permissions to view data about this session */
914  values[5] = CStringGetTextDatum("<insufficient privilege>");
915  nulls[4] = true;
916  nulls[6] = true;
917  nulls[7] = true;
918  nulls[8] = true;
919  nulls[9] = true;
920  nulls[10] = true;
921  nulls[11] = true;
922  nulls[12] = true;
923  nulls[13] = true;
924  nulls[14] = true;
925  nulls[17] = true;
926  nulls[18] = true;
927  nulls[19] = true;
928  nulls[20] = true;
929  nulls[21] = true;
930  nulls[22] = true;
931  nulls[23] = true;
932  nulls[24] = true;
933  nulls[25] = true;
934  nulls[26] = true;
935  nulls[27] = true;
936  nulls[28] = true;
937  nulls[29] = true;
938  }
939 
940  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
941 
942  /* If only a single backend was requested, and we found it, break. */
943  if (pid != -1)
944  break;
945  }
946 
947  /* clean up and return the tuplestore */
948  tuplestore_donestoring(tupstore);
949 
950  return (Datum) 0;
951 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
char ssl_issuer_dn[NAMEDATALEN]
Definition: pgstat.h:1031
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
Definition: bgworker.c:1231
char gss_princ[NAMEDATALEN]
Definition: pgstat.h:1045
bool ssl_compression
Definition: pgstat.h:1020
char ssl_cipher[NAMEDATALEN]
Definition: pgstat.h:1022
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:205
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
const char * GetBackendTypeDesc(BackendType backendType)
Definition: miscinit.c:202
uint32 wait_event_info
Definition: proc.h:178
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3517
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1093
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2362
#define PG_STAT_GET_ACTIVITY_COLS
char ssl_client_dn[NAMEDATALEN]
Definition: pgstat.h:1023
#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:1225
char ssl_version[NAMEDATALEN]
Definition: pgstat.h:1021
SockAddr st_clientaddr
Definition: pgstat.h:1099
int errcode(int sqlerrcode)
Definition: elog.c:610
#define MemSet(start, val, len)
Definition: c.h:971
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
#define lengthof(array)
Definition: c.h:668
char ssl_client_serial[NAMEDATALEN]
Definition: pgstat.h:1029
BackendState st_state
Definition: pgstat.h:1111
char * st_clienthostname
Definition: pgstat.h:1100
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2622
Oid st_databaseid
Definition: pgstat.h:1097
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:1219
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:985
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3572
char * st_activity_raw
Definition: pgstat.h:1123
#define CStringGetDatum(X)
Definition: postgres.h:578
#define NI_MAXSERV
Definition: getaddrinfo.h:91
unsigned int uint32
Definition: c.h:367
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:567
TimestampTz st_state_start_timestamp
Definition: pgstat.h:1094
char * st_appname
Definition: pgstat.h:1114
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:628
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:1213
uintptr_t Datum
Definition: postgres.h:367
BackendType st_backendType
Definition: pgstat.h:1088
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
#define ereport(elevel,...)
Definition: elog.h:144
int allowedModes
Definition: execnodes.h:305
SetFunctionReturnMode returnMode
Definition: execnodes.h:307
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2641
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:233
Tuplestorestate * setResult
Definition: execnodes.h:310
static Datum values[MAXATTR]
Definition: bootstrap.c:167
ExprContext * econtext
Definition: execnodes.h:303
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6645
#define Int32GetDatum(X)
Definition: postgres.h:479
TupleDesc setDesc
Definition: execnodes.h:311
int errmsg(const char *fmt,...)
Definition: elog.c:824
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1092
#define elog(elevel,...)
Definition: elog.h:214
int i
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:34
#define CStringGetTextDatum(s)
Definition: builtins.h:87
#define TransactionIdIsValid(xid)
Definition: transam.h:41
Definition: proc.h:95
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1091
int pid
Definition: proc.h:109
PgBackendSSLStatus * st_sslstatus
Definition: pgstat.h:1104
PGPROC * lockGroupLeader
Definition: proc.h:203
PgBackendGSSStatus * st_gssstatus
Definition: pgstat.h:1108

◆ pg_stat_get_analyze_count()

Datum pg_stat_get_analyze_count ( PG_FUNCTION_ARGS  )

Definition at line 351 of file pgstatfuncs.c.

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

352 {
353  Oid relid = PG_GETARG_OID(0);
354  int64 result;
355  PgStat_StatTabEntry *tabentry;
356 
357  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
358  result = 0;
359  else
360  result = (int64) (tabentry->analyze_count);
361 
362  PG_RETURN_INT64(result);
363 }
PgStat_Counter analyze_count
Definition: pgstat.h:692
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_archiver()

Datum pg_stat_get_archiver ( PG_FUNCTION_ARGS  )

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

2032 {
2033  TupleDesc tupdesc;
2034  Datum values[7];
2035  bool nulls[7];
2036  PgStat_ArchiverStats *archiver_stats;
2037 
2038  /* Initialise values and NULL flags arrays */
2039  MemSet(values, 0, sizeof(values));
2040  MemSet(nulls, 0, sizeof(nulls));
2041 
2042  /* Initialise attributes information in the tuple descriptor */
2043  tupdesc = CreateTemplateTupleDesc(7);
2044  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2045  INT8OID, -1, 0);
2046  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2047  TEXTOID, -1, 0);
2048  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2049  TIMESTAMPTZOID, -1, 0);
2050  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2051  INT8OID, -1, 0);
2052  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2053  TEXTOID, -1, 0);
2054  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2055  TIMESTAMPTZOID, -1, 0);
2056  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2057  TIMESTAMPTZOID, -1, 0);
2058 
2059  BlessTupleDesc(tupdesc);
2060 
2061  /* Get statistics about the archiver process */
2062  archiver_stats = pgstat_fetch_stat_archiver();
2063 
2064  /* Fill values and NULLs */
2065  values[0] = Int64GetDatum(archiver_stats->archived_count);
2066  if (*(archiver_stats->last_archived_wal) == '\0')
2067  nulls[1] = true;
2068  else
2069  values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2070 
2071  if (archiver_stats->last_archived_timestamp == 0)
2072  nulls[2] = true;
2073  else
2074  values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
2075 
2076  values[3] = Int64GetDatum(archiver_stats->failed_count);
2077  if (*(archiver_stats->last_failed_wal) == '\0')
2078  nulls[4] = true;
2079  else
2080  values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2081 
2082  if (archiver_stats->last_failed_timestamp == 0)
2083  nulls[5] = true;
2084  else
2085  values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2086 
2087  if (archiver_stats->stat_reset_timestamp == 0)
2088  nulls[6] = true;
2089  else
2090  values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2091 
2092  /* Returns the record as Datum */
2093  PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
2094 }
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:723
PgStat_Counter archived_count
Definition: pgstat.h:718
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
#define MemSet(start, val, len)
Definition: c.h:971
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
Definition: pgstat.c:2657
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2052
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1701
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:352
TimestampTz last_failed_timestamp
Definition: pgstat.h:725
PgStat_Counter failed_count
Definition: pgstat.h:722
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
static Datum values[MAXATTR]
Definition: bootstrap.c:167
TimestampTz stat_reset_timestamp
Definition: pgstat.h:726
TimestampTz last_archived_timestamp
Definition: pgstat.h:721
#define CStringGetTextDatum(s)
Definition: builtins.h:87
int16 AttrNumber
Definition: attnum.h:21
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:719

◆ pg_stat_get_autoanalyze_count()

Datum pg_stat_get_autoanalyze_count ( PG_FUNCTION_ARGS  )

Definition at line 366 of file pgstatfuncs.c.

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

367 {
368  Oid relid = PG_GETARG_OID(0);
369  int64 result;
370  PgStat_StatTabEntry *tabentry;
371 
372  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
373  result = 0;
374  else
375  result = (int64) (tabentry->autovac_analyze_count);
376 
377  PG_RETURN_INT64(result);
378 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:694

◆ pg_stat_get_autovacuum_count()

Datum pg_stat_get_autovacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 336 of file pgstatfuncs.c.

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

337 {
338  Oid relid = PG_GETARG_OID(0);
339  int64 result;
340  PgStat_StatTabEntry *tabentry;
341 
342  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
343  result = 0;
344  else
345  result = (int64) (tabentry->autovac_vacuum_count);
346 
347  PG_RETURN_INT64(result);
348 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:690

◆ pg_stat_get_backend_activity()

Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 1001 of file pgstatfuncs.c.

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

1002 {
1003  int32 beid = PG_GETARG_INT32(0);
1004  PgBackendStatus *beentry;
1005  const char *activity;
1006  char *clipped_activity;
1007  text *ret;
1008 
1009  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1010  activity = "<backend information not available>";
1011  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1012  activity = "<insufficient privilege>";
1013  else if (*(beentry->st_activity_raw) == '\0')
1014  activity = "<command string not enabled>";
1015  else
1016  activity = beentry->st_activity_raw;
1017 
1018  clipped_activity = pgstat_clip_activity(activity);
1019  ret = cstring_to_text(activity);
1020  pfree(clipped_activity);
1021 
1022  PG_RETURN_TEXT_P(ret);
1023 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
void pfree(void *pointer)
Definition: mcxt.c:1056
char * st_activity_raw
Definition: pgstat.h:1123
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:370
text * cstring_to_text(const char *s)
Definition: varlena.c:172
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6645
Definition: c.h:555

◆ pg_stat_get_backend_activity_start()

Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 1069 of file pgstatfuncs.c.

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

1070 {
1071  int32 beid = PG_GETARG_INT32(0);
1072  TimestampTz result;
1073  PgBackendStatus *beentry;
1074 
1075  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1076  PG_RETURN_NULL();
1077 
1078  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1079  PG_RETURN_NULL();
1080 
1081  result = beentry->st_activity_start_timestamp;
1082 
1083  /*
1084  * No time recorded for start of current query -- this is the case if the
1085  * user hasn't enabled query-level stats collection.
1086  */
1087  if (result == 0)
1088  PG_RETURN_NULL();
1089 
1090  PG_RETURN_TIMESTAMPTZ(result);
1091 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1093
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:355
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 1139 of file pgstatfuncs.c.

References SockAddr::addr, clean_ipv6_addr(), CStringGetDatum, DirectFunctionCall1, HAS_PGSTAT_PERMISSIONS, 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.

1140 {
1141  int32 beid = PG_GETARG_INT32(0);
1142  PgBackendStatus *beentry;
1143  SockAddr zero_clientaddr;
1144  char remote_host[NI_MAXHOST];
1145  int ret;
1146 
1147  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1148  PG_RETURN_NULL();
1149 
1150  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1151  PG_RETURN_NULL();
1152 
1153  /* A zeroed client addr means we don't know */
1154  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1155  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1156  sizeof(zero_clientaddr)) == 0)
1157  PG_RETURN_NULL();
1158 
1159  switch (beentry->st_clientaddr.addr.ss_family)
1160  {
1161  case AF_INET:
1162 #ifdef HAVE_IPV6
1163  case AF_INET6:
1164 #endif
1165  break;
1166  default:
1167  PG_RETURN_NULL();
1168  }
1169 
1170  remote_host[0] = '\0';
1171  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1172  beentry->st_clientaddr.salen,
1173  remote_host, sizeof(remote_host),
1174  NULL, 0,
1176  if (ret != 0)
1177  PG_RETURN_NULL();
1178 
1179  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1180 
1182  CStringGetDatum(remote_host)));
1183 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INET_P(x)
Definition: inet.h:125
SockAddr st_clientaddr
Definition: pgstat.h:1099
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
signed int int32
Definition: c.h:355
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define CStringGetDatum(X)
Definition: postgres.h:578
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
#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:2600
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:344

◆ pg_stat_get_backend_client_port()

Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 1186 of file pgstatfuncs.c.

References SockAddr::addr, CStringGetDatum, DirectFunctionCall1, HAS_PGSTAT_PERMISSIONS, 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.

1187 {
1188  int32 beid = PG_GETARG_INT32(0);
1189  PgBackendStatus *beentry;
1190  SockAddr zero_clientaddr;
1191  char remote_port[NI_MAXSERV];
1192  int ret;
1193 
1194  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1195  PG_RETURN_NULL();
1196 
1197  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1198  PG_RETURN_NULL();
1199 
1200  /* A zeroed client addr means we don't know */
1201  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1202  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1203  sizeof(zero_clientaddr)) == 0)
1204  PG_RETURN_NULL();
1205 
1206  switch (beentry->st_clientaddr.addr.ss_family)
1207  {
1208  case AF_INET:
1209 #ifdef HAVE_IPV6
1210  case AF_INET6:
1211 #endif
1212  break;
1213  case AF_UNIX:
1214  PG_RETURN_INT32(-1);
1215  default:
1216  PG_RETURN_NULL();
1217  }
1218 
1219  remote_port[0] = '\0';
1220  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1221  beentry->st_clientaddr.salen,
1222  NULL, 0,
1223  remote_port, sizeof(remote_port),
1225  if (ret != 0)
1226  PG_RETURN_NULL();
1227 
1229  CStringGetDatum(remote_port)));
1230 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:268
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
SockAddr st_clientaddr
Definition: pgstat.h:1099
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
signed int int32
Definition: c.h:355
#define CStringGetDatum(X)
Definition: postgres.h:578
#define NI_MAXSERV
Definition: getaddrinfo.h:91
ACCEPT_TYPE_ARG3 salen
Definition: pqcomm.h:65
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:352
#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:2600
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_dbid()

Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 975 of file pgstatfuncs.c.

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

976 {
977  int32 beid = PG_GETARG_INT32(0);
978  PgBackendStatus *beentry;
979 
980  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
981  PG_RETURN_NULL();
982 
983  PG_RETURN_OID(beentry->st_databaseid);
984 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
Oid st_databaseid
Definition: pgstat.h:1097
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_idset()

Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

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

417 {
418  FuncCallContext *funcctx;
419  int *fctx;
420  int32 result;
421 
422  /* stuff done only on the first call of the function */
423  if (SRF_IS_FIRSTCALL())
424  {
425  /* create a function context for cross-call persistence */
426  funcctx = SRF_FIRSTCALL_INIT();
427 
429  2 * sizeof(int));
430  funcctx->user_fctx = fctx;
431 
432  fctx[0] = 0;
433  fctx[1] = pgstat_fetch_stat_numbackends();
434  }
435 
436  /* stuff done on every call of the function */
437  funcctx = SRF_PERCALL_SETUP();
438  fctx = funcctx->user_fctx;
439 
440  fctx[0] += 1;
441  result = fctx[0];
442 
443  if (result <= fctx[1])
444  {
445  /* do when there is more left to send */
446  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
447  }
448  else
449  {
450  /* do when there is no more left */
451  SRF_RETURN_DONE(funcctx);
452  }
453 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:293
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:297
signed int int32
Definition: c.h:355
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:299
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2641
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
#define Int32GetDatum(X)
Definition: postgres.h:479
void * user_fctx
Definition: funcapi.h:82
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:317
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:295

◆ pg_stat_get_backend_pid()

Datum pg_stat_get_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 962 of file pgstatfuncs.c.

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

963 {
964  int32 beid = PG_GETARG_INT32(0);
965  PgBackendStatus *beentry;
966 
967  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
968  PG_RETURN_NULL();
969 
970  PG_RETURN_INT32(beentry->st_procpid);
971 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_start()

Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 1117 of file pgstatfuncs.c.

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

1118 {
1119  int32 beid = PG_GETARG_INT32(0);
1120  TimestampTz result;
1121  PgBackendStatus *beentry;
1122 
1123  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1124  PG_RETURN_NULL();
1125 
1126  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1127  PG_RETURN_NULL();
1128 
1129  result = beentry->st_proc_start_timestamp;
1130 
1131  if (result == 0) /* probably can't happen? */
1132  PG_RETURN_NULL();
1133 
1134  PG_RETURN_TIMESTAMPTZ(result);
1135 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:355
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1091
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_userid()

Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 988 of file pgstatfuncs.c.

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

989 {
990  int32 beid = PG_GETARG_INT32(0);
991  PgBackendStatus *beentry;
992 
993  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
994  PG_RETURN_NULL();
995 
996  PG_RETURN_OID(beentry->st_userid);
997 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_wait_event()

Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 1047 of file pgstatfuncs.c.

References BackendPidGetProc(), cstring_to_text(), HAS_PGSTAT_PERMISSIONS, 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.

1048 {
1049  int32 beid = PG_GETARG_INT32(0);
1050  PgBackendStatus *beentry;
1051  PGPROC *proc;
1052  const char *wait_event = NULL;
1053 
1054  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1055  wait_event = "<backend information not available>";
1056  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1057  wait_event = "<insufficient privilege>";
1058  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1059  wait_event = pgstat_get_wait_event(proc->wait_event_info);
1060 
1061  if (!wait_event)
1062  PG_RETURN_NULL();
1063 
1064  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
1065 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
uint32 wait_event_info
Definition: proc.h:178
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2362
signed int int32
Definition: c.h:355
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3572
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:370
text * cstring_to_text(const char *s)
Definition: varlena.c:172
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_wait_event_type()

Datum pg_stat_get_backend_wait_event_type ( PG_FUNCTION_ARGS  )

Definition at line 1026 of file pgstatfuncs.c.

References BackendPidGetProc(), cstring_to_text(), HAS_PGSTAT_PERMISSIONS, 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.

1027 {
1028  int32 beid = PG_GETARG_INT32(0);
1029  PgBackendStatus *beentry;
1030  PGPROC *proc;
1031  const char *wait_event_type = NULL;
1032 
1033  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1034  wait_event_type = "<backend information not available>";
1035  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1036  wait_event_type = "<insufficient privilege>";
1037  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1038  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
1039 
1040  if (!wait_event_type)
1041  PG_RETURN_NULL();
1042 
1043  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
1044 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
uint32 wait_event_info
Definition: proc.h:178
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3517
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2362
signed int int32
Definition: c.h:355
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:370
text * cstring_to_text(const char *s)
Definition: varlena.c:172
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_backend_xact_start()

Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 1095 of file pgstatfuncs.c.

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

1096 {
1097  int32 beid = PG_GETARG_INT32(0);
1098  TimestampTz result;
1099  PgBackendStatus *beentry;
1100 
1101  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1102  PG_RETURN_NULL();
1103 
1104  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1105  PG_RETURN_NULL();
1106 
1107  result = beentry->st_xact_start_timestamp;
1108 
1109  if (result == 0) /* not in a transaction */
1110  PG_RETURN_NULL();
1111 
1112  PG_RETURN_TIMESTAMPTZ(result);
1113 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:355
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1092
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_bgwriter_buf_written_checkpoints()

Datum pg_stat_get_bgwriter_buf_written_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1639 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1640 {
1641  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_checkpoints);
1642 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( 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_clean);
1648 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_bgwriter_maxwritten_clean()

Datum pg_stat_get_bgwriter_maxwritten_clean ( 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()->maxwritten_clean);
1654 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_bgwriter_requested_checkpoints()

Datum pg_stat_get_bgwriter_requested_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1633 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1634 {
1635  PG_RETURN_INT64(pgstat_fetch_global()->requested_checkpoints);
1636 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_bgwriter_stat_reset_time()

Datum pg_stat_get_bgwriter_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1671 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1672 {
1673  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stat_reset_timestamp);
1674 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674
#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 1627 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1628 {
1629  PG_RETURN_INT64(pgstat_fetch_global()->timed_checkpoints);
1630 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_blocks_fetched()

Datum pg_stat_get_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 218 of file pgstatfuncs.c.

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

219 {
220  Oid relid = PG_GETARG_OID(0);
221  int64 result;
222  PgStat_StatTabEntry *tabentry;
223 
224  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
225  result = 0;
226  else
227  result = (int64) (tabentry->blocks_fetched);
228 
229  PG_RETURN_INT64(result);
230 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter blocks_fetched
Definition: pgstat.h:684

◆ pg_stat_get_blocks_hit()

Datum pg_stat_get_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 234 of file pgstatfuncs.c.

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

235 {
236  Oid relid = PG_GETARG_OID(0);
237  int64 result;
238  PgStat_StatTabEntry *tabentry;
239 
240  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
241  result = 0;
242  else
243  result = (int64) (tabentry->blocks_hit);
244 
245  PG_RETURN_INT64(result);
246 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter blocks_hit
Definition: pgstat.h:685

◆ pg_stat_get_buf_alloc()

Datum pg_stat_get_buf_alloc ( PG_FUNCTION_ARGS  )

Definition at line 1689 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1690 {
1691  PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
1692 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_buf_fsync_backend()

Datum pg_stat_get_buf_fsync_backend ( PG_FUNCTION_ARGS  )

Definition at line 1683 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1684 {
1685  PG_RETURN_INT64(pgstat_fetch_global()->buf_fsync_backend);
1686 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_buf_written_backend()

Datum pg_stat_get_buf_written_backend ( PG_FUNCTION_ARGS  )

Definition at line 1677 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1678 {
1679  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_backend);
1680 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_checkpoint_sync_time()

Datum pg_stat_get_checkpoint_sync_time ( PG_FUNCTION_ARGS  )

Definition at line 1664 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1665 {
1666  /* time is already in msec, just convert to double for presentation */
1667  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
1668 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_checkpoint_write_time()

Datum pg_stat_get_checkpoint_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1657 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1658 {
1659  /* time is already in msec, just convert to double for presentation */
1660  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
1661 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674

◆ pg_stat_get_db_blk_read_time()

Datum pg_stat_get_db_blk_read_time ( PG_FUNCTION_ARGS  )

Definition at line 1595 of file pgstatfuncs.c.

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

1596 {
1597  Oid dbid = PG_GETARG_OID(0);
1598  double result;
1599  PgStat_StatDBEntry *dbentry;
1600 
1601  /* convert counter from microsec to millisec for display */
1602  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1603  result = 0;
1604  else
1605  result = ((double) dbentry->n_block_read_time) / 1000.0;
1606 
1607  PG_RETURN_FLOAT8(result);
1608 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_block_read_time
Definition: pgstat.h:646

◆ pg_stat_get_db_blk_write_time()

Datum pg_stat_get_db_blk_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1611 of file pgstatfuncs.c.

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

1612 {
1613  Oid dbid = PG_GETARG_OID(0);
1614  double result;
1615  PgStat_StatDBEntry *dbentry;
1616 
1617  /* convert counter from microsec to millisec for display */
1618  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1619  result = 0;
1620  else
1621  result = ((double) dbentry->n_block_write_time) / 1000.0;
1622 
1623  PG_RETURN_FLOAT8(result);
1624 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_block_write_time
Definition: pgstat.h:647

◆ pg_stat_get_db_blocks_fetched()

Datum pg_stat_get_db_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1287 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_blocks_hit()

Datum pg_stat_get_db_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1303 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_checksum_failures()

Datum pg_stat_get_db_checksum_failures ( PG_FUNCTION_ARGS  )

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

1557 {
1558  Oid dbid = PG_GETARG_OID(0);
1559  int64 result;
1560  PgStat_StatDBEntry *dbentry;
1561 
1562  if (!DataChecksumsEnabled())
1563  PG_RETURN_NULL();
1564 
1565  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1566  result = 0;
1567  else
1568  result = (int64) (dbentry->n_checksum_failures);
1569 
1570  PG_RETURN_INT64(result);
1571 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
bool DataChecksumsEnabled(void)
Definition: xlog.c:4930
PgStat_Counter n_checksum_failures
Definition: pgstat.h:644
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_db_checksum_last_failure()

Datum pg_stat_get_db_checksum_last_failure ( PG_FUNCTION_ARGS  )

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

1575 {
1576  Oid dbid = PG_GETARG_OID(0);
1577  TimestampTz result;
1578  PgStat_StatDBEntry *dbentry;
1579 
1580  if (!DataChecksumsEnabled())
1581  PG_RETURN_NULL();
1582 
1583  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1584  result = 0;
1585  else
1586  result = dbentry->last_checksum_failure;
1587 
1588  if (result == 0)
1589  PG_RETURN_NULL();
1590  else
1591  PG_RETURN_TIMESTAMPTZ(result);
1592 }
bool DataChecksumsEnabled(void)
Definition: xlog.c:4930
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz last_checksum_failure
Definition: pgstat.h:645
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
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:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_db_conflict_all()

Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

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

1523 {
1524  Oid dbid = PG_GETARG_OID(0);
1525  int64 result;
1526  PgStat_StatDBEntry *dbentry;
1527 
1528  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1529  result = 0;
1530  else
1531  result = (int64) (dbentry->n_conflict_tablespace +
1532  dbentry->n_conflict_lock +
1533  dbentry->n_conflict_snapshot +
1534  dbentry->n_conflict_bufferpin +
1535  dbentry->n_conflict_startup_deadlock);
1536 
1537  PG_RETURN_INT64(result);
1538 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:639
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:640
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:636
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:638
PgStat_Counter n_conflict_lock
Definition: pgstat.h:637

◆ pg_stat_get_db_conflict_bufferpin()

Datum pg_stat_get_db_conflict_bufferpin ( PG_FUNCTION_ARGS  )

Definition at line 1492 of file pgstatfuncs.c.

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

1493 {
1494  Oid dbid = PG_GETARG_OID(0);
1495  int64 result;
1496  PgStat_StatDBEntry *dbentry;
1497 
1498  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1499  result = 0;
1500  else
1501  result = (int64) (dbentry->n_conflict_bufferpin);
1502 
1503  PG_RETURN_INT64(result);
1504 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:639
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_db_conflict_lock()

Datum pg_stat_get_db_conflict_lock ( PG_FUNCTION_ARGS  )

Definition at line 1462 of file pgstatfuncs.c.

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

1463 {
1464  Oid dbid = PG_GETARG_OID(0);
1465  int64 result;
1466  PgStat_StatDBEntry *dbentry;
1467 
1468  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1469  result = 0;
1470  else
1471  result = (int64) (dbentry->n_conflict_lock);
1472 
1473  PG_RETURN_INT64(result);
1474 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_conflict_lock
Definition: pgstat.h:637

◆ pg_stat_get_db_conflict_snapshot()

Datum pg_stat_get_db_conflict_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1477 of file pgstatfuncs.c.

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

1478 {
1479  Oid dbid = PG_GETARG_OID(0);
1480  int64 result;
1481  PgStat_StatDBEntry *dbentry;
1482 
1483  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1484  result = 0;
1485  else
1486  result = (int64) (dbentry->n_conflict_snapshot);
1487 
1488  PG_RETURN_INT64(result);
1489 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:638

◆ pg_stat_get_db_conflict_startup_deadlock()

Datum pg_stat_get_db_conflict_startup_deadlock ( PG_FUNCTION_ARGS  )

Definition at line 1507 of file pgstatfuncs.c.

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

1508 {
1509  Oid dbid = PG_GETARG_OID(0);
1510  int64 result;
1511  PgStat_StatDBEntry *dbentry;
1512 
1513  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1514  result = 0;
1515  else
1516  result = (int64) (dbentry->n_conflict_startup_deadlock);
1517 
1518  PG_RETURN_INT64(result);
1519 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:640
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_db_conflict_tablespace()

Datum pg_stat_get_db_conflict_tablespace ( PG_FUNCTION_ARGS  )

Definition at line 1447 of file pgstatfuncs.c.

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

1448 {
1449  Oid dbid = PG_GETARG_OID(0);
1450  int64 result;
1451  PgStat_StatDBEntry *dbentry;
1452 
1453  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1454  result = 0;
1455  else
1456  result = (int64) (dbentry->n_conflict_tablespace);
1457 
1458  PG_RETURN_INT64(result);
1459 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:636
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_db_deadlocks()

Datum pg_stat_get_db_deadlocks ( PG_FUNCTION_ARGS  )

Definition at line 1541 of file pgstatfuncs.c.

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

1542 {
1543  Oid dbid = PG_GETARG_OID(0);
1544  int64 result;
1545  PgStat_StatDBEntry *dbentry;
1546 
1547  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1548  result = 0;
1549  else
1550  result = (int64) (dbentry->n_deadlocks);
1551 
1552  PG_RETURN_INT64(result);
1553 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_deadlocks
Definition: pgstat.h:643

◆ pg_stat_get_db_numbackends()

Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1234 of file pgstatfuncs.c.

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

1235 {
1236  Oid dbid = PG_GETARG_OID(0);
1237  int32 result;
1238  int tot_backends = pgstat_fetch_stat_numbackends();
1239  int beid;
1240 
1241  result = 0;
1242  for (beid = 1; beid <= tot_backends; beid++)
1243  {
1244  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1245 
1246  if (beentry && beentry->st_databaseid == dbid)
1247  result++;
1248  }
1249 
1250  PG_RETURN_INT32(result);
1251 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:355
Oid st_databaseid
Definition: pgstat.h:1097
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2641
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2600

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1398 of file pgstatfuncs.c.

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

1399 {
1400  Oid dbid = PG_GETARG_OID(0);
1401  TimestampTz result;
1402  PgStat_StatDBEntry *dbentry;
1403 
1404  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1405  result = 0;
1406  else
1407  result = dbentry->stat_reset_timestamp;
1408 
1409  if (result == 0)
1410  PG_RETURN_NULL();
1411  else
1412  PG_RETURN_TIMESTAMPTZ(result);
1413 }
int64 TimestampTz
Definition: timestamp.h:39
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
TimestampTz stat_reset_timestamp
Definition: pgstat.h:649
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:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_db_temp_bytes()

Datum pg_stat_get_db_temp_bytes ( PG_FUNCTION_ARGS  )

Definition at line 1432 of file pgstatfuncs.c.

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

1433 {
1434  Oid dbid = PG_GETARG_OID(0);
1435  int64 result;
1436  PgStat_StatDBEntry *dbentry;
1437 
1438  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1439  result = 0;
1440  else
1441  result = dbentry->n_temp_bytes;
1442 
1443  PG_RETURN_INT64(result);
1444 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_temp_bytes
Definition: pgstat.h:642

◆ pg_stat_get_db_temp_files()

Datum pg_stat_get_db_temp_files ( PG_FUNCTION_ARGS  )

Definition at line 1416 of file pgstatfuncs.c.

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

1417 {
1418  Oid dbid = PG_GETARG_OID(0);
1419  int64 result;
1420  PgStat_StatDBEntry *dbentry;
1421 
1422  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1423  result = 0;
1424  else
1425  result = dbentry->n_temp_files;
1426 
1427  PG_RETURN_INT64(result);
1428 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_Counter n_temp_files
Definition: pgstat.h:641
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_db_tuples_deleted()

Datum pg_stat_get_db_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1383 of file pgstatfuncs.c.

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

1384 {
1385  Oid dbid = PG_GETARG_OID(0);
1386  int64 result;
1387  PgStat_StatDBEntry *dbentry;
1388 
1389  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1390  result = 0;
1391  else
1392  result = (int64) (dbentry->n_tuples_deleted);
1393 
1394  PG_RETURN_INT64(result);
1395 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:634

◆ pg_stat_get_db_tuples_fetched()

Datum pg_stat_get_db_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1335 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_inserted()

Datum pg_stat_get_db_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1351 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_returned()

Datum pg_stat_get_db_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1319 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_updated()

Datum pg_stat_get_db_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1367 of file pgstatfuncs.c.

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

1368 {
1369  Oid dbid = PG_GETARG_OID(0);
1370  int64 result;
1371  PgStat_StatDBEntry *dbentry;
1372 
1373  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1374  result = 0;
1375  else
1376  result = (int64) (dbentry->n_tuples_updated);
1377 
1378  PG_RETURN_INT64(result);
1379 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2485
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter n_tuples_updated
Definition: pgstat.h:633

◆ pg_stat_get_db_xact_commit()

Datum pg_stat_get_db_xact_commit ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_xact_rollback()

Datum pg_stat_get_db_xact_rollback ( PG_FUNCTION_ARGS  )

Definition at line 1271 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_dead_tuples()

Datum pg_stat_get_dead_tuples ( PG_FUNCTION_ARGS  )

Definition at line 170 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_function_calls()

Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 381 of file pgstatfuncs.c.

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

382 {
383  Oid funcid = PG_GETARG_OID(0);
384  PgStat_StatFuncEntry *funcentry;
385 
386  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
387  PG_RETURN_NULL();
388  PG_RETURN_INT64(funcentry->f_numcalls);
389 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2568
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_numcalls
Definition: pgstat.h:706
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_function_self_time()

Datum pg_stat_get_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 404 of file pgstatfuncs.c.

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

405 {
406  Oid funcid = PG_GETARG_OID(0);
407  PgStat_StatFuncEntry *funcentry;
408 
409  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
410  PG_RETURN_NULL();
411  /* convert counter from microsec to millisec for display */
412  PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
413 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2568
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter f_self_time
Definition: pgstat.h:709
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_function_total_time()

Datum pg_stat_get_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 392 of file pgstatfuncs.c.

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

393 {
394  Oid funcid = PG_GETARG_OID(0);
395  PgStat_StatFuncEntry *funcentry;
396 
397  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
398  PG_RETURN_NULL();
399  /* convert counter from microsec to millisec for display */
400  PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
401 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
Definition: pgstat.c:2568
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_total_time
Definition: pgstat.h:708
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_ins_since_vacuum()

Datum pg_stat_get_ins_since_vacuum ( PG_FUNCTION_ARGS  )

Definition at line 202 of file pgstatfuncs.c.

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

203 {
204  Oid relid = PG_GETARG_OID(0);
205  int64 result;
206  PgStat_StatTabEntry *tabentry;
207 
208  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
209  result = 0;
210  else
211  result = (int64) (tabentry->inserts_since_vacuum);
212 
213  PG_RETURN_INT64(result);
214 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:682
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_last_analyze_time()

Datum pg_stat_get_last_analyze_time ( PG_FUNCTION_ARGS  )

Definition at line 285 of file pgstatfuncs.c.

References PgStat_StatTabEntry::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->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
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:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
TimestampTz analyze_timestamp
Definition: pgstat.h:691
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_last_autoanalyze_time()

Datum pg_stat_get_last_autoanalyze_time ( PG_FUNCTION_ARGS  )

Definition at line 303 of file pgstatfuncs.c.

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

304 {
305  Oid relid = PG_GETARG_OID(0);
306  TimestampTz result;
307  PgStat_StatTabEntry *tabentry;
308 
309  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
310  result = 0;
311  else
312  result = tabentry->autovac_analyze_timestamp;
313 
314  if (result == 0)
315  PG_RETURN_NULL();
316  else
317  PG_RETURN_TIMESTAMPTZ(result);
318 }
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:693
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:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_last_autovacuum_time()

Datum pg_stat_get_last_autovacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 267 of file pgstatfuncs.c.

References PgStat_StatTabEntry::autovac_vacuum_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->autovac_vacuum_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:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:689
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_last_vacuum_time()

Datum pg_stat_get_last_vacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 249 of file pgstatfuncs.c.

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

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->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
TimestampTz vacuum_timestamp
Definition: pgstat.h:687
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_live_tuples()

Datum pg_stat_get_live_tuples ( PG_FUNCTION_ARGS  )

Definition at line 154 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_mod_since_analyze()

Datum pg_stat_get_mod_since_analyze ( PG_FUNCTION_ARGS  )

Definition at line 186 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_numscans()

Datum pg_stat_get_numscans ( PG_FUNCTION_ARGS  )

Definition at line 42 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_progress_info()

Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 459 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(), HAS_PGSTAT_PERMISSIONS, 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_ANALYZE, PROGRESS_COMMAND_BASEBACKUP, 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.

460 {
461 #define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
462  int num_backends = pgstat_fetch_stat_numbackends();
463  int curr_backend;
464  char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
465  ProgressCommandType cmdtype;
466  TupleDesc tupdesc;
467  Tuplestorestate *tupstore;
468  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
469  MemoryContext per_query_ctx;
470  MemoryContext oldcontext;
471 
472  /* check to see if caller supports us returning a tuplestore */
473  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
474  ereport(ERROR,
475  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
476  errmsg("set-valued function called in context that cannot accept a set")));
477  if (!(rsinfo->allowedModes & SFRM_Materialize))
478  ereport(ERROR,
479  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
480  errmsg("materialize mode required, but it is not allowed in this context")));
481 
482  /* Build a tuple descriptor for our result type */
483  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
484  elog(ERROR, "return type must be a row type");
485 
486  /* Translate command name into command type code. */
487  if (pg_strcasecmp(cmd, "VACUUM") == 0)
488  cmdtype = PROGRESS_COMMAND_VACUUM;
489  else if (pg_strcasecmp(cmd, "ANALYZE") == 0)
490  cmdtype = PROGRESS_COMMAND_ANALYZE;
491  else if (pg_strcasecmp(cmd, "CLUSTER") == 0)
492  cmdtype = PROGRESS_COMMAND_CLUSTER;
493  else if (pg_strcasecmp(cmd, "CREATE INDEX") == 0)
495  else if (pg_strcasecmp(cmd, "BASEBACKUP") == 0)
496  cmdtype = PROGRESS_COMMAND_BASEBACKUP;
497  else
498  ereport(ERROR,
499  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
500  errmsg("invalid command name: \"%s\"", cmd)));
501 
502  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
503  oldcontext = MemoryContextSwitchTo(per_query_ctx);
504 
505  tupstore = tuplestore_begin_heap(true, false, work_mem);
506  rsinfo->returnMode = SFRM_Materialize;
507  rsinfo->setResult = tupstore;
508  rsinfo->setDesc = tupdesc;
509  MemoryContextSwitchTo(oldcontext);
510 
511  /* 1-based index */
512  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
513  {
514  LocalPgBackendStatus *local_beentry;
515  PgBackendStatus *beentry;
517  bool nulls[PG_STAT_GET_PROGRESS_COLS];
518  int i;
519 
520  MemSet(values, 0, sizeof(values));
521  MemSet(nulls, 0, sizeof(nulls));
522 
523  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
524 
525  if (!local_beentry)
526  continue;
527 
528  beentry = &local_beentry->backendStatus;
529 
530  /*
531  * Report values for only those backends which are running the given
532  * command.
533  */
534  if (!beentry || beentry->st_progress_command != cmdtype)
535  continue;
536 
537  /* Value available to all callers */
538  values[0] = Int32GetDatum(beentry->st_procpid);
539  values[1] = ObjectIdGetDatum(beentry->st_databaseid);
540 
541  /* show rest of the values including relid only to role members */
542  if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
543  {
544  values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
545  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
546  values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
547  }
548  else
549  {
550  nulls[2] = true;
551  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
552  nulls[i + 3] = true;
553  }
554 
555  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
556  }
557 
558  /* clean up and return the tuplestore */
559  tuplestore_donestoring(tupstore);
560 
561  return (Datum) 0;
562 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Oid st_progress_command_target
Definition: pgstat.h:1135
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:205
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:610
#define MemSet(start, val, len)
Definition: c.h:971
ProgressCommandType st_progress_command
Definition: pgstat.h:1134
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
Definition: pgstat.c:2622
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
Oid st_databaseid
Definition: pgstat.h:1097
#define PGSTAT_NUM_PROGRESS_PARAM
Definition: pgstat.h:1000
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1701
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:36
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
PgBackendStatus backendStatus
Definition: pgstat.h:1213
uintptr_t Datum
Definition: postgres.h:367
int work_mem
Definition: globals.c:121
#define ereport(elevel,...)
Definition: elog.h:144
int allowedModes
Definition: execnodes.h:305
SetFunctionReturnMode returnMode
Definition: execnodes.h:307
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2641
ProgressCommandType
Definition: pgstat.h:990
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Definition: pgstat.h:1136
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:233
Tuplestorestate * setResult
Definition: execnodes.h:310
static Datum values[MAXATTR]
Definition: bootstrap.c:167
char * text_to_cstring(const text *t)
Definition: varlena.c:205
ExprContext * econtext
Definition: execnodes.h:303
#define Int32GetDatum(X)
Definition: postgres.h:479
TupleDesc setDesc
Definition: execnodes.h:311
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_STAT_GET_PROGRESS_COLS
int i

◆ pg_stat_get_slru()

Datum pg_stat_get_slru ( PG_FUNCTION_ARGS  )

Definition at line 1698 of file pgstatfuncs.c.

References ReturnSetInfo::allowedModes, PgStat_SLRUStats::blocks_exists, PgStat_SLRUStats::blocks_hit, PgStat_SLRUStats::blocks_read, PgStat_SLRUStats::blocks_written, PgStat_SLRUStats::blocks_zeroed, cstring_to_text(), ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, PgStat_SLRUStats::flush, get_call_result_type(), i, Int64GetDatum(), IsA, MemoryContextSwitchTo(), MemSet, name, PG_STAT_GET_SLRU_COLS, pgstat_fetch_slru(), pgstat_slru_name(), PointerGetDatum, ReturnSetInfo::returnMode, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, stat, PgStat_SLRUStats::stat_reset_timestamp, TimestampTzGetDatum, PgStat_SLRUStats::truncate, tuplestore_begin_heap(), tuplestore_donestoring, tuplestore_putvalues(), TYPEFUNC_COMPOSITE, values, and work_mem.

1699 {
1700 #define PG_STAT_GET_SLRU_COLS 9
1701  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1702  TupleDesc tupdesc;
1703  Tuplestorestate *tupstore;
1704  MemoryContext per_query_ctx;
1705  MemoryContext oldcontext;
1706  int i;
1707  PgStat_SLRUStats *stats;
1708 
1709  /* check to see if caller supports us returning a tuplestore */
1710  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
1711  ereport(ERROR,
1712  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1713  errmsg("set-valued function called in context that cannot accept a set")));
1714  if (!(rsinfo->allowedModes & SFRM_Materialize))
1715  ereport(ERROR,
1716  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1717  errmsg("materialize mode required, but it is not allowed in this context")));
1718 
1719  /* Build a tuple descriptor for our result type */
1720  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1721  elog(ERROR, "return type must be a row type");
1722 
1723  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
1724  oldcontext = MemoryContextSwitchTo(per_query_ctx);
1725 
1726  tupstore = tuplestore_begin_heap(true, false, work_mem);
1727  rsinfo->returnMode = SFRM_Materialize;
1728  rsinfo->setResult = tupstore;
1729  rsinfo->setDesc = tupdesc;
1730 
1731  MemoryContextSwitchTo(oldcontext);
1732 
1733  /* request SLRU stats from the stat collector */
1734  stats = pgstat_fetch_slru();
1735 
1736  for (i = 0;; i++)
1737  {
1738  /* for each row */
1740  bool nulls[PG_STAT_GET_SLRU_COLS];
1741  PgStat_SLRUStats stat = stats[i];
1742  const char *name;
1743 
1744  name = pgstat_slru_name(i);
1745 
1746  if (!name)
1747  break;
1748 
1749  MemSet(values, 0, sizeof(values));
1750  MemSet(nulls, 0, sizeof(nulls));
1751 
1752  values[0] = PointerGetDatum(cstring_to_text(name));
1753  values[1] = Int64GetDatum(stat.blocks_zeroed);
1754  values[2] = Int64GetDatum(stat.blocks_hit);
1755  values[3] = Int64GetDatum(stat.blocks_read);
1756  values[4] = Int64GetDatum(stat.blocks_written);
1757  values[5] = Int64GetDatum(stat.blocks_exists);
1758  values[6] = Int64GetDatum(stat.flush);
1759  values[7] = Int64GetDatum(stat.truncate);
1760  values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1761 
1762  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
1763  }
1764 
1765  /* clean up and return the tuplestore */
1766  tuplestore_donestoring(tupstore);
1767 
1768  return (Datum) 0;
1769 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define PG_STAT_GET_SLRU_COLS
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:205
#define PointerGetDatum(X)
Definition: postgres.h:556
TimestampTz stat_reset_timestamp
Definition: pgstat.h:760
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:610
#define MemSet(start, val, len)
Definition: c.h:971
PgStat_Counter blocks_exists
Definition: pgstat.h:757
#define ERROR
Definition: elog.h:43
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
PgStat_Counter blocks_read
Definition: pgstat.h:755
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1701
PgStat_Counter blocks_hit
Definition: pgstat.h:754
PgStat_Counter blocks_zeroed
Definition: pgstat.h:753
#define stat(a, b)
Definition: win32_port.h:255
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
uintptr_t Datum
Definition: postgres.h:367
int work_mem
Definition: globals.c:121
#define ereport(elevel,...)
Definition: elog.h:144
int allowedModes
Definition: execnodes.h:305
SetFunctionReturnMode returnMode
Definition: execnodes.h:307
text * cstring_to_text(const char *s)
Definition: varlena.c:172
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat.c:2691
PgStat_Counter flush
Definition: pgstat.h:758
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:233
const char * name
Definition: encode.c:555
Tuplestorestate * setResult
Definition: execnodes.h:310
static Datum values[MAXATTR]
Definition: bootstrap.c:167
ExprContext * econtext
Definition: execnodes.h:303
TupleDesc setDesc
Definition: execnodes.h:311
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
int i
const char * pgstat_slru_name(int slru_idx)
Definition: pgstat.c:6710
PgStat_Counter truncate
Definition: pgstat.h:759
PgStat_Counter blocks_written
Definition: pgstat.h:756

◆ pg_stat_get_snapshot_timestamp()

Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1960 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1961 {
1962  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stats_timestamp);
1963 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2674
#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 122 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_fetched()

Datum pg_stat_get_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 74 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_hot_updated()

Datum pg_stat_get_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 138 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_inserted()

Datum pg_stat_get_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 90 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_returned()

Datum pg_stat_get_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 58 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_updated()

Datum pg_stat_get_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 106 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_vacuum_count()

Datum pg_stat_get_vacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 321 of file pgstatfuncs.c.

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

322 {
323  Oid relid = PG_GETARG_OID(0);
324  int64 result;
325  PgStat_StatTabEntry *tabentry;
326 
327  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
328  result = 0;
329  else
330  result = (int64) (tabentry->vacuum_count);
331 
332  PG_RETURN_INT64(result);
333 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_Counter vacuum_count
Definition: pgstat.h:688
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2512
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_xact_blocks_fetched()

Datum pg_stat_get_xact_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1895 of file pgstatfuncs.c.

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

1896 {
1897  Oid relid = PG_GETARG_OID(0);
1898  int64 result;
1899  PgStat_TableStatus *tabentry;
1900 
1901  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1902  result = 0;
1903  else
1904  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1905 
1906  PG_RETURN_INT64(result);
1907 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:117

◆ pg_stat_get_xact_blocks_hit()

Datum pg_stat_get_xact_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1910 of file pgstatfuncs.c.

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

1911 {
1912  Oid relid = PG_GETARG_OID(0);
1913  int64 result;
1914  PgStat_TableStatus *tabentry;
1915 
1916  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1917  result = 0;
1918  else
1919  result = (int64) (tabentry->t_counts.t_blocks_hit);
1920 
1921  PG_RETURN_INT64(result);
1922 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter t_blocks_hit
Definition: pgstat.h:118

◆ pg_stat_get_xact_function_calls()

Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

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

1926 {
1927  Oid funcid = PG_GETARG_OID(0);
1928  PgStat_BackendFunctionEntry *funcentry;
1929 
1930  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1931  PG_RETURN_NULL();
1932  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
1933 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_numcalls
Definition: pgstat.h:492
PgStat_FunctionCounts f_counts
Definition: pgstat.h:504
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1727
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_xact_function_self_time()

Datum pg_stat_get_xact_function_self_time ( PG_FUNCTION_ARGS  )

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

1948 {
1949  Oid funcid = PG_GETARG_OID(0);
1950  PgStat_BackendFunctionEntry *funcentry;
1951 
1952  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1953  PG_RETURN_NULL();
1955 }
instr_time f_self_time
Definition: pgstat.h:494
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts f_counts
Definition: pgstat.h:504
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1727
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_xact_function_total_time()

Datum pg_stat_get_xact_function_total_time ( PG_FUNCTION_ARGS  )

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

1937 {
1938  Oid funcid = PG_GETARG_OID(0);
1939  PgStat_BackendFunctionEntry *funcentry;
1940 
1941  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1942  PG_RETURN_NULL();
1944 }
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
instr_time f_total_time
Definition: pgstat.h:493
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts f_counts
Definition: pgstat.h:504
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1727
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ pg_stat_get_xact_numscans()

Datum pg_stat_get_xact_numscans ( PG_FUNCTION_ARGS  )

Definition at line 1772 of file pgstatfuncs.c.

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

1773 {
1774  Oid relid = PG_GETARG_OID(0);
1775  int64 result;
1776  PgStat_TableStatus *tabentry;
1777 
1778  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1779  result = 0;
1780  else
1781  result = (int64) (tabentry->t_counts.t_numscans);
1782 
1783  PG_RETURN_INT64(result);
1784 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
PgStat_Counter t_numscans
Definition: pgstat.h:102

◆ pg_stat_get_xact_tuples_deleted()

Datum pg_stat_get_xact_tuples_deleted ( PG_FUNCTION_ARGS  )

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

1860 {
1861  Oid relid = PG_GETARG_OID(0);
1862  int64 result;
1863  PgStat_TableStatus *tabentry;
1865 
1866  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1867  result = 0;
1868  else
1869  {
1870  result = tabentry->t_counts.t_tuples_deleted;
1871  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1872  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1873  result += trans->tuples_deleted;
1874  }
1875 
1876  PG_RETURN_INT64(result);
1877 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:179
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:109
PgStat_Counter tuples_deleted
Definition: pgstat.h:172
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:160
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 1802 of file pgstatfuncs.c.

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

1803 {
1804  Oid relid = PG_GETARG_OID(0);
1805  int64 result;
1806  PgStat_TableStatus *tabentry;
1807 
1808  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1809  result = 0;
1810  else
1811  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1812 
1813  PG_RETURN_INT64(result);
1814 }
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:105
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_xact_tuples_hot_updated()

Datum pg_stat_get_xact_tuples_hot_updated ( PG_FUNCTION_ARGS  )

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

1881 {
1882  Oid relid = PG_GETARG_OID(0);
1883  int64 result;
1884  PgStat_TableStatus *tabentry;
1885 
1886  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1887  result = 0;
1888  else
1889  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1890 
1891  PG_RETURN_INT64(result);
1892 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:110
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_xact_tuples_inserted()

Datum pg_stat_get_xact_tuples_inserted ( PG_FUNCTION_ARGS  )

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

1818 {
1819  Oid relid = PG_GETARG_OID(0);
1820  int64 result;
1821  PgStat_TableStatus *tabentry;
1823 
1824  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1825  result = 0;
1826  else
1827  {
1828  result = tabentry->t_counts.t_tuples_inserted;
1829  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1830  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1831  result += trans->tuples_inserted;
1832  }
1833 
1834  PG_RETURN_INT64(result);
1835 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
PgStat_Counter tuples_inserted
Definition: pgstat.h:170
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:179
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:160
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:107

◆ pg_stat_get_xact_tuples_returned()

Datum pg_stat_get_xact_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1787 of file pgstatfuncs.c.

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

1788 {
1789  Oid relid = PG_GETARG_OID(0);
1790  int64 result;
1791  PgStat_TableStatus *tabentry;
1792 
1793  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1794  result = 0;
1795  else
1796  result = (int64) (tabentry->t_counts.t_tuples_returned);
1797 
1798  PG_RETURN_INT64(result);
1799 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter t_tuples_returned
Definition: pgstat.h:104
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

◆ pg_stat_get_xact_tuples_updated()

Datum pg_stat_get_xact_tuples_updated ( PG_FUNCTION_ARGS  )

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

1839 {
1840  Oid relid = PG_GETARG_OID(0);
1841  int64 result;
1842  PgStat_TableStatus *tabentry;
1844 
1845  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1846  result = 0;
1847  else
1848  {
1849  result = tabentry->t_counts.t_tuples_updated;
1850  /* live subtransactions' counts aren't in t_tuples_updated yet */
1851  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1852  result += trans->tuples_updated;
1853  }
1854 
1855  PG_RETURN_INT64(result);
1856 }
PgStat_Counter tuples_updated
Definition: pgstat.h:171
#define PG_RETURN_INT64(x)
Definition: fmgr.h:366
PgStat_TableCounts t_counts
Definition: pgstat.h:161
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1932
PgStat_Counter t_tuples_updated
Definition: pgstat.h:108
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:179
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:160
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396

◆ pg_stat_reset()

Datum pg_stat_reset ( PG_FUNCTION_ARGS  )

Definition at line 1977 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_reset_counters().

1978 {
1980 
1981  PG_RETURN_VOID();
1982 }
#define PG_RETURN_VOID()
Definition: fmgr.h:348
void pgstat_reset_counters(void)
Definition: pgstat.c:1340

◆ pg_stat_reset_shared()

Datum pg_stat_reset_shared ( PG_FUNCTION_ARGS  )

Definition at line 1986 of file pgstatfuncs.c.

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

1987 {
1988  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
1989 
1991 
1992  PG_RETURN_VOID();
1993 }
void pgstat_reset_shared_counters(const char *target)
Definition: pgstat.c:1362
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define PG_RETURN_VOID()
Definition: fmgr.h:348
char * text_to_cstring(const text *t)
Definition: varlena.c:205

◆ pg_stat_reset_single_function_counters()

Datum pg_stat_reset_single_function_counters ( PG_FUNCTION_ARGS  )

Definition at line 2007 of file pgstatfuncs.c.

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

2008 {
2009  Oid funcoid = PG_GETARG_OID(0);
2010 
2012 
2013  PG_RETURN_VOID();
2014 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1393
#define PG_RETURN_VOID()
Definition: fmgr.h:348

◆ pg_stat_reset_single_table_counters()

Datum pg_stat_reset_single_table_counters ( PG_FUNCTION_ARGS  )

Definition at line 1997 of file pgstatfuncs.c.

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

1998 {
1999  Oid taboid = PG_GETARG_OID(0);
2000 
2002 
2003  PG_RETURN_VOID();
2004 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1393
#define PG_RETURN_VOID()
Definition: fmgr.h:348

◆ pg_stat_reset_slru()

Datum pg_stat_reset_slru ( PG_FUNCTION_ARGS  )

Definition at line 2018 of file pgstatfuncs.c.

References PG_ARGISNULL, PG_GETARG_TEXT_PP, PG_RETURN_VOID, pgstat_reset_slru_counter(), and text_to_cstring().

2019 {
2020  char *target = NULL;
2021 
2022  if (!PG_ARGISNULL(0))
2023  target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2024 
2025  pgstat_reset_slru_counter(target);
2026 
2027  PG_RETURN_VOID();
2028 }
void pgstat_reset_slru_counter(const char *name)
Definition: pgstat.c:1419
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define PG_RETURN_VOID()
Definition: fmgr.h:348
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
char * text_to_cstring(const text *t)
Definition: varlena.c:205

Variable Documentation

◆ bgwriterStats

PgStat_MsgBgWriter bgwriterStats