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 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_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_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 37 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; \
}
#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 1215 of file pgstatfuncs.c.

1218{ \
1219 Oid dbid = PG_GETARG_OID(0); \
1220 double result; \
1222 \
1224 result = 0; \
1225 else \
1226 result = ((double) dbentry->stat) / 1000.0; \
1227 \
1228 PG_RETURN_FLOAT8(result); \
1229}

◆ PG_STAT_GET_DBENTRY_INT64

#define PG_STAT_GET_DBENTRY_INT64 (   stat)
Value:
{ \
Oid dbid = PG_GETARG_OID(0); \
int64 result; \
result = 0; \
result = (int64) (dbentry->stat); \
PG_RETURN_INT64(result); \
}
int64_t int64
Definition c.h:555

Definition at line 1048 of file pgstatfuncs.c.

1051{ \
1052 Oid dbid = PG_GETARG_OID(0); \
1053 int64 result; \
1055 \
1057 result = 0; \
1058 else \
1059 result = (int64) (dbentry->stat); \
1060 \
1061 PG_RETURN_INT64(result); \
1062}

◆ PG_STAT_GET_FUNCENTRY_FLOAT8_MS

#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS (   stat)
Value:
{ \
Oid funcid = PG_GETARG_OID(0); \
double result; \
result = ((double) funcentry->stat) / 1000.0; \
}
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)

Definition at line 186 of file pgstatfuncs.c.

189{ \
190 Oid funcid = PG_GETARG_OID(0); \
191 double result; \
193 \
196 result = ((double) funcentry->stat) / 1000.0; \
197 PG_RETURN_FLOAT8(result); \
198}

◆ 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:
{ \
Oid relid = PG_GETARG_OID(0); \
double result; \
result = 0; \
result = (double) (tabentry->stat); \
}
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)

Definition at line 109 of file pgstatfuncs.c.

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

◆ PG_STAT_GET_RELENTRY_INT64

#define PG_STAT_GET_RELENTRY_INT64 (   stat)
Value:

Definition at line 39 of file pgstatfuncs.c.

42{ \
43 Oid relid = PG_GETARG_OID(0); \
44 int64 result; \
46 \
48 result = 0; \
49 else \
50 result = (int64) (tabentry->stat); \
51 \
52 PG_RETURN_INT64(result); \
53}

◆ PG_STAT_GET_RELENTRY_TIMESTAMPTZ

#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ (   stat)
Value:

Definition at line 137 of file pgstatfuncs.c.

140{ \
141 Oid relid = PG_GETARG_OID(0); \
142 TimestampTz result; \
144 \
146 result = 0; \
147 else \
148 result = tabentry->stat; \
149 \
150 if (result == 0) \
153 PG_RETURN_TIMESTAMPTZ(result); \
154}

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

1847{ \
1848 Oid funcid = PG_GETARG_OID(0); \
1850 \
1851 if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
1854}

◆ PG_STAT_GET_XACT_RELENTRY_INT64

#define PG_STAT_GET_XACT_RELENTRY_INT64 (   stat)
Value:
{ \
Oid relid = PG_GETARG_OID(0); \
int64 result; \
result = 0; \
result = (int64) (tabentry->counts.stat); \
PG_RETURN_INT64(result); \
}
PgStat_TableStatus * find_tabstat_entry(Oid rel_id)

Definition at line 1787 of file pgstatfuncs.c.

1790{ \
1791 Oid relid = PG_GETARG_OID(0); \
1792 int64 result; \
1794 \
1795 if ((tabentry = find_tabstat_entry(relid)) == NULL) \
1796 result = 0; \
1797 else \
1798 result = (int64) (tabentry->counts.stat); \
1799 \
1800 PG_RETURN_INT64(result); \
1801}

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

1346{
1347 IO_COL_INVALID = -1,
1369} 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 711 of file pgstatfuncs.c.

712{
714}
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
int MyProcPid
Definition globals.c:47

References MyProcPid, and PG_RETURN_INT32.

◆ pg_stat_clear_snapshot()

Datum pg_stat_clear_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 1879 of file pgstatfuncs.c.

1880{
1882
1884}
#define PG_RETURN_VOID()
Definition fmgr.h:350
void pgstat_clear_snapshot(void)
Definition pgstat.c:912

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

