PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgstatfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xlog.h"
#include "access/xlogprefetcher.h"
#include "catalog/catalog.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.h"
#include "replication/logicallauncher.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/timestamp.h"
#include "utils/tuplestore.h"
#include "utils/wait_event.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_RELENTRY_INT64(stat)
 
#define PG_STAT_GET_RELENTRY_FLOAT8(stat)
 
#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat)
 
#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS(stat)
 
#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3
 
#define PG_STAT_GET_ACTIVITY_COLS   31
 
#define PG_STAT_GET_SUBXACT_COLS   2
 
#define PG_STAT_GET_DBENTRY_INT64(stat)
 
#define PG_STAT_GET_DBENTRY_FLOAT8_MS(stat)
 
#define PG_STAT_WAL_COLS   6
 
#define PG_STAT_LOCK_COLS   5
 
#define PG_STAT_GET_SLRU_COLS   9
 
#define PG_STAT_GET_XACT_RELENTRY_INT64(stat)
 
#define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(stat)
 
#define PG_STAT_GET_REPLICATION_SLOT_COLS   13
 
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS   13
 

Typedefs

typedef enum io_stat_col io_stat_col
 

Enumerations

enum  io_stat_col {
  IO_COL_INVALID = -1 , IO_COL_BACKEND_TYPE , IO_COL_OBJECT , IO_COL_CONTEXT ,
  IO_COL_READS , IO_COL_READ_BYTES , IO_COL_READ_TIME , IO_COL_WRITES ,
  IO_COL_WRITE_BYTES , IO_COL_WRITE_TIME , IO_COL_WRITEBACKS , IO_COL_WRITEBACK_TIME ,
  IO_COL_EXTENDS , IO_COL_EXTEND_BYTES , IO_COL_EXTEND_TIME , IO_COL_HITS ,
  IO_COL_EVICTIONS , IO_COL_REUSES , IO_COL_FSYNCS , IO_COL_FSYNC_TIME ,
  IO_COL_RESET_TIME , IO_NUM_COLUMNS
}
 

Functions

