PostgreSQL Source Code git master
pgstatfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xlog.h"
#include "access/xlogprefetcher.h"
#include "catalog/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:
CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
{ \
Oid dbid = PG_GETARG_OID(0); \
double result; \
PgStat_StatDBEntry *dbentry; \
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
result = 0; \
else \
result = ((double) dbentry->stat) / 1000.0; \
}
#define CppConcat(x, y)
Definition: c.h:424
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)

Definition at line 1203 of file pgstatfuncs.c.

◆ PG_STAT_GET_DBENTRY_INT64

#define PG_STAT_GET_DBENTRY_INT64 (   stat)
Value:
CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
{ \
Oid dbid = PG_GETARG_OID(0); \
int64 result; \
PgStat_StatDBEntry *dbentry; \
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
result = 0; \
else \
result = (int64) (dbentry->stat); \
PG_RETURN_INT64(result); \
}
int64_t int64
Definition: c.h:538
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368

Definition at line 1036 of file pgstatfuncs.c.

◆ PG_STAT_GET_FUNCENTRY_FLOAT8_MS

#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS (   stat)
Value:
CppConcat(pg_stat_get_function_,stat)(PG_FUNCTION_ARGS) \
{ \
Oid funcid = PG_GETARG_OID(0); \
double result; \
PgStat_StatFuncEntry *funcentry; \
if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL) \
PG_RETURN_NULL(); \
result = ((double) funcentry->stat) / 1000.0; \
PG_RETURN_FLOAT8(result); \
}
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)

Definition at line 186 of file pgstatfuncs.c.

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

Definition at line 109 of file pgstatfuncs.c.

◆ PG_STAT_GET_RELENTRY_INT64

#define PG_STAT_GET_RELENTRY_INT64 (   stat)
Value:
{ \
Oid relid = PG_GETARG_OID(0); \
int64 result; \
PgStat_StatTabEntry *tabentry; \
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
result = 0; \
else \
result = (int64) (tabentry->stat); \
PG_RETURN_INT64(result); \
}

Definition at line 39 of file pgstatfuncs.c.

◆ PG_STAT_GET_RELENTRY_TIMESTAMPTZ

#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ (   stat)
Value:
{ \
Oid relid = PG_GETARG_OID(0); \
TimestampTz result; \
PgStat_StatTabEntry *tabentry; \
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
result = 0; \
else \
result = tabentry->stat; \
if (result == 0) \
PG_RETURN_NULL(); \
}
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:68

Definition at line 137 of file pgstatfuncs.c.

◆ 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:
CppConcat(pg_stat_get_xact_function_,stat)(PG_FUNCTION_ARGS) \
{ \
Oid funcid = PG_GETARG_OID(0); \
PgStat_FunctionCounts *funcentry; \
if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
PG_RETURN_NULL(); \
PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->stat)); \
}
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:191
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)

Definition at line 1832 of file pgstatfuncs.c.

◆ PG_STAT_GET_XACT_RELENTRY_INT64

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

Definition at line 1775 of file pgstatfuncs.c.

◆ 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

typedef enum io_stat_col 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 1333 of file pgstatfuncs.c.

1334{
1335 IO_COL_INVALID = -1,
1357} io_stat_col;
io_stat_col
Definition: pgstatfuncs.c:1334
@ IO_COL_READS
Definition: pgstatfuncs.c:1339
@ IO_NUM_COLUMNS
Definition: pgstatfuncs.c:1356
@ IO_COL_RESET_TIME
Definition: pgstatfuncs.c:1355
@ IO_COL_WRITE_TIME
Definition: pgstatfuncs.c:1344
@ IO_COL_HITS
Definition: pgstatfuncs.c:1350
@ IO_COL_EXTENDS
Definition: pgstatfuncs.c:1347
@ IO_COL_WRITEBACK_TIME
Definition: pgstatfuncs.c:1346
@ IO_COL_REUSES
Definition: pgstatfuncs.c:1352
@ IO_COL_WRITES
Definition: pgstatfuncs.c:1342
@ IO_COL_OBJECT
Definition: pgstatfuncs.c:1337
@ IO_COL_EVICTIONS
Definition: pgstatfuncs.c:1351
@ IO_COL_WRITEBACKS
Definition: pgstatfuncs.c:1345
@ IO_COL_CONTEXT
Definition: pgstatfuncs.c:1338
@ IO_COL_READ_BYTES
Definition: pgstatfuncs.c:1340
@ IO_COL_EXTEND_BYTES
Definition: pgstatfuncs.c:1348
@ IO_COL_BACKEND_TYPE
Definition: pgstatfuncs.c:1336
@ IO_COL_FSYNC_TIME
Definition: pgstatfuncs.c:1354
@ IO_COL_EXTEND_TIME
Definition: pgstatfuncs.c:1349
@ IO_COL_FSYNCS
Definition: pgstatfuncs.c:1353
@ IO_COL_WRITE_BYTES
Definition: pgstatfuncs.c:1343
@ IO_COL_INVALID
Definition: pgstatfuncs.c:1335
@ IO_COL_READ_TIME
Definition: pgstatfuncs.c:1341

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:354
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 1867 of file pgstatfuncs.c.

1868{
1870
1872}
#define PG_RETURN_VOID()
Definition: fmgr.h:349
void pgstat_clear_snapshot(void)
Definition: pgstat.c:902

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

