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

Go to the source code of this file.

Macros

#define UINT32_ACCESS_ONCE(var)   ((uint32)(*((volatile uint32 *)&(var))))
 
#define HAS_PGSTAT_PERMISSIONS(role)   (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
 
#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3
 
#define PG_STAT_GET_ACTIVITY_COLS   30
 
#define PG_STAT_GET_WAL_COLS   9
 
#define PG_STAT_GET_SLRU_COLS   9
 
#define PG_STAT_GET_REPLICATION_SLOT_COLS   10
 
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS   4
 

Functions

Datum pg_stat_get_numscans (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_returned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_inserted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_deleted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_tuples_hot_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_live_tuples (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_dead_tuples (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_mod_since_analyze (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_ins_since_vacuum (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_blocks_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_blocks_hit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_vacuum_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_autovacuum_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_analyze_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_last_autoanalyze_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_vacuum_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_autovacuum_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_analyze_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_autoanalyze_count (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_calls (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_total_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_self_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_idset (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_progress_info (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_activity (PG_FUNCTION_ARGS)
 
Datum pg_backend_pid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_pid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_dbid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_userid (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_activity (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_wait_event_type (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_wait_event (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_activity_start (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_xact_start (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_start (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_client_addr (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_client_port (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_numbackends (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_xact_commit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_xact_rollback (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blocks_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blocks_hit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_returned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_inserted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_tuples_deleted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_stat_reset_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_temp_files (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_temp_bytes (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_tablespace (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_lock (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_snapshot (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_bufferpin (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_startup_deadlock (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_all (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_deadlocks (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_checksum_failures (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_checksum_last_failure (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blk_read_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_blk_write_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_session_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_active_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_idle_in_transaction_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_sessions (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_sessions_abandoned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_sessions_fatal (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_sessions_killed (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_wal (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_slru (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_numscans (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_returned (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_inserted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_deleted (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_tuples_hot_updated (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_blocks_fetched (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_blocks_hit (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_calls (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_total_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_self_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_snapshot_timestamp (PG_FUNCTION_ARGS)
 
Datum pg_stat_clear_snapshot (PG_FUNCTION_ARGS)
 
Datum pg_stat_force_next_flush (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_shared (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_single_table_counters (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_single_function_counters (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_slru (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_replication_slot (PG_FUNCTION_ARGS)
 
Datum pg_stat_reset_subscription_stats (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_archiver (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_replication_slot (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_subscription_stats (PG_FUNCTION_ARGS)
 
Datum pg_stat_have_stats (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ HAS_PGSTAT_PERMISSIONS

#define HAS_PGSTAT_PERMISSIONS (   role)    (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))

Definition at line 37 of file pgstatfuncs.c.

◆ PG_STAT_GET_ACTIVITY_COLS

#define PG_STAT_GET_ACTIVITY_COLS   30

◆ PG_STAT_GET_PROGRESS_COLS

#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3

◆ PG_STAT_GET_REPLICATION_SLOT_COLS

#define PG_STAT_GET_REPLICATION_SLOT_COLS   10

◆ PG_STAT_GET_SLRU_COLS

#define PG_STAT_GET_SLRU_COLS   9

◆ PG_STAT_GET_SUBSCRIPTION_STATS_COLS

#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS   4

◆ PG_STAT_GET_WAL_COLS

#define PG_STAT_GET_WAL_COLS   9

◆ UINT32_ACCESS_ONCE

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

Definition at line 35 of file pgstatfuncs.c.

Function Documentation

◆ pg_backend_pid()

Datum pg_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 907 of file pgstatfuncs.c.

908 {
910 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int MyProcPid
Definition: globals.c:44

References MyProcPid, and PG_RETURN_INT32.

◆ pg_stat_clear_snapshot()

Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 2063 of file pgstatfuncs.c.

2064 {
2066 
2067  PG_RETURN_VOID();
2068 }
#define PG_RETURN_VOID()
Definition: fmgr.h:349
void pgstat_clear_snapshot(void)
Definition: pgstat.c:751

References PG_RETURN_VOID, and pgstat_clear_snapshot().

◆ pg_stat_force_next_flush()

Datum pg_stat_force_next_flush ( PG_FUNCTION_ARGS  )

Definition at line 2073 of file pgstatfuncs.c.

2074 {
2076 
2077  PG_RETURN_VOID();
2078 }
void pgstat_force_next_flush(void)
Definition: pgstat.c:664

References PG_RETURN_VOID, and pgstat_force_next_flush().

◆ pg_stat_get_activity()

Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 540 of file pgstatfuncs.c.

541 {
542 #define PG_STAT_GET_ACTIVITY_COLS 30
543  int num_backends = pgstat_fetch_stat_numbackends();
544  int curr_backend;
545  int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
546  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
547 
548  SetSingleFuncCall(fcinfo, 0);
549 
550  /* 1-based index */
551  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
552  {
553  /* for each row */
555  bool nulls[PG_STAT_GET_ACTIVITY_COLS];
556  LocalPgBackendStatus *local_beentry;
557  PgBackendStatus *beentry;
558  PGPROC *proc;
559  const char *wait_event_type = NULL;
560  const char *wait_event = NULL;
561 
562  MemSet(values, 0, sizeof(values));
563  MemSet(nulls, 0, sizeof(nulls));
564 
565  /* Get the next one in the list */
566  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
567  if (!local_beentry)
568  {
569  int i;
570 
571  /* Ignore missing entries if looking for specific PID */
572  if (pid != -1)
573  continue;
574 
575  for (i = 0; i < lengthof(nulls); i++)
576  nulls[i] = true;
577 
578  nulls[5] = false;
579  values[5] = CStringGetTextDatum("<backend information not available>");
580 
581  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
582  continue;
583  }
584 
585  beentry = &local_beentry->backendStatus;
586 
587  /* If looking for specific PID, ignore all the others */
588  if (pid != -1 && beentry->st_procpid != pid)
589  continue;
590 
591  /* Values available to all callers */
592  if (beentry->st_databaseid != InvalidOid)
593  values[0] = ObjectIdGetDatum(beentry->st_databaseid);
594  else
595  nulls[0] = true;
596 
597  values[1] = Int32GetDatum(beentry->st_procpid);
598 
599  if (beentry->st_userid != InvalidOid)
600  values[2] = ObjectIdGetDatum(beentry->st_userid);
601  else
602  nulls[2] = true;
603 
604  if (beentry->st_appname)
605  values[3] = CStringGetTextDatum(beentry->st_appname);
606  else
607  nulls[3] = true;
608 
609  if (TransactionIdIsValid(local_beentry->backend_xid))
610  values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
611  else
612  nulls[15] = true;
613 
614  if (TransactionIdIsValid(local_beentry->backend_xmin))
615  values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
616  else
617  nulls[16] = true;
618 
619  /* Values only available to role member or pg_read_all_stats */
620  if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
621  {
622  SockAddr zero_clientaddr;
623  char *clipped_activity;
624 
625  switch (beentry->st_state)
626  {
627  case STATE_IDLE:
628  values[4] = CStringGetTextDatum("idle");
629  break;
630  case STATE_RUNNING:
631  values[4] = CStringGetTextDatum("active");
632  break;
634  values[4] = CStringGetTextDatum("idle in transaction");
635  break;
636  case STATE_FASTPATH:
637  values[4] = CStringGetTextDatum("fastpath function call");
638  break;
640  values[4] = CStringGetTextDatum("idle in transaction (aborted)");
641  break;
642  case STATE_DISABLED:
643  values[4] = CStringGetTextDatum("disabled");
644  break;
645  case STATE_UNDEFINED:
646  nulls[4] = true;
647  break;
648  }
649 
650  clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
651  values[5] = CStringGetTextDatum(clipped_activity);
652  pfree(clipped_activity);
653 
654  /* leader_pid */
655  nulls[28] = true;
656 
657  proc = BackendPidGetProc(beentry->st_procpid);
658 
659  if (proc == NULL && (beentry->st_backendType != B_BACKEND))
660  {
661  /*
662  * For an auxiliary process, retrieve process info from
663  * AuxiliaryProcs stored in shared-memory.
664  */
665  proc = AuxiliaryPidGetProc(beentry->st_procpid);
666  }
667 
668  /*
669  * If a PGPROC entry was retrieved, display wait events and lock
670  * group leader information if any. To avoid extra overhead, no
671  * extra lock is being held, so there is no guarantee of
672  * consistency across multiple rows.
673  */
674  if (proc != NULL)
675  {
676  uint32 raw_wait_event;
677  PGPROC *leader;
678 
679  raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
680  wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
681  wait_event = pgstat_get_wait_event(raw_wait_event);
682 
683  leader = proc->lockGroupLeader;
684 
685  /*
686  * Show the leader only for active parallel workers. This
687  * leaves the field as NULL for the leader of a parallel
688  * group.
689  */
690  if (leader && leader->pid != beentry->st_procpid)
691  {
692  values[28] = Int32GetDatum(leader->pid);
693  nulls[28] = false;
694  }
695  }
696 
697  if (wait_event_type)
698  values[6] = CStringGetTextDatum(wait_event_type);
699  else
700  nulls[6] = true;
701 
702  if (wait_event)
703  values[7] = CStringGetTextDatum(wait_event);
704  else
705  nulls[7] = true;
706 
707  /*
708  * Don't expose transaction time for walsenders; it confuses
709  * monitoring, particularly because we don't keep the time up-to-
710  * date.
711  */
712  if (beentry->st_xact_start_timestamp != 0 &&
713  beentry->st_backendType != B_WAL_SENDER)
715  else
716  nulls[8] = true;
717 
718  if (beentry->st_activity_start_timestamp != 0)
720  else
721  nulls[9] = true;
722 
723  if (beentry->st_proc_start_timestamp != 0)
725  else
726  nulls[10] = true;
727 
728  if (beentry->st_state_start_timestamp != 0)
730  else
731  nulls[11] = true;
732 
733  /* A zeroed client addr means we don't know */
734  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
735  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
736  sizeof(zero_clientaddr)) == 0)
737  {
738  nulls[12] = true;
739  nulls[13] = true;
740  nulls[14] = true;
741  }
742  else
743  {
744  if (beentry->st_clientaddr.addr.ss_family == AF_INET
745 #ifdef HAVE_IPV6
746  || beentry->st_clientaddr.addr.ss_family == AF_INET6
747 #endif
748  )
749  {
750  char remote_host[NI_MAXHOST];
751  char remote_port[NI_MAXSERV];
752  int ret;
753 
754  remote_host[0] = '\0';
755  remote_port[0] = '\0';
756  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
757  beentry->st_clientaddr.salen,
758  remote_host, sizeof(remote_host),
759  remote_port, sizeof(remote_port),
761  if (ret == 0)
762  {
763  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
765  CStringGetDatum(remote_host));
766  if (beentry->st_clienthostname &&
767  beentry->st_clienthostname[0])
769  else
770  nulls[13] = true;
771  values[14] = Int32GetDatum(atoi(remote_port));
772  }
773  else
774  {
775  nulls[12] = true;
776  nulls[13] = true;
777  nulls[14] = true;
778  }
779  }
780  else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
781  {
782  /*
783  * Unix sockets always reports NULL for host and -1 for
784  * port, so it's possible to tell the difference to
785  * connections we have no permissions to view, or with
786  * errors.
787  */
788  nulls[12] = true;
789  nulls[13] = true;
790  values[14] = Int32GetDatum(-1);
791  }
792  else
793  {
794  /* Unknown address type, should never happen */
795  nulls[12] = true;
796  nulls[13] = true;
797  nulls[14] = true;
798  }
799  }
800  /* Add backend type */
801  if (beentry->st_backendType == B_BG_WORKER)
802  {
803  const char *bgw_type;
804 
805  bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
806  if (bgw_type)
807  values[17] = CStringGetTextDatum(bgw_type);
808  else
809  nulls[17] = true;
810  }
811  else
812  values[17] =
814 
815  /* SSL information */
816  if (beentry->st_ssl)
817  {
818  values[18] = BoolGetDatum(true); /* ssl */
821  values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
822 
823  if (beentry->st_sslstatus->ssl_client_dn[0])
825  else
826  nulls[22] = true;
827 
828  if (beentry->st_sslstatus->ssl_client_serial[0])
832  Int32GetDatum(-1));
833  else
834  nulls[23] = true;
835 
836  if (beentry->st_sslstatus->ssl_issuer_dn[0])
838  else
839  nulls[24] = true;
840  }
841  else
842  {
843  values[18] = BoolGetDatum(false); /* ssl */
844  nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = true;
845  }
846 
847  /* GSSAPI information */
848  if (beentry->st_gss)
849  {
850  values[25] = BoolGetDatum(beentry->st_gssstatus->gss_auth); /* gss_auth */
852  values[27] = BoolGetDatum(beentry->st_gssstatus->gss_enc); /* GSS Encryption in use */
853  }
854  else
855  {
856  values[25] = BoolGetDatum(false); /* gss_auth */
857  nulls[26] = true; /* No GSS principal */
858  values[27] = BoolGetDatum(false); /* GSS Encryption not in
859  * use */
860  }
861  if (beentry->st_query_id == 0)
862  nulls[29] = true;
863  else
864  values[29] = UInt64GetDatum(beentry->st_query_id);
865  }
866  else
867  {
868  /* No permissions to view data about this session */
869  values[5] = CStringGetTextDatum("<insufficient privilege>");
870  nulls[4] = true;
871  nulls[6] = true;
872  nulls[7] = true;
873  nulls[8] = true;
874  nulls[9] = true;
875  nulls[10] = true;
876  nulls[11] = true;
877  nulls[12] = true;
878  nulls[13] = true;
879  nulls[14] = true;
880  nulls[17] = true;
881  nulls[18] = true;
882  nulls[19] = true;
883  nulls[20] = true;
884  nulls[21] = true;
885  nulls[22] = true;
886  nulls[23] = true;
887  nulls[24] = true;
888  nulls[25] = true;
889  nulls[26] = true;
890  nulls[27] = true;
891  nulls[28] = true;
892  nulls[29] = true;
893  }
894 
895  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
896 
897  /* If only a single backend was requested, and we found it, break. */
898  if (pid != -1)
899  break;
900  }
901 
902  return (Datum) 0;
903 }
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:617
int pgstat_fetch_stat_numbackends(void)
LocalPgBackendStatus * pgstat_fetch_stat_local_beentry(int beid)
char * pgstat_clip_activity(const char *raw_activity)
@ STATE_UNDEFINED
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_IDLE
@ STATE_IDLEINTRANSACTION
@ STATE_DISABLED
@ STATE_FASTPATH
@ STATE_RUNNING
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
Definition: bgworker.c:1282
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
unsigned int uint32
Definition: c.h:441
#define lengthof(array)
Definition: c.h:734
#define MemSet(start, val, len)
Definition: c.h:1008
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:631
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:635
void SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
#define NI_NUMERICHOST
Definition: getaddrinfo.h:78
#define NI_MAXHOST
Definition: getaddrinfo.h:88
#define NI_MAXSERV
Definition: getaddrinfo.h:91
#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
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1175
@ B_WAL_SENDER
Definition: miscadmin.h:335
@ B_BG_WORKER
Definition: miscadmin.h:330
@ B_BACKEND
Definition: miscadmin.h:329
const char * GetBackendTypeDesc(BackendType backendType)
Definition: miscinit.c:249
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:2103
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:121
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:35
#define PG_STAT_GET_ACTIVITY_COLS
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:37
#define TransactionIdGetDatum(X)
Definition: postgres.h:565
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define BoolGetDatum(X)
Definition: postgres.h:446
#define Int32GetDatum(X)
Definition: postgres.h:523
#define UInt64GetDatum(X)
Definition: postgres.h:692
#define InvalidOid
Definition: postgres_ext.h:36
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:3170
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:968
TransactionId backend_xid
PgBackendStatus backendStatus
TransactionId backend_xmin
Definition: proc.h:160
uint32 wait_event_info
Definition: proc.h:264
int pid
Definition: proc.h:184
PGPROC * lockGroupLeader
Definition: proc.h:289
char gss_princ[NAMEDATALEN]
char ssl_version[NAMEDATALEN]
char ssl_cipher[NAMEDATALEN]
char ssl_client_dn[NAMEDATALEN]
char ssl_client_serial[NAMEDATALEN]
char ssl_issuer_dn[NAMEDATALEN]
BackendType st_backendType
TimestampTz st_state_start_timestamp
TimestampTz st_proc_start_timestamp
PgBackendGSSStatus * st_gssstatus
BackendState st_state
TimestampTz st_activity_start_timestamp
SockAddr st_clientaddr
PgBackendSSLStatus * st_sslstatus
TimestampTz st_xact_start_timestamp
char * st_clienthostname
TupleDesc setDesc
Definition: execnodes.h:317
Tuplestorestate * setResult
Definition: execnodes.h:316
struct sockaddr_storage addr
Definition: pqcomm.h:64
socklen_t salen
Definition: pqcomm.h:65
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: wait_event.c:129
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: wait_event.c:74

References SockAddr::addr, 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, GetBackendTypeDesc(), GetBackgroundWorkerTypeByPid(), PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, HAS_PGSTAT_PERMISSIONS, i, inet_in(), Int32GetDatum, InvalidOid, lengthof, PGPROC::lockGroupLeader, MemSet, NI_MAXHOST, NI_MAXSERV, NI_NUMERICHOST, NI_NUMERICSERV, numeric_in(), ObjectIdGetDatum, pfree(), PG_ARGISNULL, PG_GETARG_INT32, pg_getnameinfo_all(), PG_STAT_GET_ACTIVITY_COLS, pgstat_clip_activity(), pgstat_fetch_stat_local_beentry(), pgstat_fetch_stat_numbackends(), pgstat_get_wait_event(), pgstat_get_wait_event_type(), PGPROC::pid, SockAddr::salen, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SetSingleFuncCall(), PgBackendSSLStatus::ssl_bits, PgBackendSSLStatus::ssl_cipher, PgBackendSSLStatus::ssl_client_dn, PgBackendSSLStatus::ssl_client_serial, 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_query_id, 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_putvalues(), UINT32_ACCESS_ONCE, UInt64GetDatum, values, and PGPROC::wait_event_info.

◆ pg_stat_get_analyze_count()

Datum pg_stat_get_analyze_count ( PG_FUNCTION_ARGS  )

Definition at line 349 of file pgstatfuncs.c.

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

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

◆ pg_stat_get_archiver()

Datum pg_stat_get_archiver ( PG_FUNCTION_ARGS  )

Definition at line 2201 of file pgstatfuncs.c.

2202 {
2203  TupleDesc tupdesc;
2204  Datum values[7];
2205  bool nulls[7];
2206  PgStat_ArchiverStats *archiver_stats;
2207 
2208  /* Initialise values and NULL flags arrays */
2209  MemSet(values, 0, sizeof(values));
2210  MemSet(nulls, 0, sizeof(nulls));
2211 
2212  /* Initialise attributes information in the tuple descriptor */
2213  tupdesc = CreateTemplateTupleDesc(7);
2214  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2215  INT8OID, -1, 0);
2216  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2217  TEXTOID, -1, 0);
2218  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2219  TIMESTAMPTZOID, -1, 0);
2220  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2221  INT8OID, -1, 0);
2222  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2223  TEXTOID, -1, 0);
2224  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2225  TIMESTAMPTZOID, -1, 0);
2226  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2227  TIMESTAMPTZOID, -1, 0);
2228 
2229  BlessTupleDesc(tupdesc);
2230 
2231  /* Get statistics about the archiver process */
2232  archiver_stats = pgstat_fetch_stat_archiver();
2233 
2234  /* Fill values and NULLs */
2235  values[0] = Int64GetDatum(archiver_stats->archived_count);
2236  if (*(archiver_stats->last_archived_wal) == '\0')
2237  nulls[1] = true;
2238  else
2239  values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2240 
2241  if (archiver_stats->last_archived_timestamp == 0)
2242  nulls[2] = true;
2243  else
2244  values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
2245 
2246  values[3] = Int64GetDatum(archiver_stats->failed_count);
2247  if (*(archiver_stats->last_failed_wal) == '\0')
2248  nulls[4] = true;
2249  else
2250  values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2251 
2252  if (archiver_stats->last_failed_timestamp == 0)
2253  nulls[5] = true;
2254  else
2255  values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2256 
2257  if (archiver_stats->stat_reset_timestamp == 0)
2258  nulls[6] = true;
2259  else
2260  values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2261 
2262  /* Returns the record as Datum */
2264 }
int16 AttrNumber
Definition: attnum.h:21
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
TimestampTz last_failed_timestamp
Definition: pgstat.h:256
TimestampTz stat_reset_timestamp
Definition: pgstat.h:257
TimestampTz last_archived_timestamp
Definition: pgstat.h:252
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:254
PgStat_Counter failed_count
Definition: pgstat.h:253
PgStat_Counter archived_count
Definition: pgstat.h:249
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:250
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583

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.

◆ pg_stat_get_autoanalyze_count()

Datum pg_stat_get_autoanalyze_count ( PG_FUNCTION_ARGS  )

Definition at line 364 of file pgstatfuncs.c.

365 {
366  Oid relid = PG_GETARG_OID(0);
367  int64 result;
368  PgStat_StatTabEntry *tabentry;
369 
370  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
371  result = 0;
372  else
373  result = (int64) (tabentry->autovac_analyze_count);
374 
375  PG_RETURN_INT64(result);
376 }
PgStat_Counter autovac_analyze_count
Definition: pgstat.h:382

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

◆ pg_stat_get_autovacuum_count()

Datum pg_stat_get_autovacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 334 of file pgstatfuncs.c.

335 {
336  Oid relid = PG_GETARG_OID(0);
337  int64 result;
338  PgStat_StatTabEntry *tabentry;
339 
340  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
341  result = 0;
342  else
343  result = (int64) (tabentry->autovac_vacuum_count);
344 
345  PG_RETURN_INT64(result);
346 }
PgStat_Counter autovac_vacuum_count
Definition: pgstat.h:378

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

◆ pg_stat_get_backend_activity()

Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 953 of file pgstatfuncs.c.

954 {
955  int32 beid = PG_GETARG_INT32(0);
956  PgBackendStatus *beentry;
957  const char *activity;
958  char *clipped_activity;
959  text *ret;
960 
961  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
962  activity = "<backend information not available>";
963  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
964  activity = "<insufficient privilege>";
965  else if (*(beentry->st_activity_raw) == '\0')
966  activity = "<command string not enabled>";
967  else
968  activity = beentry->st_activity_raw;
969 
970  clipped_activity = pgstat_clip_activity(activity);
971  ret = cstring_to_text(activity);
972  pfree(clipped_activity);
973 
974  PG_RETURN_TEXT_P(ret);
975 }
PgBackendStatus * pgstat_fetch_stat_beentry(int beid)
signed int int32
Definition: c.h:429
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
Definition: c.h:622
text * cstring_to_text(const char *s)
Definition: varlena.c:188

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

◆ pg_stat_get_backend_activity_start()

Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 1021 of file pgstatfuncs.c.

1022 {
1023  int32 beid = PG_GETARG_INT32(0);
1024  TimestampTz result;
1025  PgBackendStatus *beentry;
1026 
1027  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1028  PG_RETURN_NULL();
1029 
1030  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1031  PG_RETURN_NULL();
1032 
1033  result = beentry->st_activity_start_timestamp;
1034 
1035  /*
1036  * No time recorded for start of current query -- this is the case if the
1037  * user hasn't enabled query-level stats collection.
1038  */
1039  if (result == 0)
1040  PG_RETURN_NULL();
1041 
1042  PG_RETURN_TIMESTAMPTZ(result);
1043 }
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40

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

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 1091 of file pgstatfuncs.c.

1092 {
1093  int32 beid = PG_GETARG_INT32(0);
1094  PgBackendStatus *beentry;
1095  SockAddr zero_clientaddr;
1096  char remote_host[NI_MAXHOST];
1097  int ret;
1098 
1099  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1100  PG_RETURN_NULL();
1101 
1102  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1103  PG_RETURN_NULL();
1104 
1105  /* A zeroed client addr means we don't know */
1106  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1107  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1108  sizeof(zero_clientaddr)) == 0)
1109  PG_RETURN_NULL();
1110 
1111  switch (beentry->st_clientaddr.addr.ss_family)
1112  {
1113  case AF_INET:
1114 #ifdef HAVE_IPV6
1115  case AF_INET6:
1116 #endif
1117  break;
1118  default:
1119  PG_RETURN_NULL();
1120  }
1121 
1122  remote_host[0] = '\0';
1123  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1124  beentry->st_clientaddr.salen,
1125  remote_host, sizeof(remote_host),
1126  NULL, 0,
1128  if (ret != 0)
1129  PG_RETURN_NULL();
1130 
1131  clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
1132 
1134  CStringGetDatum(remote_host)));
1135 }
#define PG_RETURN_INET_P(x)
Definition: inet.h:125

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

◆ pg_stat_get_backend_client_port()

Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 1138 of file pgstatfuncs.c.

1139 {
1140  int32 beid = PG_GETARG_INT32(0);
1141  PgBackendStatus *beentry;
1142  SockAddr zero_clientaddr;
1143  char remote_port[NI_MAXSERV];
1144  int ret;
1145 
1146  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1147  PG_RETURN_NULL();
1148 
1149  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1150  PG_RETURN_NULL();
1151 
1152  /* A zeroed client addr means we don't know */
1153  memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
1154  if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
1155  sizeof(zero_clientaddr)) == 0)
1156  PG_RETURN_NULL();
1157 
1158  switch (beentry->st_clientaddr.addr.ss_family)
1159  {
1160  case AF_INET:
1161 #ifdef HAVE_IPV6
1162  case AF_INET6:
1163 #endif
1164  break;
1165  case AF_UNIX:
1166  PG_RETURN_INT32(-1);
1167  default:
1168  PG_RETURN_NULL();
1169  }
1170 
1171  remote_port[0] = '\0';
1172  ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1173  beentry->st_clientaddr.salen,
1174  NULL, 0,
1175  remote_port, sizeof(remote_port),
1177  if (ret != 0)
1178  PG_RETURN_NULL();
1179 
1181  CStringGetDatum(remote_port)));
1182 }
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:290

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

◆ pg_stat_get_backend_dbid()

Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 927 of file pgstatfuncs.c.

928 {
929  int32 beid = PG_GETARG_INT32(0);
930  PgBackendStatus *beentry;
931 
932  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
933  PG_RETURN_NULL();
934 
935  PG_RETURN_OID(beentry->st_databaseid);
936 }
#define PG_RETURN_OID(x)
Definition: fmgr.h:360

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

◆ pg_stat_get_backend_idset()

Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

Definition at line 414 of file pgstatfuncs.c.

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

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.

◆ pg_stat_get_backend_pid()

Datum pg_stat_get_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 914 of file pgstatfuncs.c.

915 {
916  int32 beid = PG_GETARG_INT32(0);
917  PgBackendStatus *beentry;
918 
919  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
920  PG_RETURN_NULL();
921 
922  PG_RETURN_INT32(beentry->st_procpid);
923 }

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

◆ pg_stat_get_backend_start()

Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 1069 of file pgstatfuncs.c.

1070 {
1071  int32 beid = PG_GETARG_INT32(0);
1072  TimestampTz result;
1073  PgBackendStatus *beentry;
1074 
1075  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1076  PG_RETURN_NULL();
1077 
1078  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1079  PG_RETURN_NULL();
1080 
1081  result = beentry->st_proc_start_timestamp;
1082 
1083  if (result == 0) /* probably can't happen? */
1084  PG_RETURN_NULL();
1085 
1086  PG_RETURN_TIMESTAMPTZ(result);
1087 }

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

◆ pg_stat_get_backend_userid()

Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 940 of file pgstatfuncs.c.

941 {
942  int32 beid = PG_GETARG_INT32(0);
943  PgBackendStatus *beentry;
944 
945  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
946  PG_RETURN_NULL();
947 
948  PG_RETURN_OID(beentry->st_userid);
949 }

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

◆ pg_stat_get_backend_wait_event()

Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 999 of file pgstatfuncs.c.

1000 {
1001  int32 beid = PG_GETARG_INT32(0);
1002  PgBackendStatus *beentry;
1003  PGPROC *proc;
1004  const char *wait_event = NULL;
1005 
1006  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1007  wait_event = "<backend information not available>";
1008  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1009  wait_event = "<insufficient privilege>";
1010  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
1011  wait_event = pgstat_get_wait_event(proc->wait_event_info);
1012 
1013  if (!wait_event)
1014  PG_RETURN_NULL();
1015 
1016  PG_RETURN_TEXT_P(cstring_to_text(wait_event));
1017 }

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

◆ pg_stat_get_backend_wait_event_type()

Datum pg_stat_get_backend_wait_event_type ( PG_FUNCTION_ARGS  )

Definition at line 978 of file pgstatfuncs.c.

979 {
980  int32 beid = PG_GETARG_INT32(0);
981  PgBackendStatus *beentry;
982  PGPROC *proc;
983  const char *wait_event_type = NULL;
984 
985  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
986  wait_event_type = "<backend information not available>";
987  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
988  wait_event_type = "<insufficient privilege>";
989  else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
990  wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
991 
992  if (!wait_event_type)
993  PG_RETURN_NULL();
994 
995  PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
996 }

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

◆ pg_stat_get_backend_xact_start()

Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 1047 of file pgstatfuncs.c.

1048 {
1049  int32 beid = PG_GETARG_INT32(0);
1050  TimestampTz result;
1051  PgBackendStatus *beentry;
1052 
1053  if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
1054  PG_RETURN_NULL();
1055 
1056  else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1057  PG_RETURN_NULL();
1058 
1059  result = beentry->st_xact_start_timestamp;
1060 
1061  if (result == 0) /* not in a transaction */
1062  PG_RETURN_NULL();
1063 
1064  PG_RETURN_TIMESTAMPTZ(result);
1065 }

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

◆ pg_stat_get_bgwriter_buf_written_checkpoints()

Datum pg_stat_get_bgwriter_buf_written_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1685 of file pgstatfuncs.c.

1686 {
1687  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buf_written_checkpoints);
1688 }
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1691 of file pgstatfuncs.c.

1692 {
1693  PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1694 }
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)

References PG_RETURN_INT64, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_bgwriter_maxwritten_clean()

Datum pg_stat_get_bgwriter_maxwritten_clean ( PG_FUNCTION_ARGS  )

Definition at line 1697 of file pgstatfuncs.c.

1698 {
1699  PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
1700 }

References PG_RETURN_INT64, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_bgwriter_requested_checkpoints()

Datum pg_stat_get_bgwriter_requested_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1679 of file pgstatfuncs.c.

1680 {
1681  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->requested_checkpoints);
1682 }

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_bgwriter_stat_reset_time()

Datum pg_stat_get_bgwriter_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1719 of file pgstatfuncs.c.

1720 {
1721  PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
1722 }

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_bgwriter_timed_checkpoints()

Datum pg_stat_get_bgwriter_timed_checkpoints ( PG_FUNCTION_ARGS  )

Definition at line 1673 of file pgstatfuncs.c.

1674 {
1675  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->timed_checkpoints);
1676 }

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_blocks_fetched()

Datum pg_stat_get_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 216 of file pgstatfuncs.c.

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_fetched);
226 
227  PG_RETURN_INT64(result);
228 }
PgStat_Counter blocks_fetched
Definition: pgstat.h:372

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

◆ pg_stat_get_blocks_hit()

Datum pg_stat_get_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 232 of file pgstatfuncs.c.

233 {
234  Oid relid = PG_GETARG_OID(0);
235  int64 result;
236  PgStat_StatTabEntry *tabentry;
237 
238  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
239  result = 0;
240  else
241  result = (int64) (tabentry->blocks_hit);
242 
243  PG_RETURN_INT64(result);
244 }
PgStat_Counter blocks_hit
Definition: pgstat.h:373

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

◆ pg_stat_get_buf_alloc()

Datum pg_stat_get_buf_alloc ( PG_FUNCTION_ARGS  )

Definition at line 1737 of file pgstatfuncs.c.

1738 {
1740 }

References PG_RETURN_INT64, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_buf_fsync_backend()

Datum pg_stat_get_buf_fsync_backend ( PG_FUNCTION_ARGS  )

Definition at line 1731 of file pgstatfuncs.c.

1732 {
1733  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buf_fsync_backend);
1734 }

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_buf_written_backend()

Datum pg_stat_get_buf_written_backend ( PG_FUNCTION_ARGS  )

Definition at line 1725 of file pgstatfuncs.c.

1726 {
1727  PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buf_written_backend);
1728 }

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpoint_sync_time()

Datum pg_stat_get_checkpoint_sync_time ( PG_FUNCTION_ARGS  )

Definition at line 1711 of file pgstatfuncs.c.

1712 {
1713  /* time is already in msec, just convert to double for presentation */
1714  PG_RETURN_FLOAT8((double)
1715  pgstat_fetch_stat_checkpointer()->checkpoint_sync_time);
1716 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367

References PG_RETURN_FLOAT8, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpoint_write_time()

Datum pg_stat_get_checkpoint_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1703 of file pgstatfuncs.c.

1704 {
1705  /* time is already in msec, just convert to double for presentation */
1706  PG_RETURN_FLOAT8((double)
1707  pgstat_fetch_stat_checkpointer()->checkpoint_write_time);
1708 }

References PG_RETURN_FLOAT8, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_db_active_time()

Datum pg_stat_get_db_active_time ( PG_FUNCTION_ARGS  )

Definition at line 1593 of file pgstatfuncs.c.

1594 {
1595  Oid dbid = PG_GETARG_OID(0);
1596  double result = 0.0;
1597  PgStat_StatDBEntry *dbentry;
1598 
1599  /* convert counter from microsec to millisec for display */
1600  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1601  result = ((double) dbentry->total_active_time) / 1000.0;
1602 
1603  PG_RETURN_FLOAT8(result);
1604 }
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
PgStat_Counter total_active_time
Definition: pgstat.h:305

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

◆ pg_stat_get_db_blk_read_time()

Datum pg_stat_get_db_blk_read_time ( PG_FUNCTION_ARGS  )

Definition at line 1547 of file pgstatfuncs.c.

1548 {
1549  Oid dbid = PG_GETARG_OID(0);
1550  double result;
1551  PgStat_StatDBEntry *dbentry;
1552 
1553  /* convert counter from microsec to millisec for display */
1554  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1555  result = 0;
1556  else
1557  result = ((double) dbentry->n_block_read_time) / 1000.0;
1558 
1559  PG_RETURN_FLOAT8(result);
1560 }
PgStat_Counter n_block_read_time
Definition: pgstat.h:301

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

◆ pg_stat_get_db_blk_write_time()

Datum pg_stat_get_db_blk_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1563 of file pgstatfuncs.c.

1564 {
1565  Oid dbid = PG_GETARG_OID(0);
1566  double result;
1567  PgStat_StatDBEntry *dbentry;
1568 
1569  /* convert counter from microsec to millisec for display */
1570  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1571  result = 0;
1572  else
1573  result = ((double) dbentry->n_block_write_time) / 1000.0;
1574 
1575  PG_RETURN_FLOAT8(result);
1576 }
PgStat_Counter n_block_write_time
Definition: pgstat.h:302

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

◆ pg_stat_get_db_blocks_fetched()

Datum pg_stat_get_db_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1239 of file pgstatfuncs.c.

1240 {
1241  Oid dbid = PG_GETARG_OID(0);
1242  int64 result;
1243  PgStat_StatDBEntry *dbentry;
1244 
1245  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1246  result = 0;
1247  else
1248  result = (int64) (dbentry->n_blocks_fetched);
1249 
1250  PG_RETURN_INT64(result);
1251 }
PgStat_Counter n_blocks_fetched
Definition: pgstat.h:283

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

◆ pg_stat_get_db_blocks_hit()

Datum pg_stat_get_db_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file pgstatfuncs.c.

1256 {
1257  Oid dbid = PG_GETARG_OID(0);
1258  int64 result;
1259  PgStat_StatDBEntry *dbentry;
1260 
1261  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1262  result = 0;
1263  else
1264  result = (int64) (dbentry->n_blocks_hit);
1265 
1266  PG_RETURN_INT64(result);
1267 }
PgStat_Counter n_blocks_hit
Definition: pgstat.h:284

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

◆ pg_stat_get_db_checksum_failures()

Datum pg_stat_get_db_checksum_failures ( PG_FUNCTION_ARGS  )

Definition at line 1508 of file pgstatfuncs.c.

1509 {
1510  Oid dbid = PG_GETARG_OID(0);
1511  int64 result;
1512  PgStat_StatDBEntry *dbentry;
1513 
1514  if (!DataChecksumsEnabled())
1515  PG_RETURN_NULL();
1516 
1517  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1518  result = 0;
1519  else
1520  result = (int64) (dbentry->n_checksum_failures);
1521 
1522  PG_RETURN_INT64(result);
1523 }
PgStat_Counter n_checksum_failures
Definition: pgstat.h:299
bool DataChecksumsEnabled(void)
Definition: xlog.c:4226

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

◆ pg_stat_get_db_checksum_last_failure()

Datum pg_stat_get_db_checksum_last_failure ( PG_FUNCTION_ARGS  )

Definition at line 1526 of file pgstatfuncs.c.

1527 {
1528  Oid dbid = PG_GETARG_OID(0);
1529  TimestampTz result;
1530  PgStat_StatDBEntry *dbentry;
1531 
1532  if (!DataChecksumsEnabled())
1533  PG_RETURN_NULL();
1534 
1535  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1536  result = 0;
1537  else
1538  result = dbentry->last_checksum_failure;
1539 
1540  if (result == 0)
1541  PG_RETURN_NULL();
1542  else
1543  PG_RETURN_TIMESTAMPTZ(result);
1544 }
TimestampTz last_checksum_failure
Definition: pgstat.h:300

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

◆ pg_stat_get_db_conflict_all()

Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

Definition at line 1474 of file pgstatfuncs.c.

1475 {
1476  Oid dbid = PG_GETARG_OID(0);
1477  int64 result;
1478  PgStat_StatDBEntry *dbentry;
1479 
1480  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1481  result = 0;
1482  else
1483  result = (int64) (dbentry->n_conflict_tablespace +
1484  dbentry->n_conflict_lock +
1485  dbentry->n_conflict_snapshot +
1486  dbentry->n_conflict_bufferpin +
1487  dbentry->n_conflict_startup_deadlock);
1488 
1489  PG_RETURN_INT64(result);
1490 }
PgStat_Counter n_conflict_lock
Definition: pgstat.h:292
PgStat_Counter n_conflict_tablespace
Definition: pgstat.h:291
PgStat_Counter n_conflict_bufferpin
Definition: pgstat.h:294
PgStat_Counter n_conflict_startup_deadlock
Definition: pgstat.h:295
PgStat_Counter n_conflict_snapshot
Definition: pgstat.h:293

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().

◆ pg_stat_get_db_conflict_bufferpin()

Datum pg_stat_get_db_conflict_bufferpin ( PG_FUNCTION_ARGS  )

Definition at line 1444 of file pgstatfuncs.c.

1445 {
1446  Oid dbid = PG_GETARG_OID(0);
1447  int64 result;
1448  PgStat_StatDBEntry *dbentry;
1449 
1450  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1451  result = 0;
1452  else
1453  result = (int64) (dbentry->n_conflict_bufferpin);
1454 
1455  PG_RETURN_INT64(result);
1456 }

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

◆ pg_stat_get_db_conflict_lock()

Datum pg_stat_get_db_conflict_lock ( PG_FUNCTION_ARGS  )

Definition at line 1414 of file pgstatfuncs.c.

1415 {
1416  Oid dbid = PG_GETARG_OID(0);
1417  int64 result;
1418  PgStat_StatDBEntry *dbentry;
1419 
1420  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1421  result = 0;
1422  else
1423  result = (int64) (dbentry->n_conflict_lock);
1424 
1425  PG_RETURN_INT64(result);
1426 }

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

◆ pg_stat_get_db_conflict_snapshot()

Datum pg_stat_get_db_conflict_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1429 of file pgstatfuncs.c.

1430 {
1431  Oid dbid = PG_GETARG_OID(0);
1432  int64 result;
1433  PgStat_StatDBEntry *dbentry;
1434 
1435  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1436  result = 0;
1437  else
1438  result = (int64) (dbentry->n_conflict_snapshot);
1439 
1440  PG_RETURN_INT64(result);
1441 }

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

◆ pg_stat_get_db_conflict_startup_deadlock()

Datum pg_stat_get_db_conflict_startup_deadlock ( PG_FUNCTION_ARGS  )

Definition at line 1459 of file pgstatfuncs.c.

1460 {
1461  Oid dbid = PG_GETARG_OID(0);
1462  int64 result;
1463  PgStat_StatDBEntry *dbentry;
1464 
1465  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1466  result = 0;
1467  else
1468  result = (int64) (dbentry->n_conflict_startup_deadlock);
1469 
1470  PG_RETURN_INT64(result);
1471 }

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

◆ pg_stat_get_db_conflict_tablespace()

Datum pg_stat_get_db_conflict_tablespace ( PG_FUNCTION_ARGS  )

Definition at line 1399 of file pgstatfuncs.c.

1400 {
1401  Oid dbid = PG_GETARG_OID(0);
1402  int64 result;
1403  PgStat_StatDBEntry *dbentry;
1404 
1405  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1406  result = 0;
1407  else
1408  result = (int64) (dbentry->n_conflict_tablespace);
1409 
1410  PG_RETURN_INT64(result);
1411 }

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

◆ pg_stat_get_db_deadlocks()

Datum pg_stat_get_db_deadlocks ( PG_FUNCTION_ARGS  )

Definition at line 1493 of file pgstatfuncs.c.

1494 {
1495  Oid dbid = PG_GETARG_OID(0);
1496  int64 result;
1497  PgStat_StatDBEntry *dbentry;
1498 
1499  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1500  result = 0;
1501  else
1502  result = (int64) (dbentry->n_deadlocks);
1503 
1504  PG_RETURN_INT64(result);
1505 }
PgStat_Counter n_deadlocks
Definition: pgstat.h:298

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

◆ pg_stat_get_db_idle_in_transaction_time()

Datum pg_stat_get_db_idle_in_transaction_time ( PG_FUNCTION_ARGS  )

Definition at line 1607 of file pgstatfuncs.c.

1608 {
1609  Oid dbid = PG_GETARG_OID(0);
1610  double result = 0.0;
1611  PgStat_StatDBEntry *dbentry;
1612 
1613  /* convert counter from microsec to millisec for display */
1614  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1615  result = ((double) dbentry->total_idle_in_xact_time) / 1000.0;
1616 
1617  PG_RETURN_FLOAT8(result);
1618 }
PgStat_Counter total_idle_in_xact_time
Definition: pgstat.h:306

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

◆ pg_stat_get_db_numbackends()

Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1186 of file pgstatfuncs.c.

1187 {
1188  Oid dbid = PG_GETARG_OID(0);
1189  int32 result;
1190  int tot_backends = pgstat_fetch_stat_numbackends();
1191  int beid;
1192 
1193  result = 0;
1194  for (beid = 1; beid <= tot_backends; beid++)
1195  {
1196  PgBackendStatus *beentry = pgstat_fetch_stat_beentry(beid);
1197 
1198  if (beentry && beentry->st_databaseid == dbid)
1199  result++;
1200  }
1201 
1202  PG_RETURN_INT32(result);
1203 }

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

◆ pg_stat_get_db_session_time()

Datum pg_stat_get_db_session_time ( PG_FUNCTION_ARGS  )

Definition at line 1579 of file pgstatfuncs.c.

1580 {
1581  Oid dbid = PG_GETARG_OID(0);
1582  double result = 0.0;
1583  PgStat_StatDBEntry *dbentry;
1584 
1585  /* convert counter from microsec to millisec for display */
1586  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1587  result = ((double) dbentry->total_session_time) / 1000.0;
1588 
1589  PG_RETURN_FLOAT8(result);
1590 }
PgStat_Counter total_session_time
Definition: pgstat.h:304

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

◆ pg_stat_get_db_sessions()

Datum pg_stat_get_db_sessions ( PG_FUNCTION_ARGS  )

Definition at line 1621 of file pgstatfuncs.c.

1622 {
1623  Oid dbid = PG_GETARG_OID(0);
1624  int64 result = 0;
1625  PgStat_StatDBEntry *dbentry;
1626 
1627  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1628  result = (int64) (dbentry->n_sessions);
1629 
1630  PG_RETURN_INT64(result);
1631 }
PgStat_Counter n_sessions
Definition: pgstat.h:303

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

◆ pg_stat_get_db_sessions_abandoned()

Datum pg_stat_get_db_sessions_abandoned ( PG_FUNCTION_ARGS  )

Definition at line 1634 of file pgstatfuncs.c.

1635 {
1636  Oid dbid = PG_GETARG_OID(0);
1637  int64 result = 0;
1638  PgStat_StatDBEntry *dbentry;
1639 
1640  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1641  result = (int64) (dbentry->n_sessions_abandoned);
1642 
1643  PG_RETURN_INT64(result);
1644 }
PgStat_Counter n_sessions_abandoned
Definition: pgstat.h:307

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

◆ pg_stat_get_db_sessions_fatal()

Datum pg_stat_get_db_sessions_fatal ( PG_FUNCTION_ARGS  )

Definition at line 1647 of file pgstatfuncs.c.

1648 {
1649  Oid dbid = PG_GETARG_OID(0);
1650  int64 result = 0;
1651  PgStat_StatDBEntry *dbentry;
1652 
1653  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1654  result = (int64) (dbentry->n_sessions_fatal);
1655 
1656  PG_RETURN_INT64(result);
1657 }
PgStat_Counter n_sessions_fatal
Definition: pgstat.h:308

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

◆ pg_stat_get_db_sessions_killed()

Datum pg_stat_get_db_sessions_killed ( PG_FUNCTION_ARGS  )

Definition at line 1660 of file pgstatfuncs.c.

1661 {
1662  Oid dbid = PG_GETARG_OID(0);
1663  int64 result = 0;
1664  PgStat_StatDBEntry *dbentry;
1665 
1666  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) != NULL)
1667  result = (int64) (dbentry->n_sessions_killed);
1668 
1669  PG_RETURN_INT64(result);
1670 }
PgStat_Counter n_sessions_killed
Definition: pgstat.h:309

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

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1350 of file pgstatfuncs.c.

1351 {
1352  Oid dbid = PG_GETARG_OID(0);
1353  TimestampTz result;
1354  PgStat_StatDBEntry *dbentry;
1355 
1356  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1357  result = 0;
1358  else
1359  result = dbentry->stat_reset_timestamp;
1360 
1361  if (result == 0)
1362  PG_RETURN_NULL();
1363  else
1364  PG_RETURN_TIMESTAMPTZ(result);
1365 }
TimestampTz stat_reset_timestamp
Definition: pgstat.h:311

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

◆ pg_stat_get_db_temp_bytes()

Datum pg_stat_get_db_temp_bytes ( PG_FUNCTION_ARGS  )

Definition at line 1384 of file pgstatfuncs.c.

1385 {
1386  Oid dbid = PG_GETARG_OID(0);
1387  int64 result;
1388  PgStat_StatDBEntry *dbentry;
1389 
1390  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1391  result = 0;
1392  else
1393  result = dbentry->n_temp_bytes;
1394 
1395  PG_RETURN_INT64(result);
1396 }
PgStat_Counter n_temp_bytes
Definition: pgstat.h:297

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

◆ pg_stat_get_db_temp_files()

Datum pg_stat_get_db_temp_files ( PG_FUNCTION_ARGS  )

Definition at line 1368 of file pgstatfuncs.c.

1369 {
1370  Oid dbid = PG_GETARG_OID(0);
1371  int64 result;
1372  PgStat_StatDBEntry *dbentry;
1373 
1374  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1375  result = 0;
1376  else
1377  result = dbentry->n_temp_files;
1378 
1379  PG_RETURN_INT64(result);
1380 }
PgStat_Counter n_temp_files
Definition: pgstat.h:296

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

◆ pg_stat_get_db_tuples_deleted()

Datum pg_stat_get_db_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1335 of file pgstatfuncs.c.

1336 {
1337  Oid dbid = PG_GETARG_OID(0);
1338  int64 result;
1339  PgStat_StatDBEntry *dbentry;
1340 
1341  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1342  result = 0;
1343  else
1344  result = (int64) (dbentry->n_tuples_deleted);
1345 
1346  PG_RETURN_INT64(result);
1347 }
PgStat_Counter n_tuples_deleted
Definition: pgstat.h:289

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

◆ pg_stat_get_db_tuples_fetched()

Datum pg_stat_get_db_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1287 of file pgstatfuncs.c.

1288 {
1289  Oid dbid = PG_GETARG_OID(0);
1290  int64 result;
1291  PgStat_StatDBEntry *dbentry;
1292 
1293  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1294  result = 0;
1295  else
1296  result = (int64) (dbentry->n_tuples_fetched);
1297 
1298  PG_RETURN_INT64(result);
1299 }
PgStat_Counter n_tuples_fetched
Definition: pgstat.h:286

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

◆ pg_stat_get_db_tuples_inserted()

Datum pg_stat_get_db_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1303 of file pgstatfuncs.c.

1304 {
1305  Oid dbid = PG_GETARG_OID(0);
1306  int64 result;
1307  PgStat_StatDBEntry *dbentry;
1308 
1309  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1310  result = 0;
1311  else
1312  result = (int64) (dbentry->n_tuples_inserted);
1313 
1314  PG_RETURN_INT64(result);
1315 }
PgStat_Counter n_tuples_inserted
Definition: pgstat.h:287

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

◆ pg_stat_get_db_tuples_returned()

Datum pg_stat_get_db_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1271 of file pgstatfuncs.c.

1272 {
1273  Oid dbid = PG_GETARG_OID(0);
1274  int64 result;
1275  PgStat_StatDBEntry *dbentry;
1276 
1277  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1278  result = 0;
1279  else
1280  result = (int64) (dbentry->n_tuples_returned);
1281 
1282  PG_RETURN_INT64(result);
1283 }
PgStat_Counter n_tuples_returned
Definition: pgstat.h:285

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

◆ pg_stat_get_db_tuples_updated()

Datum pg_stat_get_db_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1319 of file pgstatfuncs.c.

1320 {
1321  Oid dbid = PG_GETARG_OID(0);
1322  int64 result;
1323  PgStat_StatDBEntry *dbentry;
1324 
1325  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1326  result = 0;
1327  else
1328  result = (int64) (dbentry->n_tuples_updated);
1329 
1330  PG_RETURN_INT64(result);
1331 }
PgStat_Counter n_tuples_updated
Definition: pgstat.h:288

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

◆ pg_stat_get_db_xact_commit()

Datum pg_stat_get_db_xact_commit ( PG_FUNCTION_ARGS  )

Definition at line 1207 of file pgstatfuncs.c.

1208 {
1209  Oid dbid = PG_GETARG_OID(0);
1210  int64 result;
1211  PgStat_StatDBEntry *dbentry;
1212 
1213  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1214  result = 0;
1215  else
1216  result = (int64) (dbentry->n_xact_commit);
1217 
1218  PG_RETURN_INT64(result);
1219 }
PgStat_Counter n_xact_commit
Definition: pgstat.h:281

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

◆ pg_stat_get_db_xact_rollback()

Datum pg_stat_get_db_xact_rollback ( PG_FUNCTION_ARGS  )

Definition at line 1223 of file pgstatfuncs.c.

1224 {
1225  Oid dbid = PG_GETARG_OID(0);
1226  int64 result;
1227  PgStat_StatDBEntry *dbentry;
1228 
1229  if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1230  result = 0;
1231  else
1232  result = (int64) (dbentry->n_xact_rollback);
1233 
1234  PG_RETURN_INT64(result);
1235 }
PgStat_Counter n_xact_rollback
Definition: pgstat.h:282

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

◆ pg_stat_get_dead_tuples()

Datum pg_stat_get_dead_tuples ( PG_FUNCTION_ARGS  )

Definition at line 168 of file pgstatfuncs.c.

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 }
PgStat_Counter n_dead_tuples
Definition: pgstat.h:368

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

◆ pg_stat_get_function_calls()

Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 379 of file pgstatfuncs.c.

380 {
381  Oid funcid = PG_GETARG_OID(0);
382  PgStat_StatFuncEntry *funcentry;
383 
384  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
385  PG_RETURN_NULL();
386  PG_RETURN_INT64(funcentry->f_numcalls);
387 }
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
PgStat_Counter f_numcalls
Definition: pgstat.h:316

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

◆ pg_stat_get_function_self_time()

Datum pg_stat_get_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 402 of file pgstatfuncs.c.

403 {
404  Oid funcid = PG_GETARG_OID(0);
405  PgStat_StatFuncEntry *funcentry;
406 
407  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
408  PG_RETURN_NULL();
409  /* convert counter from microsec to millisec for display */
410  PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
411 }
PgStat_Counter f_self_time
Definition: pgstat.h:319

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

◆ pg_stat_get_function_total_time()

Datum pg_stat_get_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 390 of file pgstatfuncs.c.

391 {
392  Oid funcid = PG_GETARG_OID(0);
393  PgStat_StatFuncEntry *funcentry;
394 
395  if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
396  PG_RETURN_NULL();
397  /* convert counter from microsec to millisec for display */
398  PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
399 }
PgStat_Counter f_total_time
Definition: pgstat.h:318

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

◆ pg_stat_get_ins_since_vacuum()

Datum pg_stat_get_ins_since_vacuum ( PG_FUNCTION_ARGS  )

Definition at line 200 of file pgstatfuncs.c.

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->inserts_since_vacuum);
210 
211  PG_RETURN_INT64(result);
212 }
PgStat_Counter inserts_since_vacuum
Definition: pgstat.h:370

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

◆ pg_stat_get_last_analyze_time()

Datum pg_stat_get_last_analyze_time ( PG_FUNCTION_ARGS  )

Definition at line 283 of file pgstatfuncs.c.

284 {
285  Oid relid = PG_GETARG_OID(0);
286  TimestampTz result;
287  PgStat_StatTabEntry *tabentry;
288 
289  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
290  result = 0;
291  else
292  result = tabentry->analyze_timestamp;
293 
294  if (result == 0)
295  PG_RETURN_NULL();
296  else
297  PG_RETURN_TIMESTAMPTZ(result);
298 }
TimestampTz analyze_timestamp
Definition: pgstat.h:379

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

◆ pg_stat_get_last_autoanalyze_time()

Datum pg_stat_get_last_autoanalyze_time ( PG_FUNCTION_ARGS  )

Definition at line 301 of file pgstatfuncs.c.

302 {
303  Oid relid = PG_GETARG_OID(0);
304  TimestampTz result;
305  PgStat_StatTabEntry *tabentry;
306 
307  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
308  result = 0;
309  else
310  result = tabentry->autovac_analyze_timestamp;
311 
312  if (result == 0)
313  PG_RETURN_NULL();
314  else
315  PG_RETURN_TIMESTAMPTZ(result);
316 }
TimestampTz autovac_analyze_timestamp
Definition: pgstat.h:381

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

◆ pg_stat_get_last_autovacuum_time()

Datum pg_stat_get_last_autovacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 265 of file pgstatfuncs.c.

266 {
267  Oid relid = PG_GETARG_OID(0);
268  TimestampTz result;
269  PgStat_StatTabEntry *tabentry;
270 
271  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
272  result = 0;
273  else
274  result = tabentry->autovac_vacuum_timestamp;
275 
276  if (result == 0)
277  PG_RETURN_NULL();
278  else
279  PG_RETURN_TIMESTAMPTZ(result);
280 }
TimestampTz autovac_vacuum_timestamp
Definition: pgstat.h:377

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

◆ pg_stat_get_last_vacuum_time()

Datum pg_stat_get_last_vacuum_time ( PG_FUNCTION_ARGS  )

Definition at line 247 of file pgstatfuncs.c.

248 {
249  Oid relid = PG_GETARG_OID(0);
250  TimestampTz result;
251  PgStat_StatTabEntry *tabentry;
252 
253  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
254  result = 0;
255  else
256  result = tabentry->vacuum_timestamp;
257 
258  if (result == 0)
259  PG_RETURN_NULL();
260  else
261  PG_RETURN_TIMESTAMPTZ(result);
262 }
TimestampTz vacuum_timestamp
Definition: pgstat.h:375

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

◆ pg_stat_get_live_tuples()

Datum pg_stat_get_live_tuples ( PG_FUNCTION_ARGS  )

Definition at line 152 of file pgstatfuncs.c.

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 }
PgStat_Counter n_live_tuples
Definition: pgstat.h:367

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

◆ pg_stat_get_mod_since_analyze()

Datum pg_stat_get_mod_since_analyze ( PG_FUNCTION_ARGS  )

Definition at line 184 of file pgstatfuncs.c.

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 }
PgStat_Counter changes_since_analyze
Definition: pgstat.h:369

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

◆ pg_stat_get_numscans()

Datum pg_stat_get_numscans ( PG_FUNCTION_ARGS  )

Definition at line 40 of file pgstatfuncs.c.

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 }
PgStat_Counter numscans
Definition: pgstat.h:357

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

◆ pg_stat_get_progress_info()

Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 457 of file pgstatfuncs.c.

458 {
459 #define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
460  int num_backends = pgstat_fetch_stat_numbackends();
461  int curr_backend;
462  char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
463  ProgressCommandType cmdtype;
464  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
465 
466  /* Translate command name into command type code. */
467  if (pg_strcasecmp(cmd, "VACUUM") == 0)
468  cmdtype = PROGRESS_COMMAND_VACUUM;
469  else if (pg_strcasecmp(cmd, "ANALYZE") == 0)
470  cmdtype = PROGRESS_COMMAND_ANALYZE;
471  else if (pg_strcasecmp(cmd, "CLUSTER") == 0)
472  cmdtype = PROGRESS_COMMAND_CLUSTER;
473  else if (pg_strcasecmp(cmd, "CREATE INDEX") == 0)
475  else if (pg_strcasecmp(cmd, "BASEBACKUP") == 0)
476  cmdtype = PROGRESS_COMMAND_BASEBACKUP;
477  else if (pg_strcasecmp(cmd, "COPY") == 0)
478  cmdtype = PROGRESS_COMMAND_COPY;
479  else
480  ereport(ERROR,
481  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
482  errmsg("invalid command name: \"%s\"", cmd)));
483 
484  SetSingleFuncCall(fcinfo, 0);
485 
486  /* 1-based index */
487  for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
488  {
489  LocalPgBackendStatus *local_beentry;
490  PgBackendStatus *beentry;
492  bool nulls[PG_STAT_GET_PROGRESS_COLS];
493  int i;
494 
495  MemSet(values, 0, sizeof(values));
496  MemSet(nulls, 0, sizeof(nulls));
497 
498  local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
499 
500  if (!local_beentry)
501  continue;
502 
503  beentry = &local_beentry->backendStatus;
504 
505  /*
506  * Report values for only those backends which are running the given
507  * command.
508  */
509  if (!beentry || beentry->st_progress_command != cmdtype)
510  continue;
511 
512  /* Value available to all callers */
513  values[0] = Int32GetDatum(beentry->st_procpid);
514  values[1] = ObjectIdGetDatum(beentry->st_databaseid);
515 
516  /* show rest of the values including relid only to role members */
517  if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
518  {
520  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
521  values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
522  }
523  else
524  {
525  nulls[2] = true;
526  for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
527  nulls[i + 3] = true;
528  }
529 
530  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
531  }
532 
533  return (Datum) 0;
534 }
#define PGSTAT_NUM_PROGRESS_PARAM
ProgressCommandType
@ PROGRESS_COMMAND_ANALYZE
@ PROGRESS_COMMAND_CLUSTER
@ PROGRESS_COMMAND_CREATE_INDEX
@ PROGRESS_COMMAND_VACUUM
@ PROGRESS_COMMAND_BASEBACKUP
@ PROGRESS_COMMAND_COPY
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_STAT_GET_PROGRESS_COLS
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
ProgressCommandType st_progress_command
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Oid st_progress_command_target
char * text_to_cstring(const text *t)
Definition: varlena.c:221

References LocalPgBackendStatus::backendStatus, ereport, errcode(), errmsg(), ERROR, HAS_PGSTAT_PERMISSIONS, i, if(), Int32GetDatum, Int64GetDatum(), MemSet, ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_STAT_GET_PROGRESS_COLS, pg_strcasecmp(), pgstat_fetch_stat_local_beentry(), pgstat_fetch_stat_numbackends(), PGSTAT_NUM_PROGRESS_PARAM, PROGRESS_COMMAND_ANALYZE, PROGRESS_COMMAND_BASEBACKUP, PROGRESS_COMMAND_CLUSTER, PROGRESS_COMMAND_COPY, PROGRESS_COMMAND_CREATE_INDEX, PROGRESS_COMMAND_VACUUM, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SetSingleFuncCall(), 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_putvalues(), and values.

◆ pg_stat_get_replication_slot()

Datum pg_stat_get_replication_slot ( PG_FUNCTION_ARGS  )

Definition at line 2271 of file pgstatfuncs.c.

2272 {
2273 #define PG_STAT_GET_REPLICATION_SLOT_COLS 10
2274  text *slotname_text = PG_GETARG_TEXT_P(0);
2275  NameData slotname;
2276  TupleDesc tupdesc;
2279  PgStat_StatReplSlotEntry *slotent;
2280  PgStat_StatReplSlotEntry allzero;
2281 
2282  /* Initialise values and NULL flags arrays */
2283  MemSet(values, 0, sizeof(values));
2284  MemSet(nulls, 0, sizeof(nulls));
2285 
2286  /* Initialise attributes information in the tuple descriptor */
2288  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
2289  TEXTOID, -1, 0);
2290  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "spill_txns",
2291  INT8OID, -1, 0);
2292  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "spill_count",
2293  INT8OID, -1, 0);
2294  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "spill_bytes",
2295  INT8OID, -1, 0);
2296  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stream_txns",
2297  INT8OID, -1, 0);
2298  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stream_count",
2299  INT8OID, -1, 0);
2300  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
2301  INT8OID, -1, 0);
2302  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
2303  INT8OID, -1, 0);
2304  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
2305  INT8OID, -1, 0);
2306  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
2307  TIMESTAMPTZOID, -1, 0);
2308  BlessTupleDesc(tupdesc);
2309 
2310  namestrcpy(&slotname, text_to_cstring(slotname_text));
2311  slotent = pgstat_fetch_replslot(slotname);
2312  if (!slotent)
2313  {
2314  /*
2315  * If the slot is not found, initialise its stats. This is possible if
2316  * the create slot message is lost.
2317  */
2318  memset(&allzero, 0, sizeof(PgStat_StatReplSlotEntry));
2319  slotent = &allzero;
2320  }
2321 
2322  values[0] = CStringGetTextDatum(NameStr(slotname));
2323  values[1] = Int64GetDatum(slotent->spill_txns);
2324  values[2] = Int64GetDatum(slotent->spill_count);
2325  values[3] = Int64GetDatum(slotent->spill_bytes);
2326  values[4] = Int64GetDatum(slotent->stream_txns);
2327  values[5] = Int64GetDatum(slotent->stream_count);
2328  values[6] = Int64GetDatum(slotent->stream_bytes);
2329  values[7] = Int64GetDatum(slotent->total_txns);
2330  values[8] = Int64GetDatum(slotent->total_bytes);
2331 
2332  if (slotent->stat_reset_timestamp == 0)
2333  nulls[9] = true;
2334  else
2336 
2337  /* Returns the record as Datum */
2339 }
#define NameStr(name)
Definition: c.h:681
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
void namestrcpy(Name name, const char *str)
Definition: name.c:233
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
#define PG_STAT_GET_REPLICATION_SLOT_COLS
TimestampTz stat_reset_timestamp
Definition: pgstat.h:333
PgStat_Counter stream_count
Definition: pgstat.h:329
PgStat_Counter total_txns
Definition: pgstat.h:331
PgStat_Counter total_bytes
Definition: pgstat.h:332
PgStat_Counter spill_txns
Definition: pgstat.h:325
PgStat_Counter stream_txns
Definition: pgstat.h:328
PgStat_Counter spill_count
Definition: pgstat.h:326
PgStat_Counter stream_bytes
Definition: pgstat.h:330
PgStat_Counter spill_bytes
Definition: pgstat.h:327
Definition: c.h:676

References BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, heap_form_tuple(), HeapTupleGetDatum, Int64GetDatum(), MemSet, NameStr, namestrcpy(), PG_GETARG_TEXT_P, PG_RETURN_DATUM, PG_STAT_GET_REPLICATION_SLOT_COLS, pgstat_fetch_replslot(), PgStat_StatReplSlotEntry::spill_bytes, PgStat_StatReplSlotEntry::spill_count, PgStat_StatReplSlotEntry::spill_txns, PgStat_StatReplSlotEntry::stat_reset_timestamp, PgStat_StatReplSlotEntry::stream_bytes, PgStat_StatReplSlotEntry::stream_count, PgStat_StatReplSlotEntry::stream_txns, text_to_cstring(), TimestampTzGetDatum, PgStat_StatReplSlotEntry::total_bytes, PgStat_StatReplSlotEntry::total_txns, TupleDescInitEntry(), and values.

◆ pg_stat_get_slru()

Datum pg_stat_get_slru ( PG_FUNCTION_ARGS  )

Definition at line 1814 of file pgstatfuncs.c.

1815 {
1816 #define PG_STAT_GET_SLRU_COLS 9
1817  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1818  int i;
1819  PgStat_SLRUStats *stats;
1820 
1821  SetSingleFuncCall(fcinfo, 0);
1822 
1823  /* request SLRU stats from the cumulative stats system */
1824  stats = pgstat_fetch_slru();
1825 
1826  for (i = 0;; i++)
1827  {
1828  /* for each row */
1830  bool nulls[PG_STAT_GET_SLRU_COLS];
1832  const char *name;
1833 
1835 
1836  if (!name)
1837  break;
1838 
1839  stat = stats[i];
1840  MemSet(values, 0, sizeof(values));
1841  MemSet(nulls, 0, sizeof(nulls));
1842 
1844  values[1] = Int64GetDatum(stat.blocks_zeroed);
1845  values[2] = Int64GetDatum(stat.blocks_hit);
1846  values[3] = Int64GetDatum(stat.blocks_read);
1847  values[4] = Int64GetDatum(stat.blocks_written);
1848  values[5] = Int64GetDatum(stat.blocks_exists);
1849  values[6] = Int64GetDatum(stat.flush);
1850  values[7] = Int64GetDatum(stat.truncate);
1851  values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1852 
1853  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1854  }
1855 
1856  return (Datum) 0;
1857 }
const char * name
Definition: encode.c:561
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat_slru.c:105
const char * pgstat_get_slru_name(int slru_idx)
Definition: pgstat_slru.c:118
#define PG_STAT_GET_SLRU_COLS
#define PointerGetDatum(X)
Definition: postgres.h:600
#define stat
Definition: win32_port.h:283

References cstring_to_text(), i, Int64GetDatum(), MemSet, name, PG_STAT_GET_SLRU_COLS, pgstat_fetch_slru(), pgstat_get_slru_name(), PointerGetDatum, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SetSingleFuncCall(), stat, TimestampTzGetDatum, tuplestore_putvalues(), and values.

◆ pg_stat_get_snapshot_timestamp()

Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 2048 of file pgstatfuncs.c.

2049 {
2050  bool have_snapshot;
2051  TimestampTz ts;
2052 
2053  ts = pgstat_get_stat_snapshot_timestamp(&have_snapshot);
2054 
2055  if (!have_snapshot)
2056  PG_RETURN_NULL();
2057 
2059 }
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition: pgstat.c:868

References PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, and pgstat_get_stat_snapshot_timestamp().

◆ pg_stat_get_subscription_stats()

Datum pg_stat_get_subscription_stats ( PG_FUNCTION_ARGS  )

Definition at line 2346 of file pgstatfuncs.c.

2347 {
2348 #define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
2349  Oid subid = PG_GETARG_OID(0);
2350  TupleDesc tupdesc;
2353  PgStat_StatSubEntry *subentry;
2354  PgStat_StatSubEntry allzero;
2355 
2356  /* Get subscription stats */
2357  subentry = pgstat_fetch_stat_subscription(subid);
2358 
2359  /* Initialise attributes information in the tuple descriptor */
2361  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subid",
2362  OIDOID, -1, 0);
2363  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
2364  INT8OID, -1, 0);
2365  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_error_count",
2366  INT8OID, -1, 0);
2367  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "stats_reset",
2368  TIMESTAMPTZOID, -1, 0);
2369  BlessTupleDesc(tupdesc);
2370 
2371  /* Initialise values and NULL flags arrays */
2372  MemSet(values, 0, sizeof(values));
2373  MemSet(nulls, 0, sizeof(nulls));
2374 
2375  if (!subentry)
2376  {
2377  /* If the subscription is not found, initialise its stats */
2378  memset(&allzero, 0, sizeof(PgStat_StatSubEntry));
2379  subentry = &allzero;
2380  }
2381 
2382  /* subid */
2383  values[0] = ObjectIdGetDatum(subid);
2384 
2385  /* apply_error_count */
2386  values[1] = Int64GetDatum(subentry->apply_error_count);
2387 
2388  /* sync_error_count */
2389  values[2] = Int64GetDatum(subentry->sync_error_count);
2390 
2391  /* stats_reset */
2392  if (subentry->stat_reset_timestamp == 0)
2393  nulls[3] = true;
2394  else
2396 
2397  /* Returns the record as Datum */
2399 }
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS
PgStat_Counter apply_error_count
Definition: pgstat.h:350
PgStat_Counter sync_error_count
Definition: pgstat.h:351
TimestampTz stat_reset_timestamp
Definition: pgstat.h:352

References PgStat_StatSubEntry::apply_error_count, BlessTupleDesc(), CreateTemplateTupleDesc(), heap_form_tuple(), HeapTupleGetDatum, Int64GetDatum(), MemSet, ObjectIdGetDatum, PG_GETARG_OID, PG_RETURN_DATUM, PG_STAT_GET_SUBSCRIPTION_STATS_COLS, pgstat_fetch_stat_subscription(), PgStat_StatSubEntry::stat_reset_timestamp, PgStat_StatSubEntry::sync_error_count, TimestampTzGetDatum, TupleDescInitEntry(), and values.

◆ pg_stat_get_tuples_deleted()

Datum pg_stat_get_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 120 of file pgstatfuncs.c.

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 }
PgStat_Counter tuples_deleted
Definition: pgstat.h:364

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

◆ pg_stat_get_tuples_fetched()

Datum pg_stat_get_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 72 of file pgstatfuncs.c.

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 }
PgStat_Counter tuples_fetched
Definition: pgstat.h:360

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

◆ pg_stat_get_tuples_hot_updated()

Datum pg_stat_get_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 136 of file pgstatfuncs.c.

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 }
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:365

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

◆ pg_stat_get_tuples_inserted()

Datum pg_stat_get_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 88 of file pgstatfuncs.c.

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 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:362

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

◆ pg_stat_get_tuples_returned()

Datum pg_stat_get_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 56 of file pgstatfuncs.c.

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:359

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

◆ pg_stat_get_tuples_updated()

Datum pg_stat_get_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 104 of file pgstatfuncs.c.

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 }
PgStat_Counter tuples_updated
Definition: pgstat.h:363

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