Datum pg_stat_get_function_calls (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_function_stat_reset_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_subxact (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_stat_reset_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_db_conflict_all (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_checkpointer_num_timed (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_num_requested (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_num_performed (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_restartpoints_timed (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_restartpoints_requested (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_restartpoints_performed (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_buffers_written (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_slru_written (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_checkpointer_write_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_sync_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_checkpointer_stat_reset_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_bgwriter_stat_reset_time (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_buf_alloc (PG_FUNCTION_ARGS)
 
static io_stat_col pgstat_get_io_op_index (IOOp io_op)
 
static io_stat_col pgstat_get_io_byte_index (IOOp io_op)
 
static io_stat_col pgstat_get_io_time_index (IOOp io_op)
 
static double pg_stat_us_to_ms (PgStat_Counter val_ms)
 
static void pg_stat_io_build_tuples (ReturnSetInfo *rsinfo, PgStat_BktypeIO *bktype_stats, BackendType bktype, TimestampTz stat_reset_timestamp)
 
Datum pg_stat_get_io (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_backend_io (PG_FUNCTION_ARGS)
 
static Datum pg_stat_wal_build_tuple (PgStat_WalCounters wal_counters, TimestampTz stat_reset_timestamp)
 
Datum pg_stat_get_backend_wal (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_wal (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_lock (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_slru (PG_FUNCTION_ARGS)
 
Datum pg_stat_get_xact_function_calls (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_backend_stats (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 39 of file pgstatfuncs.c.

◆ PG_STAT_GET_ACTIVITY_COLS

#define PG_STAT_GET_ACTIVITY_COLS   31

◆ PG_STAT_GET_DBENTRY_FLOAT8_MS

#define PG_STAT_GET_DBENTRY_FLOAT8_MS (   stat)
Value:
{ \
Oid dbid = PG_GETARG_OID(0); \
double result; \
result = 0; \
result = ((double) dbentry->stat) / 1000.0; \
}
uint32 result
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
unsigned int Oid
static int fb(int x)

Definition at line 1214 of file pgstatfuncs.c.

1217{ \
1218 Oid dbid = PG_GETARG_OID(0); \
1219 double result; \
1221 \
1223 result = 0; \
1224 else \
1225 result = ((double) dbentry->stat) / 1000.0; \
1226 \
1228}

◆ PG_STAT_GET_DBENTRY_INT64

#define PG_STAT_GET_DBENTRY_INT64 (   stat)
Value:

Definition at line 1053 of file pgstatfuncs.c.

1056{ \
1057 Oid dbid = PG_GETARG_OID(0); \
1058 int64 result; \
1060 \
1062 result = 0; \
1063 else \
1064 result = (int64) (dbentry->stat); \
1065 \
1067}

◆ PG_STAT_GET_FUNCENTRY_FLOAT8_MS

#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS (   stat)
Value:

Definition at line 188 of file pgstatfuncs.c.

191{ \
192 Oid funcid = PG_GETARG_OID(0); \
193 double result; \
195 \
198 result = ((double) funcentry->stat) / 1000.0; \
200}

◆ PG_STAT_GET_PROGRESS_COLS

#define PG_STAT_GET_PROGRESS_COLS   PGSTAT_NUM_PROGRESS_PARAM + 3

◆ PG_STAT_GET_RELENTRY_FLOAT8

#define PG_STAT_GET_RELENTRY_FLOAT8 (   stat)
Value:

Definition at line 111 of file pgstatfuncs.c.

114{ \
115 Oid relid = PG_GETARG_OID(0); \
116 double result; \
118 \
120 result = 0; \
121 else \
122 result = (double) (tabentry->stat); \
123 \
125}

◆ PG_STAT_GET_RELENTRY_INT64

#define PG_STAT_GET_RELENTRY_INT64 (   stat)

◆ PG_STAT_GET_RELENTRY_TIMESTAMPTZ

#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ (   stat)

◆ PG_STAT_GET_REPLICATION_SLOT_COLS

#define PG_STAT_GET_REPLICATION_SLOT_COLS   13

◆ 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   13

◆ PG_STAT_GET_SUBXACT_COLS

#define PG_STAT_GET_SUBXACT_COLS   2

◆ PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS

#define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS (   stat)
Value:

Definition at line 1880 of file pgstatfuncs.c.

1883{ \
1884 Oid funcid = PG_GETARG_OID(0); \
1886 \
1887 if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
1890}

◆ PG_STAT_GET_XACT_RELENTRY_INT64

#define PG_STAT_GET_XACT_RELENTRY_INT64 (   stat)
Value:

Definition at line 1823 of file pgstatfuncs.c.

1826{ \
1827 Oid relid = PG_GETARG_OID(0); \
1828 int64 result; \
1830 \
1831 if ((tabentry = find_tabstat_entry(relid)) == NULL) \
1832 result = 0; \
1833 else \
1834 result = (int64) (tabentry->counts.stat); \
1835 \
1837}

◆ PG_STAT_LOCK_COLS

#define PG_STAT_LOCK_COLS   5

◆ PG_STAT_WAL_COLS

#define PG_STAT_WAL_COLS   6

◆ UINT32_ACCESS_ONCE

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

Definition at line 37 of file pgstatfuncs.c.

Typedef Documentation

◆ io_stat_col

Enumeration Type Documentation

◆ io_stat_col

Enumerator
IO_COL_INVALID 
IO_COL_BACKEND_TYPE 
IO_COL_OBJECT 
IO_COL_CONTEXT 
IO_COL_READS 
IO_COL_READ_BYTES 
IO_COL_READ_TIME 
IO_COL_WRITES 
IO_COL_WRITE_BYTES 
IO_COL_WRITE_TIME 
IO_COL_WRITEBACKS 
IO_COL_WRITEBACK_TIME 
IO_COL_EXTENDS 
IO_COL_EXTEND_BYTES 
IO_COL_EXTEND_TIME 
IO_COL_HITS 
IO_COL_EVICTIONS 
IO_COL_REUSES 
IO_COL_FSYNCS 
IO_COL_FSYNC_TIME 
IO_COL_RESET_TIME 
IO_NUM_COLUMNS 

Definition at line 1344 of file pgstatfuncs.c.

1345{
1346 IO_COL_INVALID = -1,
1368} io_stat_col;
io_stat_col
@ IO_COL_READS
@ IO_NUM_COLUMNS
@ IO_COL_RESET_TIME
@ IO_COL_WRITE_TIME
@ IO_COL_HITS
@ IO_COL_EXTENDS
@ IO_COL_WRITEBACK_TIME
@ IO_COL_REUSES
@ IO_COL_WRITES
@ IO_COL_OBJECT
@ IO_COL_EVICTIONS
@ IO_COL_WRITEBACKS
@ IO_COL_CONTEXT
@ IO_COL_READ_BYTES
@ IO_COL_EXTEND_BYTES
@ IO_COL_BACKEND_TYPE
@ IO_COL_FSYNC_TIME
@ IO_COL_EXTEND_TIME
@ IO_COL_FSYNCS
@ IO_COL_WRITE_BYTES
@ IO_COL_INVALID
@ IO_COL_READ_TIME

Function Documentation

◆ pg_backend_pid()

Datum pg_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 715 of file pgstatfuncs.c.

716{
718}
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
int MyProcPid
Definition globals.c:49

References MyProcPid, and PG_RETURN_INT32.

◆ pg_stat_clear_snapshot()

Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1915 of file pgstatfuncs.c.

1916{
1918
1920}
#define PG_RETURN_VOID()
Definition fmgr.h:350
void pgstat_clear_snapshot(void)
Definition pgstat.c:930

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

1926{
1928
1930}
void pgstat_force_next_flush(void)
Definition pgstat.c:842

References PG_RETURN_VOID, and pgstat_force_next_flush().

◆ pg_stat_get_activity()

Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 356 of file pgstatfuncs.c.

357{
358#define PG_STAT_GET_ACTIVITY_COLS 31
360 int curr_backend;
361 int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
362 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
363
364 InitMaterializedSRF(fcinfo, 0);
365
366 /* 1-based index */
368 {
369 /* for each row */
371 bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
374 PGPROC *proc;
375 const char *wait_event_type = NULL;
376 const char *wait_event = NULL;
377
378 /* Get the next one in the list */
380 beentry = &local_beentry->backendStatus;
381
382 /* If looking for specific PID, ignore all the others */
383 if (pid != -1 && beentry->st_procpid != pid)
384 continue;
385
386 /* Values available to all callers */
387 if (beentry->st_databaseid != InvalidOid)
388 values[0] = ObjectIdGetDatum(beentry->st_databaseid);
389 else
390 nulls[0] = true;
391
392 values[1] = Int32GetDatum(beentry->st_procpid);
393
394 if (beentry->st_userid != InvalidOid)
395 values[2] = ObjectIdGetDatum(beentry->st_userid);
396 else
397 nulls[2] = true;
398
399 if (beentry->st_appname)
400 values[3] = CStringGetTextDatum(beentry->st_appname);
401 else
402 nulls[3] = true;
403
404 if (TransactionIdIsValid(local_beentry->backend_xid))
405 values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
406 else
407 nulls[15] = true;
408
409 if (TransactionIdIsValid(local_beentry->backend_xmin))
410 values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
411 else
412 nulls[16] = true;
413
414 /* Values only available to role member or pg_read_all_stats */
415 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
416 {
417 char *clipped_activity;
418
419 switch (beentry->st_state)
420 {
421 case STATE_STARTING:
422 values[4] = CStringGetTextDatum("starting");
423 break;
424 case STATE_IDLE:
425 values[4] = CStringGetTextDatum("idle");
426 break;
427 case STATE_RUNNING:
428 values[4] = CStringGetTextDatum("active");
429 break;
431 values[4] = CStringGetTextDatum("idle in transaction");
432 break;
433 case STATE_FASTPATH:
434 values[4] = CStringGetTextDatum("fastpath function call");
435 break;
437 values[4] = CStringGetTextDatum("idle in transaction (aborted)");
438 break;
439 case STATE_DISABLED:
440 values[4] = CStringGetTextDatum("disabled");
441 break;
442 case STATE_UNDEFINED:
443 nulls[4] = true;
444 break;
445 }
446
450
451 /* leader_pid */
452 nulls[29] = true;
453
454 proc = BackendPidGetProc(beentry->st_procpid);
455
456 if (proc == NULL && (beentry->st_backendType != B_BACKEND))
457 {
458 /*
459 * For an auxiliary process, retrieve process info from
460 * AuxiliaryProcs stored in shared-memory.
461 */
462 proc = AuxiliaryPidGetProc(beentry->st_procpid);
463 }
464
465 /*
466 * If a PGPROC entry was retrieved, display wait events and lock
467 * group leader or apply leader information if any. To avoid
468 * extra overhead, no extra lock is being held, so there is no
469 * guarantee of consistency across multiple rows.
470 */
471 if (proc != NULL)
472 {
474 PGPROC *leader;
475
479
480 leader = proc->lockGroupLeader;
481
482 /*
483 * Show the leader only for active parallel workers. This
484 * leaves the field as NULL for the leader of a parallel group
485 * or the leader of parallel apply workers.
486 */
487 if (leader && leader->pid != beentry->st_procpid)
488 {
489 values[29] = Int32GetDatum(leader->pid);
490 nulls[29] = false;
491 }
492 else if (beentry->st_backendType == B_BG_WORKER)
493 {
494 int leader_pid = GetLeaderApplyWorkerPid(beentry->st_procpid);
495
496 if (leader_pid != InvalidPid)
497 {
498 values[29] = Int32GetDatum(leader_pid);
499 nulls[29] = false;
500 }
501 }
502 }
503
504 if (wait_event_type)
506 else
507 nulls[6] = true;
508
509 if (wait_event)
511 else
512 nulls[7] = true;
513
514 /*
515 * Don't expose transaction time for walsenders; it confuses
516 * monitoring, particularly because we don't keep the time up-to-
517 * date.
518 */
519 if (beentry->st_xact_start_timestamp != 0 &&
520 beentry->st_backendType != B_WAL_SENDER)
521 values[8] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
522 else
523 nulls[8] = true;
524
525 if (beentry->st_activity_start_timestamp != 0)
526 values[9] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
527 else
528 nulls[9] = true;
529
530 if (beentry->st_proc_start_timestamp != 0)
531 values[10] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
532 else
533 nulls[10] = true;
534
535 if (beentry->st_state_start_timestamp != 0)
536 values[11] = TimestampTzGetDatum(beentry->st_state_start_timestamp);
537 else
538 nulls[11] = true;
539
540 /* A zeroed client addr means we don't know */
541 if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
542 sizeof(beentry->st_clientaddr)))
543 {
544 nulls[12] = true;
545 nulls[13] = true;
546 nulls[14] = true;
547 }
548 else
549 {
550 if (beentry->st_clientaddr.addr.ss_family == AF_INET ||
551 beentry->st_clientaddr.addr.ss_family == AF_INET6)
552 {
553 char remote_host[NI_MAXHOST];
554 char remote_port[NI_MAXSERV];
555 int ret;
556
557 remote_host[0] = '\0';
558 remote_port[0] = '\0';
559 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
560 beentry->st_clientaddr.salen,
561 remote_host, sizeof(remote_host),
562 remote_port, sizeof(remote_port),
564 if (ret == 0)
565 {
566 clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
568 CStringGetDatum(remote_host));
569 if (beentry->st_clienthostname &&
570 beentry->st_clienthostname[0])
571 values[13] = CStringGetTextDatum(beentry->st_clienthostname);
572 else
573 nulls[13] = true;
574 values[14] = Int32GetDatum(atoi(remote_port));
575 }
576 else
577 {
578 nulls[12] = true;
579 nulls[13] = true;
580 nulls[14] = true;
581 }
582 }
583 else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
584 {
585 /*
586 * Unix sockets always reports NULL for host and -1 for
587 * port, so it's possible to tell the difference to
588 * connections we have no permissions to view, or with
589 * errors.
590 */
591 nulls[12] = true;
592 nulls[13] = true;
593 values[14] = Int32GetDatum(-1);
594 }
595 else
596 {
597 /* Unknown address type, should never happen */
598 nulls[12] = true;
599 nulls[13] = true;
600 nulls[14] = true;
601 }
602 }
603 /* Add backend type */
604 if (beentry->st_backendType == B_BG_WORKER)
605 {
606 const char *bgw_type;
607
608 bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
609 if (bgw_type)
610 values[17] = CStringGetTextDatum(bgw_type);
611 else
612 nulls[17] = true;
613 }
614 else
615 values[17] =
617
618 /* SSL information */
619 if (beentry->st_ssl)
620 {
621 values[18] = BoolGetDatum(true); /* ssl */
622 values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version);
623 values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher);
624 values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
625
626 if (beentry->st_sslstatus->ssl_client_dn[0])
627 values[22] = CStringGetTextDatum(beentry->st_sslstatus->ssl_client_dn);
628 else
629 nulls[22] = true;
630
631 if (beentry->st_sslstatus->ssl_client_serial[0])
633 CStringGetDatum(beentry->st_sslstatus->ssl_client_serial),
635 Int32GetDatum(-1));
636 else
637 nulls[23] = true;
638
639 if (beentry->st_sslstatus->ssl_issuer_dn[0])
640 values[24] = CStringGetTextDatum(beentry->st_sslstatus->ssl_issuer_dn);
641 else
642 nulls[24] = true;
643 }
644 else
645 {
646 values[18] = BoolGetDatum(false); /* ssl */
647 nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = true;
648 }
649
650 /* GSSAPI information */
651 if (beentry->st_gss)
652 {
653 values[25] = BoolGetDatum(beentry->st_gssstatus->gss_auth); /* gss_auth */
654 values[26] = CStringGetTextDatum(beentry->st_gssstatus->gss_princ);
655 values[27] = BoolGetDatum(beentry->st_gssstatus->gss_enc); /* GSS Encryption in use */
656 values[28] = BoolGetDatum(beentry->st_gssstatus->gss_delegation); /* GSS credentials
657 * delegated */
658 }
659 else
660 {
661 values[25] = BoolGetDatum(false); /* gss_auth */
662 nulls[26] = true; /* No GSS principal */
663 values[27] = BoolGetDatum(false); /* GSS Encryption not in
664 * use */
665 values[28] = BoolGetDatum(false); /* GSS credentials not
666 * delegated */
667 }
668 if (beentry->st_query_id == INT64CONST(0))
669 nulls[30] = true;
670 else
671 values[30] = Int64GetDatum(beentry->st_query_id);
672 }
673 else
674 {
675 /* No permissions to view data about this session */
676 values[5] = CStringGetTextDatum("<insufficient privilege>");
677 nulls[4] = true;
678 nulls[6] = true;
679 nulls[7] = true;
680 nulls[8] = true;
681 nulls[9] = true;
682 nulls[10] = true;
683 nulls[11] = true;
684 nulls[12] = true;
685 nulls[13] = true;
686 nulls[14] = true;
687 nulls[17] = true;
688 nulls[18] = true;
689 nulls[19] = true;
690 nulls[20] = true;
691 nulls[21] = true;
692 nulls[22] = true;
693 nulls[23] = true;
694 nulls[24] = true;
695 nulls[25] = true;
696 nulls[26] = true;
697 nulls[27] = true;
698 nulls[28] = true;
699 nulls[29] = true;
700 nulls[30] = true;
701 }
702
703 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
704
705 /* If only a single backend was requested, and we found it, break. */
706 if (pid != -1)
707 break;
708 }
709
710 return (Datum) 0;
711}
Datum numeric_in(PG_FUNCTION_ARGS)
Definition numeric.c:626
int pgstat_fetch_stat_numbackends(void)
char * pgstat_clip_activity(const char *raw_activity)
LocalPgBackendStatus * pgstat_get_local_beentry_by_index(int idx)
@ STATE_UNDEFINED
@ STATE_IDLEINTRANSACTION_ABORTED
@ STATE_STARTING
@ STATE_IDLE
@ STATE_IDLEINTRANSACTION
@ STATE_DISABLED
@ STATE_FASTPATH
@ STATE_RUNNING
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
Definition bgworker.c:1394
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define INT64CONST(x)
Definition c.h:630
uint32_t uint32
Definition c.h:624
#define PG_ARGISNULL(n)
Definition fmgr.h:209
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition fmgr.h:688
void InitMaterializedSRF(FunctionCallInfo fcinfo, uint32 flags)
Definition funcapi.c:76
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition ip.c:117
pid_t GetLeaderApplyWorkerPid(pid_t pid)
Definition launcher.c:1597
void pfree(void *pointer)
Definition mcxt.c:1616
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
Definition memutils.h:219
@ B_WAL_SENDER
Definition miscadmin.h:359
@ B_BG_WORKER
Definition miscadmin.h:358
@ B_BACKEND
Definition miscadmin.h:354
#define InvalidPid
Definition miscadmin.h:32
const char * GetBackendTypeDesc(BackendType backendType)
Definition miscinit.c:264
void clean_ipv6_addr(int addr_family, char *addr)
Definition network.c:2028
Datum inet_in(PG_FUNCTION_ARGS)
Definition network.c:119
#define UINT32_ACCESS_ONCE(var)
Definition pgstatfuncs.c:37
#define PG_STAT_GET_ACTIVITY_COLS
#define HAS_PGSTAT_PERMISSIONS(role)
Definition pgstatfuncs.c:39
static Datum Int64GetDatum(int64 X)
Definition postgres.h:413
static Datum TransactionIdGetDatum(TransactionId X)
Definition postgres.h:292
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:370
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
#define InvalidOid
PGPROC * BackendPidGetProc(int pid)
Definition procarray.c:3169
PGPROC * AuxiliaryPidGetProc(int pid)
Definition proc.c:1097
Definition proc.h:179
uint32 wait_event_info
Definition proc.h:378
int pid
Definition proc.h:197
PGPROC * lockGroupLeader
Definition proc.h:298
#define TransactionIdIsValid(xid)
Definition transam.h:41
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:785
static Datum TimestampTzGetDatum(TimestampTz X)
Definition timestamp.h:52
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition wait_event.c:359
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition wait_event.c:417

References AuxiliaryPidGetProc(), B_BACKEND, B_BG_WORKER, B_WAL_SENDER, BackendPidGetProc(), BoolGetDatum(), clean_ipv6_addr(), CStringGetDatum(), CStringGetTextDatum, DirectFunctionCall1, DirectFunctionCall3, fb(), GetBackendTypeDesc(), GetBackgroundWorkerTypeByPid(), GetLeaderApplyWorkerPid(), HAS_PGSTAT_PERMISSIONS, inet_in(), InitMaterializedSRF(), Int32GetDatum(), INT64CONST, Int64GetDatum(), InvalidOid, InvalidPid, PGPROC::lockGroupLeader, numeric_in(), ObjectIdGetDatum(), pfree(), PG_ARGISNULL, PG_GETARG_INT32, pg_getnameinfo_all(), pg_memory_is_all_zeros(), PG_STAT_GET_ACTIVITY_COLS, pgstat_clip_activity(), pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), pgstat_get_wait_event(), pgstat_get_wait_event_type(), PGPROC::pid, STATE_DISABLED, STATE_FASTPATH, STATE_IDLE, STATE_IDLEINTRANSACTION, STATE_IDLEINTRANSACTION_ABORTED, STATE_RUNNING, STATE_STARTING, STATE_UNDEFINED, TimestampTzGetDatum(), TransactionIdGetDatum(), TransactionIdIsValid, tuplestore_putvalues(), UINT32_ACCESS_ONCE, values, and PGPROC::wait_event_info.

◆ pg_stat_get_archiver()

Datum pg_stat_get_archiver ( PG_FUNCTION_ARGS  )

Definition at line 2115 of file pgstatfuncs.c.

2116{
2117 TupleDesc tupdesc;
2118 Datum values[7] = {0};
2119 bool nulls[7] = {0};
2121
2122 /* Initialise attributes information in the tuple descriptor */
2123 tupdesc = CreateTemplateTupleDesc(7);
2124 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2125 INT8OID, -1, 0);
2126 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2127 TEXTOID, -1, 0);
2128 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2129 TIMESTAMPTZOID, -1, 0);
2130 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2131 INT8OID, -1, 0);
2132 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2133 TEXTOID, -1, 0);
2134 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2135 TIMESTAMPTZOID, -1, 0);
2136 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2137 TIMESTAMPTZOID, -1, 0);
2138
2139 TupleDescFinalize(tupdesc);
2140 BlessTupleDesc(tupdesc);
2141
2142 /* Get statistics about the archiver process */
2144
2145 /* Fill values and NULLs */
2146 values[0] = Int64GetDatum(archiver_stats->archived_count);
2147 if (*(archiver_stats->last_archived_wal) == '\0')
2148 nulls[1] = true;
2149 else
2150 values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2151
2152 if (archiver_stats->last_archived_timestamp == 0)
2153 nulls[2] = true;
2154 else
2155 values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
2156
2157 values[3] = Int64GetDatum(archiver_stats->failed_count);
2158 if (*(archiver_stats->last_failed_wal) == '\0')
2159 nulls[4] = true;
2160 else
2161 values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2162
2163 if (archiver_stats->last_failed_timestamp == 0)
2164 nulls[5] = true;
2165 else
2166 values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2167
2168 if (archiver_stats->stat_reset_timestamp == 0)
2169 nulls[6] = true;
2170 else
2171 values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2172
2173 /* Returns the record as Datum */
2175}
int16 AttrNumber
Definition attnum.h:21
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:900

References BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, fb(), heap_form_tuple(), HeapTupleGetDatum(), Int64GetDatum(), PG_RETURN_DATUM, pgstat_fetch_stat_archiver(), TimestampTzGetDatum(), TupleDescFinalize(), TupleDescInitEntry(), and values.

◆ pg_stat_get_backend_activity()

Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 796 of file pgstatfuncs.c.

797{
798 int32 procNumber = PG_GETARG_INT32(0);
800 const char *activity;
801 char *clipped_activity;
802 text *ret;
803
804 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
805 activity = "<backend information not available>";
806 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
807 activity = "<insufficient privilege>";
808 else if (*(beentry->st_activity_raw) == '\0')
809 activity = "<command string not enabled>";
810 else
811 activity = beentry->st_activity_raw;
812
816
817 PG_RETURN_TEXT_P(ret);
818}
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
int32_t int32
Definition c.h:620
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
Definition c.h:776
text * cstring_to_text(const char *s)
Definition varlena.c:184

References cstring_to_text(), fb(), HAS_PGSTAT_PERMISSIONS, pfree(), PG_GETARG_INT32, PG_RETURN_TEXT_P, pgstat_clip_activity(), and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_activity_start()

Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 876 of file pgstatfuncs.c.

877{
878 int32 procNumber = PG_GETARG_INT32(0);
881
882 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
884
885 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
887
888 result = beentry->st_activity_start_timestamp;
889
890 /*
891 * No time recorded for start of current query -- this is the case if the
892 * user hasn't enabled query-level stats collection.
893 */
894 if (result == 0)
896
898}
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_TIMESTAMPTZ(x)
Definition timestamp.h:68

References fb(), HAS_PGSTAT_PERMISSIONS, PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_get_beentry_by_proc_number(), and result.

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 946 of file pgstatfuncs.c.

947{
948 int32 procNumber = PG_GETARG_INT32(0);
950 char remote_host[NI_MAXHOST];
951 int ret;
952
953 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
955
956 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
958
959 /* A zeroed client addr means we don't know */
960 if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
961 sizeof(beentry->st_clientaddr)))
963
964 switch (beentry->st_clientaddr.addr.ss_family)
965 {
966 case AF_INET:
967 case AF_INET6:
968 break;
969 default:
971 }
972
973 remote_host[0] = '\0';
974 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
975 beentry->st_clientaddr.salen,
976 remote_host, sizeof(remote_host),
977 NULL, 0,
979 if (ret != 0)
981
982 clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
983
985 CStringGetDatum(remote_host)));
986}