1878{
1880
1882}
void pgstat_force_next_flush(void)
Definition: pgstat.c:814

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
355 int num_backends = pgstat_fetch_stat_numbackends();
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 */
363 for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
364 {
365 /* for each row */
367 bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
368 LocalPgBackendStatus *local_beentry;
369 PgBackendStatus *beentry;
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 */
375 local_beentry = pgstat_get_local_beentry_by_index(curr_backend);
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)
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)
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
443 clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
444 values[5] = CStringGetTextDatum(clipped_activity);
445 pfree(clipped_activity);
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 {
469 uint32 raw_wait_event;
470 PGPROC *leader;
471
472 raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
473 wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
474 wait_event = pgstat_get_wait_event(raw_wait_event);
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)
501 values[6] = CStringGetTextDatum(wait_event_type);
502 else
503 nulls[6] = true;
504
505 if (wait_event)
506 values[7] = CStringGetTextDatum(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)
518 else
519 nulls[8] = true;
520
521 if (beentry->st_activity_start_timestamp != 0)
523 else
524 nulls[9] = true;
525
526 if (beentry->st_proc_start_timestamp != 0)
528 else
529 nulls[10] = true;
530
531 if (beentry->st_state_start_timestamp != 0)
533 else
534 nulls[11] = true;
535
536 /* A zeroed client addr means we don't know */
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),
559 NI_NUMERICHOST | NI_NUMERICSERV);
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])
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 */
620 values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
621
622 if (beentry->st_sslstatus->ssl_client_dn[0])
624 else
625 nulls[22] = true;
626
627 if (beentry->st_sslstatus->ssl_client_serial[0])
631 Int32GetDatum(-1));
632 else
633 nulls[23] = true;
634
635 if (beentry->st_sslstatus->ssl_issuer_dn[0])
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 */
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:1375
static Datum values[MAXATTR]
Definition: bootstrap.c:153
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define INT64CONST(x)
Definition: c.h:555
uint32_t uint32
Definition: c.h:541
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:682
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:686
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:1595
void pfree(void *pointer)
Definition: mcxt.c:1594
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:403
static Datum TransactionIdGetDatum(TransactionId X)
Definition: postgres.h:282
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:360
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:222
#define InvalidOid
Definition: postgres_ext.h:37
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:3158
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:1101
TransactionId backend_xid
PgBackendStatus backendStatus
TransactionId backend_xmin
Definition: proc.h:179
uint32 wait_event_info
Definition: proc.h:296
int pid
Definition: proc.h:199
PGPROC * lockGroupLeader
Definition: proc.h:321
char gss_princ[NAMEDATALEN]
char ssl_version[NAMEDATALEN]
char ssl_cipher[NAMEDATALEN]
char ssl_client_dn[NAMEDATALEN]
char ssl_client_serial[NAMEDATALEN]
char ssl_issuer_dn[NAMEDATALEN]
BackendType st_backendType
TimestampTz st_state_start_timestamp
TimestampTz st_proc_start_timestamp
PgBackendGSSStatus * st_gssstatus
BackendState st_state
TimestampTz st_activity_start_timestamp
SockAddr st_clientaddr
PgBackendSSLStatus * st_sslstatus
TimestampTz st_xact_start_timestamp
char * st_clienthostname
TupleDesc setDesc
Definition: execnodes.h:364
Tuplestorestate * setResult
Definition: execnodes.h:363
struct sockaddr_storage addr
Definition: pqcomm.h:32
socklen_t salen
Definition: pqcomm.h:33
#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 SockAddr::addr, AuxiliaryPidGetProc(), B_BACKEND, B_BG_WORKER, B_WAL_SENDER, LocalPgBackendStatus::backend_xid, LocalPgBackendStatus::backend_xmin, BackendPidGetProc(), LocalPgBackendStatus::backendStatus, BoolGetDatum(), clean_ipv6_addr(), CStringGetDatum(), CStringGetTextDatum, DirectFunctionCall1, DirectFunctionCall3, GetBackendTypeDesc(), GetBackgroundWorkerTypeByPid(), GetLeaderApplyWorkerPid(), PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_delegation, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, 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, SockAddr::salen, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, PgBackendSSLStatus::ssl_bits, PgBackendSSLStatus::ssl_cipher, PgBackendSSLStatus::ssl_client_dn, PgBackendSSLStatus::ssl_client_serial, PgBackendSSLStatus::ssl_issuer_dn, PgBackendSSLStatus::ssl_version, PgBackendStatus::st_activity_raw, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_appname, PgBackendStatus::st_backendType, PgBackendStatus::st_clientaddr, PgBackendStatus::st_clienthostname, PgBackendStatus::st_databaseid, PgBackendStatus::st_gss, PgBackendStatus::st_gssstatus, PgBackendStatus::st_proc_start_timestamp, PgBackendStatus::st_procpid, PgBackendStatus::st_query_id, PgBackendStatus::st_ssl, PgBackendStatus::st_sslstatus, PgBackendStatus::st_state, PgBackendStatus::st_state_start_timestamp, PgBackendStatus::st_userid, PgBackendStatus::st_xact_start_timestamp, STATE_DISABLED, STATE_FASTPATH, STATE_IDLE, STATE_IDLEINTRANSACTION, STATE_IDLEINTRANSACTION_ABORTED, STATE_RUNNING, STATE_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 2064 of file pgstatfuncs.c.

2065{
2066 TupleDesc tupdesc;
2067 Datum values[7] = {0};
2068 bool nulls[7] = {0};
2069 PgStat_ArchiverStats *archiver_stats;
2070
2071 /* Initialise attributes information in the tuple descriptor */
2072 tupdesc = CreateTemplateTupleDesc(7);
2073 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2074 INT8OID, -1, 0);
2075 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2076 TEXTOID, -1, 0);
2077 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2078 TIMESTAMPTZOID, -1, 0);
2079 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2080 INT8OID, -1, 0);
2081 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2082 TEXTOID, -1, 0);
2083 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2084 TIMESTAMPTZOID, -1, 0);
2085 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2086 TIMESTAMPTZOID, -1, 0);
2087
2088 BlessTupleDesc(tupdesc);
2089
2090 /* Get statistics about the archiver process */
2091 archiver_stats = pgstat_fetch_stat_archiver();
2092
2093 /* Fill values and NULLs */
2094 values[0] = Int64GetDatum(archiver_stats->archived_count);
2095 if (*(archiver_stats->last_archived_wal) == '\0')
2096 nulls[1] = true;
2097 else
2098 values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2099
2100 if (archiver_stats->last_archived_timestamp == 0)
2101 nulls[2] = true;
2102 else
2104
2105 values[3] = Int64GetDatum(archiver_stats->failed_count);
2106 if (*(archiver_stats->last_failed_wal) == '\0')
2107 nulls[4] = true;
2108 else
2109 values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2110
2111 if (archiver_stats->last_failed_timestamp == 0)
2112 nulls[5] = true;
2113 else
2114 values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2115
2116 if (archiver_stats->stat_reset_timestamp == 0)
2117 nulls[6] = true;
2118 else
2119 values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2120
2121 /* Returns the record as Datum */
2123}
int16 AttrNumber
Definition: attnum.h:21
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
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)
TimestampTz last_failed_timestamp
Definition: pgstat.h:228
TimestampTz stat_reset_timestamp
Definition: pgstat.h:229
TimestampTz last_archived_timestamp
Definition: pgstat.h:224
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:226
PgStat_Counter failed_count
Definition: pgstat.h:225
PgStat_Counter archived_count
Definition: pgstat.h:221
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:222
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:182
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:842

References PgStat_ArchiverStats::archived_count, BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, PgStat_ArchiverStats::failed_count, heap_form_tuple(), HeapTupleGetDatum(), Int64GetDatum(), PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, PG_RETURN_DATUM, pgstat_fetch_stat_archiver(), PgStat_ArchiverStats::stat_reset_timestamp, 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);
794 PgBackendStatus *beentry;
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
808 clipped_activity = pgstat_clip_activity(activity);
809 ret = cstring_to_text(activity);
810 pfree(clipped_activity);
811
812 PG_RETURN_TEXT_P(ret);
813}
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
int32_t int32
Definition: c.h:537
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
Definition: c.h:695
text * cstring_to_text(const char *s)
Definition: varlena.c:181

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

◆ pg_stat_get_backend_activity_start()

Datum pg_stat_get_backend_activity_start ( PG_FUNCTION_ARGS  )

Definition at line 859 of file pgstatfuncs.c.

860{
861 int32 procNumber = PG_GETARG_INT32(0);
862 TimestampTz result;
863 PgBackendStatus *beentry;
864
865 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
867
868 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
870
871 result = beentry->st_activity_start_timestamp;
872
873 /*
874 * No time recorded for start of current query -- this is the case if the
875 * user hasn't enabled query-level stats collection.
876 */
877 if (result == 0)
879
880 PG_RETURN_TIMESTAMPTZ(result);
881}
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_NULL()
Definition: fmgr.h:345

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

◆ pg_stat_get_backend_client_addr()

Datum pg_stat_get_backend_client_addr ( PG_FUNCTION_ARGS  )

Definition at line 929 of file pgstatfuncs.c.