◆ pg_stat_get_vacuum_count()

Datum pg_stat_get_vacuum_count ( PG_FUNCTION_ARGS  )

Definition at line 319 of file pgstatfuncs.c.

320 {
321  Oid relid = PG_GETARG_OID(0);
322  int64 result;
323  PgStat_StatTabEntry *tabentry;
324 
325  if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
326  result = 0;
327  else
328  result = (int64) (tabentry->vacuum_count);
329 
330  PG_RETURN_INT64(result);
331 }
PgStat_Counter vacuum_count
Definition: pgstat.h:376

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

◆ pg_stat_get_wal()

Datum pg_stat_get_wal ( PG_FUNCTION_ARGS  )

Definition at line 1746 of file pgstatfuncs.c.

1747 {
1748 #define PG_STAT_GET_WAL_COLS 9
1749  TupleDesc tupdesc;
1751  bool nulls[PG_STAT_GET_WAL_COLS];
1752  char buf[256];
1753  PgStat_WalStats *wal_stats;
1754 
1755  /* Initialise values and NULL flags arrays */
1756  MemSet(values, 0, sizeof(values));
1757  MemSet(nulls, 0, sizeof(nulls));
1758 
1759  /* Initialise attributes information in the tuple descriptor */
1761  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1762  INT8OID, -1, 0);
1763  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1764  INT8OID, -1, 0);
1765  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1766  NUMERICOID, -1, 0);
1767  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_buffers_full",
1768  INT8OID, -1, 0);
1769  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_write",
1770  INT8OID, -1, 0);
1771  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "wal_sync",
1772  INT8OID, -1, 0);
1773  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "wal_write_time",
1774  FLOAT8OID, -1, 0);
1775  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "wal_sync_time",
1776  FLOAT8OID, -1, 0);
1777  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "stats_reset",
1778  TIMESTAMPTZOID, -1, 0);
1779 
1780  BlessTupleDesc(tupdesc);
1781 
1782  /* Get statistics about WAL activity */
1783  wal_stats = pgstat_fetch_stat_wal();
1784 
1785  /* Fill values and NULLs */
1786  values[0] = Int64GetDatum(wal_stats->wal_records);
1787  values[1] = Int64GetDatum(wal_stats->wal_fpi);
1788 
1789  /* Convert to numeric. */
1790  snprintf(buf, sizeof buf, UINT64_FORMAT, wal_stats->wal_bytes);
1793  ObjectIdGetDatum(0),
1794  Int32GetDatum(-1));
1795 
1796  values[3] = Int64GetDatum(wal_stats->wal_buffers_full);
1797  values[4] = Int64GetDatum(wal_stats->wal_write);
1798  values[5] = Int64GetDatum(wal_stats->wal_sync);
1799 
1800  /* Convert counters from microsec to millisec for display */
1801  values[6] = Float8GetDatum(((double) wal_stats->wal_write_time) / 1000.0);
1802  values[7] = Float8GetDatum(((double) wal_stats->wal_sync_time) / 1000.0);
1803 
1805 
1806  /* Returns the record as Datum */
1808 }
#define UINT64_FORMAT
Definition: c.h:484
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1692
static char * buf
Definition: pg_test_fsync.c:67
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition: pgstat_wal.c:53
#define PG_STAT_GET_WAL_COLS
#define snprintf
Definition: port.h:225
PgStat_Counter wal_write
Definition: pgstat.h:391
PgStat_Counter wal_buffers_full
Definition: pgstat.h:390
PgStat_Counter wal_write_time
Definition: pgstat.h:393
TimestampTz stat_reset_timestamp
Definition: pgstat.h:395
uint64 wal_bytes
Definition: pgstat.h:389
PgStat_Counter wal_sync_time
Definition: pgstat.h:394
PgStat_Counter wal_fpi
Definition: pgstat.h:388
PgStat_Counter wal_sync
Definition: pgstat.h:392
PgStat_Counter wal_records
Definition: pgstat.h:387

