PostgreSQL Source Code  git master
pgstatfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xlog.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_type.h"
#include "common/ip.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/bgworker_internals.h"
#include "postmaster/postmaster.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/inet.h"
#include "utils/timestamp.h"
Include dependency graph for pgstatfuncs.c:

Go to the source code of this file.

Macros

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

Functions

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

Variables

PgStat_MsgBgWriter bgwriterStats
 

Macro Definition Documentation

◆ PG_STAT_GET_ACTIVITY_COLS

#define PG_STAT_GET_ACTIVITY_COLS   30

Referenced by pg_stat_get_activity().

◆ PG_STAT_GET_PROGRESS_COLS

#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3

◆ UINT32_ACCESS_ONCE

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

Definition at line 34 of file pgstatfuncs.c.

Referenced by pg_stat_get_activity().

Function Documentation

◆ pg_backend_pid()

Datum pg_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 936 of file pgstatfuncs.c.

References MyProcPid, and PG_RETURN_INT32.

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

◆ pg_stat_clear_snapshot()

Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1871 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_clear_snapshot().

1872 {
1874 
1875  PG_RETURN_VOID();
1876 }
#define PG_RETURN_VOID()
Definition: fmgr.h:339
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5766

◆ pg_stat_get_activity()

Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 548 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(), GetBackgroundWorkerTypeByPid(), GetUserId(), PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, has_privs_of_role(), i, inet_in(), Int32GetDatum, InvalidOid, is_member_of_role(), IsA, lengthof, 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_backend_desc(), 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.

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

◆ pg_stat_get_analyze_count()

Datum pg_stat_get_analyze_count ( PG_FUNCTION_ARGS  )

Definition at line 333 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_archiver()

Datum pg_stat_get_archiver ( PG_FUNCTION_ARGS  )

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

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

◆ pg_stat_get_autoanalyze_count()

Datum pg_stat_get_autoanalyze_count ( PG_FUNCTION_ARGS  )

Definition at line 348 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_autovacuum_count()

Datum pg_stat_get_autovacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 318 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_backend_activity()

Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 982 of file pgstatfuncs.c.

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

983 {
984  int32 beid = PG_GETARG_INT32(0);
985  PgBackendStatus *beentry;
986  const char *activity;
987  char *clipped_activity;
988  text *ret;
989 
990  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
991  activity = "<backend information not available>";
992  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
993  activity = "<insufficient privilege>";
994  else if (*(beentry->st_activity_raw) == '\0')
995  activity = "<command string not enabled>";
996  else
997  activity = beentry->st_activity_raw;
998 
999  clipped_activity = pgstat_clip_activity(activity);
1000  ret = cstring_to_text(activity);
1001  pfree(clipped_activity);
1002 
1003  PG_RETURN_TEXT_P(ret);
1004 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:378
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
signed int int32
Definition: c.h:355
void pfree(void *pointer)
Definition: mcxt.c:1056
char * st_activity_raw
Definition: pgstat.h:1087
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
char * pgstat_clip_activity(const char *raw_activity)
Definition: pgstat.c:6514
Definition: c.h:555

◆ pg_stat_get_backend_activity_start()

Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 1050 of file pgstatfuncs.c.

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

1051 {
1052  int32 beid = PG_GETARG_INT32(0);
1053  TimestampTz result;
1054  PgBackendStatus *beentry;
1055 
1056  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1057  PG_RETURN_NULL();
1058 
1059  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1060  PG_RETURN_NULL();
1061 
1062  result = beentry->st_activity_start_timestamp;
1063 
1064  /*
1065  * No time recorded for start of current query -- this is the case if the
1066  * user hasn't enabled query-level stats collection.
1067  */
1068  if (result == 0)
1069  PG_RETURN_NULL();
1070 
1071  PG_RETURN_TIMESTAMPTZ(result);
1072 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:378
TimestampTz st_activity_start_timestamp
Definition: pgstat.h:1057
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 1120 of file pgstatfuncs.c.

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

1121 {
1122  int32 beid = PG_GETARG_INT32(0);
1123  PgBackendStatus *beentry;
1124  SockAddr zero_clientaddr;
1125  char remote_host[NI_MAXHOST];
1126  int ret;
1127 
1128  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1129  PG_RETURN_NULL();
1130 
1131  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1132  PG_RETURN_NULL();
1133 
1134  /* A zeroed client addr means we don't know */
1135  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1136  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1137  sizeof(zero_clientaddr)) == 0)
1138  PG_RETURN_NULL();
1139 
1140  switch (beentry->st_clientaddr.addr.ss_family)
1141  {
1142  case AF_INET:
1143 #ifdef HAVE_IPV6
1144  case AF_INET6:
1145 #endif
1146  break;
1147  default:
1148  PG_RETURN_NULL();
1149  }
1150 
1151  remote_host[0] = '\0';
1152  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1153  beentry->st_clientaddr.salen,
1154  remote_host, sizeof(remote_host),
1155  NULL, 0,
1157  if (ret != 0)
1158  PG_RETURN_NULL();
1159 
1160  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1161 
1163  CStringGetDatum(remote_host)));
1164 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Oid GetUserId(void)
Definition: miscinit.c:378
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INET_P(x)
Definition: inet.h:125
SockAddr st_clientaddr
Definition: pgstat.h:1063
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:615
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 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:2543
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:122
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:2118
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_client_port()

Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 1167 of file pgstatfuncs.c.

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