References clean_ipv6_addr(), CStringGetDatum(), DirectFunctionCall1, fb(), HAS_PGSTAT_PERMISSIONS, inet_in(), PG_GETARG_INT32, pg_getnameinfo_all(), pg_memory_is_all_zeros(), PG_RETURN_DATUM, PG_RETURN_NULL, and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_client_port()

Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 989 of file pgstatfuncs.c.

990{
991 int32 procNumber = PG_GETARG_INT32(0);
993 char remote_port[NI_MAXSERV];
994 int ret;
995
996 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
998
999 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
1001
1002 /* A zeroed client addr means we don't know */
1003 if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
1004 sizeof(beentry->st_clientaddr)))
1006
1007 switch (beentry->st_clientaddr.addr.ss_family)
1008 {
1009 case AF_INET:
1010 case AF_INET6:
1011 break;
1012 case AF_UNIX:
1013 PG_RETURN_INT32(-1);
1014 default:
1016 }
1017
1018 remote_port[0] = '\0';
1019 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1020 beentry->st_clientaddr.salen,
1021 NULL, 0,
1022 remote_port, sizeof(remote_port),
1024 if (ret != 0)
1026
1028 CStringGetDatum(remote_port)));
1029}
Datum int4in(PG_FUNCTION_ARGS)
Definition int.c:316