References BlessTupleDesc(), buf, CreateTemplateTupleDesc(), CStringGetDatum, DirectFunctionCall3, Float8GetDatum(), heap_form_tuple(), HeapTupleGetDatum, Int32GetDatum, Int64GetDatum(), MemSet, numeric_in(), ObjectIdGetDatum, PG_RETURN_DATUM, PG_STAT_GET_WAL_COLS, pgstat_fetch_stat_wal(), snprintf, PgStat_WalStats::stat_reset_timestamp, TimestampTzGetDatum, TupleDescInitEntry(), UINT64_FORMAT, values, PgStat_WalStats::wal_buffers_full, PgStat_WalStats::wal_bytes, PgStat_WalStats::wal_fpi, PgStat_WalStats::wal_records, PgStat_WalStats::wal_sync, PgStat_WalStats::wal_sync_time, PgStat_WalStats::wal_write, and PgStat_WalStats::wal_write_time.

◆ pg_stat_get_xact_blocks_fetched()

Datum pg_stat_get_xact_blocks_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1983 of file pgstatfuncs.c.

1984 {
1985  Oid relid = PG_GETARG_OID(0);
1986  int64 result;
1987  PgStat_TableStatus *tabentry;
1988 
1989  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1990  result = 0;
1991  else
1992  result = (int64) (tabentry->t_counts.t_blocks_fetched);
1993 
1994  PG_RETURN_INT64(result);
1995 }
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)
PgStat_Counter t_blocks_fetched
Definition: pgstat.h:185
PgStat_TableCounts t_counts
Definition: pgstat.h:209

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

