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

1221{ \
1222 Oid dbid = PG_GETARG_OID(0); \
1223 double result; \
1225 \
1227 result = 0; \
1228 else \
1229 result = ((double) dbentry->stat) / 1000.0; \
1230 \
1231 PG_RETURN_FLOAT8(result); \
1232}

◆ 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:615

Definition at line 1051 of file pgstatfuncs.c.

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

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

191{ \
192 Oid funcid = PG_GETARG_OID(0); \
193 double result; \
195 \
198 result = ((double) funcentry->stat) / 1000.0; \
199 PG_RETURN_FLOAT8(result); \
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:
{ \
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 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 \
124 PG_RETURN_FLOAT8(result); \
125}

◆ PG_STAT_GET_RELENTRY_INT64

#define PG_STAT_GET_RELENTRY_INT64 (   stat)
Value:

Definition at line 41 of file pgstatfuncs.c.

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

◆ PG_STAT_GET_RELENTRY_TIMESTAMPTZ

#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ (   stat)
Value:

Definition at line 139 of file pgstatfuncs.c.

142{ \
143 Oid relid = PG_GETARG_OID(0); \
144 TimestampTz result; \
146 \
148 result = 0; \
149 else \
150 result = tabentry->stat; \
151 \
152 if (result == 0) \
155 PG_RETURN_TIMESTAMPTZ(result); \
156}

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

1851{ \
1852 Oid funcid = PG_GETARG_OID(0); \
1854 \
1855 if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
1858}

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

1794{ \
1795 Oid relid = PG_GETARG_OID(0); \
1796 int64 result; \
1798 \
1799 if ((tabentry = find_tabstat_entry(relid)) == NULL) \
1800 result = 0; \
1801 else \
1802 result = (int64) (tabentry->counts.stat); \
1803 \
1804 PG_RETURN_INT64(result); \
1805}

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

1349{
1350 IO_COL_INVALID = -1,
1372} 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 713 of file pgstatfuncs.c.

714{
716}
#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 1883 of file pgstatfuncs.c.

1884{
1886
1888}
#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 1893 of file pgstatfuncs.c.

1894{
1896
1898}
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 354 of file pgstatfuncs.c.

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

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

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

795{
796 int32 procNumber = PG_GETARG_INT32(0);
798 const char *activity;
799 char *clipped_activity;
800 text *ret;
801
802 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
803 activity = "<backend information not available>";
804 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
805 activity = "<insufficient privilege>";
806 else if (*(beentry->st_activity_raw) == '\0')
807 activity = "<command string not enabled>";
808 else
809 activity = beentry->st_activity_raw;
810
814
815 PG_RETURN_TEXT_P(ret);
816}
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
int32_t int32
Definition c.h:614
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
Definition c.h:778
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 874 of file pgstatfuncs.c.

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

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

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

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

734{
735 int32 procNumber = PG_GETARG_INT32(0);
737
738 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
740
741 PG_RETURN_OID(beentry->st_databaseid);
742}
#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 1613 of file pgstatfuncs.c.

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

721{
722 int32 procNumber = PG_GETARG_INT32(0);
724
725 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
727
728 PG_RETURN_INT32(beentry->st_procpid);
729}

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

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

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

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

747{
748 int32 procNumber = PG_GETARG_INT32(0);
750
751 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
753
754 PG_RETURN_OID(beentry->st_userid);
755}

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

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

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

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

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

1712{
1713 int pid;
1716
1717 pid = PG_GETARG_INT32(0);
1719
1720 if (!backend_stats)
1722
1723 bktype_stats = backend_stats->wal_counters;
1724
1725 /* save tuples with data from this PgStat_WalCounters */
1726 return (pg_stat_wal_build_tuple(bktype_stats, backend_stats->stat_reset_timestamp));
1727}
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 900 of file pgstatfuncs.c.

901{
902 int32 procNumber = PG_GETARG_INT32(0);
903 TimestampTz result;
905
906 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
908
909 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
911
912 result = beentry->st_xact_start_timestamp;
913
914 if (result == 0) /* not in a transaction */
916
917 PG_RETURN_TIMESTAMPTZ(result);
918}

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

1299{
1300 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1301}
#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 1304 of file pgstatfuncs.c.

1305{
1306 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
1307}

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

1333{
1334 PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
1335}

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

1339{
1341}

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

1287{
1289}
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 1262 of file pgstatfuncs.c.

1263{
1265}

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

1257{
1259}

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

1251{
1253}

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

1281{
1282 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_performed);
1283}

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

1275{
1276 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_requested);
1277}

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

1269{
1270 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_timed);
1271}

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