References CStringGetDatum(), DirectFunctionCall1, fb(), HAS_PGSTAT_PERMISSIONS, int4in(), PG_GETARG_INT32, pg_getnameinfo_all(), pg_memory_is_all_zeros(), PG_RETURN_DATUM, PG_RETURN_INT32, PG_RETURN_NULL, and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_dbid()

Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 735 of file pgstatfuncs.c.

736{
737 int32 procNumber = PG_GETARG_INT32(0);
739
740 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
742
743 PG_RETURN_OID(beentry->st_databaseid);
744}
#define PG_RETURN_OID(x)
Definition fmgr.h:361

References fb(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_OID, and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_idset()

Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

Definition at line 227 of file pgstatfuncs.c.

228{
230 int *fctx;
231
232 /* stuff done only on the first call of the function */
233 if (SRF_IS_FIRSTCALL())
234 {
235 /* create a function context for cross-call persistence */
237
238 fctx = MemoryContextAlloc(funcctx->multi_call_memory_ctx,
239 sizeof(int));
240 funcctx->user_fctx = fctx;
241
242 fctx[0] = 0;
243 }
244
245 /* stuff done on every call of the function */
247 fctx = funcctx->user_fctx;
248
249 fctx[0] += 1;
250
251 /*
252 * We recheck pgstat_fetch_stat_numbackends() each time through, just in
253 * case the local status data has been refreshed since we started. It's
254 * plenty cheap enough if not. If a refresh does happen, we'll likely
255 * miss or duplicate some backend IDs, but we're content not to crash.
256 * (Refreshing midway through such a query would be problematic usage
257 * anyway, since the backend IDs we've already returned might no longer
258 * refer to extant sessions.)
259 */
261 {
262 /* do when there is more left to send */
264
266 }
267 else
268 {
269 /* do when there is no more left */
271 }
272}
#define SRF_IS_FIRSTCALL()
Definition funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition funcapi.h:328
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232

References fb(), Int32GetDatum(), MemoryContextAlloc(), pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, and SRF_RETURN_NEXT.

◆ pg_stat_get_backend_io()

Datum pg_stat_get_backend_io ( PG_FUNCTION_ARGS  )

Definition at line 1609 of file pgstatfuncs.c.

1610{
1613 int pid;
1616
1617 InitMaterializedSRF(fcinfo, 0);
1618 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1619
1620 pid = PG_GETARG_INT32(0);
1622
1623 if (!backend_stats)
1624 return (Datum) 0;
1625
1626 bktype_stats = &backend_stats->io_stats;
1627
1628 /*
1629 * In Assert builds, we can afford an extra loop through all of the
1630 * counters (in pg_stat_io_build_tuples()), checking that only expected
1631 * stats are non-zero, since it keeps the non-Assert code cleaner.
1632 */
1634
1635 /* save tuples with data from this PgStat_BktypeIO */
1637 backend_stats->stat_reset_timestamp);
1638 return (Datum) 0;
1639}
#define Assert(condition)
Definition c.h:943
BackendType
Definition miscadmin.h:350
PgStat_Backend * pgstat_fetch_stat_backend_by_pid(int pid, BackendType *bktype)
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
Definition pgstat_io.c:37
static void pg_stat_io_build_tuples(ReturnSetInfo *rsinfo, PgStat_BktypeIO *bktype_stats, BackendType bktype, TimestampTz stat_reset_timestamp)

References Assert, fb(), InitMaterializedSRF(), PG_GETARG_INT32, pg_stat_io_build_tuples(), pgstat_bktype_io_stats_valid(), and pgstat_fetch_stat_backend_by_pid().

◆ pg_stat_get_backend_pid()

Datum pg_stat_get_backend_pid ( PG_FUNCTION_ARGS  )

Definition at line 722 of file pgstatfuncs.c.

723{
724 int32 procNumber = PG_GETARG_INT32(0);
726
727 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
729
730 PG_RETURN_INT32(beentry->st_procpid);
731}

References fb(), PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_start()

Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 924 of file pgstatfuncs.c.

925{
926 int32 procNumber = PG_GETARG_INT32(0);
929
930 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
932
933 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
935
936 result = beentry->st_proc_start_timestamp;
937
938 if (result == 0) /* probably can't happen? */
940
942}

References fb(), HAS_PGSTAT_PERMISSIONS, PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_get_beentry_by_proc_number(), and result.

◆ pg_stat_get_backend_subxact()

Datum pg_stat_get_backend_subxact ( PG_FUNCTION_ARGS  )

Definition at line 760 of file pgstatfuncs.c.

761{
762#define PG_STAT_GET_SUBXACT_COLS 2
763 TupleDesc tupdesc;
765 bool nulls[PG_STAT_GET_SUBXACT_COLS] = {0};
766 int32 procNumber = PG_GETARG_INT32(0);
768
769 /* Initialise attributes information in the tuple descriptor */
771 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subxact_count",
772 INT4OID, -1, 0);
773 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "subxact_overflow",
774 BOOLOID, -1, 0);
775
776 TupleDescFinalize(tupdesc);
777 BlessTupleDesc(tupdesc);
778
780 {
781 /* Fill values and NULLs */
782 values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
783 values[1] = BoolGetDatum(local_beentry->backend_subxact_overflowed);
784 }
785 else
786 {
787 nulls[0] = true;
788 nulls[1] = true;
789 }
790
791 /* Returns the record as Datum */
793}
LocalPgBackendStatus * pgstat_get_local_beentry_by_proc_number(ProcNumber procNumber)
#define PG_STAT_GET_SUBXACT_COLS

References BlessTupleDesc(), BoolGetDatum(), CreateTemplateTupleDesc(), fb(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), PG_GETARG_INT32, PG_RETURN_DATUM, PG_STAT_GET_SUBXACT_COLS, pgstat_get_local_beentry_by_proc_number(), TupleDescFinalize(), TupleDescInitEntry(), and values.

◆ pg_stat_get_backend_userid()

Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 748 of file pgstatfuncs.c.

749{
750 int32 procNumber = PG_GETARG_INT32(0);
752
753 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
755
756 PG_RETURN_OID(beentry->st_userid);
757}

References fb(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_OID, and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_wait_event()

Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 848 of file pgstatfuncs.c.

849{
850 int32 procNumber = PG_GETARG_INT32(0);
852 PGPROC *proc;
853 const char *wait_event = NULL;
854
855 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
856 wait_event = "<backend information not available>";
857 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
858 wait_event = "<insufficient privilege>";
859 else
860 {
861 proc = BackendPidGetProc(beentry->st_procpid);
862 if (!proc)
863 proc = AuxiliaryPidGetProc(beentry->st_procpid);
864 if (proc)
866 }
867
868 if (!wait_event)
870
872}

References AuxiliaryPidGetProc(), BackendPidGetProc(), cstring_to_text(), fb(), HAS_PGSTAT_PERMISSIONS, PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TEXT_P, pgstat_get_beentry_by_proc_number(), pgstat_get_wait_event(), 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 821 of file pgstatfuncs.c.

822{
823 int32 procNumber = PG_GETARG_INT32(0);
825 PGPROC *proc;
826 const char *wait_event_type = NULL;
827
828 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
829 wait_event_type = "<backend information not available>";
830 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
831 wait_event_type = "<insufficient privilege>";
832 else
833 {
834 proc = BackendPidGetProc(beentry->st_procpid);
835 if (!proc)
836 proc = AuxiliaryPidGetProc(beentry->st_procpid);
837 if (proc)
839 }
840
841 if (!wait_event_type)
843
845}

References AuxiliaryPidGetProc(), BackendPidGetProc(), cstring_to_text(), fb(), HAS_PGSTAT_PERMISSIONS, PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TEXT_P, pgstat_get_beentry_by_proc_number(), pgstat_get_wait_event_type(), and PGPROC::wait_event_info.

◆ pg_stat_get_backend_wal()

Datum pg_stat_get_backend_wal ( PG_FUNCTION_ARGS  )

Definition at line 1707 of file pgstatfuncs.c.

1708{
1709 int pid;
1712
1713 pid = PG_GETARG_INT32(0);
1715
1716 if (!backend_stats)
1718
1719 bktype_stats = backend_stats->wal_counters;
1720
1721 /* save tuples with data from this PgStat_WalCounters */
1722 return (pg_stat_wal_build_tuple(bktype_stats, backend_stats->stat_reset_timestamp));
1723}
static Datum pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters, TimestampTz stat_reset_timestamp)

References fb(), PG_GETARG_INT32, PG_RETURN_NULL, pg_stat_wal_build_tuple(), and pgstat_fetch_stat_backend_by_pid().

◆ pg_stat_get_backend_xact_start()

Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 902 of file pgstatfuncs.c.

903{
904 int32 procNumber = PG_GETARG_INT32(0);
907
908 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
910
911 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
913
914 result = beentry->st_xact_start_timestamp;
915
916 if (result == 0) /* not in a transaction */
918
920}

References fb(), HAS_PGSTAT_PERMISSIONS, PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_get_beentry_by_proc_number(), and result.

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1294 of file pgstatfuncs.c.

1295{
1296 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1297}
#define PG_RETURN_INT64(x)
Definition fmgr.h:370
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 1300 of file pgstatfuncs.c.

1301{
1302 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
1303}

References PG_RETURN_INT64, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_bgwriter_stat_reset_time()

Datum pg_stat_get_bgwriter_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1328 of file pgstatfuncs.c.

1329{
1330 PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
1331}

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_buf_alloc()

Datum pg_stat_get_buf_alloc ( PG_FUNCTION_ARGS  )

Definition at line 1334 of file pgstatfuncs.c.

1335{
1337}

References PG_RETURN_INT64, and pgstat_fetch_stat_bgwriter().

◆ pg_stat_get_checkpointer_buffers_written()

Datum pg_stat_get_checkpointer_buffers_written ( PG_FUNCTION_ARGS  )

Definition at line 1282 of file pgstatfuncs.c.

1283{
1285}
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_num_performed()

Datum pg_stat_get_checkpointer_num_performed ( PG_FUNCTION_ARGS  )