930{
931 int32 procNumber = PG_GETARG_INT32(0);
932 PgBackendStatus *beentry;
933 char remote_host[NI_MAXHOST];
934 int ret;
935
936 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
938
939 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
941
942 /* A zeroed client addr means we don't know */
944 sizeof(beentry->st_clientaddr)))
946
947 switch (beentry->st_clientaddr.addr.ss_family)
948 {
949 case AF_INET:
950 case AF_INET6:
951 break;
952 default:
954 }
955
956 remote_host[0] = '\0';
957 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
958 beentry->st_clientaddr.salen,
959 remote_host, sizeof(remote_host),
960 NULL, 0,
961 NI_NUMERICHOST | NI_NUMERICSERV);
962 if (ret != 0)
964
965 clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
966
968 CStringGetDatum(remote_host)));
969}

References SockAddr::addr, clean_ipv6_addr(), CStringGetDatum(), DirectFunctionCall1, HAS_PGSTAT_PERMISSIONS, inet_in(), PG_GETARG_INT32, pg_getnameinfo_all(), pg_memory_is_all_zeros(), PG_RETURN_DATUM, PG_RETURN_NULL, pgstat_get_beentry_by_proc_number(), SockAddr::salen, PgBackendStatus::st_clientaddr, and PgBackendStatus::st_userid.

◆ pg_stat_get_backend_client_port()

Datum pg_stat_get_backend_client_port ( PG_FUNCTION_ARGS  )

Definition at line 972 of file pgstatfuncs.c.

973{
974 int32 procNumber = PG_GETARG_INT32(0);
975 PgBackendStatus *beentry;
976 char remote_port[NI_MAXSERV];
977 int ret;
978
979 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
981
982 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
984
985 /* A zeroed client addr means we don't know */
987 sizeof(beentry->st_clientaddr)))
989
990 switch (beentry->st_clientaddr.addr.ss_family)
991 {
992 case AF_INET:
993 case AF_INET6:
994 break;
995 case AF_UNIX:
996 PG_RETURN_INT32(-1);
997 default:
999 }
1000
1001 remote_port[0] = '\0';
1002 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
1003 beentry->st_clientaddr.salen,
1004 NULL, 0,
1005 remote_port, sizeof(remote_port),
1006 NI_NUMERICHOST | NI_NUMERICSERV);
1007 if (ret != 0)
1009
1011 CStringGetDatum(remote_port)));
1012}
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:287

References SockAddr::addr, CStringGetDatum(), DirectFunctionCall1, HAS_PGSTAT_PERMISSIONS, int4in(), PG_GETARG_INT32, pg_getnameinfo_all(), pg_memory_is_all_zeros(), PG_RETURN_DATUM, PG_RETURN_INT32, PG_RETURN_NULL, pgstat_get_beentry_by_proc_number(), SockAddr::salen, PgBackendStatus::st_clientaddr, and PgBackendStatus::st_userid.

◆ pg_stat_get_backend_dbid()

Datum pg_stat_get_backend_dbid ( PG_FUNCTION_ARGS  )

Definition at line 731 of file pgstatfuncs.c.

732{
733 int32 procNumber = PG_GETARG_INT32(0);
734 PgBackendStatus *beentry;
735
736 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
738
740}
#define PG_RETURN_OID(x)
Definition: fmgr.h:360

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

◆ pg_stat_get_backend_idset()

Datum pg_stat_get_backend_idset ( PG_FUNCTION_ARGS  )

Definition at line 225 of file pgstatfuncs.c.

226{
227 FuncCallContext *funcctx;
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 */
234 funcctx = SRF_FIRSTCALL_INIT();
235
237 sizeof(int));
238 funcctx->user_fctx = fctx;
239
240 fctx[0] = 0;
241 }
242
243 /* stuff done on every call of the function */
244 funcctx = SRF_PERCALL_SETUP();
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 */
258 if (fctx[0] <= pgstat_fetch_stat_numbackends())
259 {
260 /* do when there is more left to send */
262
263 SRF_RETURN_NEXT(funcctx, Int32GetDatum(local_beentry->proc_number));
264 }
265 else
266 {
267 /* do when there is no more left */
268 SRF_RETURN_DONE(funcctx);
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:1229
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101

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

◆ pg_stat_get_backend_io()

Datum pg_stat_get_backend_io ( PG_FUNCTION_ARGS  )

Definition at line 1598 of file pgstatfuncs.c.

1599{
1600 ReturnSetInfo *rsinfo;
1601 BackendType bktype;
1602 int pid;
1603 PgStat_Backend *backend_stats;
1604 PgStat_BktypeIO *bktype_stats;
1605
1606 InitMaterializedSRF(fcinfo, 0);
1607 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1608
1609 pid = PG_GETARG_INT32(0);
1610 backend_stats = pgstat_fetch_stat_backend_by_pid(pid, &bktype);
1611
1612 if (!backend_stats)
1613 return (Datum) 0;
1614
1615 bktype_stats = &backend_stats->io_stats;
1616
1617 /*
1618 * In Assert builds, we can afford an extra loop through all of the
1619 * counters (in pg_stat_io_build_tuples()), checking that only expected
1620 * stats are non-zero, since it keeps the non-Assert code cleaner.
1621 */
1622 Assert(pgstat_bktype_io_stats_valid(bktype_stats, bktype));
1623
1624 /* save tuples with data from this PgStat_BktypeIO */
1625 pg_stat_io_build_tuples(rsinfo, bktype_stats, bktype,
1626 backend_stats->stat_reset_timestamp);
1627 return (Datum) 0;
1628}
Assert(PointerIsAligned(start, uint64))
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)
Definition: pgstatfuncs.c:1460
TimestampTz stat_reset_timestamp
Definition: pgstat.h:501
PgStat_BktypeIO io_stats
Definition: pgstat.h:502

References Assert(), InitMaterializedSRF(), PgStat_Backend::io_stats, PG_GETARG_INT32, pg_stat_io_build_tuples(), pgstat_bktype_io_stats_valid(), pgstat_fetch_stat_backend_by_pid(), and PgStat_Backend::stat_reset_timestamp.

◆ 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);
721 PgBackendStatus *beentry;
722
723 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
725
726 PG_RETURN_INT32(beentry->st_procpid);
727}

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

◆ pg_stat_get_backend_start()

Datum pg_stat_get_backend_start ( PG_FUNCTION_ARGS  )

Definition at line 907 of file pgstatfuncs.c.

908{
909 int32 procNumber = PG_GETARG_INT32(0);
910 TimestampTz result;
911 PgBackendStatus *beentry;
912
913 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
915
916 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
918
919 result = beentry->st_proc_start_timestamp;
920
921 if (result == 0) /* probably can't happen? */
923
924 PG_RETURN_TIMESTAMPTZ(result);
925}

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

◆ 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);
763 LocalPgBackendStatus *local_beentry;
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
774 if ((local_beentry = pgstat_get_local_beentry_by_proc_number(procNumber)) != NULL)
775 {
776 /* Fill values and NULLs */
777 values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
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 LocalPgBackendStatus::backend_subxact_count, LocalPgBackendStatus::backend_subxact_overflowed, BlessTupleDesc(), BoolGetDatum(), CreateTemplateTupleDesc(), 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);
747 PgBackendStatus *beentry;
748
749 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
751
752 PG_RETURN_OID(beentry->st_userid);
753}

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

◆ pg_stat_get_backend_wait_event()

Datum pg_stat_get_backend_wait_event ( PG_FUNCTION_ARGS  )

Definition at line 837 of file pgstatfuncs.c.