◆ pg_stat_get_xact_blocks_hit()

Datum pg_stat_get_xact_blocks_hit ( PG_FUNCTION_ARGS  )

Definition at line 1998 of file pgstatfuncs.c.

1999 {
2000  Oid relid = PG_GETARG_OID(0);
2001  int64 result;
2002  PgStat_TableStatus *tabentry;
2003 
2004  if ((tabentry = find_tabstat_entry(relid)) == NULL)
2005  result = 0;
2006  else
2007  result = (int64) (tabentry->t_counts.t_blocks_hit);
2008 
2009  PG_RETURN_INT64(result);
2010 }
PgStat_Counter t_blocks_hit
Definition: pgstat.h:186

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

◆ pg_stat_get_xact_function_calls()

Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 2013 of file pgstatfuncs.c.

2014 {
2015  Oid funcid = PG_GETARG_OID(0);
2016  PgStat_BackendFunctionEntry *funcentry;
2017 
2018  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
2019  PG_RETURN_NULL();
2020  PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
2021 }
PgStat_BackendFunctionEntry * find_funcstat_entry(Oid func_id)
PgStat_FunctionCounts f_counts
Definition: pgstat.h:119
PgStat_Counter f_numcalls
Definition: pgstat.h:108

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

◆ pg_stat_get_xact_function_self_time()

