PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pgstatfuncs.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pgstatfuncs.c
4 * Functions for accessing various forms of statistics data
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/utils/adt/pgstatfuncs.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "access/htup_details.h"
18#include "access/xlog.h"
20#include "catalog/catalog.h"
21#include "catalog/pg_authid.h"
22#include "catalog/pg_type.h"
23#include "common/ip.h"
24#include "funcapi.h"
25#include "miscadmin.h"
26#include "pgstat.h"
27#include "postmaster/bgworker.h"
29#include "storage/proc.h"
30#include "storage/procarray.h"
31#include "utils/acl.h"
32#include "utils/builtins.h"
33#include "utils/timestamp.h"
34
35#define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var))))
36
37#define HAS_PGSTAT_PERMISSIONS(role) (has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
38
39#define PG_STAT_GET_RELENTRY_INT64(stat) \
40Datum \
41CppConcat(pg_stat_get_,stat)(PG_FUNCTION_ARGS) \
42{ \
43 Oid relid = PG_GETARG_OID(0); \
44 int64 result; \
45 PgStat_StatTabEntry *tabentry; \
46 \
47 if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
48 result = 0; \
49 else \
50 result = (int64) (tabentry->stat); \
51 \
52 PG_RETURN_INT64(result); \
53}
54
55/* pg_stat_get_analyze_count */
56PG_STAT_GET_RELENTRY_INT64(analyze_count)
57
58/* pg_stat_get_autoanalyze_count */
59PG_STAT_GET_RELENTRY_INT64(autoanalyze_count)
60
61/* pg_stat_get_autovacuum_count */
62PG_STAT_GET_RELENTRY_INT64(autovacuum_count)
63
64/* pg_stat_get_blocks_fetched */
65PG_STAT_GET_RELENTRY_INT64(blocks_fetched)
66
67/* pg_stat_get_blocks_hit */
69
70/* pg_stat_get_dead_tuples */
72
73/* pg_stat_get_ins_since_vacuum */
74PG_STAT_GET_RELENTRY_INT64(ins_since_vacuum)
75
76/* pg_stat_get_live_tuples */
78
79/* pg_stat_get_mod_since_analyze */
80PG_STAT_GET_RELENTRY_INT64(mod_since_analyze)
81
82/* pg_stat_get_numscans */
84
85/* pg_stat_get_tuples_deleted */
86PG_STAT_GET_RELENTRY_INT64(tuples_deleted)
87
88/* pg_stat_get_tuples_fetched */
89PG_STAT_GET_RELENTRY_INT64(tuples_fetched)
90
91/* pg_stat_get_tuples_hot_updated */
92PG_STAT_GET_RELENTRY_INT64(tuples_hot_updated)
93
94/* pg_stat_get_tuples_newpage_updated */
95PG_STAT_GET_RELENTRY_INT64(tuples_newpage_updated)
96
97/* pg_stat_get_tuples_inserted */
98PG_STAT_GET_RELENTRY_INT64(tuples_inserted)
99
100/* pg_stat_get_tuples_returned */
101PG_STAT_GET_RELENTRY_INT64(tuples_returned)
102
103/* pg_stat_get_tuples_updated */
104PG_STAT_GET_RELENTRY_INT64(tuples_updated)
105
106/* pg_stat_get_vacuum_count */
107PG_STAT_GET_RELENTRY_INT64(vacuum_count)
108
109#define PG_STAT_GET_RELENTRY_FLOAT8(stat) \
110Datum \
111CppConcat(pg_stat_get_,stat)(PG_FUNCTION_ARGS) \
112{ \
113 Oid relid = PG_GETARG_OID(0); \
114 double result; \
115 PgStat_StatTabEntry *tabentry; \
116 \
117 if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
118 result = 0; \
119 else \
120 result = (double) (tabentry->stat); \
121 \
122 PG_RETURN_FLOAT8(result); \
123}
124
125/* pg_stat_get_total_vacuum_time */
126PG_STAT_GET_RELENTRY_FLOAT8(total_vacuum_time)
127
128/* pg_stat_get_total_autovacuum_time */
129PG_STAT_GET_RELENTRY_FLOAT8(total_autovacuum_time)
130
131/* pg_stat_get_total_analyze_time */
132PG_STAT_GET_RELENTRY_FLOAT8(total_analyze_time)
133
134/* pg_stat_get_total_autoanalyze_time */
135PG_STAT_GET_RELENTRY_FLOAT8(total_autoanalyze_time)
136
137#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat) \
138Datum \
139CppConcat(pg_stat_get_,stat)(PG_FUNCTION_ARGS) \
140{ \
141 Oid relid = PG_GETARG_OID(0); \
142 TimestampTz result; \
143 PgStat_StatTabEntry *tabentry; \
144 \
145 if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \
146 result = 0; \
147 else \
148 result = tabentry->stat; \
149 \
150 if (result == 0) \
151 PG_RETURN_NULL(); \
152 else \
153 PG_RETURN_TIMESTAMPTZ(result); \
154}
155
156/* pg_stat_get_last_analyze_time */
157PG_STAT_GET_RELENTRY_TIMESTAMPTZ(last_analyze_time)
158
159/* pg_stat_get_last_autoanalyze_time */
160PG_STAT_GET_RELENTRY_TIMESTAMPTZ(last_autoanalyze_time)
161
162/* pg_stat_get_last_autovacuum_time */
163PG_STAT_GET_RELENTRY_TIMESTAMPTZ(last_autovacuum_time)
164
165/* pg_stat_get_last_vacuum_time */
166PG_STAT_GET_RELENTRY_TIMESTAMPTZ(last_vacuum_time)
167
168/* pg_stat_get_lastscan */
170
171/* pg_stat_get_stat_reset_time */
173
174Datum
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}
184
185/* convert counter from microsec to millisec for display */
186#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS(stat) \
187Datum \
188CppConcat(pg_stat_get_function_,stat)(PG_FUNCTION_ARGS) \
189{ \
190 Oid funcid = PG_GETARG_OID(0); \
191 double result; \
192 PgStat_StatFuncEntry *funcentry; \
193 \
194 if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL) \
195 PG_RETURN_NULL(); \
196 result = ((double) funcentry->stat) / 1000.0; \
197 PG_RETURN_FLOAT8(result); \
198}
199
200/* pg_stat_get_function_total_time */
202
203/* pg_stat_get_function_self_time */
205
206Datum
208{
209 FuncCallContext *funcctx;
210 int *fctx;
211
212 /* stuff done only on the first call of the function */
213 if (SRF_IS_FIRSTCALL())
214 {
215 /* create a function context for cross-call persistence */
216 funcctx = SRF_FIRSTCALL_INIT();
217
219 sizeof(int));
220 funcctx->user_fctx = fctx;
221
222 fctx[0] = 0;
223 }
224
225 /* stuff done on every call of the function */
226 funcctx = SRF_PERCALL_SETUP();
227 fctx = funcctx->user_fctx;
228
229 fctx[0] += 1;
230
231 /*
232 * We recheck pgstat_fetch_stat_numbackends() each time through, just in
233 * case the local status data has been refreshed since we started. It's
234 * plenty cheap enough if not. If a refresh does happen, we'll likely
235 * miss or duplicate some backend IDs, but we're content not to crash.
236 * (Refreshing midway through such a query would be problematic usage
237 * anyway, since the backend IDs we've already returned might no longer
238 * refer to extant sessions.)
239 */
240 if (fctx[0] <= pgstat_fetch_stat_numbackends())
241 {
242 /* do when there is more left to send */
244
245 SRF_RETURN_NEXT(funcctx, Int32GetDatum(local_beentry->proc_number));
246 }
247 else
248 {
249 /* do when there is no more left */
250 SRF_RETURN_DONE(funcctx);
251 }
252}
253
254/*
255 * Returns command progress information for the named command.
256 */
257Datum
259{
260#define PG_STAT_GET_PROGRESS_COLS PGSTAT_NUM_PROGRESS_PARAM + 3
261 int num_backends = pgstat_fetch_stat_numbackends();
262 int curr_backend;
263 char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
264 ProgressCommandType cmdtype;
265 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
266
267 /* Translate command name into command type code. */
268 if (pg_strcasecmp(cmd, "VACUUM") == 0)
269 cmdtype = PROGRESS_COMMAND_VACUUM;
270 else if (pg_strcasecmp(cmd, "ANALYZE") == 0)
271 cmdtype = PROGRESS_COMMAND_ANALYZE;
272 else if (pg_strcasecmp(cmd, "CLUSTER") == 0)
273 cmdtype = PROGRESS_COMMAND_CLUSTER;
274 else if (pg_strcasecmp(cmd, "CREATE INDEX") == 0)
276 else if (pg_strcasecmp(cmd, "BASEBACKUP") == 0)
278 else if (pg_strcasecmp(cmd, "COPY") == 0)
279 cmdtype = PROGRESS_COMMAND_COPY;
280 else
282 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
283 errmsg("invalid command name: \"%s\"", cmd)));
284
285 InitMaterializedSRF(fcinfo, 0);
286
287 /* 1-based index */
288 for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
289 {
290 LocalPgBackendStatus *local_beentry;
291 PgBackendStatus *beentry;
293 bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
294 int i;
295
296 local_beentry = pgstat_get_local_beentry_by_index(curr_backend);
297 beentry = &local_beentry->backendStatus;
298
299 /*
300 * Report values for only those backends which are running the given
301 * command.
302 */
303 if (beentry->st_progress_command != cmdtype)
304 continue;
305
306 /* Value available to all callers */
307 values[0] = Int32GetDatum(beentry->st_procpid);
309
310 /* show rest of the values including relid only to role members */
311 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
312 {
314 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
315 values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
316 }
317 else
318 {
319 nulls[2] = true;
320 for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
321 nulls[i + 3] = true;
322 }
323
324 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
325 }
326
327 return (Datum) 0;
328}
329
330/*
331 * Returns activity of PG backends.
332 */
333Datum
335{
336#define PG_STAT_GET_ACTIVITY_COLS 31
337 int num_backends = pgstat_fetch_stat_numbackends();
338 int curr_backend;
339 int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
340 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
341
342 InitMaterializedSRF(fcinfo, 0);
343
344 /* 1-based index */
345 for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
346 {
347 /* for each row */
349 bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
350 LocalPgBackendStatus *local_beentry;
351 PgBackendStatus *beentry;
352 PGPROC *proc;
353 const char *wait_event_type = NULL;
354 const char *wait_event = NULL;
355
356 /* Get the next one in the list */
357 local_beentry = pgstat_get_local_beentry_by_index(curr_backend);
358 beentry = &local_beentry->backendStatus;
359
360 /* If looking for specific PID, ignore all the others */
361 if (pid != -1 && beentry->st_procpid != pid)
362 continue;
363
364 /* Values available to all callers */
365 if (beentry->st_databaseid != InvalidOid)
367 else
368 nulls[0] = true;
369
370 values[1] = Int32GetDatum(beentry->st_procpid);
371
372 if (beentry->st_userid != InvalidOid)
373 values[2] = ObjectIdGetDatum(beentry->st_userid);
374 else
375 nulls[2] = true;
376
377 if (beentry->st_appname)
379 else
380 nulls[3] = true;
381
382 if (TransactionIdIsValid(local_beentry->backend_xid))
383 values[15] = TransactionIdGetDatum(local_beentry->backend_xid);
384 else
385 nulls[15] = true;
386
387 if (TransactionIdIsValid(local_beentry->backend_xmin))
388 values[16] = TransactionIdGetDatum(local_beentry->backend_xmin);
389 else
390 nulls[16] = true;
391
392 /* Values only available to role member or pg_read_all_stats */
393 if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
394 {
395 char *clipped_activity;
396
397 switch (beentry->st_state)
398 {
399 case STATE_STARTING:
400 values[4] = CStringGetTextDatum("starting");
401 break;
402 case STATE_IDLE:
403 values[4] = CStringGetTextDatum("idle");
404 break;
405 case STATE_RUNNING:
406 values[4] = CStringGetTextDatum("active");
407 break;
409 values[4] = CStringGetTextDatum("idle in transaction");
410 break;
411 case STATE_FASTPATH:
412 values[4] = CStringGetTextDatum("fastpath function call");
413 break;
415 values[4] = CStringGetTextDatum("idle in transaction (aborted)");
416 break;
417 case STATE_DISABLED:
418 values[4] = CStringGetTextDatum("disabled");
419 break;
420 case STATE_UNDEFINED:
421 nulls[4] = true;
422 break;
423 }
424
425 clipped_activity = pgstat_clip_activity(beentry->st_activity_raw);
426 values[5] = CStringGetTextDatum(clipped_activity);
427 pfree(clipped_activity);
428
429 /* leader_pid */
430 nulls[29] = true;
431
432 proc = BackendPidGetProc(beentry->st_procpid);
433
434 if (proc == NULL && (beentry->st_backendType != B_BACKEND))
435 {
436 /*
437 * For an auxiliary process, retrieve process info from
438 * AuxiliaryProcs stored in shared-memory.
439 */
440 proc = AuxiliaryPidGetProc(beentry->st_procpid);
441 }
442
443 /*
444 * If a PGPROC entry was retrieved, display wait events and lock
445 * group leader or apply leader information if any. To avoid
446 * extra overhead, no extra lock is being held, so there is no
447 * guarantee of consistency across multiple rows.
448 */
449 if (proc != NULL)
450 {
451 uint32 raw_wait_event;
452 PGPROC *leader;
453
454 raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
455 wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
456 wait_event = pgstat_get_wait_event(raw_wait_event);
457
458 leader = proc->lockGroupLeader;
459
460 /*
461 * Show the leader only for active parallel workers. This
462 * leaves the field as NULL for the leader of a parallel group
463 * or the leader of parallel apply workers.
464 */
465 if (leader && leader->pid != beentry->st_procpid)
466 {
467 values[29] = Int32GetDatum(leader->pid);
468 nulls[29] = false;
469 }
470 else if (beentry->st_backendType == B_BG_WORKER)
471 {
472 int leader_pid = GetLeaderApplyWorkerPid(beentry->st_procpid);
473
474 if (leader_pid != InvalidPid)
475 {
476 values[29] = Int32GetDatum(leader_pid);
477 nulls[29] = false;
478 }
479 }
480 }
481
482 if (wait_event_type)
483 values[6] = CStringGetTextDatum(wait_event_type);
484 else
485 nulls[6] = true;
486
487 if (wait_event)
488 values[7] = CStringGetTextDatum(wait_event);
489 else
490 nulls[7] = true;
491
492 /*
493 * Don't expose transaction time for walsenders; it confuses
494 * monitoring, particularly because we don't keep the time up-to-
495 * date.
496 */
497 if (beentry->st_xact_start_timestamp != 0 &&
498 beentry->st_backendType != B_WAL_SENDER)
500 else
501 nulls[8] = true;
502
503 if (beentry->st_activity_start_timestamp != 0)
505 else
506 nulls[9] = true;
507
508 if (beentry->st_proc_start_timestamp != 0)
510 else
511 nulls[10] = true;
512
513 if (beentry->st_state_start_timestamp != 0)
515 else
516 nulls[11] = true;
517
518 /* A zeroed client addr means we don't know */
520 sizeof(beentry->st_clientaddr)))
521 {
522 nulls[12] = true;
523 nulls[13] = true;
524 nulls[14] = true;
525 }
526 else
527 {
528 if (beentry->st_clientaddr.addr.ss_family == AF_INET ||
529 beentry->st_clientaddr.addr.ss_family == AF_INET6)
530 {
531 char remote_host[NI_MAXHOST];
532 char remote_port[NI_MAXSERV];
533 int ret;
534
535 remote_host[0] = '\0';
536 remote_port[0] = '\0';
537 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
538 beentry->st_clientaddr.salen,
539 remote_host, sizeof(remote_host),
540 remote_port, sizeof(remote_port),
541 NI_NUMERICHOST | NI_NUMERICSERV);
542 if (ret == 0)
543 {
544 clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
546 CStringGetDatum(remote_host));
547 if (beentry->st_clienthostname &&
548 beentry->st_clienthostname[0])
550 else
551 nulls[13] = true;
552 values[14] = Int32GetDatum(atoi(remote_port));
553 }
554 else
555 {
556 nulls[12] = true;
557 nulls[13] = true;
558 nulls[14] = true;
559 }
560 }
561 else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
562 {
563 /*
564 * Unix sockets always reports NULL for host and -1 for
565 * port, so it's possible to tell the difference to
566 * connections we have no permissions to view, or with
567 * errors.
568 */
569 nulls[12] = true;
570 nulls[13] = true;
571 values[14] = Int32GetDatum(-1);
572 }
573 else
574 {
575 /* Unknown address type, should never happen */
576 nulls[12] = true;
577 nulls[13] = true;
578 nulls[14] = true;
579 }
580 }
581 /* Add backend type */
582 if (beentry->st_backendType == B_BG_WORKER)
583 {
584 const char *bgw_type;
585
586 bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
587 if (bgw_type)
588 values[17] = CStringGetTextDatum(bgw_type);
589 else
590 nulls[17] = true;
591 }
592 else
593 values[17] =
595
596 /* SSL information */
597 if (beentry->st_ssl)
598 {
599 values[18] = BoolGetDatum(true); /* ssl */
602 values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits);
603
604 if (beentry->st_sslstatus->ssl_client_dn[0])
606 else
607 nulls[22] = true;
608
609 if (beentry->st_sslstatus->ssl_client_serial[0])
613 Int32GetDatum(-1));
614 else
615 nulls[23] = true;
616
617 if (beentry->st_sslstatus->ssl_issuer_dn[0])
619 else
620 nulls[24] = true;
621 }
622 else
623 {
624 values[18] = BoolGetDatum(false); /* ssl */
625 nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = true;
626 }
627
628 /* GSSAPI information */
629 if (beentry->st_gss)
630 {
631 values[25] = BoolGetDatum(beentry->st_gssstatus->gss_auth); /* gss_auth */
633 values[27] = BoolGetDatum(beentry->st_gssstatus->gss_enc); /* GSS Encryption in use */
634 values[28] = BoolGetDatum(beentry->st_gssstatus->gss_delegation); /* GSS credentials
635 * delegated */
636 }
637 else
638 {
639 values[25] = BoolGetDatum(false); /* gss_auth */
640 nulls[26] = true; /* No GSS principal */
641 values[27] = BoolGetDatum(false); /* GSS Encryption not in
642 * use */
643 values[28] = BoolGetDatum(false); /* GSS credentials not
644 * delegated */
645 }
646 if (beentry->st_query_id == INT64CONST(0))
647 nulls[30] = true;
648 else
649 values[30] = Int64GetDatum(beentry->st_query_id);
650 }
651 else
652 {
653 /* No permissions to view data about this session */
654 values[5] = CStringGetTextDatum("<insufficient privilege>");
655 nulls[4] = true;
656 nulls[6] = true;
657 nulls[7] = true;
658 nulls[8] = true;
659 nulls[9] = true;
660 nulls[10] = true;
661 nulls[11] = true;
662 nulls[12] = true;
663 nulls[13] = true;
664 nulls[14] = true;
665 nulls[17] = true;
666 nulls[18] = true;
667 nulls[19] = true;
668 nulls[20] = true;
669 nulls[21] = true;
670 nulls[22] = true;
671 nulls[23] = true;
672 nulls[24] = true;
673 nulls[25] = true;
674 nulls[26] = true;
675 nulls[27] = true;
676 nulls[28] = true;
677 nulls[29] = true;
678 nulls[30] = true;
679 }
680
681 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
682
683 /* If only a single backend was requested, and we found it, break. */
684 if (pid != -1)
685 break;
686 }
687
688 return (Datum) 0;
689}
690
691
692Datum
694{
696}
697
698
699Datum
701{
702 int32 procNumber = PG_GETARG_INT32(0);
703 PgBackendStatus *beentry;
704
705 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
707
708 PG_RETURN_INT32(beentry->st_procpid);
709}
710
711
712Datum
714{
715 int32 procNumber = PG_GETARG_INT32(0);
716 PgBackendStatus *beentry;
717
718 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
720
722}
723
724
725Datum
727{
728 int32 procNumber = PG_GETARG_INT32(0);
729 PgBackendStatus *beentry;
730
731 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
733
734 PG_RETURN_OID(beentry->st_userid);
735}
736
737Datum
739{
740#define PG_STAT_GET_SUBXACT_COLS 2
741 TupleDesc tupdesc;
743 bool nulls[PG_STAT_GET_SUBXACT_COLS] = {0};
744 int32 procNumber = PG_GETARG_INT32(0);
745 LocalPgBackendStatus *local_beentry;
746
747 /* Initialise attributes information in the tuple descriptor */
749 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subxact_count",
750 INT4OID, -1, 0);
751 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "subxact_overflow",
752 BOOLOID, -1, 0);
753
754 BlessTupleDesc(tupdesc);
755
756 if ((local_beentry = pgstat_get_local_beentry_by_proc_number(procNumber)) != NULL)
757 {
758 /* Fill values and NULLs */
759 values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
761 }
762 else
763 {
764 nulls[0] = true;
765 nulls[1] = true;
766 }
767
768 /* Returns the record as Datum */
770}
771
772Datum
774{
775 int32 procNumber = PG_GETARG_INT32(0);
776 PgBackendStatus *beentry;
777 const char *activity;
778 char *clipped_activity;
779 text *ret;
780
781 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
782 activity = "<backend information not available>";
783 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
784 activity = "<insufficient privilege>";
785 else if (*(beentry->st_activity_raw) == '\0')
786 activity = "<command string not enabled>";
787 else
788 activity = beentry->st_activity_raw;
789
790 clipped_activity = pgstat_clip_activity(activity);
791 ret = cstring_to_text(activity);
792 pfree(clipped_activity);
793
794 PG_RETURN_TEXT_P(ret);
795}
796
797Datum
799{
800 int32 procNumber = PG_GETARG_INT32(0);
801 PgBackendStatus *beentry;
802 PGPROC *proc;
803 const char *wait_event_type = NULL;
804
805 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
806 wait_event_type = "<backend information not available>";
807 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
808 wait_event_type = "<insufficient privilege>";
809 else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
810 wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
811
812 if (!wait_event_type)
814
815 PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
816}
817
818Datum
820{
821 int32 procNumber = PG_GETARG_INT32(0);
822 PgBackendStatus *beentry;
823 PGPROC *proc;
824 const char *wait_event = NULL;
825
826 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
827 wait_event = "<backend information not available>";
828 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
829 wait_event = "<insufficient privilege>";
830 else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
831 wait_event = pgstat_get_wait_event(proc->wait_event_info);
832
833 if (!wait_event)
835
837}
838
839
840Datum
842{
843 int32 procNumber = PG_GETARG_INT32(0);
844 TimestampTz result;
845 PgBackendStatus *beentry;
846
847 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
849
850 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
852
853 result = beentry->st_activity_start_timestamp;
854
855 /*
856 * No time recorded for start of current query -- this is the case if the
857 * user hasn't enabled query-level stats collection.
858 */
859 if (result == 0)
861
862 PG_RETURN_TIMESTAMPTZ(result);
863}
864
865
866Datum
868{
869 int32 procNumber = PG_GETARG_INT32(0);
870 TimestampTz result;
871 PgBackendStatus *beentry;
872
873 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
875
876 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
878
879 result = beentry->st_xact_start_timestamp;
880
881 if (result == 0) /* not in a transaction */
883
884 PG_RETURN_TIMESTAMPTZ(result);
885}
886
887
888Datum
890{
891 int32 procNumber = PG_GETARG_INT32(0);
892 TimestampTz result;
893 PgBackendStatus *beentry;
894
895 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
897
898 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
900
901 result = beentry->st_proc_start_timestamp;
902
903 if (result == 0) /* probably can't happen? */
905
906 PG_RETURN_TIMESTAMPTZ(result);
907}
908
909
910Datum
912{
913 int32 procNumber = PG_GETARG_INT32(0);
914 PgBackendStatus *beentry;
915 char remote_host[NI_MAXHOST];
916 int ret;
917
918 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
920
921 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
923
924 /* A zeroed client addr means we don't know */
926 sizeof(beentry->st_clientaddr)))
928
929 switch (beentry->st_clientaddr.addr.ss_family)
930 {
931 case AF_INET:
932 case AF_INET6:
933 break;
934 default:
936 }
937
938 remote_host[0] = '\0';
939 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
940 beentry->st_clientaddr.salen,
941 remote_host, sizeof(remote_host),
942 NULL, 0,
943 NI_NUMERICHOST | NI_NUMERICSERV);
944 if (ret != 0)
946
947 clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
948
950 CStringGetDatum(remote_host)));
951}
952
953Datum
955{
956 int32 procNumber = PG_GETARG_INT32(0);
957 PgBackendStatus *beentry;
958 char remote_port[NI_MAXSERV];
959 int ret;
960
961 if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
963
964 else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
966
967 /* A zeroed client addr means we don't know */
969 sizeof(beentry->st_clientaddr)))
971
972 switch (beentry->st_clientaddr.addr.ss_family)
973 {
974 case AF_INET:
975 case AF_INET6:
976 break;
977 case AF_UNIX:
978 PG_RETURN_INT32(-1);
979 default:
981 }
982
983 remote_port[0] = '\0';
984 ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr,
985 beentry->st_clientaddr.salen,
986 NULL, 0,
987 remote_port, sizeof(remote_port),
988 NI_NUMERICHOST | NI_NUMERICSERV);
989 if (ret != 0)
991
993 CStringGetDatum(remote_port)));
994}
995
996
997Datum
999{
1000 Oid dbid = PG_GETARG_OID(0);
1001 int32 result;
1002 int tot_backends = pgstat_fetch_stat_numbackends();
1003 int idx;
1004
1005 result = 0;
1006 for (idx = 1; idx <= tot_backends; idx++)
1007 {
1009
1010 if (local_beentry->backendStatus.st_databaseid == dbid)
1011 result++;
1012 }
1013
1014 PG_RETURN_INT32(result);
1015}
1016
1017
1018#define PG_STAT_GET_DBENTRY_INT64(stat) \
1019Datum \
1020CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
1021{ \
1022 Oid dbid = PG_GETARG_OID(0); \
1023 int64 result; \
1024 PgStat_StatDBEntry *dbentry; \
1025 \
1026 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
1027 result = 0; \
1028 else \
1029 result = (int64) (dbentry->stat); \
1030 \
1031 PG_RETURN_INT64(result); \
1032}
1033
1034/* pg_stat_get_db_blocks_fetched */
1035PG_STAT_GET_DBENTRY_INT64(blocks_fetched)
1036
1037/* pg_stat_get_db_blocks_hit */
1038PG_STAT_GET_DBENTRY_INT64(blocks_hit)
1039
1040/* pg_stat_get_db_conflict_bufferpin */
1041PG_STAT_GET_DBENTRY_INT64(conflict_bufferpin)
1042
1043/* pg_stat_get_db_conflict_lock */
1044PG_STAT_GET_DBENTRY_INT64(conflict_lock)
1045
1046/* pg_stat_get_db_conflict_snapshot */
1047PG_STAT_GET_DBENTRY_INT64(conflict_snapshot)
1048
1049/* pg_stat_get_db_conflict_startup_deadlock */
1050PG_STAT_GET_DBENTRY_INT64(conflict_startup_deadlock)
1051
1052/* pg_stat_get_db_conflict_tablespace */
1053PG_STAT_GET_DBENTRY_INT64(conflict_tablespace)
1054
1055/* pg_stat_get_db_deadlocks */
1057
1058/* pg_stat_get_db_sessions */
1060
1061/* pg_stat_get_db_sessions_abandoned */
1062PG_STAT_GET_DBENTRY_INT64(sessions_abandoned)
1063
1064/* pg_stat_get_db_sessions_fatal */
1065PG_STAT_GET_DBENTRY_INT64(sessions_fatal)
1066
1067/* pg_stat_get_db_sessions_killed */
1068PG_STAT_GET_DBENTRY_INT64(sessions_killed)
1069
1070/* pg_stat_get_db_parallel_workers_to_launch */
1071PG_STAT_GET_DBENTRY_INT64(parallel_workers_to_launch)
1072
1073/* pg_stat_get_db_parallel_workers_launched */
1074PG_STAT_GET_DBENTRY_INT64(parallel_workers_launched)
1075
1076/* pg_stat_get_db_temp_bytes */
1077PG_STAT_GET_DBENTRY_INT64(temp_bytes)
1078
1079/* pg_stat_get_db_temp_files */
1080PG_STAT_GET_DBENTRY_INT64(temp_files)
1081
1082/* pg_stat_get_db_tuples_deleted */
1083PG_STAT_GET_DBENTRY_INT64(tuples_deleted)
1084
1085/* pg_stat_get_db_tuples_fetched */
1086PG_STAT_GET_DBENTRY_INT64(tuples_fetched)
1087
1088/* pg_stat_get_db_tuples_inserted */
1089PG_STAT_GET_DBENTRY_INT64(tuples_inserted)
1090
1091/* pg_stat_get_db_tuples_returned */
1092PG_STAT_GET_DBENTRY_INT64(tuples_returned)
1093
1094/* pg_stat_get_db_tuples_updated */
1095PG_STAT_GET_DBENTRY_INT64(tuples_updated)
1096
1097/* pg_stat_get_db_xact_commit */
1098PG_STAT_GET_DBENTRY_INT64(xact_commit)
1099
1100/* pg_stat_get_db_xact_rollback */
1101PG_STAT_GET_DBENTRY_INT64(xact_rollback)
1102
1103/* pg_stat_get_db_conflict_logicalslot */
1104PG_STAT_GET_DBENTRY_INT64(conflict_logicalslot)
1105
1106Datum
1108{
1109 Oid dbid = PG_GETARG_OID(0);
1110 TimestampTz result;
1111 PgStat_StatDBEntry *dbentry;
1112
1113 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1114 result = 0;
1115 else
1116 result = dbentry->stat_reset_timestamp;
1117
1118 if (result == 0)
1120 else
1121 PG_RETURN_TIMESTAMPTZ(result);
1122}
1123
1124
1125Datum
1127{
1128 Oid dbid = PG_GETARG_OID(0);
1129 int64 result;
1130 PgStat_StatDBEntry *dbentry;
1131
1132 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1133 result = 0;
1134 else
1135 result = (int64) (dbentry->conflict_tablespace +
1136 dbentry->conflict_lock +
1137 dbentry->conflict_snapshot +
1138 dbentry->conflict_logicalslot +
1139 dbentry->conflict_bufferpin +
1140 dbentry->conflict_startup_deadlock);
1141
1142 PG_RETURN_INT64(result);
1143}
1144
1145Datum
1147{
1148 Oid dbid = PG_GETARG_OID(0);
1149 int64 result;
1150 PgStat_StatDBEntry *dbentry;
1151
1152 if (!DataChecksumsEnabled())
1154
1155 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
1156 result = 0;
1157 else
1158 result = (int64) (dbentry->checksum_failures);
1159
1160 PG_RETURN_INT64(result);
1161}
1162
1163Datum
1165{
1166 Oid dbid = PG_GETARG_OID(0);
1167 TimestampTz 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 = dbentry->last_checksum_failure;
1177
1178 if (result == 0)
1180 else
1181 PG_RETURN_TIMESTAMPTZ(result);
1182}
1183
1184/* convert counter from microsec to millisec for display */
1185#define PG_STAT_GET_DBENTRY_FLOAT8_MS(stat) \
1186Datum \
1187CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
1188{ \
1189 Oid dbid = PG_GETARG_OID(0); \
1190 double result; \
1191 PgStat_StatDBEntry *dbentry; \
1192 \
1193 if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) \
1194 result = 0; \
1195 else \
1196 result = ((double) dbentry->stat) / 1000.0; \
1197 \
1198 PG_RETURN_FLOAT8(result); \
1199}
1200
1201/* pg_stat_get_db_active_time */
1203
1204/* pg_stat_get_db_blk_read_time */
1205PG_STAT_GET_DBENTRY_FLOAT8_MS(blk_read_time)
1206
1207/* pg_stat_get_db_blk_write_time */
1208PG_STAT_GET_DBENTRY_FLOAT8_MS(blk_write_time)
1209
1210/* pg_stat_get_db_idle_in_transaction_time */
1211PG_STAT_GET_DBENTRY_FLOAT8_MS(idle_in_transaction_time)
1212
1213/* pg_stat_get_db_session_time */
1215
1216Datum
1218{
1220}
1221
1222Datum
1224{
1226}
1227
1228Datum
1230{
1232}
1233
1234Datum
1236{
1237 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_timed);
1238}
1239
1240Datum
1242{
1243 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_requested);
1244}
1245
1246Datum
1248{
1249 PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->restartpoints_performed);
1250}
1251
1252Datum
1254{
1256}
1257
1258Datum
1260{
1262}
1263
1264Datum
1266{
1267 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
1268}
1269
1270Datum
1272{
1273 PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
1274}
1275
1276Datum
1278{
1279 /* time is already in msec, just convert to double for presentation */
1280 PG_RETURN_FLOAT8((double)
1281 pgstat_fetch_stat_checkpointer()->write_time);
1282}
1283
1284Datum
1286{
1287 /* time is already in msec, just convert to double for presentation */
1288 PG_RETURN_FLOAT8((double)
1289 pgstat_fetch_stat_checkpointer()->sync_time);
1290}
1291
1292Datum
1294{
1296}
1297
1298Datum
1300{
1301 PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
1302}
1303
1304Datum
1306{
1308}
1309
1310/*
1311* When adding a new column to the pg_stat_io view and the
1312* pg_stat_get_backend_io() function, add a new enum value here above
1313* IO_NUM_COLUMNS.
1314*/
1315typedef enum io_stat_col
1316{
1340
1341/*
1342 * When adding a new IOOp, add a new io_stat_col and add a case to this
1343 * function returning the corresponding io_stat_col.
1344 */
1345static io_stat_col
1347{
1348 switch (io_op)
1349 {
1350 case IOOP_EVICT:
1351 return IO_COL_EVICTIONS;
1352 case IOOP_EXTEND:
1353 return IO_COL_EXTENDS;
1354 case IOOP_FSYNC:
1355 return IO_COL_FSYNCS;
1356 case IOOP_HIT:
1357 return IO_COL_HITS;
1358 case IOOP_READ:
1359 return IO_COL_READS;
1360 case IOOP_REUSE:
1361 return IO_COL_REUSES;
1362 case IOOP_WRITE:
1363 return IO_COL_WRITES;
1364 case IOOP_WRITEBACK:
1365 return IO_COL_WRITEBACKS;
1366 }
1367
1368 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1370}
1371
1372/*
1373 * Get the number of the column containing IO bytes for the specified IOOp.
1374 * If an IOOp is not tracked in bytes, IO_COL_INVALID is returned.
1375 */
1376static io_stat_col
1378{
1379 switch (io_op)
1380 {
1381 case IOOP_EXTEND:
1382 return IO_COL_EXTEND_BYTES;
1383 case IOOP_READ:
1384 return IO_COL_READ_BYTES;
1385 case IOOP_WRITE:
1386 return IO_COL_WRITE_BYTES;
1387 case IOOP_EVICT:
1388 case IOOP_FSYNC:
1389 case IOOP_HIT:
1390 case IOOP_REUSE:
1391 case IOOP_WRITEBACK:
1392 return IO_COL_INVALID;
1393 }
1394
1395 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1397}
1398
1399/*
1400 * Get the number of the column containing IO times for the specified IOOp.
1401 * If an op has no associated time, IO_COL_INVALID is returned.
1402 */
1403static io_stat_col
1405{
1406 switch (io_op)
1407 {
1408 case IOOP_READ:
1409 return IO_COL_READ_TIME;
1410 case IOOP_WRITE:
1411 return IO_COL_WRITE_TIME;
1412 case IOOP_WRITEBACK:
1413 return IO_COL_WRITEBACK_TIME;
1414 case IOOP_EXTEND:
1415 return IO_COL_EXTEND_TIME;
1416 case IOOP_FSYNC:
1417 return IO_COL_FSYNC_TIME;
1418 case IOOP_EVICT:
1419 case IOOP_HIT:
1420 case IOOP_REUSE:
1421 return IO_COL_INVALID;
1422 }
1423
1424 elog(ERROR, "unrecognized IOOp value: %d", io_op);
1426}
1427
1428static inline double
1430{
1431 return val_ms * (double) 0.001;
1432}
1433
1434/*
1435 * pg_stat_io_build_tuples
1436 *
1437 * Helper routine for pg_stat_get_io() and pg_stat_get_backend_io()
1438 * filling a result tuplestore with one tuple for each object and each
1439 * context supported by the caller, based on the contents of bktype_stats.
1440 */
1441static void
1443 PgStat_BktypeIO *bktype_stats,
1444 BackendType bktype,
1445 TimestampTz stat_reset_timestamp)
1446{
1447 Datum bktype_desc = CStringGetTextDatum(GetBackendTypeDesc(bktype));
1448
1449 for (int io_obj = 0; io_obj < IOOBJECT_NUM_TYPES; io_obj++)
1450 {
1451 const char *obj_name = pgstat_get_io_object_name(io_obj);
1452
1453 for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
1454 {
1455 const char *context_name = pgstat_get_io_context_name(io_context);
1456
1458 bool nulls[IO_NUM_COLUMNS] = {0};
1459
1460 /*
1461 * Some combinations of BackendType, IOObject, and IOContext are
1462 * not valid for any type of IOOp. In such cases, omit the entire
1463 * row from the view.
1464 */
1465 if (!pgstat_tracks_io_object(bktype, io_obj, io_context))
1466 continue;
1467
1468 values[IO_COL_BACKEND_TYPE] = bktype_desc;
1469 values[IO_COL_CONTEXT] = CStringGetTextDatum(context_name);
1471 if (stat_reset_timestamp != 0)
1472 values[IO_COL_RESET_TIME] = TimestampTzGetDatum(stat_reset_timestamp);
1473 else
1474 nulls[IO_COL_RESET_TIME] = true;
1475
1476 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
1477 {
1478 int op_idx = pgstat_get_io_op_index(io_op);
1479 int time_idx = pgstat_get_io_time_index(io_op);
1480 int byte_idx = pgstat_get_io_byte_index(io_op);
1481
1482 /*
1483 * Some combinations of BackendType and IOOp, of IOContext and
1484 * IOOp, and of IOObject and IOOp are not tracked. Set these
1485 * cells in the view NULL.
1486 */
1487 if (pgstat_tracks_io_op(bktype, io_obj, io_context, io_op))
1488 {
1489 PgStat_Counter count =
1490 bktype_stats->counts[io_obj][io_context][io_op];
1491
1492 values[op_idx] = Int64GetDatum(count);
1493 }
1494 else
1495 nulls[op_idx] = true;
1496
1497 if (!nulls[op_idx])
1498 {
1499 /* not every operation is timed */
1500 if (time_idx != IO_COL_INVALID)
1501 {
1502 PgStat_Counter time =
1503 bktype_stats->times[io_obj][io_context][io_op];
1504
1505 values[time_idx] = Float8GetDatum(pg_stat_us_to_ms(time));
1506 }
1507
1508 /* not every IO is tracked in bytes */
1509 if (byte_idx != IO_COL_INVALID)
1510 {
1511 char buf[256];
1512 PgStat_Counter byte =
1513 bktype_stats->bytes[io_obj][io_context][io_op];
1514
1515 /* Convert to numeric */
1516 snprintf(buf, sizeof buf, INT64_FORMAT, byte);
1520 Int32GetDatum(-1));
1521 }
1522 }
1523 else
1524 {
1525 if (time_idx != IO_COL_INVALID)
1526 nulls[time_idx] = true;
1527 if (byte_idx != IO_COL_INVALID)
1528 nulls[byte_idx] = true;
1529 }
1530 }
1531
1532 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1533 values, nulls);
1534 }
1535 }
1536}
1537
1538Datum
1540{
1541 ReturnSetInfo *rsinfo;
1542 PgStat_IO *backends_io_stats;
1543
1544 InitMaterializedSRF(fcinfo, 0);
1545 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1546
1547 backends_io_stats = pgstat_fetch_stat_io();
1548
1549 for (int bktype = 0; bktype < BACKEND_NUM_TYPES; bktype++)
1550 {
1551 PgStat_BktypeIO *bktype_stats = &backends_io_stats->stats[bktype];
1552
1553 /*
1554 * In Assert builds, we can afford an extra loop through all of the
1555 * counters (in pg_stat_io_build_tuples()), checking that only
1556 * expected stats are non-zero, since it keeps the non-Assert code
1557 * cleaner.
1558 */
1559 Assert(pgstat_bktype_io_stats_valid(bktype_stats, bktype));
1560
1561 /*
1562 * For those BackendTypes without IO Operation stats, skip
1563 * representing them in the view altogether.
1564 */
1565 if (!pgstat_tracks_io_bktype(bktype))
1566 continue;
1567
1568 /* save tuples with data from this PgStat_BktypeIO */
1569 pg_stat_io_build_tuples(rsinfo, bktype_stats, bktype,
1570 backends_io_stats->stat_reset_timestamp);
1571 }
1572
1573 return (Datum) 0;
1574}
1575
1576/*
1577 * Returns I/O statistics for a backend with given PID.
1578 */
1579Datum
1581{
1582 ReturnSetInfo *rsinfo;
1583 BackendType bktype;
1584 int pid;
1585 PgStat_Backend *backend_stats;
1586 PgStat_BktypeIO *bktype_stats;
1587
1588 InitMaterializedSRF(fcinfo, 0);
1589 rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1590
1591 pid = PG_GETARG_INT32(0);
1592 backend_stats = pgstat_fetch_stat_backend_by_pid(pid, &bktype);
1593
1594 if (!backend_stats)
1595 return (Datum) 0;
1596
1597 bktype_stats = &backend_stats->io_stats;
1598
1599 /*
1600 * In Assert builds, we can afford an extra loop through all of the
1601 * counters (in pg_stat_io_build_tuples()), checking that only expected
1602 * stats are non-zero, since it keeps the non-Assert code cleaner.
1603 */
1604 Assert(pgstat_bktype_io_stats_valid(bktype_stats, bktype));
1605
1606 /* save tuples with data from this PgStat_BktypeIO */
1607 pg_stat_io_build_tuples(rsinfo, bktype_stats, bktype,
1608 backend_stats->stat_reset_timestamp);
1609 return (Datum) 0;
1610}
1611
1612/*
1613 * pg_stat_wal_build_tuple
1614 *
1615 * Helper routine for pg_stat_get_wal() and pg_stat_get_backend_wal()
1616 * returning one tuple based on the contents of wal_counters.
1617 */
1618static Datum
1620 TimestampTz stat_reset_timestamp)
1621{
1622#define PG_STAT_WAL_COLS 5
1623 TupleDesc tupdesc;
1625 bool nulls[PG_STAT_WAL_COLS] = {0};
1626 char buf[256];
1627
1628 /* Initialise attributes information in the tuple descriptor */
1630 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
1631 INT8OID, -1, 0);
1632 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "wal_fpi",
1633 INT8OID, -1, 0);
1634 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
1635 NUMERICOID, -1, 0);
1636 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_buffers_full",
1637 INT8OID, -1, 0);
1638 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stats_reset",
1639 TIMESTAMPTZOID, -1, 0);
1640
1641 BlessTupleDesc(tupdesc);
1642
1643 /* Fill values and NULLs */
1644 values[0] = Int64GetDatum(wal_counters.wal_records);
1645 values[1] = Int64GetDatum(wal_counters.wal_fpi);
1646
1647 /* Convert to numeric. */
1648 snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_bytes);
1652 Int32GetDatum(-1));
1653
1654 values[3] = Int64GetDatum(wal_counters.wal_buffers_full);
1655
1656 if (stat_reset_timestamp != 0)
1657 values[4] = TimestampTzGetDatum(stat_reset_timestamp);
1658 else
1659 nulls[4] = true;
1660
1661 /* Returns the record as Datum */
1663}
1664
1665/*
1666 * Returns WAL statistics for a backend with given PID.
1667 */
1668Datum
1670{
1671 int pid;
1672 PgStat_Backend *backend_stats;
1673 PgStat_WalCounters bktype_stats;
1674
1675 pid = PG_GETARG_INT32(0);
1676 backend_stats = pgstat_fetch_stat_backend_by_pid(pid, NULL);
1677
1678 if (!backend_stats)
1680
1681 bktype_stats = backend_stats->wal_counters;
1682
1683 /* save tuples with data from this PgStat_WalCounters */
1684 return (pg_stat_wal_build_tuple(bktype_stats, backend_stats->stat_reset_timestamp));
1685}
1686
1687/*
1688 * Returns statistics of WAL activity
1689 */
1690Datum
1692{
1693 PgStat_WalStats *wal_stats;
1694
1695 /* Get statistics about WAL activity */
1696 wal_stats = pgstat_fetch_stat_wal();
1697
1698 return (pg_stat_wal_build_tuple(wal_stats->wal_counters,
1699 wal_stats->stat_reset_timestamp));
1700}
1701
1702/*
1703 * Returns statistics of SLRU caches.
1704 */
1705Datum
1707{
1708#define PG_STAT_GET_SLRU_COLS 9
1709 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1710 int i;
1711 PgStat_SLRUStats *stats;
1712
1713 InitMaterializedSRF(fcinfo, 0);
1714
1715 /* request SLRU stats from the cumulative stats system */
1716 stats = pgstat_fetch_slru();
1717
1718 for (i = 0;; i++)
1719 {
1720 /* for each row */
1722 bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
1724 const char *name;
1725
1727
1728 if (!name)
1729 break;
1730
1731 stat = stats[i];
1732
1734 values[1] = Int64GetDatum(stat.blocks_zeroed);
1735 values[2] = Int64GetDatum(stat.blocks_hit);
1736 values[3] = Int64GetDatum(stat.blocks_read);
1737 values[4] = Int64GetDatum(stat.blocks_written);
1738 values[5] = Int64GetDatum(stat.blocks_exists);
1739 values[6] = Int64GetDatum(stat.flush);
1740 values[7] = Int64GetDatum(stat.truncate);
1741 values[8] = TimestampTzGetDatum(stat.stat_reset_timestamp);
1742
1743 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
1744 }
1745
1746 return (Datum) 0;
1747}
1748
1749#define PG_STAT_GET_XACT_RELENTRY_INT64(stat) \
1750Datum \
1751CppConcat(pg_stat_get_xact_,stat)(PG_FUNCTION_ARGS) \
1752{ \
1753 Oid relid = PG_GETARG_OID(0); \
1754 int64 result; \
1755 PgStat_TableStatus *tabentry; \
1756 \
1757 if ((tabentry = find_tabstat_entry(relid)) == NULL) \
1758 result = 0; \
1759 else \
1760 result = (int64) (tabentry->counts.stat); \
1761 \
1762 PG_RETURN_INT64(result); \
1763}
1764
1765/* pg_stat_get_xact_numscans */
1767
1768/* pg_stat_get_xact_tuples_returned */
1769PG_STAT_GET_XACT_RELENTRY_INT64(tuples_returned)
1770
1771/* pg_stat_get_xact_tuples_fetched */
1772PG_STAT_GET_XACT_RELENTRY_INT64(tuples_fetched)
1773
1774/* pg_stat_get_xact_tuples_hot_updated */
1775PG_STAT_GET_XACT_RELENTRY_INT64(tuples_hot_updated)
1776
1777/* pg_stat_get_xact_tuples_newpage_updated */
1778PG_STAT_GET_XACT_RELENTRY_INT64(tuples_newpage_updated)
1779
1780/* pg_stat_get_xact_blocks_fetched */
1781PG_STAT_GET_XACT_RELENTRY_INT64(blocks_fetched)
1782
1783/* pg_stat_get_xact_blocks_hit */
1785
1786/* pg_stat_get_xact_tuples_inserted */
1787PG_STAT_GET_XACT_RELENTRY_INT64(tuples_inserted)
1788
1789/* pg_stat_get_xact_tuples_updated */
1790PG_STAT_GET_XACT_RELENTRY_INT64(tuples_updated)
1791
1792/* pg_stat_get_xact_tuples_deleted */
1793PG_STAT_GET_XACT_RELENTRY_INT64(tuples_deleted)
1794
1795Datum
1797{
1798 Oid funcid = PG_GETARG_OID(0);
1799 PgStat_FunctionCounts *funcentry;
1800
1801 if ((funcentry = find_funcstat_entry(funcid)) == NULL)
1803 PG_RETURN_INT64(funcentry->numcalls);
1804}
1805
1806#define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(stat) \
1807Datum \
1808CppConcat(pg_stat_get_xact_function_,stat)(PG_FUNCTION_ARGS) \
1809{ \
1810 Oid funcid = PG_GETARG_OID(0); \
1811 PgStat_FunctionCounts *funcentry; \
1812 \
1813 if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
1814 PG_RETURN_NULL(); \
1815 PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->stat)); \
1816}
1817
1818/* pg_stat_get_xact_function_total_time */
1820
1821/* pg_stat_get_xact_function_self_time */
1823
1824/* Get the timestamp of the current statistics snapshot */
1825Datum
1827{
1828 bool have_snapshot;
1829 TimestampTz ts;
1830
1831 ts = pgstat_get_stat_snapshot_timestamp(&have_snapshot);
1832
1833 if (!have_snapshot)
1835
1837}
1838
1839/* Discard the active statistics snapshot */
1840Datum
1842{
1844
1846}
1847
1848
1849/* Force statistics to be reported at the next occasion */
1850Datum
1852{
1854
1856}
1857
1858
1859/* Reset all counters for the current database */
1860Datum
1862{
1864
1866}
1867
1868/*
1869 * Reset some shared cluster-wide counters
1870 *
1871 * When adding a new reset target, ideally the name should match that in
1872 * pgstat_kind_builtin_infos, if relevant.
1873 */
1874Datum
1876{
1877 char *target = NULL;
1878
1879 if (PG_ARGISNULL(0))
1880 {
1881 /* Reset all the statistics when nothing is specified */
1889
1891 }
1892
1894
1895 if (strcmp(target, "archiver") == 0)
1897 else if (strcmp(target, "bgwriter") == 0)
1899 else if (strcmp(target, "checkpointer") == 0)
1901 else if (strcmp(target, "io") == 0)
1903 else if (strcmp(target, "recovery_prefetch") == 0)
1905 else if (strcmp(target, "slru") == 0)
1907 else if (strcmp(target, "wal") == 0)
1909 else
1910 ereport(ERROR,
1911 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1912 errmsg("unrecognized reset target: \"%s\"", target),
1913 errhint("Target must be \"archiver\", \"bgwriter\", \"checkpointer\", \"io\", \"recovery_prefetch\", \"slru\", or \"wal\".")));
1914
1916}
1917
1918/*
1919 * Reset a statistics for a single object, which may be of current
1920 * database or shared across all databases in the cluster.
1921 */
1922Datum
1924{
1925 Oid taboid = PG_GETARG_OID(0);
1926 Oid dboid = (IsSharedRelation(taboid) ? InvalidOid : MyDatabaseId);
1927
1928 pgstat_reset(PGSTAT_KIND_RELATION, dboid, taboid);
1929
1931}
1932
1933Datum
1935{
1936 Oid funcoid = PG_GETARG_OID(0);
1937
1939
1941}
1942
1943/*
1944 * Reset statistics of backend with given PID.
1945 */
1946Datum
1948{
1949 PGPROC *proc;
1950 PgBackendStatus *beentry;
1951 ProcNumber procNumber;
1952 int backend_pid = PG_GETARG_INT32(0);
1953
1954 proc = BackendPidGetProc(backend_pid);
1955
1956 /* This could be an auxiliary process */
1957 if (!proc)
1958 proc = AuxiliaryPidGetProc(backend_pid);
1959
1960 if (!proc)
1962
1963 procNumber = GetNumberFromPGProc(proc);
1964
1965 beentry = pgstat_get_beentry_by_proc_number(procNumber);
1966 if (!beentry)
1968
1969 /* Check if the backend type tracks statistics */
1972
1974
1976}
1977
1978/* Reset SLRU counters (a specific one or all of them). */
1979Datum
1981{
1982 char *target = NULL;
1983
1984 if (PG_ARGISNULL(0))
1986 else
1987 {
1989 pgstat_reset_slru(target);
1990 }
1991
1993}
1994
1995/* Reset replication slots stats (a specific one or all of them). */
1996Datum
1998{
1999 char *target = NULL;
2000
2001 if (PG_ARGISNULL(0))
2003 else
2004 {
2006 pgstat_reset_replslot(target);
2007 }
2008
2010}
2011
2012/* Reset subscription stats (a specific one or all of them) */
2013Datum
2015{
2016 Oid subid;
2017
2018 if (PG_ARGISNULL(0))
2019 {
2020 /* Clear all subscription stats */
2022 }
2023 else
2024 {
2025 subid = PG_GETARG_OID(0);
2026
2027 if (!OidIsValid(subid))
2028 ereport(ERROR,
2029 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2030 errmsg("invalid subscription OID %u", subid)));
2032 }
2033
2035}
2036
2037Datum
2039{
2040 TupleDesc tupdesc;
2041 Datum values[7] = {0};
2042 bool nulls[7] = {0};
2043 PgStat_ArchiverStats *archiver_stats;
2044
2045 /* Initialise attributes information in the tuple descriptor */
2046 tupdesc = CreateTemplateTupleDesc(7);
2047 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
2048 INT8OID, -1, 0);
2049 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
2050 TEXTOID, -1, 0);
2051 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
2052 TIMESTAMPTZOID, -1, 0);
2053 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
2054 INT8OID, -1, 0);
2055 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
2056 TEXTOID, -1, 0);
2057 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
2058 TIMESTAMPTZOID, -1, 0);
2059 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
2060 TIMESTAMPTZOID, -1, 0);
2061
2062 BlessTupleDesc(tupdesc);
2063
2064 /* Get statistics about the archiver process */
2065 archiver_stats = pgstat_fetch_stat_archiver();
2066
2067 /* Fill values and NULLs */
2068 values[0] = Int64GetDatum(archiver_stats->archived_count);
2069 if (*(archiver_stats->last_archived_wal) == '\0')
2070 nulls[1] = true;
2071 else
2072 values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
2073
2074 if (archiver_stats->last_archived_timestamp == 0)
2075 nulls[2] = true;
2076 else
2078
2079 values[3] = Int64GetDatum(archiver_stats->failed_count);
2080 if (*(archiver_stats->last_failed_wal) == '\0')
2081 nulls[4] = true;
2082 else
2083 values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
2084
2085 if (archiver_stats->last_failed_timestamp == 0)
2086 nulls[5] = true;
2087 else
2088 values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
2089
2090 if (archiver_stats->stat_reset_timestamp == 0)
2091 nulls[6] = true;
2092 else
2093 values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
2094
2095 /* Returns the record as Datum */
2097}
2098
2099/*
2100 * Get the statistics for the replication slot. If the slot statistics is not
2101 * available, return all-zeroes stats.
2102 */
2103Datum
2105{
2106#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
2107 text *slotname_text = PG_GETARG_TEXT_P(0);
2108 NameData slotname;
2109 TupleDesc tupdesc;
2111 bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
2112 PgStat_StatReplSlotEntry *slotent;
2114
2115 /* Initialise attributes information in the tuple descriptor */
2117 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
2118 TEXTOID, -1, 0);
2119 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "spill_txns",
2120 INT8OID, -1, 0);
2121 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "spill_count",
2122 INT8OID, -1, 0);
2123 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "spill_bytes",
2124 INT8OID, -1, 0);
2125 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stream_txns",
2126 INT8OID, -1, 0);
2127 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stream_count",
2128 INT8OID, -1, 0);
2129 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stream_bytes",
2130 INT8OID, -1, 0);
2131 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "total_txns",
2132 INT8OID, -1, 0);
2133 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "total_bytes",
2134 INT8OID, -1, 0);
2135 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "stats_reset",
2136 TIMESTAMPTZOID, -1, 0);
2137 BlessTupleDesc(tupdesc);
2138
2139 namestrcpy(&slotname, text_to_cstring(slotname_text));
2140 slotent = pgstat_fetch_replslot(slotname);
2141 if (!slotent)
2142 {
2143 /*
2144 * If the slot is not found, initialise its stats. This is possible if
2145 * the create slot message is lost.
2146 */
2147 memset(&allzero, 0, sizeof(PgStat_StatReplSlotEntry));
2148 slotent = &allzero;
2149 }
2150
2151 values[0] = CStringGetTextDatum(NameStr(slotname));
2152 values[1] = Int64GetDatum(slotent->spill_txns);
2153 values[2] = Int64GetDatum(slotent->spill_count);
2154 values[3] = Int64GetDatum(slotent->spill_bytes);
2155 values[4] = Int64GetDatum(slotent->stream_txns);
2156 values[5] = Int64GetDatum(slotent->stream_count);
2157 values[6] = Int64GetDatum(slotent->stream_bytes);
2158 values[7] = Int64GetDatum(slotent->total_txns);
2159 values[8] = Int64GetDatum(slotent->total_bytes);
2160
2161 if (slotent->stat_reset_timestamp == 0)
2162 nulls[9] = true;
2163 else
2165
2166 /* Returns the record as Datum */
2168}
2169
2170/*
2171 * Get the subscription statistics for the given subscription. If the
2172 * subscription statistics is not available, return all-zeros stats.
2173 */
2174Datum
2176{
2177#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 12
2178 Oid subid = PG_GETARG_OID(0);
2179 TupleDesc tupdesc;
2181 bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
2182 PgStat_StatSubEntry *subentry;
2183 PgStat_StatSubEntry allzero;
2184 int i = 0;
2185
2186 /* Get subscription stats */
2187 subentry = pgstat_fetch_stat_subscription(subid);
2188
2189 /* Initialise attributes information in the tuple descriptor */
2191 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subid",
2192 OIDOID, -1, 0);
2193 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "apply_error_count",
2194 INT8OID, -1, 0);
2195 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "sync_error_count",
2196 INT8OID, -1, 0);
2197 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "confl_insert_exists",
2198 INT8OID, -1, 0);
2199 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "confl_update_origin_differs",
2200 INT8OID, -1, 0);
2201 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "confl_update_exists",
2202 INT8OID, -1, 0);
2203 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "confl_update_deleted",
2204 INT8OID, -1, 0);
2205 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "confl_update_missing",
2206 INT8OID, -1, 0);
2207 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "confl_delete_origin_differs",
2208 INT8OID, -1, 0);
2209 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "confl_delete_missing",
2210 INT8OID, -1, 0);
2211 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "confl_multiple_unique_conflicts",
2212 INT8OID, -1, 0);
2213 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "stats_reset",
2214 TIMESTAMPTZOID, -1, 0);
2215 BlessTupleDesc(tupdesc);
2216
2217 if (!subentry)
2218 {
2219 /* If the subscription is not found, initialise its stats */
2220 memset(&allzero, 0, sizeof(PgStat_StatSubEntry));
2221 subentry = &allzero;
2222 }
2223
2224 /* subid */
2225 values[i++] = ObjectIdGetDatum(subid);
2226
2227 /* apply_error_count */
2228 values[i++] = Int64GetDatum(subentry->apply_error_count);
2229
2230 /* sync_error_count */
2231 values[i++] = Int64GetDatum(subentry->sync_error_count);
2232
2233 /* conflict count */
2234 for (int nconflict = 0; nconflict < CONFLICT_NUM_TYPES; nconflict++)
2235 values[i++] = Int64GetDatum(subentry->conflict_count[nconflict]);
2236
2237 /* stats_reset */
2238 if (subentry->stat_reset_timestamp == 0)
2239 nulls[i] = true;
2240 else
2242
2244
2245 /* Returns the record as Datum */
2247}
2248
2249/*
2250 * Checks for presence of stats for object with provided kind, database oid,
2251 * object oid.
2252 *
2253 * This is useful for tests, but not really anything else. Therefore not
2254 * documented.
2255 */
2256Datum
2258{
2259 char *stats_type = text_to_cstring(PG_GETARG_TEXT_P(0));
2260 Oid dboid = PG_GETARG_OID(1);
2261 uint64 objid = PG_GETARG_INT64(2);
2262 PgStat_Kind kind = pgstat_get_kind_from_str(stats_type);
2263
2264 PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objid));
2265}
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:262
int16 AttrNumber
Definition: attnum.h:21
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:626
#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 pgstat_fetch_stat_numbackends(void)
LocalPgBackendStatus * pgstat_get_local_beentry_by_proc_number(ProcNumber procNumber)
char * pgstat_clip_activity(const char *raw_activity)
LocalPgBackendStatus * pgstat_get_local_beentry_by_index(int idx)
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
@ 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:1372
static Datum values[MAXATTR]
Definition: bootstrap.c:153
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define NameStr(name)
Definition: c.h:751
#define INT64CONST(x)
Definition: c.h:552
#define INT64_FORMAT
Definition: c.h:556
int64_t int64
Definition: c.h:535
#define UINT64_FORMAT
Definition: c.h:557
int32_t int32
Definition: c.h:534
uint64_t uint64
Definition: c.h:539
#define pg_unreachable()
Definition: c.h:331
uint32_t uint32
Definition: c.h:538
#define OidIsValid(objectId)
Definition: c.h:774
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:304
#define CONFLICT_NUM_TYPES
Definition: conflict.h:64
int64 TimestampTz
Definition: timestamp.h:39
int errhint(const char *fmt,...)
Definition: elog.c:1321
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:150
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:682
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:686
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
#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
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
int MyProcPid
Definition: globals.c:47
Oid MyDatabaseId
Definition: globals.c:94
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:287
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition: ip.c:114
int i
Definition: isn.c:77
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
pid_t GetLeaderApplyWorkerPid(pid_t pid)
Definition: launcher.c:1541
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
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
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:376
BackendType
Definition: miscadmin.h:337
@ B_WAL_SENDER
Definition: miscadmin.h:346
@ B_BG_WORKER
Definition: miscadmin.h:345
@ B_BACKEND
Definition: miscadmin.h:341
#define InvalidPid
Definition: miscadmin.h:32
const char * GetBackendTypeDesc(BackendType backendType)
Definition: miscinit.c:263
void namestrcpy(Name name, const char *str)
Definition: name.c:233
void clean_ipv6_addr(int addr_family, char *addr)
Definition: network.c:2028
Datum inet_in(PG_FUNCTION_ARGS)
Definition: network.c:119
static char * buf
Definition: pg_test_fsync.c:72
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:853
void pgstat_reset_counters(void)
Definition: pgstat.c:834
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition: pgstat.c:875
void pgstat_force_next_flush(void)
Definition: pgstat.c:813
void pgstat_clear_snapshot(void)
Definition: pgstat.c:901
TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
Definition: pgstat.c:1026
bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:1043
PgStat_Kind pgstat_get_kind_from_str(char *kind_str)
Definition: pgstat.c:1400
#define IOOP_NUM_TYPES
Definition: pgstat.h:317
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:291
IOOp
Definition: pgstat.h:303
@ IOOP_EXTEND
Definition: pgstat.h:312
@ IOOP_FSYNC
Definition: pgstat.h:306
@ IOOP_READ
Definition: pgstat.h:313
@ IOOP_WRITEBACK
Definition: pgstat.h:309
@ IOOP_HIT
Definition: pgstat.h:307
@ IOOP_EVICT
Definition: pgstat.h:305
@ IOOP_REUSE
Definition: pgstat.h:308
@ IOOP_WRITE
Definition: pgstat.h:314
int64 PgStat_Counter
Definition: pgstat.h:66
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:280
PgStat_ArchiverStats * pgstat_fetch_stat_archiver(void)
bool pgstat_tracks_backend_bktype(BackendType bktype)
PgStat_Backend * pgstat_fetch_stat_backend_by_pid(int pid, BackendType *bktype)
PgStat_BgWriterStats * pgstat_fetch_stat_bgwriter(void)
PgStat_CheckpointerStats * pgstat_fetch_stat_checkpointer(void)
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dboid)
PgStat_StatFuncEntry * pgstat_fetch_stat_funcentry(Oid func_id)
PgStat_FunctionCounts * find_funcstat_entry(Oid func_id)
PgStat_IO * pgstat_fetch_stat_io(void)
Definition: pgstat_io.c:164
const char * pgstat_get_io_context_name(IOContext io_context)
Definition: pgstat_io.c:240
bool pgstat_tracks_io_bktype(BackendType bktype)
Definition: pgstat_io.c:351
const char * pgstat_get_io_object_name(IOObject io_object)
Definition: pgstat_io.c:261
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
Definition: pgstat_io.c:37
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
#define PGSTAT_KIND_ARCHIVER
Definition: pgstat_kind.h:35
#define PGSTAT_KIND_WAL
Definition: pgstat_kind.h:40
#define PgStat_Kind
Definition: pgstat_kind.h:17
#define PGSTAT_KIND_BGWRITER
Definition: pgstat_kind.h:36
#define PGSTAT_KIND_REPLSLOT
Definition: pgstat_kind.h:30
#define PGSTAT_KIND_FUNCTION
Definition: pgstat_kind.h:29
#define PGSTAT_KIND_SLRU
Definition: pgstat_kind.h:39
#define PGSTAT_KIND_RELATION
Definition: pgstat_kind.h:28
#define PGSTAT_KIND_CHECKPOINTER
Definition: pgstat_kind.h:37
#define PGSTAT_KIND_IO
Definition: pgstat_kind.h:38
#define PGSTAT_KIND_SUBSCRIPTION
Definition: pgstat_kind.h:31
#define PGSTAT_KIND_BACKEND
Definition: pgstat_kind.h:32
void pgstat_reset_replslot(const char *name)
PgStat_StatReplSlotEntry * pgstat_fetch_replslot(NameData slotname)
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
void pgstat_reset_slru(const char *name)
Definition: pgstat_slru.c:45
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
PgStat_WalStats * pgstat_fetch_stat_wal(void)
Definition: pgstat_wal.c:67
#define PG_STAT_GET_XACT_RELENTRY_INT64(stat)
Definition: pgstatfuncs.c:1749
Datum pg_stat_get_progress_info(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:258
Datum pg_stat_get_checkpointer_num_requested(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1223
Datum pg_stat_get_snapshot_timestamp(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1826
Datum pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:911
Datum pg_stat_get_db_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1107
Datum pg_stat_get_wal(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1691
Datum pg_stat_reset_replication_slot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1997
Datum pg_stat_get_checkpointer_num_timed(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1217
#define UINT32_ACCESS_ONCE(var)
Definition: pgstatfuncs.c:35
Datum pg_stat_get_activity(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:334
Datum pg_stat_get_slru(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1706
static void pg_stat_io_build_tuples(ReturnSetInfo *rsinfo, PgStat_BktypeIO *bktype_stats, BackendType bktype, TimestampTz stat_reset_timestamp)
Definition: pgstatfuncs.c:1442
Datum pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:954
Datum pg_stat_get_backend_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:889
Datum pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1126
Datum pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2175
#define PG_STAT_GET_SLRU_COLS
#define PG_STAT_GET_DBENTRY_INT64(stat)
Definition: pgstatfuncs.c:1018
Datum pg_stat_get_checkpointer_buffers_written(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1253
Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:700
Datum pg_stat_get_checkpointer_sync_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1285
static double pg_stat_us_to_ms(PgStat_Counter val_ms)
Definition: pgstatfuncs.c:1429
#define PG_STAT_WAL_COLS
#define PG_STAT_GET_ACTIVITY_COLS
static Datum pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters, TimestampTz stat_reset_timestamp)
Definition: pgstatfuncs.c:1619
static io_stat_col pgstat_get_io_time_index(IOOp io_op)
Definition: pgstatfuncs.c:1404
Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:773
#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS(stat)
Definition: pgstatfuncs.c:186
Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:998
Datum pg_stat_get_db_checksum_failures(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1146
Datum pg_stat_reset_subscription_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2014
Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1841
Datum pg_stat_reset_slru(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1980
Datum pg_stat_get_checkpointer_restartpoints_requested(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1241
Datum pg_stat_get_checkpointer_num_performed(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1229
Datum pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1164
Datum pg_stat_get_backend_wal(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1669
static io_stat_col pgstat_get_io_op_index(IOOp io_op)
Definition: pgstatfuncs.c:1346
Datum pg_stat_have_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2257
Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:207
Datum pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:798
static io_stat_col pgstat_get_io_byte_index(IOOp io_op)
Definition: pgstatfuncs.c:1377
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS
Datum pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1271
Datum pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1265
Datum pg_stat_get_io(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1539
Datum pg_stat_get_checkpointer_restartpoints_performed(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1247
#define PG_STAT_GET_DBENTRY_FLOAT8_MS(stat)
Definition: pgstatfuncs.c:1185
Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:726
Datum pg_stat_reset(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1861
Datum pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:819
#define PG_STAT_GET_SUBXACT_COLS
#define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(stat)
Definition: pgstatfuncs.c:1806
#define PG_STAT_GET_RELENTRY_INT64(stat)
Definition: pgstatfuncs.c:39
Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:713
Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1796
#define PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat)
Definition: pgstatfuncs.c:137
Datum pg_stat_reset_backend_stats(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1947
#define PG_STAT_GET_PROGRESS_COLS
Datum pg_stat_get_checkpointer_write_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1277
#define HAS_PGSTAT_PERMISSIONS(role)
Definition: pgstatfuncs.c:37
Datum pg_stat_get_backend_io(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1580
Datum pg_stat_get_checkpointer_slru_written(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1259
#define PG_STAT_GET_RELENTRY_FLOAT8(stat)
Definition: pgstatfuncs.c:109
Datum pg_stat_get_archiver(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2038
Datum pg_stat_get_checkpointer_restartpoints_timed(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1235
Datum pg_stat_reset_shared(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1875
Datum pg_stat_force_next_flush(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1851
Datum pg_stat_reset_single_table_counters(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1923
Datum pg_stat_get_bgwriter_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1299
Datum pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:867
Datum pg_stat_get_checkpointer_stat_reset_time(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1293
Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:175
Datum pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:738
Datum pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:2104
io_stat_col
Definition: pgstatfuncs.c:1316
@ IO_COL_READS
Definition: pgstatfuncs.c:1321
@ IO_NUM_COLUMNS
Definition: pgstatfuncs.c:1338
@ IO_COL_RESET_TIME
Definition: pgstatfuncs.c:1337
@ IO_COL_WRITE_TIME
Definition: pgstatfuncs.c:1326
@ IO_COL_HITS
Definition: pgstatfuncs.c:1332
@ IO_COL_EXTENDS
Definition: pgstatfuncs.c:1329
@ IO_COL_WRITEBACK_TIME
Definition: pgstatfuncs.c:1328
@ IO_COL_REUSES
Definition: pgstatfuncs.c:1334
@ IO_COL_WRITES
Definition: pgstatfuncs.c:1324
@ IO_COL_OBJECT
Definition: pgstatfuncs.c:1319
@ IO_COL_EVICTIONS
Definition: pgstatfuncs.c:1333
@ IO_COL_WRITEBACKS
Definition: pgstatfuncs.c:1327
@ IO_COL_CONTEXT
Definition: pgstatfuncs.c:1320
@ IO_COL_READ_BYTES
Definition: pgstatfuncs.c:1322
@ IO_COL_EXTEND_BYTES
Definition: pgstatfuncs.c:1330
@ IO_COL_BACKEND_TYPE
Definition: pgstatfuncs.c:1318
@ IO_COL_FSYNC_TIME
Definition: pgstatfuncs.c:1336
@ IO_COL_EXTEND_TIME
Definition: pgstatfuncs.c:1331
@ IO_COL_FSYNCS
Definition: pgstatfuncs.c:1335
@ IO_COL_WRITE_BYTES
Definition: pgstatfuncs.c:1325
@ IO_COL_INVALID
Definition: pgstatfuncs.c:1317
@ IO_COL_READ_TIME
Definition: pgstatfuncs.c:1323
Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:841
Datum pg_stat_reset_single_function_counters(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1934
Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:1305
Datum pg_backend_pid(PG_FUNCTION_ARGS)
Definition: pgstatfuncs.c:693
#define PG_STAT_GET_REPLICATION_SLOT_COLS
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define snprintf
Definition: port.h:239
static Datum Int64GetDatum(int64 X)
Definition: postgres.h:403
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
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 Float8GetDatum(float8 X)
Definition: postgres.h:492
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
unsigned int Oid
Definition: postgres_ext.h:32
#define GetNumberFromPGProc(proc)
Definition: proc.h:441
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:3158
int ProcNumber
Definition: procnumber.h:24
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:1091
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
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
ProgressCommandType st_progress_command
SockAddr st_clientaddr
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
PgBackendSSLStatus * st_sslstatus
TimestampTz st_xact_start_timestamp
char * st_clienthostname
Oid st_progress_command_target
TimestampTz last_failed_timestamp
Definition: pgstat.h:226
TimestampTz stat_reset_timestamp
Definition: pgstat.h:227
TimestampTz last_archived_timestamp
Definition: pgstat.h:222
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:224
PgStat_Counter failed_count
Definition: pgstat.h:223
PgStat_Counter archived_count
Definition: pgstat.h:219
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:220
TimestampTz stat_reset_timestamp
Definition: pgstat.h:493
PgStat_WalCounters wal_counters
Definition: pgstat.h:495
PgStat_BktypeIO io_stats
Definition: pgstat.h:494
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:327
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:325
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:326
PgStat_Counter numcalls
Definition: pgstat.h:83
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:340
TimestampTz stat_reset_timestamp
Definition: pgstat.h:339
PgStat_Counter conflict_startup_deadlock
Definition: pgstat.h:360
PgStat_Counter conflict_lock
Definition: pgstat.h:356
TimestampTz stat_reset_timestamp
Definition: pgstat.h:378
PgStat_Counter conflict_snapshot
Definition: pgstat.h:357
TimestampTz last_checksum_failure
Definition: pgstat.h:365
PgStat_Counter conflict_bufferpin
Definition: pgstat.h:359
PgStat_Counter conflict_logicalslot
Definition: pgstat.h:358
PgStat_Counter checksum_failures
Definition: pgstat.h:364
PgStat_Counter conflict_tablespace
Definition: pgstat.h:355
PgStat_Counter numcalls
Definition: pgstat.h:383
TimestampTz stat_reset_timestamp
Definition: pgstat.h:399
PgStat_Counter stream_count
Definition: pgstat.h:395
PgStat_Counter total_txns
Definition: pgstat.h:397
PgStat_Counter total_bytes
Definition: pgstat.h:398
PgStat_Counter spill_txns
Definition: pgstat.h:391
PgStat_Counter stream_txns
Definition: pgstat.h:394
PgStat_Counter spill_count
Definition: pgstat.h:392
PgStat_Counter stream_bytes
Definition: pgstat.h:396
PgStat_Counter spill_bytes
Definition: pgstat.h:393
PgStat_Counter apply_error_count
Definition: pgstat.h:416
PgStat_Counter sync_error_count
Definition: pgstat.h:417
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition: pgstat.h:418
TimestampTz stat_reset_timestamp
Definition: pgstat.h:419
PgStat_Counter wal_fpi
Definition: pgstat.h:472
uint64 wal_bytes
Definition: pgstat.h:473
PgStat_Counter wal_buffers_full
Definition: pgstat.h:474
PgStat_Counter wal_records
Definition: pgstat.h:471
TimestampTz stat_reset_timestamp
Definition: pgstat.h:484
PgStat_WalCounters wal_counters
Definition: pgstat.h:483
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
Definition: c.h:746
Definition: c.h:692
#define TransactionIdIsValid(xid)
Definition: transam.h:41
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
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
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:68
text * cstring_to_text(const char *s)
Definition: varlena.c:181
char * text_to_cstring(const text *t)
Definition: varlena.c:214
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
const char * name
#define stat
Definition: win32_port.h:274
bool DataChecksumsEnabled(void)
Definition: xlog.c:4615
void XLogPrefetchResetStats(void)