1168 {
1169  int32 beid = PG_GETARG_INT32(0);
1170  PgBackendStatus *beentry;
1171  SockAddr zero_clientaddr;
1172  char remote_port[NI_MAXSERV];
1173  int ret;
1174 
1175  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1176  PG_RETURN_NULL();
1177 
1178  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1179  PG_RETURN_NULL();
1180 
1181  /* A zeroed client addr means we don't know */
1182  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1183  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1184  sizeof(zero_clientaddr)) == 0)
1185  PG_RETURN_NULL();
1186 
1187  switch (beentry->st_clientaddr.addr.ss_family)
1188  {
1189  case AF_INET:
1190 #ifdef HAVE_IPV6
1191  case AF_INET6:
1192 #endif
1193  break;
1194  case AF_UNIX:
1195  PG_RETURN_INT32(-1);
1196  default:
1197  PG_RETURN_NULL();
1198  }
1199 
1200  remote_port[0] = '\0';
1201  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1202  beentry->st_clientaddr.salen,
1203  NULL, 0,
1204  remote_port, sizeof(remote_port),
1206  if (ret != 0)
1207  PG_RETURN_NULL();
1208 
1210  CStringGetDatum(remote_port)));
1211 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
Oid GetUserId(void)
Definition: miscinit.c:378
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:268
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
struct sockaddr_storage addr
Definition: pqcomm.h:64
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
SockAddr st_clientaddr
Definition: pgstat.h:1063
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:615
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 PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#define NI_NUMERICSERV
Definition: getaddrinfo.h:81
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition: ip.c:122
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_dbid()

Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 956 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_backend_idset()

Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

Definition at line 398 of file pgstatfuncs.c.

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

399 {
400  FuncCallContext *funcctx;
401  int *fctx;
402  int32 result;
403 
404  /* stuff done only on the first call of the function */
405  if (SRF_IS_FIRSTCALL())
406  {
407  /* create a function context for cross-call persistence */
408  funcctx = SRF_FIRSTCALL_INIT();
409 
411  2 * sizeof(int));
412  funcctx->user_fctx = fctx;
413 
414  fctx[0] = 0;
415  fctx[1] = pgstat_fetch_stat_numbackends();
416  }
417 
418  /* stuff done on every call of the function */
419  funcctx = SRF_PERCALL_SETUP();
420  fctx = funcctx->user_fctx;
421 
422  fctx[0] += 1;
423  result = fctx[0];
424 
425  if (result <= fctx[1])
426  {
427  /* do when there is more left to send */
428  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
429  }
430  else
431  {
432  /* do when there is no more left */
433  SRF_RETURN_DONE(funcctx);
434  }
435 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:282
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:286
signed int int32
Definition: c.h:355
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:288
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2584
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:306
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:284

◆ pg_stat_get_backend_pid()