Datum pg_stat_get_xact_function_self_time ( PG_FUNCTION_ARGS  )

Definition at line 2035 of file pgstatfuncs.c.

2036 {
2037  Oid funcid = PG_GETARG_OID(0);
2038  PgStat_BackendFunctionEntry *funcentry;
2039 
2040  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
2041  PG_RETURN_NULL();
2043 }
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:202
instr_time f_self_time
Definition: pgstat.h:110

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.

◆ pg_stat_get_xact_function_total_time()

Datum pg_stat_get_xact_function_total_time ( PG_FUNCTION_ARGS  )

Definition at line 2024 of file pgstatfuncs.c.

2025 {
2026  Oid funcid = PG_GETARG_OID(0);
2027  PgStat_BackendFunctionEntry *funcentry;
2028 
2029  if ((funcentry = find_funcstat_entry(funcid)) == NULL)
2030  PG_RETURN_NULL();
2032 }
instr_time f_total_time
Definition: pgstat.h:109

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.

◆ pg_stat_get_xact_numscans()

Datum pg_stat_get_xact_numscans ( PG_FUNCTION_ARGS  )

Definition at line 1860 of file pgstatfuncs.c.

1861 {
1862  Oid relid = PG_GETARG_OID(0);
1863  int64 result;
1864  PgStat_TableStatus *tabentry;
1865 
1866  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1867  result = 0;
1868  else
1869  result = (int64) (tabentry->t_counts.t_numscans);
1870 
1871  PG_RETURN_INT64(result);
1872 }
PgStat_Counter t_numscans
Definition: pgstat.h:170

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