1293{
1295}

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

1327{
1329}

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

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

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

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

1180{
1181 Oid dbid = PG_GETARG_OID(0);
1182 int64 result;
1184
1185 if (!DataChecksumsEnabled())
1187
1188 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1189 result = 0;
1190 else
1191 result = (int64) (dbentry->checksum_failures);
1192
1193 PG_RETURN_INT64(result);
1194}
bool DataChecksumsEnabled(void)
Definition xlog.c:4631

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

1198{
1199 Oid dbid = PG_GETARG_OID(0);
1200 TimestampTz result;
1202
1203 if (!DataChecksumsEnabled())
1205
1206 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1207 result = 0;
1208 else
1209 result = dbentry->last_checksum_failure;
1210
1211 if (result == 0)
1213 else
1214 PG_RETURN_TIMESTAMPTZ(result);
1215}

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

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

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

1032{
1033 Oid dbid = PG_GETARG_OID(0);
1034 int32 result;
1036 int idx;
1037
1038 result = 0;
1039 for (idx = 1; idx <= tot_backends; idx++)
1040 {
1042
1043 if (local_beentry->backendStatus.st_databaseid == dbid)
1044 result++;
1045 }
1046
1047 PG_RETURN_INT32(result);
1048}
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 1140 of file pgstatfuncs.c.

1141{
1142 Oid dbid = PG_GETARG_OID(0);
1143 TimestampTz result;
1145
1146 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1147 result = 0;
1148 else
1149 result = dbentry->stat_reset_timestamp;
1150
1151 if (result == 0)
1153 else
1154 PG_RETURN_TIMESTAMPTZ(result);
1155}
TimestampTz stat_reset_timestamp
Definition pgstat.h:383

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

Definition at line 209 of file pgstatfuncs.c.

210{
211 Oid funcid = PG_GETARG_OID(0);
212 TimestampTz result;
214
215 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
216 result = 0;
217 else
219
220 if (result == 0)
222 else
223 PG_RETURN_TIMESTAMPTZ(result);
224}
TimestampTz stat_reset_timestamp
Definition pgstat.h:392

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

1573{
1576
1577 InitMaterializedSRF(fcinfo, 0);
1578 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1579
1581
1582 for (int bktype = 0; bktype < BACKEND_NUM_TYPES; bktype++)
1583 {
1585
1586 /*
1587 * In Assert builds, we can afford an extra loop through all of the
1588 * counters (in pg_stat_io_build_tuples()), checking that only
1589 * expected stats are non-zero, since it keeps the non-Assert code
1590 * cleaner.
1591 */
1593
1594 /*
1595 * For those BackendTypes without IO Operation stats, skip
1596 * representing them in the view altogether.
1597 */
1599 continue;
1600
1601 /* save tuples with data from this PgStat_BktypeIO */
1603 backends_io_stats->stat_reset_timestamp);
1604 }
1605
1606 return (Datum) 0;
1607}
#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 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
303 errmsg("invalid command name: \"%s\"", cmd)));
304
305 InitMaterializedSRF(fcinfo, 0);
306
307 /* 1-based index */
309 {
313 bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
314 int i;
315
317 beentry = &local_beentry->backendStatus;
318
319 /*
320 * Report values for only those backends which are running the given
321 * command.
322 */
323 if (beentry->st_progress_command != cmdtype)
324 continue;
325
326 /* Value available to all callers */
327 values[0] = Int32GetDatum(beentry->st_procpid);
328 values[1] = ObjectIdGetDatum(beentry->st_databaseid);
329
330 /* show rest of the values including relid only to role members */
331 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
332 {
333 values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
334 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
335 values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
336 }
337 else
338 {
339 nulls[2] = true;
340 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
341 nulls[i + 3] = true;
342 }
343
344 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
345 }
346
347 return (Datum) 0;
348}
#define PGSTAT_NUM_PROGRESS_PARAM
ProgressCommandType
@ PROGRESS_COMMAND_ANALYZE
@ PROGRESS_COMMAND_CREATE_INDEX
@ PROGRESS_COMMAND_VACUUM
@ PROGRESS_COMMAND_BASEBACKUP
@ PROGRESS_COMMAND_REPACK
@ PROGRESS_COMMAND_COPY
int errcode(int sqlerrcode)
Definition elog.c:874
#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
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_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 2147 of file pgstatfuncs.c.

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

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

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

1869{
1870 bool have_snapshot;
1871 TimestampTz ts;
1872
1874
1875 if (!have_snapshot)
1877
1879}
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 2232 of file pgstatfuncs.c.

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