838{
839 int32 procNumber = PG_GETARG_INT32(0);
840 PgBackendStatus *beentry;
841 PGPROC *proc;
842 const char *wait_event = NULL;
843
844 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
845 wait_event = "<backend information not available>";
846 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
847 wait_event = "<insufficient privilege>";
848 else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
849 wait_event = pgstat_get_wait_event(proc->wait_event_info);
850
851 if (!wait_event)
853
855}

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

◆ pg_stat_get_backend_wait_event_type()

Datum pg_stat_get_backend_wait_event_type ( PG_FUNCTION_ARGS  )

Definition at line 816 of file pgstatfuncs.c.

817{
818 int32 procNumber = PG_GETARG_INT32(0);
819 PgBackendStatus *beentry;
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 if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
828 wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
829
830 if (!wait_event_type)
832
833 PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
834}

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

◆ pg_stat_get_backend_wal()

Datum pg_stat_get_backend_wal ( PG_FUNCTION_ARGS  )

Definition at line 1695 of file pgstatfuncs.c.

1696{
1697 int pid;
1698 PgStat_Backend *backend_stats;
1699 PgStat_WalCounters bktype_stats;
1700
1701 pid = PG_GETARG_INT32(0);
1702 backend_stats = pgstat_fetch_stat_backend_by_pid(pid, NULL);
1703
1704 if (!backend_stats)
1706
1707 bktype_stats = backend_stats->wal_counters;
1708
1709 /* save tuples with data from this PgStat_WalCounters */
1710 return (pg_stat_wal_build_tuple(bktype_stats, backend_stats->stat_reset_timestamp));
1711}
static Datum pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters, TimestampTz stat_reset_timestamp)
Definition: pgstatfuncs.c:1637
PgStat_WalCounters wal_counters
Definition: pgstat.h:503

References PG_GETARG_INT32, PG_RETURN_NULL, pg_stat_wal_build_tuple(), pgstat_fetch_stat_backend_by_pid(), PgStat_Backend::stat_reset_timestamp, and PgStat_Backend::wal_counters.

◆ pg_stat_get_backend_xact_start()

Datum pg_stat_get_backend_xact_start ( PG_FUNCTION_ARGS  )

Definition at line 885 of file pgstatfuncs.c.

886{
887 int32 procNumber = PG_GETARG_INT32(0);
888 TimestampTz result;
889 PgBackendStatus *beentry;
890
891 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
893
894 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
896
897 result = beentry->st_xact_start_timestamp;
898
899 if (result == 0) /* not in a transaction */
901
902 PG_RETURN_TIMESTAMPTZ(result);
903}

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

◆ pg_stat_get_bgwriter_buf_written_clean()

Datum pg_stat_get_bgwriter_buf_written_clean ( PG_FUNCTION_ARGS  )

Definition at line 1283 of file pgstatfuncs.c.

1284{
1285 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1286}
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 1289 of file pgstatfuncs.c.

1290{
1291 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
1292}

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

1318{
1319 PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
1320}

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

1324{
1326}

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

1272{
1274}
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 1247 of file pgstatfuncs.c.

1248{
1250}

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

1242{
1244}

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

1236{
1238}

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

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

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

1260{
1261 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_requested);
1262}

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

1254{
1255 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_timed);
1256}

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

1278{
1280}

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

1312{
1314}

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

1304{
1305 /* time is already in msec, just convert to double for presentation */
1306 PG_RETURN_FLOAT8((double)
1307 pgstat_fetch_stat_checkpointer()->sync_time);
1308}

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

1296{
1297 /* time is already in msec, just convert to double for presentation */
1298 PG_RETURN_FLOAT8((double)
1299 pgstat_fetch_stat_checkpointer()->write_time);
1300}

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

1165{
1166 Oid dbid = PG_GETARG_OID(0);
1167 int64 result;
1168 PgStat_StatDBEntry *dbentry;
1169
1170 if (!DataChecksumsEnabled())
1172
1173 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1174 result = 0;
1175 else
1176 result = (int64) (dbentry->checksum_failures);
1177
1178 PG_RETURN_INT64(result);
1179}
unsigned int Oid
Definition: postgres_ext.h:32
PgStat_Counter checksum_failures
Definition: pgstat.h:366
bool DataChecksumsEnabled(void)
Definition: xlog.c:4629

References PgStat_StatDBEntry::checksum_failures, DataChecksumsEnabled(), 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 1182 of file pgstatfuncs.c.

1183{
1184 Oid dbid = PG_GETARG_OID(0);
1185 TimestampTz result;
1186 PgStat_StatDBEntry *dbentry;
1187
1188 if (!DataChecksumsEnabled())
1190
1191 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1192 result = 0;
1193 else
1194 result = dbentry->last_checksum_failure;
1195
1196 if (result == 0)
1198 else
1199 PG_RETURN_TIMESTAMPTZ(result);
1200}
TimestampTz last_checksum_failure
Definition: pgstat.h:367

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

◆ pg_stat_get_db_conflict_all()

Datum pg_stat_get_db_conflict_all ( PG_FUNCTION_ARGS  )

Definition at line 1144 of file pgstatfuncs.c.

1145{
1146 Oid dbid = PG_GETARG_OID(0);
1147 int64 result;
1148 PgStat_StatDBEntry *dbentry;
1149
1150 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1151 result = 0;
1152 else
1153 result = (int64) (dbentry->conflict_tablespace +
1154 dbentry->conflict_lock +
1155 dbentry->conflict_snapshot +
1156 dbentry->conflict_logicalslot +
1157 dbentry->conflict_bufferpin +
1158 dbentry->conflict_startup_deadlock);
1159
1160 PG_RETURN_INT64(result);
1161}
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:362
PgStat_Counter conflict_lock
Definition: pgstat.h:358
PgStat_Counter conflict_snapshot
Definition: pgstat.h:359
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:361
PgStat_Counter conflict_logicalslot
Definition: pgstat.h:360
PgStat_Counter conflict_tablespace
Definition: pgstat.h:357

References PgStat_StatDBEntry::conflict_bufferpin, PgStat_StatDBEntry::conflict_lock, PgStat_StatDBEntry::conflict_logicalslot, PgStat_StatDBEntry::conflict_snapshot, PgStat_StatDBEntry::conflict_startup_deadlock, PgStat_StatDBEntry::conflict_tablespace, 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 1016 of file pgstatfuncs.c.

1017{
1018 Oid dbid = PG_GETARG_OID(0);
1019 int32 result;
1020 int tot_backends = pgstat_fetch_stat_numbackends();
1021 int idx;
1022
1023 result = 0;
1024 for (idx = 1; idx <= tot_backends; idx++)
1025 {
1027
1028 if (local_beentry->backendStatus.st_databaseid == dbid)
1029 result++;
1030 }
1031
1032 PG_RETURN_INT32(result);
1033}
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:262

References LocalPgBackendStatus::backendStatus, idx(), PG_GETARG_OID, PG_RETURN_INT32, pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), and PgBackendStatus::st_databaseid.

◆ pg_stat_get_db_stat_reset_time()

Datum pg_stat_get_db_stat_reset_time ( PG_FUNCTION_ARGS  )

Definition at line 1125 of file pgstatfuncs.c.

1126{
1127 Oid dbid = PG_GETARG_OID(0);
1128 TimestampTz result;
1129 PgStat_StatDBEntry *dbentry;
1130
1131 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1132 result = 0;
1133 else
1134 result = dbentry->stat_reset_timestamp;
1135
1136 if (result == 0)
1138 else
1139 PG_RETURN_TIMESTAMPTZ(result);
1140}
TimestampTz stat_reset_timestamp
Definition: pgstat.h:380