◆ pg_stat_get_xact_tuples_deleted()

Datum pg_stat_get_xact_tuples_deleted ( PG_FUNCTION_ARGS  )

Definition at line 1947 of file pgstatfuncs.c.

1948 {
1949  Oid relid = PG_GETARG_OID(0);
1950  int64 result;
1951  PgStat_TableStatus *tabentry;
1953 
1954  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1955  result = 0;
1956  else
1957  {
1958  result = tabentry->t_counts.t_tuples_deleted;
1959  /* live subtransactions' counts aren't in t_tuples_deleted yet */
1960  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1961  result += trans->tuples_deleted;
1962  }
1963 
1964  PG_RETURN_INT64(result);
1965 }
PgStat_Counter t_tuples_deleted
Definition: pgstat.h:177
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:208
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:400

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

◆ pg_stat_get_xact_tuples_fetched()

Datum pg_stat_get_xact_tuples_fetched ( PG_FUNCTION_ARGS  )

Definition at line 1890 of file pgstatfuncs.c.

1891 {
1892  Oid relid = PG_GETARG_OID(0);
1893  int64 result;
1894  PgStat_TableStatus *tabentry;
1895 
1896  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1897  result = 0;
1898  else
1899  result = (int64) (tabentry->t_counts.t_tuples_fetched);
1900 
1901  PG_RETURN_INT64(result);
1902 }
PgStat_Counter t_tuples_fetched
Definition: pgstat.h:173

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