1734{
1736
1737 /* Get statistics about WAL activity */
1739
1740 return (pg_stat_wal_build_tuple(wal_stats->wal_counters,
1741 wal_stats->stat_reset_timestamp));
1742}
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 1838 of file pgstatfuncs.c.

1839{
1840 Oid funcid = PG_GETARG_OID(0);
1842
1843 if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1845 PG_RETURN_INT64(funcentry->numcalls);
1846}

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

2321{
2323 Oid dboid = PG_GETARG_OID(1);
2324 uint64 objid = PG_GETARG_INT64(2);
2326
2327 PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objid));
2328}
uint64_t uint64
Definition c.h:619
#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 1475 of file pgstatfuncs.c.

1479{
1481
1482 for (int io_obj = 0; io_obj < IOOBJECT_NUM_TYPES; io_obj++)
1483 {
1485
1487 {
1489
1491 bool nulls[IO_NUM_COLUMNS] = {0};
1492
1493 /*
1494 * Some combinations of BackendType, IOObject, and IOContext are
1495 * not valid for any type of IOOp. In such cases, omit the entire
1496 * row from the view.
1497 */
1499 continue;
1500
1504 if (stat_reset_timestamp != 0)
1505 values[IO_COL_RESET_TIME] = TimestampTzGetDatum(stat_reset_timestamp);
1506 else
1507 nulls[IO_COL_RESET_TIME] = true;
1508
1509 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
1510 {
1514
1515 /*
1516 * Some combinations of BackendType and IOOp, of IOContext and
1517 * IOOp, and of IOObject and IOOp are not tracked. Set these
1518 * cells in the view NULL.
1519 */
1521 {
1522 PgStat_Counter count =
1524
1525 values[op_idx] = Int64GetDatum(count);
1526 }
1527 else
1528 nulls[op_idx] = true;
1529
1530 if (!nulls[op_idx])
1531 {
1532 /* not every operation is timed */
1533 if (time_idx != IO_COL_INVALID)
1534 {
1535 PgStat_Counter time =
1537
1539 }
1540
1541 /* not every IO is tracked in bytes */
1542 if (byte_idx != IO_COL_INVALID)
1543 {
1544 char buf[256];
1545 PgStat_Counter byte =
1547
1548 /* Convert to numeric */
1549 snprintf(buf, sizeof buf, INT64_FORMAT, byte);
1553 Int32GetDatum(-1));
1554 }
1555 }
1556 else
1557 {
1558 if (time_idx != IO_COL_INVALID)
1559 nulls[time_idx] = true;
1560 if (byte_idx != IO_COL_INVALID)
1561 nulls[byte_idx] = true;
1562 }
1563 }
1564
1565 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1566 values, nulls);
1567 }
1568 }
1569}
#define INT64_FORMAT
Definition c.h:636
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define IOOP_NUM_TYPES
Definition pgstat.h:322
#define IOCONTEXT_NUM_TYPES
Definition pgstat.h:296
int64 PgStat_Counter
Definition pgstat.h:70
#define IOOBJECT_NUM_TYPES
Definition pgstat.h:285
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: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 1903 of file pgstatfuncs.c.

1904{
1906
1908}
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 1989 of file pgstatfuncs.c.

1990{
1991 PGPROC *proc;
1993 ProcNumber procNumber;
1994 int backend_pid = PG_GETARG_INT32(0);
1995
1996 proc = BackendPidGetProc(backend_pid);
1997
1998 /* This could be an auxiliary process */
1999 if (!proc)
2000 proc = AuxiliaryPidGetProc(backend_pid);
2001
2002 if (!proc)
2004
2005 procNumber = GetNumberFromPGProc(proc);
2006
2008 if (!beentry)
2010
2011 /* Check if the backend type tracks statistics */
2012 if (!pgstat_tracks_backend_bktype(beentry->st_backendType))
2014
2016
2018}
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:502
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 2039 of file pgstatfuncs.c.

2040{
2041 char *target = NULL;
2042
2043 if (PG_ARGISNULL(0))
2045 else
2046 {
2048 pgstat_reset_replslot(target);
2049 }
2050
2052}
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 1917 of file pgstatfuncs.c.