References 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);
178 PgStat_StatFuncEntry *funcentry;
179
180 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
182 PG_RETURN_INT64(funcentry->numcalls);
183}
PgStat_Counter numcalls
Definition: pgstat.h:385

References PgStat_StatFuncEntry::numcalls, 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;
211 PgStat_StatFuncEntry *funcentry;
212
213 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
214 result = 0;
215 else
216 result = funcentry->stat_reset_timestamp;
217
218 if (result == 0)
220 else
221 PG_RETURN_TIMESTAMPTZ(result);
222}
TimestampTz stat_reset_timestamp
Definition: pgstat.h:389

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

1558{
1559 ReturnSetInfo *rsinfo;
1560 PgStat_IO *backends_io_stats;
1561
1562 InitMaterializedSRF(fcinfo, 0);
1563 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1564
1565 backends_io_stats = pgstat_fetch_stat_io();
1566
1567 for (int bktype = 0; bktype < BACKEND_NUM_TYPES; bktype++)
1568 {
1569 PgStat_BktypeIO *bktype_stats = &backends_io_stats->stats[bktype];
1570
1571 /*
1572 * In Assert builds, we can afford an extra loop through all of the
1573 * counters (in pg_stat_io_build_tuples()), checking that only
1574 * expected stats are non-zero, since it keeps the non-Assert code
1575 * cleaner.
1576 */
1577 Assert(pgstat_bktype_io_stats_valid(bktype_stats, bktype));
1578
1579 /*
1580 * For those BackendTypes without IO Operation stats, skip
1581 * representing them in the view altogether.
1582 */
1583 if (!pgstat_tracks_io_bktype(bktype))
1584 continue;
1585
1586 /* save tuples with data from this PgStat_BktypeIO */
1587 pg_stat_io_build_tuples(rsinfo, bktype_stats, bktype,
1588 backends_io_stats->stat_reset_timestamp);
1589 }
1590
1591 return (Datum) 0;
1592}
#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
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:342
TimestampTz stat_reset_timestamp
Definition: pgstat.h:341

References Assert(), BACKEND_NUM_TYPES, InitMaterializedSRF(), pg_stat_io_build_tuples(), pgstat_bktype_io_stats_valid(), pgstat_fetch_stat_io(), pgstat_tracks_io_bktype(), PgStat_IO::stat_reset_timestamp, and PgStat_IO::stats.

◆ 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
279 int num_backends = pgstat_fetch_stat_numbackends();
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
300 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
301 errmsg("invalid command name: \"%s\"", cmd)));
302
303 InitMaterializedSRF(fcinfo, 0);
304
305 /* 1-based index */
306 for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
307 {
308 LocalPgBackendStatus *local_beentry;
309 PgBackendStatus *beentry;
311 bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
312 int i;
313
314 local_beentry = pgstat_get_local_beentry_by_index(curr_backend);
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);
327
328 /* show rest of the values including relid only to role members */
329 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
330 {
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:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
int i
Definition: isn.c:77
#define PG_STAT_GET_PROGRESS_COLS
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:32
ProgressCommandType st_progress_command
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Oid st_progress_command_target
char * text_to_cstring(const text *t)
Definition: varlena.c:214

References LocalPgBackendStatus::backendStatus, ereport, errcode(), errmsg(), ERROR, HAS_PGSTAT_PERMISSIONS, i, if(), 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, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, PgBackendStatus::st_databaseid, PgBackendStatus::st_procpid, PgBackendStatus::st_progress_command, PgBackendStatus::st_progress_command_target, PgBackendStatus::st_progress_param, PgBackendStatus::st_userid, text_to_cstring(), tuplestore_putvalues(), and values.

◆ pg_stat_get_replication_slot()

Datum pg_stat_get_replication_slot ( PG_FUNCTION_ARGS  )

Definition at line 2130 of file pgstatfuncs.c.

2131{
2132#define PG_STAT_GET_REPLICATION_SLOT_COLS 13
2133 text *slotname_text = PG_GETARG_TEXT_P(0);
2134 NameData slotname;
2135 TupleDesc tupdesc;
2137 bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
2138 PgStat_StatReplSlotEntry *slotent;
2140
2141 /* Initialise attributes information in the tuple descriptor */
2143 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
2144 TEXTOID, -1, 0);
2145 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "spill_txns",
2146 INT8OID, -1, 0);
2147 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "spill_count",
2148 INT8OID, -1, 0);
2149 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "spill_bytes",
2150 INT8OID, -1, 0);
2151 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stream_txns",
2152 INT8OID, -1, 0);
2153 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stream_count",
2154 INT8OID, -1, 0);
2155 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
2156 INT8OID, -1, 0);
2157 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "mem_exceeded_count",
2158 INT8OID, -1, 0);
2159 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_txns",
2160 INT8OID, -1, 0);
2161 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "total_bytes",
2162 INT8OID, -1, 0);
2163 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "slotsync_skip_count",
2164 INT8OID, -1, 0);
2165 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "slotsync_skip_at",
2166 TIMESTAMPTZOID, -1, 0);
2167 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
2168 TIMESTAMPTZOID, -1, 0);
2169 BlessTupleDesc(tupdesc);
2170
2171 namestrcpy(&slotname, text_to_cstring(slotname_text));
2172 slotent = pgstat_fetch_replslot(slotname);
2173 if (!slotent)
2174 {
2175 /*
2176 * If the slot is not found, initialise its stats. This is possible if
2177 * the create slot message is lost.
2178 */
2179 memset(&allzero, 0, sizeof(PgStat_StatReplSlotEntry));
2180 slotent = &allzero;
2181 }
2182
2183 values[0] = CStringGetTextDatum(NameStr(slotname));
2184 values[1] = Int64GetDatum(slotent->spill_txns);
2185 values[2] = Int64GetDatum(slotent->spill_count);
2186 values[3] = Int64GetDatum(slotent->spill_bytes);
2187 values[4] = Int64GetDatum(slotent->stream_txns);
2188 values[5] = Int64GetDatum(slotent->stream_count);
2189 values[6] = Int64GetDatum(slotent->stream_bytes);
2191 values[8] = Int64GetDatum(slotent->total_txns);
2192 values[9] = Int64GetDatum(slotent->total_bytes);
2194
2195 if (slotent->slotsync_skip_at == 0)
2196 nulls[11] = true;
2197 else
2199
2200 if (slotent->stat_reset_timestamp == 0)
2201 nulls[12] = true;
2202 else
2204
2205 /* Returns the record as Datum */
2207}
#define NameStr(name)
Definition: c.h:754
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
void namestrcpy(Name name, const char *str)
Definition: name.c:233
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
#define PG_STAT_GET_REPLICATION_SLOT_COLS
TimestampTz stat_reset_timestamp
Definition: pgstat.h:405
PgStat_Counter mem_exceeded_count
Definition: pgstat.h:400
PgStat_Counter stream_count
Definition: pgstat.h:398
PgStat_Counter total_txns
Definition: pgstat.h:401
PgStat_Counter slotsync_skip_count
Definition: pgstat.h:403
PgStat_Counter total_bytes
Definition: pgstat.h:402
PgStat_Counter spill_txns
Definition: pgstat.h:394
PgStat_Counter stream_txns
Definition: pgstat.h:397
TimestampTz slotsync_skip_at
Definition: pgstat.h:404
PgStat_Counter spill_count
Definition: pgstat.h:395
PgStat_Counter stream_bytes
Definition: pgstat.h:399
PgStat_Counter spill_bytes
Definition: pgstat.h:396
Definition: c.h:749

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