◆ pg_stat_get_xact_tuples_hot_updated()

Datum pg_stat_get_xact_tuples_hot_updated ( PG_FUNCTION_ARGS  )

Definition at line 1968 of file pgstatfuncs.c.

1969 {
1970  Oid relid = PG_GETARG_OID(0);
1971  int64 result;
1972  PgStat_TableStatus *tabentry;
1973 
1974  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1975  result = 0;
1976  else
1977  result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
1978 
1979  PG_RETURN_INT64(result);
1980 }
PgStat_Counter t_tuples_hot_updated
Definition: pgstat.h:178

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

◆ pg_stat_get_xact_tuples_inserted()

Datum pg_stat_get_xact_tuples_inserted ( PG_FUNCTION_ARGS  )

Definition at line 1905 of file pgstatfuncs.c.

1906 {
1907  Oid relid = PG_GETARG_OID(0);
1908  int64 result;
1909  PgStat_TableStatus *tabentry;
1911 
1912  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1913  result = 0;
1914  else
1915  {
1916  result = tabentry->t_counts.t_tuples_inserted;
1917  /* live subtransactions' counts aren't in t_tuples_inserted yet */
1918  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1919  result += trans->tuples_inserted;
1920  }
1921 
1922  PG_RETURN_INT64(result);
1923 }
PgStat_Counter t_tuples_inserted
Definition: pgstat.h:175

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