1890{
1892
1894}
void pgstat_force_next_flush(void)
Definition pgstat.c:824

References PG_RETURN_VOID, and pgstat_force_next_flush().

◆ pg_stat_get_activity()

Datum pg_stat_get_activity ( PG_FUNCTION_ARGS  )

Definition at line 352 of file pgstatfuncs.c.

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

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

2077{
2078 TupleDesc tupdesc;
2079 Datum values[7] = {0};
2080 bool nulls[7] = {0};
2082
2083 /* Initialise attributes information in the tuple descriptor */
2084 tupdesc = CreateTemplateTupleDesc(7);
2085 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2086 INT8OID, -1, 0);
2087 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2088 TEXTOID, -1, 0);
2089 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2090 TIMESTAMPTZOID, -1, 0);
2091 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2092 INT8OID, -1, 0);
2093 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2094 TEXTOID, -1, 0);
2095 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2096 TIMESTAMPTZOID, -1, 0);
2097 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2098 TIMESTAMPTZOID, -1, 0);
2099
2100 BlessTupleDesc(tupdesc);
2101
2102 /* Get statistics about the archiver process */
2104
2105 /* Fill values and NULLs */
2106 values[0] = Int64GetDatum(archiver_stats->archived_count);
2107 if (*(archiver_stats->last_archived_wal) == '\0')
2108 nulls[1] = true;
2109 else
2110 values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2111
2112 if (archiver_stats->last_archived_timestamp == 0)
2113 nulls[2] = true;
2114 else
2115 values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
2116
2117 values[3] = Int64GetDatum(archiver_stats->failed_count);
2118 if (*(archiver_stats->last_failed_wal) == '\0')
2119 nulls[4] = true;
2120 else
2121 values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2122
2123 if (archiver_stats->last_failed_timestamp == 0)
2124 nulls[5] = true;
2125 else
2126 values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2127
2128 if (archiver_stats->stat_reset_timestamp == 0)
2129 nulls[6] = true;
2130 else
2131 values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2132
2133 /* Returns the record as Datum */
2135}
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:1117
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:825

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

◆ pg_stat_get_backend_activity()

Datum pg_stat_get_backend_activity ( PG_FUNCTION_ARGS  )

Definition at line 791 of file pgstatfuncs.c.

792{
793 int32 procNumber = PG_GETARG_INT32(0);
795 const char *activity;
796 char *clipped_activity;
797 text *ret;
798
799 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
800 activity = "<backend information not available>";
801 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
802 activity = "<insufficient privilege>";
803 else if (*(beentry->st_activity_raw) == '\0')
804 activity = "<command string not enabled>";
805 else
806 activity = beentry->st_activity_raw;
807
811
812 PG_RETURN_TEXT_P(ret);
813}
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
int32_t int32
Definition c.h:554
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
Definition c.h:718
text * cstring_to_text(const char *s)
Definition varlena.c:182

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

872{
873 int32 procNumber = PG_GETARG_INT32(0);
874 TimestampTz result;
876
877 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
879
880 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
882
883 result = beentry->st_activity_start_timestamp;
884
885 /*
886 * No time recorded for start of current query -- this is the case if the
887 * user hasn't enabled query-level stats collection.
888 */
889 if (result == 0)
891
892 PG_RETURN_TIMESTAMPTZ(result);
893}
#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, and pgstat_get_beentry_by_proc_number().

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 941 of file pgstatfuncs.c.

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

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

985{
986 int32 procNumber = PG_GETARG_INT32(0);
988 char remote_port[NI_MAXSERV];
989 int ret;
990
991 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
993
994 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
996
997 /* A zeroed client addr means we don't know */
998 if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
999 sizeof(beentry->st_clientaddr)))
1001
1002 switch (beentry->st_clientaddr.addr.ss_family)
1003 {
1004 case AF_INET:
1005 case AF_INET6:
1006 break;
1007 case AF_UNIX:
1008 PG_RETURN_INT32(-1);
1009 default:
1011 }
1012
1013 remote_port[0] = '\0';
1014 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1015 beentry->st_clientaddr.salen,
1016 NULL, 0,
1017 remote_port, sizeof(remote_port),
1019 if (ret != 0)
1021
1023 CStringGetDatum(remote_port)));
1024}
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 731 of file pgstatfuncs.c.