◆ pg_stat_get_slru()

Datum pg_stat_get_slru ( PG_FUNCTION_ARGS  )

Definition at line 1732 of file pgstatfuncs.c.

1733{
1734#define PG_STAT_GET_SLRU_COLS 9
1735 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1736 int i;
1737 PgStat_SLRUStats *stats;
1738
1739 InitMaterializedSRF(fcinfo, 0);
1740
1741 /* request SLRU stats from the cumulative stats system */
1742 stats = pgstat_fetch_slru();
1743
1744 for (i = 0;; i++)
1745 {
1746 /* for each row */
1748 bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
1750 const char *name;
1751
1753
1754 if (!name)
1755 break;
1756
1757 stat = stats[i];
1758
1760 values[1] = Int64GetDatum(stat.blocks_zeroed);
1761 values[2] = Int64GetDatum(stat.blocks_hit);
1762 values[3] = Int64GetDatum(stat.blocks_read);
1763 values[4] = Int64GetDatum(stat.blocks_written);
1764 values[5] = Int64GetDatum(stat.blocks_exists);
1765 values[6] = Int64GetDatum(stat.flush);
1766 values[7] = Int64GetDatum(stat.truncate);
1767 values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1768
1769 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1770 }
1771
1772 return (Datum) 0;
1773}
PgStat_SLRUStats * pgstat_fetch_slru(void)
Definition: pgstat_slru.c:91
const char * pgstat_get_slru_name(int slru_idx)
Definition: pgstat_slru.c:104
#define PG_STAT_GET_SLRU_COLS
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
const char * name
#define stat
Definition: win32_port.h:274

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

◆ pg_stat_get_snapshot_timestamp()

Datum pg_stat_get_snapshot_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1852 of file pgstatfuncs.c.

1853{
1854 bool have_snapshot;
1855 TimestampTz ts;
1856
1857 ts = pgstat_get_stat_snapshot_timestamp(&have_snapshot);
1858
1859 if (!have_snapshot)
1861
1863}
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition: pgstat.c:1027

References PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, and pgstat_get_stat_snapshot_timestamp().

◆ pg_stat_get_subscription_stats()

Datum pg_stat_get_subscription_stats ( PG_FUNCTION_ARGS  )

Definition at line 2214 of file pgstatfuncs.c.

2215{
2216#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 13
2217 Oid subid = PG_GETARG_OID(0);
2218 TupleDesc tupdesc;
2220 bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
2221 PgStat_StatSubEntry *subentry;
2222 PgStat_StatSubEntry allzero;
2223 int i = 0;
2224
2225 /* Get subscription stats */
2226 subentry = pgstat_fetch_stat_subscription(subid);
2227
2228 /* Initialise attributes information in the tuple descriptor */
2230 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subid",
2231 OIDOID, -1, 0);
2232 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
2233 INT8OID, -1, 0);
2234 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_seq_error_count",
2235 INT8OID, -1, 0);
2236 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "sync_table_error_count",
2237 INT8OID, -1, 0);
2238 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "confl_insert_exists",
2239 INT8OID, -1, 0);
2240 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "confl_update_origin_differs",
2241 INT8OID, -1, 0);
2242 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "confl_update_exists",
2243 INT8OID, -1, 0);
2244 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "confl_update_deleted",
2245 INT8OID, -1, 0);
2246 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "confl_update_missing",
2247 INT8OID, -1, 0);
2248 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "confl_delete_origin_differs",
2249 INT8OID, -1, 0);
2250 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "confl_delete_missing",
2251 INT8OID, -1, 0);
2252 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "confl_multiple_unique_conflicts",
2253 INT8OID, -1, 0);
2254 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "stats_reset",
2255 TIMESTAMPTZOID, -1, 0);
2256 BlessTupleDesc(tupdesc);
2257
2258 if (!subentry)
2259 {
2260 /* If the subscription is not found, initialise its stats */
2261 memset(&allzero, 0, sizeof(PgStat_StatSubEntry));
2262 subentry = &allzero;
2263 }
2264
2265 /* subid */
2266 values[i++] = ObjectIdGetDatum(subid);
2267
2268 /* apply_error_count */
2269 values[i++] = Int64GetDatum(subentry->apply_error_count);
2270
2271 /* sync_seq_error_count */
2273
2274 /* sync_table_error_count */
2276
2277 /* conflict count */
2278 for (int nconflict = 0; nconflict < CONFLICT_NUM_TYPES; nconflict++)
2279 values[i++] = Int64GetDatum(subentry->conflict_count[nconflict]);
2280
2281 /* stats_reset */
2282 if (subentry->stat_reset_timestamp == 0)
2283 nulls[i] = true;
2284 else
2286
2288
2289 /* Returns the record as Datum */
2291}
#define CONFLICT_NUM_TYPES
Definition: conflict.h:64
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS
PgStat_Counter sync_table_error_count
Definition: pgstat.h:424
PgStat_Counter apply_error_count
Definition: pgstat.h:422
PgStat_Counter sync_seq_error_count
Definition: pgstat.h:423
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition: pgstat.h:425
TimestampTz stat_reset_timestamp
Definition: pgstat.h:426

References PgStat_StatSubEntry::apply_error_count, Assert(), BlessTupleDesc(), PgStat_StatSubEntry::conflict_count, CONFLICT_NUM_TYPES, CreateTemplateTupleDesc(), heap_form_tuple(), HeapTupleGetDatum(), i, Int64GetDatum(), ObjectIdGetDatum(), PG_GETARG_OID, PG_RETURN_DATUM, PG_STAT_GET_SUBSCRIPTION_STATS_COLS, pgstat_fetch_stat_subscription(), PgStat_StatSubEntry::stat_reset_timestamp, PgStat_StatSubEntry::sync_seq_error_count, PgStat_StatSubEntry::sync_table_error_count, TimestampTzGetDatum(), TupleDescInitEntry(), and values.

◆ pg_stat_get_wal()

Datum pg_stat_get_wal ( PG_FUNCTION_ARGS  )

Definition at line 1717 of file pgstatfuncs.c.

1718{
1719 PgStat_WalStats *wal_stats;
1720
1721 /* Get statistics about WAL activity */
1722 wal_stats = pgstat_fetch_stat_wal();
1723
1724 return (pg_stat_wal_build_tuple(wal_stats->wal_counters,
1725 wal_stats->stat_reset_timestamp));
1726}
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition: pgstat_wal.c:67
TimestampTz stat_reset_timestamp
Definition: pgstat.h:492
PgStat_WalCounters wal_counters
Definition: pgstat.h:491

References pg_stat_wal_build_tuple(), pgstat_fetch_stat_wal(), PgStat_WalStats::stat_reset_timestamp, and PgStat_WalStats::wal_counters.

◆ pg_stat_get_xact_function_calls()

Datum pg_stat_get_xact_function_calls ( PG_FUNCTION_ARGS  )

Definition at line 1822 of file pgstatfuncs.c.

1823{
1824 Oid funcid = PG_GETARG_OID(0);
1825 PgStat_FunctionCounts *funcentry;
1826
1827 if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1829 PG_RETURN_INT64(funcentry->numcalls);
1830}
PgStat_Counter numcalls
Definition: pgstat.h:84