Datum pg_stat_get_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 943 of file pgstatfuncs.c.

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

944 {
945  int32 beid = PG_GETARG_INT32(0);
946  PgBackendStatus *beentry;
947 
948  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
949  PG_RETURN_NULL();
950 
951  PG_RETURN_INT32(beentry->st_procpid);
952 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_start()

Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 1098 of file pgstatfuncs.c.

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

1099 {
1100  int32 beid = PG_GETARG_INT32(0);
1101  TimestampTz result;
1102  PgBackendStatus *beentry;
1103 
1104  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1105  PG_RETURN_NULL();
1106 
1107  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1108  PG_RETURN_NULL();
1109 
1110  result = beentry->st_proc_start_timestamp;
1111 
1112  if (result == 0) /* probably can't happen? */
1113  PG_RETURN_NULL();
1114 
1115  PG_RETURN_TIMESTAMPTZ(result);
1116 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:378
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
TimestampTz st_proc_start_timestamp
Definition: pgstat.h:1055
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_userid()

Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 969 of file pgstatfuncs.c.

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

970 {
971  int32 beid = PG_GETARG_INT32(0);
972  PgBackendStatus *beentry;
973 
974  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
975  PG_RETURN_NULL();
976 
977  PG_RETURN_OID(beentry->st_userid);
978 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
#define PG_RETURN_OID(x)
Definition: fmgr.h:350
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_wait_event()

Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 1028 of file pgstatfuncs.c.

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

1029 {
1030  int32 beid = PG_GETARG_INT32(0);
1031  PgBackendStatus *beentry;
1032  PGPROC *proc;
1033  const char *wait_event = NULL;
1034 
1035  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1036  wait_event = "<backend information not available>";
1037  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1038  wait_event = "<insufficient privilege>";
1039  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1040  wait_event = pgstat_get_wait_event(proc->wait_event_info);
1041 
1042  if (!wait_event)
1043  PG_RETURN_NULL();
1044 
1045  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
1046 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
uint32 wait_event_info
Definition: proc.h:176
Oid GetUserId(void)
Definition: miscinit.c:378
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2365
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
signed int int32
Definition: c.h:355
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: pgstat.c:3553
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_wait_event_type()

Datum pg_stat_get_backend_wait_event_type ( PG_FUNCTION_ARGS  )

Definition at line 1007 of file pgstatfuncs.c.

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

1008 {
1009  int32 beid = PG_GETARG_INT32(0);
1010  PgBackendStatus *beentry;
1011  PGPROC *proc;
1012  const char *wait_event_type = NULL;
1013 
1014  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1015  wait_event_type = "<backend information not available>";
1016  else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1017  wait_event_type = "<insufficient privilege>";
1018  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1019  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
1020 
1021  if (!wait_event_type)
1022  PG_RETURN_NULL();
1023 
1024  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
1025 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
uint32 wait_event_info
Definition: proc.h:176
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: pgstat.c:3498
Oid GetUserId(void)
Definition: miscinit.c:378
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2365
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
signed int int32
Definition: c.h:355
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
Definition: proc.h:95
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_backend_xact_start()

Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 1076 of file pgstatfuncs.c.

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

1077 {
1078  int32 beid = PG_GETARG_INT32(0);
1079  TimestampTz result;
1080  PgBackendStatus *beentry;
1081 
1082  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1083  PG_RETURN_NULL();
1084 
1085  if (!has_privs_of_role(GetUserId(), beentry->st_userid))
1086  PG_RETURN_NULL();
1087 
1088  result = beentry->st_xact_start_timestamp;
1089 
1090  if (result == 0) /* not in a transaction */
1091  PG_RETURN_NULL();
1092 
1093  PG_RETURN_TIMESTAMPTZ(result);
1094 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Oid GetUserId(void)
Definition: miscinit.c:378
int64 TimestampTz
Definition: timestamp.h:39
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4900
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
signed int int32
Definition: c.h:355
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543
TimestampTz st_xact_start_timestamp
Definition: pgstat.h:1056
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_bgwriter_buf_written_checkpoints()

Datum pg_stat_get_bgwriter_buf_written_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1620 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

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

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1626 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1627 {
1628  PG_RETURN_INT64(pgstat_fetch_global()->buf_written_clean);
1629 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617

◆ pg_stat_get_bgwriter_maxwritten_clean()

Datum pg_stat_get_bgwriter_maxwritten_clean ( PG_FUNCTION_ARGS  )

Definition at line 1632 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1633 {
1634  PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_clean);
1635 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617

◆ pg_stat_get_bgwriter_requested_checkpoints()

Datum pg_stat_get_bgwriter_requested_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1614 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

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

◆ pg_stat_get_bgwriter_stat_reset_time()

Datum pg_stat_get_bgwriter_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1652 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1653 {
1654  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stat_reset_timestamp);
1655 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617
#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 1608 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

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

◆ pg_stat_get_blocks_fetched()

Datum pg_stat_get_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 200 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_blocks_hit()

Datum pg_stat_get_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 216 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_buf_alloc()

Datum pg_stat_get_buf_alloc ( PG_FUNCTION_ARGS  )

Definition at line 1670 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1671 {
1672  PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
1673 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617

◆ pg_stat_get_buf_fsync_backend()

Datum pg_stat_get_buf_fsync_backend ( PG_FUNCTION_ARGS  )

Definition at line 1664 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

1665 {
1666  PG_RETURN_INT64(pgstat_fetch_global()->buf_fsync_backend);
1667 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617

◆ pg_stat_get_buf_written_backend()

Datum pg_stat_get_buf_written_backend ( PG_FUNCTION_ARGS  )

Definition at line 1658 of file pgstatfuncs.c.

References PG_RETURN_INT64, and pgstat_fetch_global().

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

◆ pg_stat_get_checkpoint_sync_time()

Datum pg_stat_get_checkpoint_sync_time ( PG_FUNCTION_ARGS  )

Definition at line 1645 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1646 {
1647  /* time is already in msec, just convert to double for presentation */
1648  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
1649 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617

◆ pg_stat_get_checkpoint_write_time()

Datum pg_stat_get_checkpoint_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1638 of file pgstatfuncs.c.

References PG_RETURN_FLOAT8, and pgstat_fetch_global().

1639 {
1640  /* time is already in msec, just convert to double for presentation */
1641  PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
1642 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617

◆ pg_stat_get_db_blk_read_time()

Datum pg_stat_get_db_blk_read_time ( PG_FUNCTION_ARGS  )

Definition at line 1576 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_blk_write_time()

Datum pg_stat_get_db_blk_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1592 of file pgstatfuncs.c.

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

1593 {
1594  Oid dbid = PG_GETARG_OID(0);
1595  double result;
1596  PgStat_StatDBEntry *dbentry;
1597 
1598  /* convert counter from microsec to millisec for display */
1599  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1600  result = 0;
1601  else
1602  result = ((double) dbentry->n_block_write_time) / 1000.0;
1603 
1604  PG_RETURN_FLOAT8(result);
1605 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_block_write_time
Definition: pgstat.h:614

◆ pg_stat_get_db_blocks_fetched()

Datum pg_stat_get_db_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1268 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_blocks_hit()

Datum pg_stat_get_db_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1284 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_checksum_failures()

Datum pg_stat_get_db_checksum_failures ( PG_FUNCTION_ARGS  )

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

1538 {
1539  Oid dbid = PG_GETARG_OID(0);
1540  int64 result;
1541  PgStat_StatDBEntry *dbentry;
1542 
1543  if (!DataChecksumsEnabled())
1544  PG_RETURN_NULL();
1545 
1546  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1547  result = 0;
1548  else
1549  result = (int64) (dbentry->n_checksum_failures);
1550 
1551  PG_RETURN_INT64(result);
1552 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
bool DataChecksumsEnabled(void)
Definition: xlog.c:4862
PgStat_Counter n_checksum_failures
Definition: pgstat.h:611
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_db_checksum_last_failure()

Datum pg_stat_get_db_checksum_last_failure ( PG_FUNCTION_ARGS  )

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

1556 {
1557  Oid dbid = PG_GETARG_OID(0);
1558  TimestampTz result;
1559  PgStat_StatDBEntry *dbentry;
1560 
1561  if (!DataChecksumsEnabled())
1562  PG_RETURN_NULL();
1563 
1564  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1565  result = 0;
1566  else
1567  result = dbentry->last_checksum_failure;
1568 
1569  if (result == 0)
1570  PG_RETURN_NULL();
1571  else
1572  PG_RETURN_TIMESTAMPTZ(result);
1573 }
bool DataChecksumsEnabled(void)
Definition: xlog.c:4862
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz last_checksum_failure
Definition: pgstat.h:612
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_db_conflict_all()

Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

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

1504 {
1505  Oid dbid = PG_GETARG_OID(0);
1506  int64 result;
1507  PgStat_StatDBEntry *dbentry;
1508 
1509  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1510  result = 0;
1511  else
1512  result = (int64) (dbentry->n_conflict_tablespace +
1513  dbentry->n_conflict_lock +
1514  dbentry->n_conflict_snapshot +
1515  dbentry->n_conflict_bufferpin +
1516  dbentry->n_conflict_startup_deadlock);
1517 
1518  PG_RETURN_INT64(result);
1519 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:606
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:607
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:605
PgStat_Counter n_conflict_lock
Definition: pgstat.h:604

◆ pg_stat_get_db_conflict_bufferpin()

Datum pg_stat_get_db_conflict_bufferpin ( PG_FUNCTION_ARGS  )

Definition at line 1473 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_conflict_lock()

Datum pg_stat_get_db_conflict_lock ( PG_FUNCTION_ARGS  )

Definition at line 1443 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_conflict_snapshot()

Datum pg_stat_get_db_conflict_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1458 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_conflict_startup_deadlock()

Datum pg_stat_get_db_conflict_startup_deadlock ( PG_FUNCTION_ARGS  )

Definition at line 1488 of file pgstatfuncs.c.

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

1489 {
1490  Oid dbid = PG_GETARG_OID(0);
1491  int64 result;
1492  PgStat_StatDBEntry *dbentry;
1493 
1494  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1495  result = 0;
1496  else
1497  result = (int64) (dbentry->n_conflict_startup_deadlock);
1498 
1499  PG_RETURN_INT64(result);
1500 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:607
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_db_conflict_tablespace()

Datum pg_stat_get_db_conflict_tablespace ( PG_FUNCTION_ARGS  )

Definition at line 1428 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_deadlocks()

Datum pg_stat_get_db_deadlocks ( PG_FUNCTION_ARGS  )

Definition at line 1522 of file pgstatfuncs.c.

References PgStat_StatDBEntry::n_deadlocks, 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_deadlocks);
1532 
1533  PG_RETURN_INT64(result);
1534 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_deadlocks
Definition: pgstat.h:610

◆ pg_stat_get_db_numbackends()

Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1215 of file pgstatfuncs.c.

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

1216 {
1217  Oid dbid = PG_GETARG_OID(0);
1218  int32 result;
1219  int tot_backends = pgstat_fetch_stat_numbackends();
1220  int beid;
1221 
1222  result = 0;
1223  for (beid = 1; beid <= tot_backends; beid++)
1224  {
1225  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1226 
1227  if (beentry && beentry->st_databaseid == dbid)
1228  result++;
1229  }
1230 
1231  PG_RETURN_INT32(result);
1232 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:355
Oid st_databaseid
Definition: pgstat.h:1061
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
int pgstat_fetch_stat_numbackends(void)
Definition: pgstat.c:2584
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
Definition: pgstat.c:2543

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1379 of file pgstatfuncs.c.

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

1380 {
1381  Oid dbid = PG_GETARG_OID(0);
1382  TimestampTz result;
1383  PgStat_StatDBEntry *dbentry;
1384 
1385  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1386  result = 0;
1387  else
1388  result = dbentry->stat_reset_timestamp;
1389 
1390  if (result == 0)
1391  PG_RETURN_NULL();
1392  else
1393  PG_RETURN_TIMESTAMPTZ(result);
1394 }
int64 TimestampTz
Definition: timestamp.h:39
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
TimestampTz stat_reset_timestamp
Definition: pgstat.h:616
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_db_temp_bytes()

Datum pg_stat_get_db_temp_bytes ( PG_FUNCTION_ARGS  )

Definition at line 1413 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_temp_files()

Datum pg_stat_get_db_temp_files ( PG_FUNCTION_ARGS  )

Definition at line 1397 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_deleted()

Datum pg_stat_get_db_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1364 of file pgstatfuncs.c.

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

1365 {
1366  Oid dbid = PG_GETARG_OID(0);
1367  int64 result;
1368  PgStat_StatDBEntry *dbentry;
1369 
1370  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1371  result = 0;
1372  else
1373  result = (int64) (dbentry->n_tuples_deleted);
1374 
1375  PG_RETURN_INT64(result);
1376 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2428
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:601

◆ pg_stat_get_db_tuples_fetched()

Datum pg_stat_get_db_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1316 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_inserted()

Datum pg_stat_get_db_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1332 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_returned()

Datum pg_stat_get_db_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1300 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_tuples_updated()

Datum pg_stat_get_db_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1348 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_xact_commit()

Datum pg_stat_get_db_xact_commit ( PG_FUNCTION_ARGS  )

Definition at line 1236 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_db_xact_rollback()

Datum pg_stat_get_db_xact_rollback ( PG_FUNCTION_ARGS  )

Definition at line 1252 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_dead_tuples()

Datum pg_stat_get_dead_tuples ( PG_FUNCTION_ARGS  )

Definition at line 168 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_function_calls()

Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 363 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_function_self_time()

Datum pg_stat_get_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 386 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_function_total_time()

Datum pg_stat_get_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 374 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_last_analyze_time()

Datum pg_stat_get_last_analyze_time ( PG_FUNCTION_ARGS  )

Definition at line 267 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_last_autoanalyze_time()

Datum pg_stat_get_last_autoanalyze_time ( PG_FUNCTION_ARGS  )

Definition at line 285 of file pgstatfuncs.c.

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

286 {
287  Oid relid = PG_GETARG_OID(0);
288  TimestampTz result;
289  PgStat_StatTabEntry *tabentry;
290 
291  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
292  result = 0;
293  else
294  result = tabentry->autovac_analyze_timestamp;
295 
296  if (result == 0)
297  PG_RETURN_NULL();
298  else
299  PG_RETURN_TIMESTAMPTZ(result);
300 }
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:659
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2455
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_last_autovacuum_time()

Datum pg_stat_get_last_autovacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 249 of file pgstatfuncs.c.

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

250 {
251  Oid relid = PG_GETARG_OID(0);
252  TimestampTz result;
253  PgStat_StatTabEntry *tabentry;
254 
255  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
256  result = 0;
257  else
258  result = tabentry->autovac_vacuum_timestamp;
259 
260  if (result == 0)
261  PG_RETURN_NULL();
262  else
263  PG_RETURN_TIMESTAMPTZ(result);
264 }
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
Definition: pgstat.c:2455
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:655
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_last_vacuum_time()

Datum pg_stat_get_last_vacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 231 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_live_tuples()

Datum pg_stat_get_live_tuples ( PG_FUNCTION_ARGS  )

Definition at line 152 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_mod_since_analyze()

Datum pg_stat_get_mod_since_analyze ( PG_FUNCTION_ARGS  )

Definition at line 184 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_numscans()

Datum pg_stat_get_numscans ( PG_FUNCTION_ARGS  )

Definition at line 40 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_progress_info()

Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 441 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_snapshot_timestamp()

Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1864 of file pgstatfuncs.c.

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_global().

1865 {
1866  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stats_timestamp);
1867 }
PgStat_GlobalStats * pgstat_fetch_global(void)
Definition: pgstat.c:2617
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40

◆ pg_stat_get_tuples_deleted()

Datum pg_stat_get_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 120 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_fetched()

Datum pg_stat_get_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 72 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_hot_updated()

Datum pg_stat_get_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 136 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_inserted()

Datum pg_stat_get_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 88 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_returned()

Datum pg_stat_get_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 56 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_tuples_updated()

Datum pg_stat_get_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 104 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_vacuum_count()

Datum pg_stat_get_vacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 303 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_xact_blocks_fetched()

Datum pg_stat_get_xact_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1799 of file pgstatfuncs.c.

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

1800 {
1801  Oid relid = PG_GETARG_OID(0);
1802  int64 result;
1803  PgStat_TableStatus *tabentry;
1804 
1805  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1806  result = 0;
1807  else
1808  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1809 
1810  PG_RETURN_INT64(result);
1811 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:114

◆ pg_stat_get_xact_blocks_hit()

Datum pg_stat_get_xact_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1814 of file pgstatfuncs.c.

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

1815 {
1816  Oid relid = PG_GETARG_OID(0);
1817  int64 result;
1818  PgStat_TableStatus *tabentry;
1819 
1820  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1821  result = 0;
1822  else
1823  result = (int64) (tabentry->t_counts.t_blocks_hit);
1824 
1825  PG_RETURN_INT64(result);
1826 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter t_blocks_hit
Definition: pgstat.h:115

◆ pg_stat_get_xact_function_calls()

Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

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

1830 {
1831  Oid funcid = PG_GETARG_OID(0);
1832  PgStat_BackendFunctionEntry *funcentry;
1833 
1834  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1835  PG_RETURN_NULL();
1836  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
1837 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter f_numcalls
Definition: pgstat.h:461
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1670
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_xact_function_self_time()

Datum pg_stat_get_xact_function_self_time ( PG_FUNCTION_ARGS  )

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

1852 {
1853  Oid funcid = PG_GETARG_OID(0);
1854  PgStat_BackendFunctionEntry *funcentry;
1855 
1856  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1857  PG_RETURN_NULL();
1859 }
instr_time f_self_time
Definition: pgstat.h:463
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_FunctionCounts f_counts
Definition: pgstat.h:473
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
Definition: pgstat.c:1670
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ pg_stat_get_xact_function_total_time()

Datum pg_stat_get_xact_function_total_time ( PG_FUNCTION_ARGS  )

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

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

◆ pg_stat_get_xact_numscans()

Datum pg_stat_get_xact_numscans ( PG_FUNCTION_ARGS  )

Definition at line 1676 of file pgstatfuncs.c.

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

1677 {
1678  Oid relid = PG_GETARG_OID(0);
1679  int64 result;
1680  PgStat_TableStatus *tabentry;
1681 
1682  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1683  result = 0;
1684  else
1685  result = (int64) (tabentry->t_counts.t_numscans);
1686 
1687  PG_RETURN_INT64(result);
1688 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
PgStat_Counter t_numscans
Definition: pgstat.h:99

◆ pg_stat_get_xact_tuples_deleted()

Datum pg_stat_get_xact_tuples_deleted ( PG_FUNCTION_ARGS  )

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

1764 {
1765  Oid relid = PG_GETARG_OID(0);
1766  int64 result;
1767  PgStat_TableStatus *tabentry;
1769 
1770  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1771  result = 0;
1772  else
1773  {
1774  result = tabentry->t_counts.t_tuples_deleted;
1775  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1776  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1777  result += trans->tuples_deleted;
1778  }
1779 
1780  PG_RETURN_INT64(result);
1781 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:106
PgStat_Counter tuples_deleted
Definition: pgstat.h:169
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396

◆ pg_stat_get_xact_tuples_fetched()

Datum pg_stat_get_xact_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1706 of file pgstatfuncs.c.

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

1707 {
1708  Oid relid = PG_GETARG_OID(0);
1709  int64 result;
1710  PgStat_TableStatus *tabentry;
1711 
1712  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1713  result = 0;
1714  else
1715  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1716 
1717  PG_RETURN_INT64(result);
1718 }
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:102
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_tuples_hot_updated()

Datum pg_stat_get_xact_tuples_hot_updated ( PG_FUNCTION_ARGS  )

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

1785 {
1786  Oid relid = PG_GETARG_OID(0);
1787  int64 result;
1788  PgStat_TableStatus *tabentry;
1789 
1790  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1791  result = 0;
1792  else
1793  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1794 
1795  PG_RETURN_INT64(result);
1796 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:107
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_tuples_inserted()

Datum pg_stat_get_xact_tuples_inserted ( PG_FUNCTION_ARGS  )

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

1722 {
1723  Oid relid = PG_GETARG_OID(0);
1724  int64 result;
1725  PgStat_TableStatus *tabentry;
1727 
1728  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1729  result = 0;
1730  else
1731  {
1732  result = tabentry->t_counts.t_tuples_inserted;
1733  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1734  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1735  result += trans->tuples_inserted;
1736  }
1737 
1738  PG_RETURN_INT64(result);
1739 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
PgStat_Counter tuples_inserted
Definition: pgstat.h:167
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:104

◆ pg_stat_get_xact_tuples_returned()

Datum pg_stat_get_xact_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1691 of file pgstatfuncs.c.

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

1692 {
1693  Oid relid = PG_GETARG_OID(0);
1694  int64 result;
1695  PgStat_TableStatus *tabentry;
1696 
1697  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1698  result = 0;
1699  else
1700  result = (int64) (tabentry->t_counts.t_tuples_returned);
1701 
1702  PG_RETURN_INT64(result);
1703 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_Counter t_tuples_returned
Definition: pgstat.h:101
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ pg_stat_get_xact_tuples_updated()

Datum pg_stat_get_xact_tuples_updated ( PG_FUNCTION_ARGS  )

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

1743 {
1744  Oid relid = PG_GETARG_OID(0);
1745  int64 result;
1746  PgStat_TableStatus *tabentry;
1748 
1749  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1750  result = 0;
1751  else
1752  {
1753  result = tabentry->t_counts.t_tuples_updated;
1754  /* live subtransactions' counts aren't in t_tuples_updated yet */
1755  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1756  result += trans->tuples_updated;
1757  }
1758 
1759  PG_RETURN_INT64(result);
1760 }
PgStat_Counter tuples_updated
Definition: pgstat.h:168
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
PgStat_TableCounts t_counts
Definition: pgstat.h:158
unsigned int Oid
Definition: postgres_ext.h:31
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
Definition: pgstat.c:1875
PgStat_Counter t_tuples_updated
Definition: pgstat.h:105
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
struct PgStat_TableXactStatus * upper
Definition: pgstat.h:176
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:157
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:396

◆ pg_stat_reset()

Datum pg_stat_reset ( PG_FUNCTION_ARGS  )

Definition at line 1881 of file pgstatfuncs.c.

References PG_RETURN_VOID, and pgstat_reset_counters().

1882 {
1884 
1885  PG_RETURN_VOID();
1886 }
#define PG_RETURN_VOID()
Definition: fmgr.h:339
void pgstat_reset_counters(void)
Definition: pgstat.c:1307

◆ pg_stat_reset_shared()

Datum pg_stat_reset_shared ( PG_FUNCTION_ARGS  )

Definition at line 1890 of file pgstatfuncs.c.

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

1891 {
1892  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
1893 
1895 
1896  PG_RETURN_VOID();
1897 }
void pgstat_reset_shared_counters(const char *target)
Definition: pgstat.c:1329
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_VOID()
Definition: fmgr.h:339
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ pg_stat_reset_single_function_counters()

Datum pg_stat_reset_single_function_counters ( PG_FUNCTION_ARGS  )

Definition at line 1911 of file pgstatfuncs.c.

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

1912 {
1913  Oid funcoid = PG_GETARG_OID(0);
1914 
1916 
1917  PG_RETURN_VOID();
1918 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1360
#define PG_RETURN_VOID()
Definition: fmgr.h:339

◆ pg_stat_reset_single_table_counters()

Datum pg_stat_reset_single_table_counters ( PG_FUNCTION_ARGS  )

Definition at line 1901 of file pgstatfuncs.c.

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

1902 {
1903  Oid taboid = PG_GETARG_OID(0);
1904 
1906 
1907  PG_RETURN_VOID();
1908 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
Definition: pgstat.c:1360
#define PG_RETURN_VOID()
Definition: fmgr.h:339

Variable Documentation

◆ bgwriterStats

PgStat_MsgBgWriter bgwriterStats