Definition at line 1258 of file pgstatfuncs.c.

1259{
1261}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_num_requested()

Datum pg_stat_get_checkpointer_num_requested ( PG_FUNCTION_ARGS  )

Definition at line 1252 of file pgstatfuncs.c.

1253{
1255}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_num_timed()

Datum pg_stat_get_checkpointer_num_timed ( PG_FUNCTION_ARGS  )

Definition at line 1246 of file pgstatfuncs.c.

1247{
1249}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_restartpoints_performed()

Datum pg_stat_get_checkpointer_restartpoints_performed ( PG_FUNCTION_ARGS  )

Definition at line 1276 of file pgstatfuncs.c.

1277{
1278 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_performed);
1279}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_restartpoints_requested()

Datum pg_stat_get_checkpointer_restartpoints_requested ( PG_FUNCTION_ARGS  )

Definition at line 1270 of file pgstatfuncs.c.

1271{
1272 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_requested);
1273}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_restartpoints_timed()

Datum pg_stat_get_checkpointer_restartpoints_timed ( PG_FUNCTION_ARGS  )

Definition at line 1264 of file pgstatfuncs.c.

1265{
1266 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_timed);
1267}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_slru_written()

Datum pg_stat_get_checkpointer_slru_written ( PG_FUNCTION_ARGS  )

Definition at line 1288 of file pgstatfuncs.c.

1289{
1291}

References PG_RETURN_INT64, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_stat_reset_time()

Datum pg_stat_get_checkpointer_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1322 of file pgstatfuncs.c.

1323{
1325}

References PG_RETURN_TIMESTAMPTZ, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_sync_time()

Datum pg_stat_get_checkpointer_sync_time ( PG_FUNCTION_ARGS  )

Definition at line 1314 of file pgstatfuncs.c.

1315{
1316 /* time is already in msec, just convert to double for presentation */
1317 PG_RETURN_FLOAT8((double)
1318 pgstat_fetch_stat_checkpointer()->sync_time);
1319}
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369

References PG_RETURN_FLOAT8, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_checkpointer_write_time()

Datum pg_stat_get_checkpointer_write_time ( PG_FUNCTION_ARGS  )

Definition at line 1306 of file pgstatfuncs.c.

1307{
1308 /* time is already in msec, just convert to double for presentation */
1309 PG_RETURN_FLOAT8((double)
1310 pgstat_fetch_stat_checkpointer()->write_time);
1311}

References PG_RETURN_FLOAT8, and pgstat_fetch_stat_checkpointer().

◆ pg_stat_get_db_checksum_failures()

Datum pg_stat_get_db_checksum_failures ( PG_FUNCTION_ARGS  )

Definition at line 1181 of file pgstatfuncs.c.

1182{
1183 Oid dbid = PG_GETARG_OID(0);
1184 int64 result;
1186
1187 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1188 result = 0;
1189 else
1190 result = (int64) (dbentry->checksum_failures);
1191
1193}

References fb(), PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_dbentry(), and result.

◆ pg_stat_get_db_checksum_last_failure()

Datum pg_stat_get_db_checksum_last_failure ( PG_FUNCTION_ARGS  )

Definition at line 1196 of file pgstatfuncs.c.

1197{
1198 Oid dbid = PG_GETARG_OID(0);
1201
1202 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1203 result = 0;
1204 else
1206
1207 if (result == 0)
1209 else
1211}
TimestampTz last_checksum_failure
Definition pgstat.h:389

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

◆ pg_stat_get_db_conflict_all()

Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

Definition at line 1161 of file pgstatfuncs.c.

1162{
1163 Oid dbid = PG_GETARG_OID(0);
1164 int64 result;
1166
1167 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1168 result = 0;
1169 else
1170 result = (int64) (dbentry->conflict_tablespace +
1171 dbentry->conflict_lock +
1172 dbentry->conflict_snapshot +
1173 dbentry->conflict_logicalslot +
1174 dbentry->conflict_bufferpin +
1175 dbentry->conflict_startup_deadlock);
1176
1178}

References fb(), PG_GETARG_OID, PG_RETURN_INT64, pgstat_fetch_stat_dbentry(), and result.

◆ pg_stat_get_db_numbackends()

Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1033 of file pgstatfuncs.c.

1034{
1035 Oid dbid = PG_GETARG_OID(0);
1036 int32 result;
1038 int idx;
1039
1040 result = 0;
1041 for (idx = 1; idx <= tot_backends; idx++)
1042 {
1044
1045 if (local_beentry->backendStatus.st_databaseid == dbid)
1046 result++;
1047 }
1048
1050}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262

References fb(), idx(), PG_GETARG_OID, PG_RETURN_INT32, pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), and result.

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1142 of file pgstatfuncs.c.

1143{
1144 Oid dbid = PG_GETARG_OID(0);
1147
1148 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1149 result = 0;
1150 else
1152
1153 if (result == 0)
1155 else
1157}
TimestampTz stat_reset_timestamp
Definition pgstat.h:402

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

◆ pg_stat_get_function_calls()

Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 177 of file pgstatfuncs.c.

178{
179 Oid funcid = PG_GETARG_OID(0);
181
182 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
184 PG_RETURN_INT64(funcentry->numcalls);
185}

References fb(), PG_GETARG_OID, PG_RETURN_INT64, PG_RETURN_NULL, and pgstat_fetch_stat_funcentry().

◆ pg_stat_get_function_stat_reset_time()

Datum pg_stat_get_function_stat_reset_time ( PG_FUNCTION_ARGS  )

◆ pg_stat_get_io()

Datum pg_stat_get_io ( PG_FUNCTION_ARGS  )

Definition at line 1568 of file pgstatfuncs.c.

1569{
1572
1573 InitMaterializedSRF(fcinfo, 0);
1574 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1575
1577
1578 for (int bktype = 0; bktype < BACKEND_NUM_TYPES; bktype++)
1579 {
1581
1582 /*
1583 * In Assert builds, we can afford an extra loop through all of the
1584 * counters (in pg_stat_io_build_tuples()), checking that only
1585 * expected stats are non-zero, since it keeps the non-Assert code
1586 * cleaner.
1587 */
1589
1590 /*
1591 * For those BackendTypes without IO Operation stats, skip
1592 * representing them in the view altogether.
1593 */
1595 continue;
1596
1597 /* save tuples with data from this PgStat_BktypeIO */
1599 backends_io_stats->stat_reset_timestamp);
1600 }
1601
1602 return (Datum) 0;
1603}
#define BACKEND_NUM_TYPES
Definition miscadmin.h:392
PgStat_IO * pgstat_fetch_stat_io(void)
Definition pgstat_io.c:164
bool pgstat_tracks_io_bktype(BackendType bktype)
Definition pgstat_io.c:351

References Assert, BACKEND_NUM_TYPES, fb(), InitMaterializedSRF(), pg_stat_io_build_tuples(), pgstat_bktype_io_stats_valid(), pgstat_fetch_stat_io(), and pgstat_tracks_io_bktype().

◆ pg_stat_get_lock()

Datum pg_stat_get_lock ( PG_FUNCTION_ARGS  )

Definition at line 1741 of file pgstatfuncs.c.

1742{
1743#define PG_STAT_LOCK_COLS 5
1746
1747 InitMaterializedSRF(fcinfo, 0);
1748 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1749
1751
1752 for (int lcktype = 0; lcktype <= LOCKTAG_LAST_TYPE; lcktype++)
1753 {
1754 const char *locktypename;
1756 bool nulls[PG_STAT_LOCK_COLS] = {0};
1758 int i = 0;
1759
1761
1763 values[i++] = Int64GetDatum(lck_stats->waits);
1764 values[i++] = Int64GetDatum(lck_stats->wait_time);
1765 values[i++] = Int64GetDatum(lck_stats->fastpath_exceeded);
1766 values[i] = TimestampTzGetDatum(lock_stats->stat_reset_timestamp);
1767
1768 Assert(i + 1 == PG_STAT_LOCK_COLS);
1769
1770 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1771 }
1772
1773 return (Datum) 0;
1774}
int i
Definition isn.c:77
const char *const LockTagTypeNames[]
Definition lockfuncs.c:28
#define LOCKTAG_LAST_TYPE
Definition locktag.h:52
PgStat_Lock * pgstat_fetch_stat_lock(void)
Definition pgstat_lock.c:26
#define PG_STAT_LOCK_COLS

References Assert, CStringGetTextDatum, fb(), i, InitMaterializedSRF(), Int64GetDatum(), LOCKTAG_LAST_TYPE, LockTagTypeNames, PG_STAT_LOCK_COLS, pgstat_fetch_stat_lock(), TimestampTzGetDatum(), tuplestore_putvalues(), and values.

◆ pg_stat_get_progress_info()

Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 278 of file pgstatfuncs.c.