References find_funcstat_entry(), PgStat_FunctionCounts::numcalls, 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 2301 of file pgstatfuncs.c.

2302{
2303 char *stats_type = text_to_cstring(PG_GETARG_TEXT_P(0));
2304 Oid dboid = PG_GETARG_OID(1);
2305 uint64 objid = PG_GETARG_INT64(2);
2306 PgStat_Kind kind = pgstat_get_kind_from_str(stats_type);
2307
2308 PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objid));
2309}
uint64_t uint64
Definition: c.h:542
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:1044
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1401
#define PgStat_Kind
Definition: pgstat_kind.h:17

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

1464{
1465 Datum bktype_desc = CStringGetTextDatum(GetBackendTypeDesc(bktype));
1466
1467 for (int io_obj = 0; io_obj < IOOBJECT_NUM_TYPES; io_obj++)
1468 {
1469 const char *obj_name = pgstat_get_io_object_name(io_obj);
1470
1471 for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
1472 {
1473 const char *context_name = pgstat_get_io_context_name(io_context);
1474
1476 bool nulls[IO_NUM_COLUMNS] = {0};
1477
1478 /*
1479 * Some combinations of BackendType, IOObject, and IOContext are
1480 * not valid for any type of IOOp. In such cases, omit the entire
1481 * row from the view.
1482 */
1483 if (!pgstat_tracks_io_object(bktype, io_obj, io_context))
1484 continue;
1485
1486 values[IO_COL_BACKEND_TYPE] = bktype_desc;
1487 values[IO_COL_CONTEXT] = CStringGetTextDatum(context_name);
1489 if (stat_reset_timestamp != 0)
1490 values[IO_COL_RESET_TIME] = TimestampTzGetDatum(stat_reset_timestamp);
1491 else
1492 nulls[IO_COL_RESET_TIME] = true;
1493
1494 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
1495 {
1496 int op_idx = pgstat_get_io_op_index(io_op);
1497 int time_idx = pgstat_get_io_time_index(io_op);
1498 int byte_idx = pgstat_get_io_byte_index(io_op);
1499
1500 /*
1501 * Some combinations of BackendType and IOOp, of IOContext and
1502 * IOOp, and of IOObject and IOOp are not tracked. Set these
1503 * cells in the view NULL.
1504 */
1505 if (pgstat_tracks_io_op(bktype, io_obj, io_context, io_op))
1506 {
1507 PgStat_Counter count =
1508 bktype_stats->counts[io_obj][io_context][io_op];
1509
1510 values[op_idx] = Int64GetDatum(count);
1511 }
1512 else
1513 nulls[op_idx] = true;
1514
1515 if (!nulls[op_idx])
1516 {
1517 /* not every operation is timed */
1518 if (time_idx != IO_COL_INVALID)
1519 {
1520 PgStat_Counter time =
1521 bktype_stats->times[io_obj][io_context][io_op];
1522
1523 values[time_idx] = Float8GetDatum(pg_stat_us_to_ms(time));
1524 }
1525
1526 /* not every IO is tracked in bytes */
1527 if (byte_idx != IO_COL_INVALID)
1528 {
1529 char buf[256];
1530 PgStat_Counter byte =
1531 bktype_stats->bytes[io_obj][io_context][io_op];
1532
1533 /* Convert to numeric */
1534 snprintf(buf, sizeof buf, INT64_FORMAT, byte);
1538 Int32GetDatum(-1));
1539 }
1540 }
1541 else
1542 {
1543 if (time_idx != IO_COL_INVALID)
1544 nulls[time_idx] = true;
1545 if (byte_idx != IO_COL_INVALID)
1546 nulls[byte_idx] = true;
1547 }
1548 }
1549
1550 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1551 values, nulls);
1552 }
1553 }
1554}
#define INT64_FORMAT
Definition: c.h:559
static char * buf
Definition: pg_test_fsync.c:72
#define IOOP_NUM_TYPES
Definition: pgstat.h:319
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:293
int64 PgStat_Counter
Definition: pgstat.h:67
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:282
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)
Definition: pgstatfuncs.c:1447
static io_stat_col pgstat_get_io_time_index(IOOp io_op)
Definition: pgstatfuncs.c:1422
static io_stat_col pgstat_get_io_op_index(IOOp io_op)
Definition: pgstatfuncs.c:1364
static io_stat_col pgstat_get_io_byte_index(IOOp io_op)
Definition: pgstatfuncs.c:1395
#define snprintf
Definition: port.h:260
static Datum Float8GetDatum(float8 X)
Definition: postgres.h:492
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:329
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:327
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:328

References buf, PgStat_BktypeIO::bytes, PgStat_BktypeIO::counts, CStringGetDatum(), CStringGetTextDatum, DirectFunctionCall3, 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(), ReturnSetInfo::setDesc, ReturnSetInfo::setResult, snprintf, PgStat_BktypeIO::times, 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 1887 of file pgstatfuncs.c.

1888{
1890
1892}
void pgstat_reset_counters(void)
Definition: pgstat.c:835

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

1974{
1975 PGPROC *proc;
1976 PgBackendStatus *beentry;
1977 ProcNumber procNumber;
1978 int backend_pid = PG_GETARG_INT32(0);
1979
1980 proc = BackendPidGetProc(backend_pid);
1981
1982 /* This could be an auxiliary process */
1983 if (!proc)
1984 proc = AuxiliaryPidGetProc(backend_pid);
1985
1986 if (!proc)
1988
1989 procNumber = GetNumberFromPGProc(proc);
1990
1991 beentry = pgstat_get_beentry_by_proc_number(procNumber);
1992 if (!beentry)
1994
1995 /* Check if the backend type tracks statistics */
1998
2000
2002}
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:854
bool pgstat_tracks_backend_bktype(BackendType bktype)
#define PGSTAT_KIND_BACKEND
Definition: pgstat_kind.h:32
#define GetNumberFromPGProc(proc)
Definition: proc.h:441
int ProcNumber
Definition: procnumber.h:24

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

◆ pg_stat_reset_replication_slot()

Datum pg_stat_reset_replication_slot ( PG_FUNCTION_ARGS  )

Definition at line 2023 of file pgstatfuncs.c.

2024{
2025 char *target = NULL;
2026
2027 if (PG_ARGISNULL(0))
2029 else
2030 {
2032 pgstat_reset_replslot(target);
2033 }
2034
2036}
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition: pgstat.c:876
#define PGSTAT_KIND_REPLSLOT
Definition: pgstat_kind.h:30
void pgstat_reset_replslot(const char *name)

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

◆ pg_stat_reset_shared()

Datum pg_stat_reset_shared ( PG_FUNCTION_ARGS  )

Definition at line 1901 of file pgstatfuncs.c.

1902{
1903 char *target = NULL;
1904
1905 if (PG_ARGISNULL(0))
1906 {
1907 /* Reset all the statistics when nothing is specified */
1915
1917 }
1918
1920
1921 if (strcmp(target, "archiver") == 0)
1923 else if (strcmp(target, "bgwriter") == 0)
1925 else if (strcmp(target, "checkpointer") == 0)
1927 else if (strcmp(target, "io") == 0)
1929 else if (strcmp(target, "recovery_prefetch") == 0)
1931 else if (strcmp(target, "slru") == 0)
1933 else if (strcmp(target, "wal") == 0)
1935 else
1936 ereport(ERROR,
1937 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1938 errmsg("unrecognized reset target: \"%s\"", target),
1939 errhint("Target must be \"archiver\", \"bgwriter\", \"checkpointer\", \"io\", \"recovery_prefetch\", \"slru\", or \"wal\".")));
1940
1942}
int errhint(const char *fmt,...)
Definition: elog.c:1330
#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, 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 1960 of file pgstatfuncs.c.

