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