279{
280#define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
282 int curr_backend;
283 char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
284 ProgressCommandType cmdtype;
285 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
286
287 /* Translate command name into command type code. */
288 if (pg_strcasecmp(cmd, "VACUUM") == 0)
289 cmdtype = PROGRESS_COMMAND_VACUUM;
290 else if (pg_strcasecmp(cmd, "ANALYZE") == 0)
291 cmdtype = PROGRESS_COMMAND_ANALYZE;
292 else if (pg_strcasecmp(cmd, "REPACK") == 0)
293 cmdtype = PROGRESS_COMMAND_REPACK;
294 else if (pg_strcasecmp(cmd, "CREATE INDEX") == 0)
296 else if (pg_strcasecmp(cmd, "BASEBACKUP") == 0)
298 else if (pg_strcasecmp(cmd, "COPY") == 0)
299 cmdtype = PROGRESS_COMMAND_COPY;
300 else if (pg_strcasecmp(cmd, "DATACHECKSUMS") == 0)
302 else
305 errmsg("invalid command name: \"%s\"", cmd)));
306
307 InitMaterializedSRF(fcinfo, 0);
308
309 /* 1-based index */
311 {
315 bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
316 int i;
317
319 beentry = &local_beentry->backendStatus;
320
321 /*
322 * Report values for only those backends which are running the given
323 * command.
324 */
325 if (beentry->st_progress_command != cmdtype)
326 continue;
327
328 /* Value available to all callers */
329 values[0] = Int32GetDatum(beentry->st_procpid);
330 values[1] = ObjectIdGetDatum(beentry->st_databaseid);
331
332 /* show rest of the values including relid only to role members */
333 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
334 {
335 values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
336 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
337 values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
338 }
339 else
340 {
341 nulls[2] = true;
342 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
343 nulls[i + 3] = true;
344 }
345
346 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
347 }
348
349 return (Datum) 0;
350}
#define PGSTAT_NUM_PROGRESS_PARAM
ProgressCommandType
@ PROGRESS_COMMAND_ANALYZE
@ PROGRESS_COMMAND_CREATE_INDEX
@ PROGRESS_COMMAND_VACUUM
@ PROGRESS_COMMAND_BASEBACKUP
@ PROGRESS_COMMAND_REPACK
@ PROGRESS_COMMAND_DATACHECKSUMS
@ PROGRESS_COMMAND_COPY
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
static char * errmsg
#define PG_STAT_GET_PROGRESS_COLS
int pg_strcasecmp(const char *s1, const char *s2)
char * text_to_cstring(const text *t)
Definition varlena.c:217

References ereport, errcode(), errmsg, ERROR, fb(), HAS_PGSTAT_PERMISSIONS, i, InitMaterializedSRF(), Int32GetDatum(), Int64GetDatum(), ObjectIdGetDatum(), PG_GETARG_TEXT_PP, PG_STAT_GET_PROGRESS_COLS, pg_strcasecmp(), pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), PGSTAT_NUM_PROGRESS_PARAM, PROGRESS_COMMAND_ANALYZE, PROGRESS_COMMAND_BASEBACKUP, PROGRESS_COMMAND_COPY, PROGRESS_COMMAND_CREATE_INDEX, PROGRESS_COMMAND_DATACHECKSUMS, PROGRESS_COMMAND_REPACK, PROGRESS_COMMAND_VACUUM, text_to_cstring(), tuplestore_putvalues(), and values.

◆ pg_stat_get_replication_slot()

Datum pg_stat_get_replication_slot ( PG_FUNCTION_ARGS  )

Definition at line 2182 of file pgstatfuncs.c.

2183{
2184#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
2186 NameData slotname;
2187 TupleDesc tupdesc;
2189 bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
2192
2193 /* Initialise attributes information in the tuple descriptor */
2195 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
2196 TEXTOID, -1, 0);
2197 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "spill_txns",
2198 INT8OID, -1, 0);
2199 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "spill_count",
2200 INT8OID, -1, 0);
2201 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "spill_bytes",
2202 INT8OID, -1, 0);
2203 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stream_txns",
2204 INT8OID, -1, 0);
2205 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stream_count",
2206 INT8OID, -1, 0);
2207 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
2208 INT8OID, -1, 0);
2209 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
2210 INT8OID, -1, 0);
2211 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
2212 INT8OID, -1, 0);
2213 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
2214 INT8OID, -1, 0);
2215 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
2216 INT8OID, -1, 0);
2217 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
2218 TIMESTAMPTZOID, -1, 0);
2219 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
2220 TIMESTAMPTZOID, -1, 0);
2221 TupleDescFinalize(tupdesc);
2222 BlessTupleDesc(tupdesc);
2223
2225 slotent = pgstat_fetch_replslot(slotname);
2226 if (!slotent)
2227 {
2228 /*
2229 * If the slot is not found, initialise its stats. This is possible if
2230 * the create slot message is lost.
2231 */
2233 slotent = &allzero;
2234 }
2235
2236 values[0] = CStringGetTextDatum(NameStr(slotname));
2237 values[1] = Int64GetDatum(slotent->spill_txns);
2238 values[2] = Int64GetDatum(slotent->spill_count);
2239 values[3] = Int64GetDatum(slotent->spill_bytes);
2240 values[4] = Int64GetDatum(slotent->stream_txns);
2241 values[5] = Int64GetDatum(slotent->stream_count);
2242 values[6] = Int64GetDatum(slotent->stream_bytes);
2243 values[7] = Int64GetDatum(slotent->mem_exceeded_count);
2244 values[8] = Int64GetDatum(slotent->total_txns);
2245 values[9] = Int64GetDatum(slotent->total_bytes);
2246 values[10] = Int64GetDatum(slotent->slotsync_skip_count);
2247
2248 if (slotent->slotsync_last_skip == 0)
2249 nulls[11] = true;
2250 else
2251 values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
2252
2253 if (slotent->stat_reset_timestamp == 0)
2254 nulls[12] = true;
2255 else
2256 values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
2257
2258 /* Returns the record as Datum */
2260}
#define NameStr(name)
Definition c.h:835
#define PG_GETARG_TEXT_P(n)
Definition fmgr.h:337
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
Definition c.h:830

References BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, fb(), heap_form_tuple(), HeapTupleGetDatum(), Int64GetDatum(), NameStr, namestrcpy(), PG_GETARG_TEXT_P, PG_RETURN_DATUM, PG_STAT_GET_REPLICATION_SLOT_COLS, pgstat_fetch_replslot(), text_to_cstring(), TimestampTzGetDatum(), TupleDescFinalize(), TupleDescInitEntry(), and values.

◆ pg_stat_get_slru()

Datum pg_stat_get_slru ( PG_FUNCTION_ARGS  )

Definition at line 1780 of file pgstatfuncs.c.

1781{
1782#define PG_STAT_GET_SLRU_COLS 9
1783 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1784 int i;
1785 PgStat_SLRUStats *stats;
1786
1787 InitMaterializedSRF(fcinfo, 0);
1788
1789 /* request SLRU stats from the cumulative stats system */
1790 stats = pgstat_fetch_slru();
1791
1792 for (i = 0;; i++)
1793 {
1794 /* for each row */
1796 bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
1798 const char *name;
1799
1801
1802 if (!name)
1803 break;
1804
1805 stat = stats[i];
1806
1808 values[1] = Int64GetDatum(stat.blocks_zeroed);
1809 values[2] = Int64GetDatum(stat.blocks_hit);
1810 values[3] = Int64GetDatum(stat.blocks_read);
1811 values[4] = Int64GetDatum(stat.blocks_written);
1812 values[5] = Int64GetDatum(stat.blocks_exists);
1813 values[6] = Int64GetDatum(stat.flush);
1814 values[7] = Int64GetDatum(stat.truncate);
1815 values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1816
1817 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1818 }
1819
1820 return (Datum) 0;
1821}
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition pgstat_slru.c:91
const char * pgstat_get_slru_name(int slru_idx)
#define PG_STAT_GET_SLRU_COLS
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
const char * name
#define stat
Definition win32_port.h:74

References cstring_to_text(), fb(), i, InitMaterializedSRF(), Int64GetDatum(), name, PG_STAT_GET_SLRU_COLS, pgstat_fetch_slru(), pgstat_get_slru_name(), PointerGetDatum(), stat, TimestampTzGetDatum(), tuplestore_putvalues(), and values.

◆ pg_stat_get_snapshot_timestamp()

Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1900 of file pgstatfuncs.c.

1901{
1902 bool have_snapshot;
1903 TimestampTz ts;
1904
1906
1907 if (!have_snapshot)
1909
1911}
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition pgstat.c:1071

References fb(), 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 2267 of file pgstatfuncs.c.

2268{
2269#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 13
2270 Oid subid = PG_GETARG_OID(0);
2271 TupleDesc tupdesc;
2273 bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
2276 int i = 0;
2277
2278 /* Get subscription stats */
2280
2281 /* Initialise attributes information in the tuple descriptor */
2283 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subid",
2284 OIDOID, -1, 0);
2285 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
2286 INT8OID, -1, 0);
2287 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_seq_error_count",
2288 INT8OID, -1, 0);
2289 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "sync_table_error_count",
2290 INT8OID, -1, 0);
2291 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "confl_insert_exists",
2292 INT8OID, -1, 0);
2293 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "confl_update_origin_differs",
2294 INT8OID, -1, 0);
2295 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "confl_update_exists",
2296 INT8OID, -1, 0);
2297 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "confl_update_deleted",
2298 INT8OID, -1, 0);
2299 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "confl_update_missing",
2300 INT8OID, -1, 0);
2301 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "confl_delete_origin_differs",
2302 INT8OID, -1, 0);
2303 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "confl_delete_missing",
2304 INT8OID, -1, 0);
2305 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "confl_multiple_unique_conflicts",
2306 INT8OID, -1, 0);
2307 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
2308 TIMESTAMPTZOID, -1, 0);
2309 TupleDescFinalize(tupdesc);
2310 BlessTupleDesc(tupdesc);
2311
2312 if (!subentry)
2313 {
2314 /* If the subscription is not found, initialise its stats */
2315 memset(&allzero, 0, sizeof(PgStat_StatSubEntry));
2316 subentry = &allzero;
2317 }
2318
2319 /* subid */
2320 values[i++] = ObjectIdGetDatum(subid);
2321
2322 /* apply_error_count */
2323 values[i++] = Int64GetDatum(subentry->apply_error_count);
2324
2325 /* sync_seq_error_count */
2326 values[i++] = Int64GetDatum(subentry->sync_seq_error_count);
2327
2328 /* sync_table_error_count */
2329 values[i++] = Int64GetDatum(subentry->sync_table_error_count);
2330
2331 /* conflict count */
2333 values[i++] = Int64GetDatum(subentry->conflict_count[nconflict]);
2334
2335 /* stats_reset */
2336 if (subentry->stat_reset_timestamp == 0)
2337 nulls[i] = true;
2338 else
2339 values[i] = TimestampTzGetDatum(subentry->stat_reset_timestamp);
2340
2342
2343 /* Returns the record as Datum */
2345}
#define CONFLICT_NUM_TYPES
Definition conflict.h:64
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS

References Assert, BlessTupleDesc(), CONFLICT_NUM_TYPES, CreateTemplateTupleDesc(), fb(), heap_form_tuple(), HeapTupleGetDatum(), i, Int64GetDatum(), ObjectIdGetDatum(), PG_GETARG_OID, PG_RETURN_DATUM, PG_STAT_GET_SUBSCRIPTION_STATS_COLS, pgstat_fetch_stat_subscription(), TimestampTzGetDatum(), TupleDescFinalize(), TupleDescInitEntry(), and values.

◆ pg_stat_get_wal()

Datum pg_stat_get_wal ( PG_FUNCTION_ARGS  )

Definition at line 1729 of file pgstatfuncs.c.

1730{
1732
1733 /* Get statistics about WAL activity */
1735
1736 return (pg_stat_wal_build_tuple(wal_stats->wal_counters,
1737 wal_stats->stat_reset_timestamp));
1738}
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition pgstat_wal.c:67

References fb(), pg_stat_wal_build_tuple(), and pgstat_fetch_stat_wal().

◆ pg_stat_get_xact_function_calls()

Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 1870 of file pgstatfuncs.c.

1871{
1872 Oid funcid = PG_GETARG_OID(0);
1874
1875 if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1877 PG_RETURN_INT64(funcentry->numcalls);
1878}

References fb(), find_funcstat_entry(), PG_GETARG_OID, PG_RETURN_INT64, and PG_RETURN_NULL.

◆ pg_stat_have_stats()

Datum pg_stat_have_stats ( PG_FUNCTION_ARGS  )

Definition at line 2355 of file pgstatfuncs.c.

2356{
2358 Oid dboid = PG_GETARG_OID(1);
2359 uint64 objid = PG_GETARG_INT64(2);
2361
2362 PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objid));
2363}
uint64_t uint64
Definition c.h:625
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:1088
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition pgstat.c:1445
#define PgStat_Kind
Definition pgstat_kind.h:17

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

◆ pg_stat_io_build_tuples()

static void pg_stat_io_build_tuples ( ReturnSetInfo rsinfo,
PgStat_BktypeIO bktype_stats,
BackendType  bktype,
TimestampTz  stat_reset_timestamp 
)
static

Definition at line 1471 of file pgstatfuncs.c.

1475{
1477
1478 for (int io_obj = 0; io_obj < IOOBJECT_NUM_TYPES; io_obj++)
1479 {
1481
1483 {
1485
1487 bool nulls[IO_NUM_COLUMNS] = {0};
1488
1489 /*
1490 * Some combinations of BackendType, IOObject, and IOContext are
1491 * not valid for any type of IOOp. In such cases, omit the entire
1492 * row from the view.
1493 */
1495 continue;
1496
1500 if (stat_reset_timestamp != 0)
1501 values[IO_COL_RESET_TIME] = TimestampTzGetDatum(stat_reset_timestamp);
1502 else
1503 nulls[IO_COL_RESET_TIME] = true;
1504
1505 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
1506 {
1510
1511 /*
1512 * Some combinations of BackendType and IOOp, of IOContext and
1513 * IOOp, and of IOObject and IOOp are not tracked. Set these
1514 * cells in the view NULL.
1515 */
1517 {
1518 PgStat_Counter count =
1520
1521 values[op_idx] = Int64GetDatum(count);
1522 }
1523 else
1524 nulls[op_idx] = true;
1525
1526 if (!nulls[op_idx])
1527 {
1528 /* not every operation is timed */
1529 if (time_idx != IO_COL_INVALID)
1530 {
1531 PgStat_Counter time =
1533
1535 }
1536
1537 /* not every IO is tracked in bytes */
1538 if (byte_idx != IO_COL_INVALID)
1539 {
1540 char buf[256];
1541 PgStat_Counter byte =
1543
1544 /* Convert to numeric */
1545 snprintf(buf, sizeof buf, INT64_FORMAT, byte);
1549 Int32GetDatum(-1));
1550 }
1551 }
1552 else
1553 {
1554 if (time_idx != IO_COL_INVALID)
1555 nulls[time_idx] = true;
1556 if (byte_idx != IO_COL_INVALID)
1557 nulls[byte_idx] = true;
1558 }
1559 }
1560
1561 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1562 values, nulls);
1563 }
1564 }
1565}
#define INT64_FORMAT
Definition c.h:634
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define IOOP_NUM_TYPES
Definition pgstat.h:323
#define IOCONTEXT_NUM_TYPES
Definition pgstat.h:297
int64 PgStat_Counter
Definition pgstat.h:71
#define IOOBJECT_NUM_TYPES
Definition pgstat.h:286
const char * pgstat_get_io_context_name(IOContext io_context)
Definition pgstat_io.c:240
const char * pgstat_get_io_object_name(IOObject io_object)
Definition pgstat_io.c:261
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition pgstat_io.c:479
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition pgstat_io.c:395
static double pg_stat_us_to_ms(PgStat_Counter val_ms)
static io_stat_col pgstat_get_io_time_index(IOOp io_op)
static io_stat_col pgstat_get_io_op_index(IOOp io_op)
static io_stat_col pgstat_get_io_byte_index(IOOp io_op)
#define snprintf
Definition port.h:260
static Datum Float8GetDatum(float8 X)
Definition postgres.h:502

References buf, CStringGetDatum(), CStringGetTextDatum, DirectFunctionCall3, fb(), Float8GetDatum(), GetBackendTypeDesc(), Int32GetDatum(), INT64_FORMAT, Int64GetDatum(), IO_COL_BACKEND_TYPE, IO_COL_CONTEXT, IO_COL_INVALID, IO_COL_OBJECT, IO_COL_RESET_TIME, IO_NUM_COLUMNS, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, numeric_in(), ObjectIdGetDatum(), pg_stat_us_to_ms(), pgstat_get_io_byte_index(), pgstat_get_io_context_name(), pgstat_get_io_object_name(), pgstat_get_io_op_index(), pgstat_get_io_time_index(), pgstat_tracks_io_object(), pgstat_tracks_io_op(), snprintf, TimestampTzGetDatum(), tuplestore_putvalues(), and values.

Referenced by pg_stat_get_backend_io(), and pg_stat_get_io().

◆ pg_stat_reset()

Datum pg_stat_reset ( PG_FUNCTION_ARGS  )

Definition at line 1935 of file pgstatfuncs.c.

1936{
1938
1940}
void pgstat_reset_counters(void)
Definition pgstat.c:863

References PG_RETURN_VOID, and pgstat_reset_counters().

◆ pg_stat_reset_backend_stats()

Datum pg_stat_reset_backend_stats ( PG_FUNCTION_ARGS  )

Definition at line 2024 of file pgstatfuncs.c.

2025{
2026 PGPROC *proc;
2028 ProcNumber procNumber;
2029 int backend_pid = PG_GETARG_INT32(0);
2030
2031 proc = BackendPidGetProc(backend_pid);
2032
2033 /* This could be an auxiliary process */
2034 if (!proc)
2035 proc = AuxiliaryPidGetProc(backend_pid);
2036
2037 if (!proc)
2039
2040 procNumber = GetNumberFromPGProc(proc);
2041
2043 if (!beentry)
2045
2046 /* Check if the backend type tracks statistics */
2047 if (!pgstat_tracks_backend_bktype(beentry->st_backendType))
2049
2051
2053}
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:882
bool pgstat_tracks_backend_bktype(BackendType bktype)
#define PGSTAT_KIND_BACKEND
Definition pgstat_kind.h:32
#define GetNumberFromPGProc(proc)
Definition proc.h:505
int ProcNumber
Definition procnumber.h:24

References AuxiliaryPidGetProc(), BackendPidGetProc(), fb(), GetNumberFromPGProc, InvalidOid, PG_GETARG_INT32, PG_RETURN_VOID, pgstat_get_beentry_by_proc_number(), PGSTAT_KIND_BACKEND, pgstat_reset(), and pgstat_tracks_backend_bktype().

◆ pg_stat_reset_replication_slot()

Datum pg_stat_reset_replication_slot ( PG_FUNCTION_ARGS  )

Definition at line 2074 of file pgstatfuncs.c.

2075{
2076 char *target = NULL;
2077
2078 if (PG_ARGISNULL(0))
2080 else
2081 {
2083 pgstat_reset_replslot(target);
2084 }
2085
2087}
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition pgstat.c:904
#define PGSTAT_KIND_REPLSLOT
Definition pgstat_kind.h:30
void pgstat_reset_replslot(const char *name)

References fb(), 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 1949 of file pgstatfuncs.c.