732{
733 int32 procNumber = PG_GETARG_INT32(0);
735
736 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
738
739 PG_RETURN_OID(beentry->st_databaseid);
740}
#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 225 of file pgstatfuncs.c.

226{
228 int *fctx;
229
230 /* stuff done only on the first call of the function */
231 if (SRF_IS_FIRSTCALL())
232 {
233 /* create a function context for cross-call persistence */
235
236 fctx = MemoryContextAlloc(funcctx->multi_call_memory_ctx,
237 sizeof(int));
238 funcctx->user_fctx = fctx;
239
240 fctx[0] = 0;
241 }
242
243 /* stuff done on every call of the function */
245 fctx = funcctx->user_fctx;
246
247 fctx[0] += 1;
248
249 /*
250 * We recheck pgstat_fetch_stat_numbackends() each time through, just in
251 * case the local status data has been refreshed since we started. It's
252 * plenty cheap enough if not. If a refresh does happen, we'll likely
253 * miss or duplicate some backend IDs, but we're content not to crash.
254 * (Refreshing midway through such a query would be problematic usage
255 * anyway, since the backend IDs we've already returned might no longer
256 * refer to extant sessions.)
257 */
259 {
260 /* do when there is more left to send */
262
264 }
265 else
266 {
267 /* do when there is no more left */
269 }
270}
#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 1610 of file pgstatfuncs.c.

1611{
1614 int pid;
1617
1618 InitMaterializedSRF(fcinfo, 0);
1619 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1620
1621 pid = PG_GETARG_INT32(0);
1623
1624 if (!backend_stats)
1625 return (Datum) 0;
1626
1627 bktype_stats = &backend_stats->io_stats;
1628
1629 /*
1630 * In Assert builds, we can afford an extra loop through all of the
1631 * counters (in pg_stat_io_build_tuples()), checking that only expected
1632 * stats are non-zero, since it keeps the non-Assert code cleaner.
1633 */
1635
1636 /* save tuples with data from this PgStat_BktypeIO */
1638 backend_stats->stat_reset_timestamp);
1639 return (Datum) 0;
1640}
#define Assert(condition)
Definition c.h:885
BackendType
Definition miscadmin.h:338
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 718 of file pgstatfuncs.c.

719{
720 int32 procNumber = PG_GETARG_INT32(0);
722
723 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
725
726 PG_RETURN_INT32(beentry->st_procpid);
727}

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

920{
921 int32 procNumber = PG_GETARG_INT32(0);
922 TimestampTz result;
924
925 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
927
928 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
930
931 result = beentry->st_proc_start_timestamp;
932
933 if (result == 0) /* probably can't happen? */
935
936 PG_RETURN_TIMESTAMPTZ(result);
937}

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

◆ pg_stat_get_backend_subxact()

Datum pg_stat_get_backend_subxact ( PG_FUNCTION_ARGS  )

Definition at line 756 of file pgstatfuncs.c.

757{
758#define PG_STAT_GET_SUBXACT_COLS 2
759 TupleDesc tupdesc;
761 bool nulls[PG_STAT_GET_SUBXACT_COLS] = {0};
762 int32 procNumber = PG_GETARG_INT32(0);
764
765 /* Initialise attributes information in the tuple descriptor */
767 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subxact_count",
768 INT4OID, -1, 0);
769 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "subxact_overflow",
770 BOOLOID, -1, 0);
771
772 BlessTupleDesc(tupdesc);
773
775 {
776 /* Fill values and NULLs */
777 values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
778 values[1] = BoolGetDatum(local_beentry->backend_subxact_overflowed);
779 }
780 else
781 {
782 nulls[0] = true;
783 nulls[1] = true;
784 }
785
786 /* Returns the record as Datum */
788}
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(), TupleDescInitEntry(), and values.

◆ pg_stat_get_backend_userid()

Datum pg_stat_get_backend_userid ( PG_FUNCTION_ARGS  )

Definition at line 744 of file pgstatfuncs.c.

745{
746 int32 procNumber = PG_GETARG_INT32(0);
748
749 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
751
752 PG_RETURN_OID(beentry->st_userid);
753}

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

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

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

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

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

898{
899 int32 procNumber = PG_GETARG_INT32(0);
900 TimestampTz result;
902
903 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
905
906 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
908
909 result = beentry->st_xact_start_timestamp;
910
911 if (result == 0) /* not in a transaction */
913
914 PG_RETURN_TIMESTAMPTZ(result);
915}

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

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1295 of file pgstatfuncs.c.