◆ pg_stat_get_xact_tuples_returned()

Datum pg_stat_get_xact_tuples_returned ( PG_FUNCTION_ARGS  )

Definition at line 1875 of file pgstatfuncs.c.

1876 {
1877  Oid relid = PG_GETARG_OID(0);
1878  int64 result;
1879  PgStat_TableStatus *tabentry;
1880 
1881  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1882  result = 0;
1883  else
1884  result = (int64) (tabentry->t_counts.t_tuples_returned);
1885 
1886  PG_RETURN_INT64(result);
1887 }
PgStat_Counter t_tuples_returned
Definition: pgstat.h:172

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

◆ pg_stat_get_xact_tuples_updated()

Datum pg_stat_get_xact_tuples_updated ( PG_FUNCTION_ARGS  )

Definition at line 1926 of file pgstatfuncs.c.

1927 {
1928  Oid relid = PG_GETARG_OID(0);
1929  int64 result;
1930  PgStat_TableStatus *tabentry;
1932 
1933  if ((tabentry = find_tabstat_entry(relid)) == NULL)
1934  result = 0;
1935  else
1936  {
1937  result = tabentry->t_counts.t_tuples_updated;
1938  /* live subtransactions' counts aren't in t_tuples_updated yet */
1939  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
1940  result += trans->tuples_updated;
1941  }
1942 
1943  PG_RETURN_INT64(result);
1944 }
PgStat_Counter t_tuples_updated
Definition: pgstat.h:176

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

◆ pg_stat_have_stats()

Datum pg_stat_have_stats ( PG_FUNCTION_ARGS  )

Definition at line 2409 of file pgstatfuncs.c.

2410 {
2411  char *stats_type = text_to_cstring(PG_GETARG_TEXT_P(0));
2412  Oid dboid = PG_GETARG_OID(1);
2413  Oid objoid = PG_GETARG_OID(2);
2414  PgStat_Kind kind = pgstat_get_kind_from_str(stats_type);
2415 
2416  PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objoid));
2417 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:882
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1189
PgStat_Kind
Definition: pgstat.h:36

References PG_GETARG_OID, PG_GETARG_TEXT_P, PG_RETURN_BOOL, pgstat_get_kind_from_str(), pgstat_have_entry(), and text_to_cstring().

◆ pg_stat_reset()

Datum pg_stat_reset ( PG_FUNCTION_ARGS  )

Definition at line 2083 of file pgstatfuncs.c.

2084 {
2086 
2087  PG_RETURN_VOID();
2088 }
void pgstat_reset_counters(void)
Definition: pgstat.c:685

References PG_RETURN_VOID, and pgstat_reset_counters().

◆ pg_stat_reset_replication_slot()

Datum pg_stat_reset_replication_slot ( PG_FUNCTION_ARGS  )

Definition at line 2160 of file pgstatfuncs.c.

2161 {
2162  char *target = NULL;
2163 
2164  if (PG_ARGISNULL(0))
2166  else
2167  {
2168  target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2169  pgstat_reset_replslot(target);
2170  }
2171 
2172  PG_RETURN_VOID();
2173 }
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition: pgstat.c:726
@ PGSTAT_KIND_REPLSLOT
Definition: pgstat.h:44
void pgstat_reset_replslot(const char *name)

References PG_ARGISNULL, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_KIND_REPLSLOT, pgstat_reset_of_kind(), pgstat_reset_replslot(), and text_to_cstring().

◆ pg_stat_reset_shared()

Datum pg_stat_reset_shared ( PG_FUNCTION_ARGS  )

Definition at line 2092 of file pgstatfuncs.c.

2093 {
2094  char *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2095 
2096  if (strcmp(target, "archiver") == 0)
2098  else if (strcmp(target, "bgwriter") == 0)
2099  {
2100  /*
2101  * Historically checkpointer was part of bgwriter, continue to reset
2102  * both for now.
2103  */
2106  }
2107  else if (strcmp(target, "recovery_prefetch") == 0)
2109  else if (strcmp(target, "wal") == 0)
2111  else
2112  ereport(ERROR,
2113  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2114  errmsg("unrecognized reset target: \"%s\"", target),
2115  errhint("Target must be \"archiver\", \"bgwriter\", \"recovery_prefetch\", or \"wal\".")));
2116 
2117  PG_RETURN_VOID();
2118 }
int errhint(const char *fmt,...)
Definition: elog.c:1151
@ PGSTAT_KIND_ARCHIVER
Definition: pgstat.h:48
@ PGSTAT_KIND_BGWRITER
Definition: pgstat.h:49
@ PGSTAT_KIND_CHECKPOINTER
Definition: pgstat.h:50
@ PGSTAT_KIND_WAL
Definition: pgstat.h:52
void XLogPrefetchResetStats(void)

References ereport, errcode(), errhint(), errmsg(), ERROR, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_KIND_ARCHIVER, PGSTAT_KIND_BGWRITER, PGSTAT_KIND_CHECKPOINTER, PGSTAT_KIND_WAL, pgstat_reset_of_kind(), text_to_cstring(), and XLogPrefetchResetStats().

◆ pg_stat_reset_single_function_counters()

Datum pg_stat_reset_single_function_counters ( PG_FUNCTION_ARGS  )

Definition at line 2132 of file pgstatfuncs.c.

2133 {
2134  Oid funcoid = PG_GETARG_OID(0);
2135 
2137 
2138  PG_RETURN_VOID();
2139 }
Oid MyDatabaseId
Definition: globals.c:89
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:704
@ PGSTAT_KIND_FUNCTION
Definition: pgstat.h:43

References MyDatabaseId, PG_GETARG_OID, PG_RETURN_VOID, PGSTAT_KIND_FUNCTION, and pgstat_reset().

◆ pg_stat_reset_single_table_counters()

Datum pg_stat_reset_single_table_counters ( PG_FUNCTION_ARGS  )

Definition at line 2122 of file pgstatfuncs.c.

2123 {
2124  Oid taboid = PG_GETARG_OID(0);
2125 
2127 
2128  PG_RETURN_VOID();
2129 }
@ PGSTAT_KIND_RELATION
Definition: pgstat.h:42

References MyDatabaseId, PG_GETARG_OID, PG_RETURN_VOID, PGSTAT_KIND_RELATION, and pgstat_reset().

◆ pg_stat_reset_slru()

Datum pg_stat_reset_slru ( PG_FUNCTION_ARGS  )

Definition at line 2143 of file pgstatfuncs.c.

2144 {
2145  char *target = NULL;
2146 
2147  if (PG_ARGISNULL(0))
2149  else
2150  {
2151  target = text_to_cstring(PG_GETARG_TEXT_PP(0));
2152  pgstat_reset_slru(target);
2153  }
2154 
2155  PG_RETURN_VOID();
2156 }
@ PGSTAT_KIND_SLRU
Definition: pgstat.h:51
void pgstat_reset_slru(const char *name)
Definition: pgstat_slru.c:45

References PG_ARGISNULL, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_KIND_SLRU, pgstat_reset_of_kind(), pgstat_reset_slru(), and text_to_cstring().

◆ pg_stat_reset_subscription_stats()

Datum pg_stat_reset_subscription_stats ( PG_FUNCTION_ARGS  )

Definition at line 2177 of file pgstatfuncs.c.

2178 {
2179  Oid subid;
2180 
2181  if (PG_ARGISNULL(0))
2182  {
2183  /* Clear all subscription stats */
2185  }
2186  else
2187  {
2188  subid = PG_GETARG_OID(0);
2189 
2190  if (!OidIsValid(subid))
2191  ereport(ERROR,
2192  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2193  errmsg("invalid subscription OID %u", subid)));
2195  }
2196 
2197  PG_RETURN_VOID();
2198 }
#define OidIsValid(objectId)
Definition: c.h:710
@ PGSTAT_KIND_SUBSCRIPTION
Definition: pgstat.h:45

References ereport, errcode(), errmsg(), ERROR, InvalidOid, OidIsValid, PG_ARGISNULL, PG_GETARG_OID, PG_RETURN_VOID, PGSTAT_KIND_SUBSCRIPTION, pgstat_reset(), and pgstat_reset_of_kind().