1918{
1919 char *target = NULL;
1920
1921 if (PG_ARGISNULL(0))
1922 {
1923 /* Reset all the statistics when nothing is specified */
1931
1933 }
1934
1936
1937 if (strcmp(target, "archiver") == 0)
1939 else if (strcmp(target, "bgwriter") == 0)
1941 else if (strcmp(target, "checkpointer") == 0)
1943 else if (strcmp(target, "io") == 0)
1945 else if (strcmp(target, "recovery_prefetch") == 0)
1947 else if (strcmp(target, "slru") == 0)
1949 else if (strcmp(target, "wal") == 0)
1951 else
1952 ereport(ERROR,
1954 errmsg("unrecognized reset target: \"%s\"", target),
1955 errhint("Target must be \"archiver\", \"bgwriter\", \"checkpointer\", \"io\", \"recovery_prefetch\", \"slru\", or \"wal\".")));
1956
1958}
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 1976 of file pgstatfuncs.c.

1977{
1979
1981
1983}
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 1965 of file pgstatfuncs.c.

1966{
1969
1971
1973}
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 2022 of file pgstatfuncs.c.

2023{
2024 char *target = NULL;
2025
2026 if (PG_ARGISNULL(0))
2028 else
2029 {
2031 pgstat_reset_slru(target);
2032 }
2033
2035}
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 2056 of file pgstatfuncs.c.

2057{
2058 Oid subid;
2059
2060 if (PG_ARGISNULL(0))
2061 {
2062 /* Clear all subscription stats */
2064 }
2065 else
2066 {
2067 subid = PG_GETARG_OID(0);
2068
2069 if (!OidIsValid(subid))
2070 ereport(ERROR,
2072 errmsg("invalid subscription OID %u", subid)));
2074 }
2075
2077}
#define OidIsValid(objectId)
Definition c.h:860
#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 1462 of file pgstatfuncs.c.

1463{
1464 return val_ms * (double) 0.001;
1465}

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

1654{
1655#define PG_STAT_WAL_COLS 6
1656 TupleDesc tupdesc;
1658 bool nulls[PG_STAT_WAL_COLS] = {0};
1659 char buf[256];
1660
1661 /* Initialise attributes information in the tuple descriptor */
1663 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1664 INT8OID, -1, 0);
1665 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1666 INT8OID, -1, 0);
1667 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1668 NUMERICOID, -1, 0);
1669 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_fpi_bytes",
1670 NUMERICOID, -1, 0);
1671 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_buffers_full",
1672 INT8OID, -1, 0);
1673 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stats_reset",
1674 TIMESTAMPTZOID, -1, 0);
1675
1676 TupleDescFinalize(tupdesc);
1677 BlessTupleDesc(tupdesc);
1678
1679 /* Fill values and NULLs */
1680 values[0] = Int64GetDatum(wal_counters.wal_records);
1681 values[1] = Int64GetDatum(wal_counters.wal_fpi);
1682
1683 /* Convert to numeric. */
1684 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_bytes);
1688 Int32GetDatum(-1));
1689
1690 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_fpi_bytes);
1694 Int32GetDatum(-1));
1695
1696 values[4] = Int64GetDatum(wal_counters.wal_buffers_full);
1697
1698 if (stat_reset_timestamp != 0)
1699 values[5] = TimestampTzGetDatum(stat_reset_timestamp);
1700 else
1701 nulls[5] = true;
1702
1703 /* Returns the record as Datum */
1705}
#define UINT64_FORMAT
Definition c.h:637
#define PG_STAT_WAL_COLS
PgStat_Counter wal_fpi
Definition pgstat.h:482
uint64 wal_fpi_bytes
Definition pgstat.h:484
PgStat_Counter wal_buffers_full
Definition pgstat.h:485
PgStat_Counter wal_records
Definition pgstat.h:481

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

1411{
1412 switch (io_op)
1413 {
1414 case IOOP_EXTEND:
1415 return IO_COL_EXTEND_BYTES;
1416 case IOOP_READ:
1417 return IO_COL_READ_BYTES;
1418 case IOOP_WRITE:
1419 return IO_COL_WRITE_BYTES;
1420 case IOOP_EVICT:
1421 case IOOP_FSYNC:
1422 case IOOP_HIT:
1423 case IOOP_REUSE:
1424 case IOOP_WRITEBACK:
1425 return IO_COL_INVALID;
1426 }
1427
1428 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1430}
#define pg_unreachable()
Definition c.h:361
#define elog(elevel,...)
Definition elog.h:226
@ IOOP_EXTEND
Definition pgstat.h:317
@ IOOP_FSYNC
Definition pgstat.h:311
@ IOOP_READ
Definition pgstat.h:318
@ IOOP_WRITEBACK
Definition pgstat.h:314
@ IOOP_HIT
Definition pgstat.h:312
@ IOOP_EVICT
Definition pgstat.h:310
@ IOOP_REUSE
Definition pgstat.h:313
@ IOOP_WRITE
Definition pgstat.h:319

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

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

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

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

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