1296{
1297 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1298}
#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 1301 of file pgstatfuncs.c.

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

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

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

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

1336{
1338}

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

1284{
1286}
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 1259 of file pgstatfuncs.c.

1260{
1262}

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

1254{
1256}

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

1248{
1250}

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

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

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

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

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

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

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

1290{
1292}

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

1324{
1326}

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

1316{
1317 /* time is already in msec, just convert to double for presentation */
1318 PG_RETURN_FLOAT8((double)
1319 pgstat_fetch_stat_checkpointer()->sync_time);
1320}
#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 1307 of file pgstatfuncs.c.

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

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

1177{
1178 Oid dbid = PG_GETARG_OID(0);
1179 int64 result;
1181
1182 if (!DataChecksumsEnabled())
1184
1185 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1186 result = 0;
1187 else
1188 result = (int64) (dbentry->checksum_failures);
1189
1190 PG_RETURN_INT64(result);
1191}
bool DataChecksumsEnabled(void)
Definition xlog.c:4647

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

1195{
1196 Oid dbid = PG_GETARG_OID(0);
1197 TimestampTz result;
1199
1200 if (!DataChecksumsEnabled())
1202
1203 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1204 result = 0;
1205 else
1206 result = dbentry->last_checksum_failure;
1207
1208 if (result == 0)
1210 else
1211 PG_RETURN_TIMESTAMPTZ(result);
1212}

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

1157{
1158 Oid dbid = PG_GETARG_OID(0);
1159 int64 result;
1161
1162 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1163 result = 0;
1164 else
1165 result = (int64) (dbentry->conflict_tablespace +
1166 dbentry->conflict_lock +
1167 dbentry->conflict_snapshot +
1168 dbentry->conflict_logicalslot +
1169 dbentry->conflict_bufferpin +
1170 dbentry->conflict_startup_deadlock);
1171
1172 PG_RETURN_INT64(result);
1173}

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

◆ pg_stat_get_db_numbackends()

Datum pg_stat_get_db_numbackends ( PG_FUNCTION_ARGS  )

Definition at line 1028 of file pgstatfuncs.c.

1029{
1030 Oid dbid = PG_GETARG_OID(0);
1031 int32 result;
1033 int idx;
1034
1035 result = 0;
1036 for (idx = 1; idx <= tot_backends; idx++)
1037 {
1039
1040 if (local_beentry->backendStatus.st_databaseid == dbid)
1041 result++;
1042 }
1043
1044 PG_RETURN_INT32(result);
1045}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262

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

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1137 of file pgstatfuncs.c.

1138{
1139 Oid dbid = PG_GETARG_OID(0);
1140 TimestampTz result;
1142
1143 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1144 result = 0;
1145 else
1146 result = dbentry->stat_reset_timestamp;
1147
1148 if (result == 0)
1150 else
1151 PG_RETURN_TIMESTAMPTZ(result);
1152}
TimestampTz stat_reset_timestamp
Definition pgstat.h:384

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

◆ pg_stat_get_function_calls()

Datum pg_stat_get_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 175 of file pgstatfuncs.c.

176{
177 Oid funcid = PG_GETARG_OID(0);
179
180 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
182 PG_RETURN_INT64(funcentry->numcalls);
183}

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  )

Definition at line 207 of file pgstatfuncs.c.

208{
209 Oid funcid = PG_GETARG_OID(0);
210 TimestampTz result;
212
213 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
214 result = 0;
215 else
217
218 if (result == 0)
220 else
221 PG_RETURN_TIMESTAMPTZ(result);
222}
TimestampTz stat_reset_timestamp
Definition pgstat.h:393

References fb(), PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, pgstat_fetch_stat_funcentry(), and PgStat_StatFuncEntry::stat_reset_timestamp.

◆ pg_stat_get_io()

Datum pg_stat_get_io ( PG_FUNCTION_ARGS  )

Definition at line 1569 of file pgstatfuncs.c.