1961{
1962 Oid funcoid = PG_GETARG_OID(0);
1963
1965
1967}
Oid MyDatabaseId
Definition: globals.c:94
#define PGSTAT_KIND_FUNCTION
Definition: pgstat_kind.h:29

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

◆ pg_stat_reset_single_table_counters()

Datum pg_stat_reset_single_table_counters ( PG_FUNCTION_ARGS  )

Definition at line 1949 of file pgstatfuncs.c.

1950{
1951 Oid taboid = PG_GETARG_OID(0);
1952 Oid dboid = (IsSharedRelation(taboid) ? InvalidOid : MyDatabaseId);
1953
1954 pgstat_reset(PGSTAT_KIND_RELATION, dboid, taboid);
1955
1957}
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:304
#define PGSTAT_KIND_RELATION
Definition: pgstat_kind.h:28

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

2007{
2008 char *target = NULL;
2009
2010 if (PG_ARGISNULL(0))
2012 else
2013 {
2015 pgstat_reset_slru(target);
2016 }
2017
2019}
void pgstat_reset_slru(const char *name)
Definition: pgstat_slru.c:45

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

◆ pg_stat_reset_subscription_stats()

Datum pg_stat_reset_subscription_stats ( PG_FUNCTION_ARGS  )

Definition at line 2040 of file pgstatfuncs.c.

2041{
2042 Oid subid;
2043
2044 if (PG_ARGISNULL(0))
2045 {
2046 /* Clear all subscription stats */
2048 }
2049 else
2050 {
2051 subid = PG_GETARG_OID(0);
2052
2053 if (!OidIsValid(subid))
2054 ereport(ERROR,
2055 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2056 errmsg("invalid subscription OID %u", subid)));
2058 }
2059
2061}
#define OidIsValid(objectId)
Definition: c.h:777
#define PGSTAT_KIND_SUBSCRIPTION
Definition: pgstat_kind.h:31

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

◆ pg_stat_us_to_ms()

static double pg_stat_us_to_ms ( PgStat_Counter  val_ms)
inlinestatic

Definition at line 1447 of file pgstatfuncs.c.

1448{
1449 return val_ms * (double) 0.001;
1450}

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

1639{
1640#define PG_STAT_WAL_COLS 6
1641 TupleDesc tupdesc;
1643 bool nulls[PG_STAT_WAL_COLS] = {0};
1644 char buf[256];
1645
1646 /* Initialise attributes information in the tuple descriptor */
1648 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1649 INT8OID, -1, 0);
1650 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1651 INT8OID, -1, 0);
1652 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1653 NUMERICOID, -1, 0);
1654 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_fpi_bytes",
1655 NUMERICOID, -1, 0);
1656 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_buffers_full",
1657 INT8OID, -1, 0);
1658 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stats_reset",
1659 TIMESTAMPTZOID, -1, 0);
1660
1661 BlessTupleDesc(tupdesc);
1662
1663 /* Fill values and NULLs */
1664 values[0] = Int64GetDatum(wal_counters.wal_records);
1665 values[1] = Int64GetDatum(wal_counters.wal_fpi);
1666
1667 /* Convert to numeric. */
1668 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_bytes);
1672 Int32GetDatum(-1));
1673
1674 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_fpi_bytes);
1678 Int32GetDatum(-1));
1679
1680 values[4] = Int64GetDatum(wal_counters.wal_buffers_full);
1681
1682 if (stat_reset_timestamp != 0)
1683 values[5] = TimestampTzGetDatum(stat_reset_timestamp);
1684 else
1685 nulls[5] = true;
1686
1687 /* Returns the record as Datum */
1689}
#define UINT64_FORMAT
Definition: c.h:560
#define PG_STAT_WAL_COLS
PgStat_Counter wal_fpi
Definition: pgstat.h:479
uint64 wal_bytes
Definition: pgstat.h:480
uint64 wal_fpi_bytes
Definition: pgstat.h:481
PgStat_Counter wal_buffers_full
Definition: pgstat.h:482
PgStat_Counter wal_records
Definition: pgstat.h:478

References BlessTupleDesc(), buf, CreateTemplateTupleDesc(), CStringGetDatum(), DirectFunctionCall3, 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 1395 of file pgstatfuncs.c.

1396{
1397 switch (io_op)
1398 {
1399 case IOOP_EXTEND:
1400 return IO_COL_EXTEND_BYTES;
1401 case IOOP_READ:
1402 return IO_COL_READ_BYTES;
1403 case IOOP_WRITE:
1404 return IO_COL_WRITE_BYTES;
1405 case IOOP_EVICT:
1406 case IOOP_FSYNC:
1407 case IOOP_HIT:
1408 case IOOP_REUSE:
1409 case IOOP_WRITEBACK:
1410 return IO_COL_INVALID;
1411 }
1412
1413 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1415}
#define pg_unreachable()
Definition: c.h:336
#define elog(elevel,...)
Definition: elog.h:226
@ IOOP_EXTEND
Definition: pgstat.h:314
@ IOOP_FSYNC
Definition: pgstat.h:308
@ IOOP_READ
Definition: pgstat.h:315
@ IOOP_WRITEBACK
Definition: pgstat.h:311
@ IOOP_HIT
Definition: pgstat.h:309
@ IOOP_EVICT
Definition: pgstat.h:307
@ IOOP_REUSE
Definition: pgstat.h:310
@ IOOP_WRITE
Definition: pgstat.h:316

References elog, ERROR, 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 1364 of file pgstatfuncs.c.

1365{
1366 switch (io_op)
1367 {
1368 case IOOP_EVICT:
1369 return IO_COL_EVICTIONS;
1370 case IOOP_EXTEND:
1371 return IO_COL_EXTENDS;
1372 case IOOP_FSYNC:
1373 return IO_COL_FSYNCS;
1374 case IOOP_HIT:
1375 return IO_COL_HITS;
1376 case IOOP_READ:
1377 return IO_COL_READS;
1378 case IOOP_REUSE:
1379 return IO_COL_REUSES;
1380 case IOOP_WRITE:
1381 return IO_COL_WRITES;
1382 case IOOP_WRITEBACK:
1383 return IO_COL_WRITEBACKS;
1384 }
1385
1386 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1388}

References elog, ERROR, 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 1422 of file pgstatfuncs.c.

1423{
1424 switch (io_op)
1425 {
1426 case IOOP_READ:
1427 return IO_COL_READ_TIME;
1428 case IOOP_WRITE:
1429 return IO_COL_WRITE_TIME;
1430 case IOOP_WRITEBACK:
1431 return IO_COL_WRITEBACK_TIME;
1432 case IOOP_EXTEND:
1433 return IO_COL_EXTEND_TIME;
1434 case IOOP_FSYNC:
1435 return IO_COL_FSYNC_TIME;
1436 case IOOP_EVICT:
1437 case IOOP_HIT:
1438 case IOOP_REUSE:
1439 return IO_COL_INVALID;
1440 }
1441
1442 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1444}

References elog, ERROR, 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().