1950{
1951 char *target = NULL;
1952
1953 if (PG_ARGISNULL(0))
1954 {
1955 /* Reset all the statistics when nothing is specified */
1964
1966 }
1967
1969
1970 if (strcmp(target, "archiver") == 0)
1972 else if (strcmp(target, "bgwriter") == 0)
1974 else if (strcmp(target, "checkpointer") == 0)
1976 else if (strcmp(target, "io") == 0)
1978 else if (strcmp(target, "lock") == 0)
1980 else if (strcmp(target, "recovery_prefetch") == 0)
1982 else if (strcmp(target, "slru") == 0)
1984 else if (strcmp(target, "wal") == 0)
1986 else
1987 ereport(ERROR,
1989 errmsg("unrecognized reset target: \"%s\"", target),
1990 errhint("Target must be \"archiver\", \"bgwriter\", \"checkpointer\", \"io\", \"recovery_prefetch\", \"slru\", or \"wal\".")));
1991
1993}
int errhint(const char *fmt,...) pg_attribute_printf(1
#define PGSTAT_KIND_ARCHIVER
Definition pgstat_kind.h:35
#define PGSTAT_KIND_WAL
Definition pgstat_kind.h:41
#define PGSTAT_KIND_BGWRITER
Definition pgstat_kind.h:36
#define PGSTAT_KIND_LOCK
Definition pgstat_kind.h:39
#define PGSTAT_KIND_SLRU
Definition pgstat_kind.h:40
#define PGSTAT_KIND_CHECKPOINTER
Definition pgstat_kind.h:37
#define PGSTAT_KIND_IO
Definition pgstat_kind.h:38
void XLogPrefetchResetStats(void)

References ereport, errcode(), errhint(), errmsg, ERROR, fb(), PG_ARGISNULL, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_KIND_ARCHIVER, PGSTAT_KIND_BGWRITER, PGSTAT_KIND_CHECKPOINTER, PGSTAT_KIND_IO, PGSTAT_KIND_LOCK, PGSTAT_KIND_SLRU, 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 2011 of file pgstatfuncs.c.

2012{
2014
2016
2018}
Oid MyDatabaseId
Definition globals.c:96
#define PGSTAT_KIND_FUNCTION
Definition pgstat_kind.h:29

References fb(), 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 2000 of file pgstatfuncs.c.

2001{
2004
2006
2008}
bool IsSharedRelation(Oid relationId)
Definition catalog.c:304
#define PGSTAT_KIND_RELATION
Definition pgstat_kind.h:28

References fb(), InvalidOid, IsSharedRelation(), 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 2057 of file pgstatfuncs.c.

2058{
2059 char *target = NULL;
2060
2061 if (PG_ARGISNULL(0))
2063 else
2064 {
2066 pgstat_reset_slru(target);
2067 }
2068
2070}
void pgstat_reset_slru(const char *name)
Definition pgstat_slru.c:45

References fb(), 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 2091 of file pgstatfuncs.c.

2092{
2093 Oid subid;
2094
2095 if (PG_ARGISNULL(0))
2096 {
2097 /* Clear all subscription stats */
2099 }
2100 else
2101 {
2102 subid = PG_GETARG_OID(0);
2103
2104 if (!OidIsValid(subid))
2105 ereport(ERROR,
2107 errmsg("invalid subscription OID %u", subid)));
2109 }
2110
2112}
#define OidIsValid(objectId)
Definition c.h:858
#define PGSTAT_KIND_SUBSCRIPTION
Definition pgstat_kind.h:31

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

◆ pg_stat_us_to_ms()

static double pg_stat_us_to_ms ( PgStat_Counter  val_ms)
inlinestatic

Definition at line 1458 of file pgstatfuncs.c.

1459{
1460 return val_ms * (double) 0.001;
1461}

References fb().

Referenced by pg_stat_io_build_tuples().

◆ pg_stat_wal_build_tuple()

static Datum pg_stat_wal_build_tuple ( PgStat_WalCounters  wal_counters,
TimestampTz  stat_reset_timestamp 
)
static

Definition at line 1648 of file pgstatfuncs.c.

1650{
1651#define PG_STAT_WAL_COLS 6
1652 TupleDesc tupdesc;
1654 bool nulls[PG_STAT_WAL_COLS] = {0};
1655 char buf[256];
1656
1657 /* Initialise attributes information in the tuple descriptor */
1659 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1660 INT8OID, -1, 0);
1661 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1662 INT8OID, -1, 0);
1663 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1664 NUMERICOID, -1, 0);
1665 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_fpi_bytes",
1666 NUMERICOID, -1, 0);
1667 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_buffers_full",
1668 INT8OID, -1, 0);
1669 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stats_reset",
1670 TIMESTAMPTZOID, -1, 0);
1671
1672 TupleDescFinalize(tupdesc);
1673 BlessTupleDesc(tupdesc);
1674
1675 /* Fill values and NULLs */
1676 values[0] = Int64GetDatum(wal_counters.wal_records);
1677 values[1] = Int64GetDatum(wal_counters.wal_fpi);
1678
1679 /* Convert to numeric. */
1680 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_bytes);
1684 Int32GetDatum(-1));
1685
1686 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_fpi_bytes);
1690 Int32GetDatum(-1));
1691
1692 values[4] = Int64GetDatum(wal_counters.wal_buffers_full);
1693
1694 if (stat_reset_timestamp != 0)
1695 values[5] = TimestampTzGetDatum(stat_reset_timestamp);
1696 else
1697 nulls[5] = true;
1698
1699 /* Returns the record as Datum */
1701}
#define UINT64_FORMAT
Definition c.h:635
#define PG_STAT_WAL_COLS
PgStat_Counter wal_fpi
Definition pgstat.h:501
uint64 wal_fpi_bytes
Definition pgstat.h:503
PgStat_Counter wal_buffers_full
Definition pgstat.h:504
PgStat_Counter wal_records
Definition pgstat.h:500

References BlessTupleDesc(), buf, CreateTemplateTupleDesc(), CStringGetDatum(), DirectFunctionCall3, fb(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), Int64GetDatum(), numeric_in(), ObjectIdGetDatum(), PG_RETURN_DATUM, PG_STAT_WAL_COLS, snprintf, TimestampTzGetDatum(), TupleDescFinalize(), TupleDescInitEntry(), UINT64_FORMAT, values, PgStat_WalCounters::wal_buffers_full, PgStat_WalCounters::wal_bytes, PgStat_WalCounters::wal_fpi, PgStat_WalCounters::wal_fpi_bytes, and PgStat_WalCounters::wal_records.

Referenced by pg_stat_get_backend_wal(), and pg_stat_get_wal().

◆ pgstat_get_io_byte_index()

static io_stat_col pgstat_get_io_byte_index ( IOOp  io_op)
static

Definition at line 1406 of file pgstatfuncs.c.

1407{
1408 switch (io_op)
1409 {
1410 case IOOP_EXTEND:
1411 return IO_COL_EXTEND_BYTES;
1412 case IOOP_READ:
1413 return IO_COL_READ_BYTES;
1414 case IOOP_WRITE:
1415 return IO_COL_WRITE_BYTES;
1416 case IOOP_EVICT:
1417 case IOOP_FSYNC:
1418 case IOOP_HIT:
1419 case IOOP_REUSE:
1420 case IOOP_WRITEBACK:
1421 return IO_COL_INVALID;
1422 }
1423
1424 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1426}
#define pg_unreachable()
Definition c.h:367
#define elog(elevel,...)
Definition elog.h:228
@ IOOP_EXTEND
Definition pgstat.h:318
@ IOOP_FSYNC
Definition pgstat.h:312
@ IOOP_READ
Definition pgstat.h:319
@ IOOP_WRITEBACK
Definition pgstat.h:315
@ IOOP_HIT
Definition pgstat.h:313
@ IOOP_EVICT
Definition pgstat.h:311
@ IOOP_REUSE
Definition pgstat.h:314
@ IOOP_WRITE
Definition pgstat.h:320

References elog, ERROR, fb(), IO_COL_EXTEND_BYTES, IO_COL_INVALID, IO_COL_READ_BYTES, IO_COL_WRITE_BYTES, IOOP_EVICT, IOOP_EXTEND, IOOP_FSYNC, IOOP_HIT, IOOP_READ, IOOP_REUSE, IOOP_WRITE, IOOP_WRITEBACK, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().

◆ pgstat_get_io_op_index()

static io_stat_col pgstat_get_io_op_index ( IOOp  io_op)
static

Definition at line 1375 of file pgstatfuncs.c.

1376{
1377 switch (io_op)
1378 {
1379 case IOOP_EVICT:
1380 return IO_COL_EVICTIONS;
1381 case IOOP_EXTEND:
1382 return IO_COL_EXTENDS;
1383 case IOOP_FSYNC:
1384 return IO_COL_FSYNCS;
1385 case IOOP_HIT:
1386 return IO_COL_HITS;
1387 case IOOP_READ:
1388 return IO_COL_READS;
1389 case IOOP_REUSE:
1390 return IO_COL_REUSES;
1391 case IOOP_WRITE:
1392 return IO_COL_WRITES;
1393 case IOOP_WRITEBACK:
1394 return IO_COL_WRITEBACKS;
1395 }
1396
1397 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1399}

References elog, ERROR, fb(), IO_COL_EVICTIONS, IO_COL_EXTENDS, IO_COL_FSYNCS, IO_COL_HITS, IO_COL_READS, IO_COL_REUSES, IO_COL_WRITEBACKS, IO_COL_WRITES, IOOP_EVICT, IOOP_EXTEND, IOOP_FSYNC, IOOP_HIT, IOOP_READ, IOOP_REUSE, IOOP_WRITE, IOOP_WRITEBACK, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().

◆ pgstat_get_io_time_index()

static io_stat_col pgstat_get_io_time_index ( IOOp  io_op)
static

Definition at line 1433 of file pgstatfuncs.c.

1434{
1435 switch (io_op)
1436 {
1437 case IOOP_READ:
1438 return IO_COL_READ_TIME;
1439 case IOOP_WRITE:
1440 return IO_COL_WRITE_TIME;
1441 case IOOP_WRITEBACK:
1442 return IO_COL_WRITEBACK_TIME;
1443 case IOOP_EXTEND:
1444 return IO_COL_EXTEND_TIME;
1445 case IOOP_FSYNC:
1446 return IO_COL_FSYNC_TIME;
1447 case IOOP_EVICT:
1448 case IOOP_HIT:
1449 case IOOP_REUSE:
1450 return IO_COL_INVALID;
1451 }
1452
1453 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1455}

References elog, ERROR, fb(), IO_COL_EXTEND_TIME, IO_COL_FSYNC_TIME, IO_COL_INVALID, IO_COL_READ_TIME, IO_COL_WRITE_TIME, IO_COL_WRITEBACK_TIME, IOOP_EVICT, IOOP_EXTEND, IOOP_FSYNC, IOOP_HIT, IOOP_READ, IOOP_REUSE, IOOP_WRITE, IOOP_WRITEBACK, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().