1570{
1573
1574 InitMaterializedSRF(fcinfo, 0);
1575 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1576
1578
1579 for (int bktype = 0; bktype < BACKEND_NUM_TYPES; bktype++)
1580 {
1582
1583 /*
1584 * In Assert builds, we can afford an extra loop through all of the
1585 * counters (in pg_stat_io_build_tuples()), checking that only
1586 * expected stats are non-zero, since it keeps the non-Assert code
1587 * cleaner.
1588 */
1590
1591 /*
1592 * For those BackendTypes without IO Operation stats, skip
1593 * representing them in the view altogether.
1594 */
1596 continue;
1597
1598 /* save tuples with data from this PgStat_BktypeIO */
1600 backends_io_stats->stat_reset_timestamp);
1601 }
1602
1603 return (Datum) 0;
1604}
#define BACKEND_NUM_TYPES
Definition miscadmin.h:377
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_progress_info()

Datum pg_stat_get_progress_info ( PG_FUNCTION_ARGS  )

Definition at line 276 of file pgstatfuncs.c.

277{
278#define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
280 int curr_backend;
281 char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
282 ProgressCommandType cmdtype;
283 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
284
285 /* Translate command name into command type code. */
286 if (pg_strcasecmp(cmd, "VACUUM") == 0)
287 cmdtype = PROGRESS_COMMAND_VACUUM;
288 else if (pg_strcasecmp(cmd, "ANALYZE") == 0)
289 cmdtype = PROGRESS_COMMAND_ANALYZE;
290 else if (pg_strcasecmp(cmd, "CLUSTER") == 0)
291 cmdtype = PROGRESS_COMMAND_CLUSTER;
292 else if (pg_strcasecmp(cmd, "CREATE INDEX") == 0)
294 else if (pg_strcasecmp(cmd, "BASEBACKUP") == 0)
296 else if (pg_strcasecmp(cmd, "COPY") == 0)
297 cmdtype = PROGRESS_COMMAND_COPY;
298 else
301 errmsg("invalid command name: \"%s\"", cmd)));
302
303 InitMaterializedSRF(fcinfo, 0);
304
305 /* 1-based index */
307 {
311 bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
312 int i;
313
315 beentry = &local_beentry->backendStatus;
316
317 /*
318 * Report values for only those backends which are running the given
319 * command.
320 */
321 if (beentry->st_progress_command != cmdtype)
322 continue;
323
324 /* Value available to all callers */
325 values[0] = Int32GetDatum(beentry->st_procpid);
326 values[1] = ObjectIdGetDatum(beentry->st_databaseid);
327
328 /* show rest of the values including relid only to role members */
329 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
330 {
331 values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
332 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
333 values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
334 }
335 else
336 {
337 nulls[2] = true;
338 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
339 nulls[i + 3] = true;
340 }
341
342 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
343 }
344
345 return (Datum) 0;
346}
#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:874
int errmsg(const char *fmt,...)
Definition elog.c:1093
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
int i
Definition isn.c:77
#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:215

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_CLUSTER, PROGRESS_COMMAND_COPY, PROGRESS_COMMAND_CREATE_INDEX, 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 2142 of file pgstatfuncs.c.

2143{
2144#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
2146 NameData slotname;
2147 TupleDesc tupdesc;
2149 bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
2152
2153 /* Initialise attributes information in the tuple descriptor */
2155 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
2156 TEXTOID, -1, 0);
2157 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "spill_txns",
2158 INT8OID, -1, 0);
2159 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "spill_count",
2160 INT8OID, -1, 0);
2161 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "spill_bytes",
2162 INT8OID, -1, 0);
2163 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stream_txns",
2164 INT8OID, -1, 0);
2165 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stream_count",
2166 INT8OID, -1, 0);
2167 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
2168 INT8OID, -1, 0);
2169 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
2170 INT8OID, -1, 0);
2171 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
2172 INT8OID, -1, 0);
2173 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
2174 INT8OID, -1, 0);
2175 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
2176 INT8OID, -1, 0);
2177 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_last_skip",
2178 TIMESTAMPTZOID, -1, 0);
2179 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
2180 TIMESTAMPTZOID, -1, 0);
2181 BlessTupleDesc(tupdesc);
2182
2184 slotent = pgstat_fetch_replslot(slotname);
2185 if (!slotent)
2186 {
2187 /*
2188 * If the slot is not found, initialise its stats. This is possible if
2189 * the create slot message is lost.
2190 */
2192 slotent = &allzero;
2193 }
2194
2195 values[0] = CStringGetTextDatum(NameStr(slotname));
2196 values[1] = Int64GetDatum(slotent->spill_txns);
2197 values[2] = Int64GetDatum(slotent->spill_count);
2198 values[3] = Int64GetDatum(slotent->spill_bytes);
2199 values[4] = Int64GetDatum(slotent->stream_txns);
2200 values[5] = Int64GetDatum(slotent->stream_count);
2201 values[6] = Int64GetDatum(slotent->stream_bytes);
2202 values[7] = Int64GetDatum(slotent->mem_exceeded_count);
2203 values[8] = Int64GetDatum(slotent->total_txns);
2204 values[9] = Int64GetDatum(slotent->total_bytes);
2205 values[10] = Int64GetDatum(slotent->slotsync_skip_count);
2206
2207 if (slotent->slotsync_last_skip == 0)
2208 nulls[11] = true;
2209 else
2210 values[11] = TimestampTzGetDatum(slotent->slotsync_last_skip);
2211
2212 if (slotent->stat_reset_timestamp == 0)
2213 nulls[12] = true;
2214 else
2215 values[12] = TimestampTzGetDatum(slotent->stat_reset_timestamp);
2216
2217 /* Returns the record as Datum */
2219}
#define NameStr(name)
Definition c.h:777
#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:772

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(), TupleDescInitEntry(), and values.

◆ pg_stat_get_slru()

Datum pg_stat_get_slru ( PG_FUNCTION_ARGS  )

Definition at line 1744 of file pgstatfuncs.c.

1745{
1746#define PG_STAT_GET_SLRU_COLS 9
1747 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1748 int i;
1749 PgStat_SLRUStats *stats;
1750
1751 InitMaterializedSRF(fcinfo, 0);
1752
1753 /* request SLRU stats from the cumulative stats system */
1754 stats = pgstat_fetch_slru();
1755
1756 for (i = 0;; i++)
1757 {
1758 /* for each row */
1760 bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
1762 const char *name;
1763
1765
1766 if (!name)
1767 break;
1768
1769 stat = stats[i];
1770
1772 values[1] = Int64GetDatum(stat.blocks_zeroed);
1773 values[2] = Int64GetDatum(stat.blocks_hit);
1774 values[3] = Int64GetDatum(stat.blocks_read);
1775 values[4] = Int64GetDatum(stat.blocks_written);
1776 values[5] = Int64GetDatum(stat.blocks_exists);
1777 values[6] = Int64GetDatum(stat.flush);
1778 values[7] = Int64GetDatum(stat.truncate);
1779 values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1780
1781 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1782 }
1783
1784 return (Datum) 0;
1785}
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:352
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 1864 of file pgstatfuncs.c.

1865{
1866 bool have_snapshot;
1867 TimestampTz ts;
1868
1870
1871 if (!have_snapshot)
1873
1875}
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition pgstat.c:1037

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

2227{
2228#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 13
2229 Oid subid = PG_GETARG_OID(0);
2230 TupleDesc tupdesc;
2232 bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
2235 int i = 0;
2236
2237 /* Get subscription stats */
2239
2240 /* Initialise attributes information in the tuple descriptor */
2242 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subid",
2243 OIDOID, -1, 0);
2244 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
2245 INT8OID, -1, 0);
2246 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_seq_error_count",
2247 INT8OID, -1, 0);
2248 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "sync_table_error_count",
2249 INT8OID, -1, 0);
2250 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "confl_insert_exists",
2251 INT8OID, -1, 0);
2252 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "confl_update_origin_differs",
2253 INT8OID, -1, 0);
2254 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "confl_update_exists",
2255 INT8OID, -1, 0);
2256 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "confl_update_deleted",
2257 INT8OID, -1, 0);
2258 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "confl_update_missing",
2259 INT8OID, -1, 0);
2260 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "confl_delete_origin_differs",
2261 INT8OID, -1, 0);
2262 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "confl_delete_missing",
2263 INT8OID, -1, 0);
2264 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "confl_multiple_unique_conflicts",
2265 INT8OID, -1, 0);
2266 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
2267 TIMESTAMPTZOID, -1, 0);
2268 BlessTupleDesc(tupdesc);
2269
2270 if (!subentry)
2271 {
2272 /* If the subscription is not found, initialise its stats */
2273 memset(&allzero, 0, sizeof(PgStat_StatSubEntry));
2274 subentry = &allzero;
2275 }
2276
2277 /* subid */
2278 values[i++] = ObjectIdGetDatum(subid);
2279
2280 /* apply_error_count */
2281 values[i++] = Int64GetDatum(subentry->apply_error_count);
2282
2283 /* sync_seq_error_count */
2284 values[i++] = Int64GetDatum(subentry->sync_seq_error_count);
2285
2286 /* sync_table_error_count */
2287 values[i++] = Int64GetDatum(subentry->sync_table_error_count);
2288
2289 /* conflict count */
2291 values[i++] = Int64GetDatum(subentry->conflict_count[nconflict]);
2292
2293 /* stats_reset */
2294 if (subentry->stat_reset_timestamp == 0)
2295 nulls[i] = true;
2296 else
2297 values[i] = TimestampTzGetDatum(subentry->stat_reset_timestamp);
2298
2300
2301 /* Returns the record as Datum */
2303}
#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(), 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 1834 of file pgstatfuncs.c.

1835{
1836 Oid funcid = PG_GETARG_OID(0);
1838
1839 if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1841 PG_RETURN_INT64(funcentry->numcalls);
1842}

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

2314{
2316 Oid dboid = PG_GETARG_OID(1);
2317 uint64 objid = PG_GETARG_INT64(2);
2319
2320 PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objid));
2321}
uint64_t uint64
Definition c.h:559
#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:1054
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition pgstat.c:1411
#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 1472 of file pgstatfuncs.c.

1476{
1478
1479 for (int io_obj = 0; io_obj < IOOBJECT_NUM_TYPES; io_obj++)
1480 {
1482
1484 {
1486
1488 bool nulls[IO_NUM_COLUMNS] = {0};
1489
1490 /*
1491 * Some combinations of BackendType, IOObject, and IOContext are
1492 * not valid for any type of IOOp. In such cases, omit the entire
1493 * row from the view.
1494 */
1496 continue;
1497
1501 if (stat_reset_timestamp != 0)
1502 values[IO_COL_RESET_TIME] = TimestampTzGetDatum(stat_reset_timestamp);
1503 else
1504 nulls[IO_COL_RESET_TIME] = true;
1505
1506 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
1507 {
1511
1512 /*
1513 * Some combinations of BackendType and IOOp, of IOContext and
1514 * IOOp, and of IOObject and IOOp are not tracked. Set these
1515 * cells in the view NULL.
1516 */
1518 {
1519 PgStat_Counter count =
1521
1522 values[op_idx] = Int64GetDatum(count);
1523 }
1524 else
1525 nulls[op_idx] = true;
1526
1527 if (!nulls[op_idx])
1528 {
1529 /* not every operation is timed */
1530 if (time_idx != IO_COL_INVALID)
1531 {
1532 PgStat_Counter time =
1534
1536 }
1537
1538 /* not every IO is tracked in bytes */
1539 if (byte_idx != IO_COL_INVALID)
1540 {
1541 char buf[256];
1542 PgStat_Counter byte =
1544
1545 /* Convert to numeric */
1546 snprintf(buf, sizeof buf, INT64_FORMAT, byte);
1550 Int32GetDatum(-1));
1551 }
1552 }
1553 else
1554 {
1555 if (time_idx != IO_COL_INVALID)
1556 nulls[time_idx] = true;
1557 if (byte_idx != IO_COL_INVALID)
1558 nulls[byte_idx] = true;
1559 }
1560 }
1561
1562 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1563 values, nulls);
1564 }
1565 }
1566}
#define INT64_FORMAT
Definition c.h:576
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:477
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition pgstat_io.c:393
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:512

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

1900{
1902
1904}
void pgstat_reset_counters(void)
Definition pgstat.c:845

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

1986{
1987 PGPROC *proc;
1989 ProcNumber procNumber;
1990 int backend_pid = PG_GETARG_INT32(0);
1991
1992 proc = BackendPidGetProc(backend_pid);
1993
1994 /* This could be an auxiliary process */
1995 if (!proc)
1996 proc = AuxiliaryPidGetProc(backend_pid);
1997
1998 if (!proc)
2000
2001 procNumber = GetNumberFromPGProc(proc);
2002
2004 if (!beentry)
2006
2007 /* Check if the backend type tracks statistics */
2008 if (!pgstat_tracks_backend_bktype(beentry->st_backendType))
2010
2012
2014}
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:864
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 2035 of file pgstatfuncs.c.

2036{
2037 char *target = NULL;
2038
2039 if (PG_ARGISNULL(0))
2041 else
2042 {
2044 pgstat_reset_replslot(target);
2045 }
2046
2048}
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition pgstat.c:886
#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 1913 of file pgstatfuncs.c.

1914{
1915 char *target = NULL;
1916
1917 if (PG_ARGISNULL(0))
1918 {
1919 /* Reset all the statistics when nothing is specified */
1927
1929 }
1930
1932
1933 if (strcmp(target, "archiver") == 0)
1935 else if (strcmp(target, "bgwriter") == 0)
1937 else if (strcmp(target, "checkpointer") == 0)
1939 else if (strcmp(target, "io") == 0)
1941 else if (strcmp(target, "recovery_prefetch") == 0)
1943 else if (strcmp(target, "slru") == 0)
1945 else if (strcmp(target, "wal") == 0)
1947 else
1948 ereport(ERROR,
1950 errmsg("unrecognized reset target: \"%s\"", target),
1951 errhint("Target must be \"archiver\", \"bgwriter\", \"checkpointer\", \"io\", \"recovery_prefetch\", \"slru\", or \"wal\".")));
1952
1954}
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:40
#define PGSTAT_KIND_BGWRITER
Definition pgstat_kind.h:36
#define PGSTAT_KIND_SLRU
Definition pgstat_kind.h:39
#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_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 1972 of file pgstatfuncs.c.

1973{
1975
1977
1979}
Oid MyDatabaseId
Definition globals.c:94
#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 1961 of file pgstatfuncs.c.

1962{
1965
1967
1969}
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 2018 of file pgstatfuncs.c.

2019{
2020 char *target = NULL;
2021
2022 if (PG_ARGISNULL(0))
2024 else
2025 {
2027 pgstat_reset_slru(target);
2028 }
2029
2031}
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 2052 of file pgstatfuncs.c.

2053{
2054 Oid subid;
2055
2056 if (PG_ARGISNULL(0))
2057 {
2058 /* Clear all subscription stats */
2060 }
2061 else
2062 {
2063 subid = PG_GETARG_OID(0);
2064
2065 if (!OidIsValid(subid))
2066 ereport(ERROR,
2068 errmsg("invalid subscription OID %u", subid)));
2070 }
2071
2073}
#define OidIsValid(objectId)
Definition c.h:800
#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 1459 of file pgstatfuncs.c.

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

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

1651{
1652#define PG_STAT_WAL_COLS 6
1653 TupleDesc tupdesc;
1655 bool nulls[PG_STAT_WAL_COLS] = {0};
1656 char buf[256];
1657
1658 /* Initialise attributes information in the tuple descriptor */
1660 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1661 INT8OID, -1, 0);
1662 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1663 INT8OID, -1, 0);
1664 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1665 NUMERICOID, -1, 0);
1666 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_fpi_bytes",
1667 NUMERICOID, -1, 0);
1668 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_buffers_full",
1669 INT8OID, -1, 0);
1670 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stats_reset",
1671 TIMESTAMPTZOID, -1, 0);
1672
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:577
#define PG_STAT_WAL_COLS
PgStat_Counter wal_fpi
Definition pgstat.h:483
uint64 wal_fpi_bytes
Definition pgstat.h:485
PgStat_Counter wal_buffers_full
Definition pgstat.h:486
PgStat_Counter wal_records
Definition pgstat.h:482

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

1408{
1409 switch (io_op)
1410 {
1411 case IOOP_EXTEND:
1412 return IO_COL_EXTEND_BYTES;
1413 case IOOP_READ:
1414 return IO_COL_READ_BYTES;
1415 case IOOP_WRITE:
1416 return IO_COL_WRITE_BYTES;
1417 case IOOP_EVICT:
1418 case IOOP_FSYNC:
1419 case IOOP_HIT:
1420 case IOOP_REUSE:
1421 case IOOP_WRITEBACK:
1422 return IO_COL_INVALID;
1423 }
1424
1425 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1427}
#define pg_unreachable()
Definition c.h:353
#define elog(elevel,...)
Definition elog.h:226
@ 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 1376 of file pgstatfuncs.c.

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

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

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

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