aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/pgstat_internal.h
blob: 1923f56a3adfe285f6eef5ddf6c33212de4eb73b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* ----------
 * pgstat_internal.h
 *
 * Definitions for the PostgreSQL cumulative statistics system that should
 * only be needed by files implementing statistics support (rather than ones
 * reporting / querying stats).
 *
 * Copyright (c) 2001-2022, PostgreSQL Global Development Group
 *
 * src/include/utils/pgstat_internal.h
 * ----------
 */
#ifndef PGSTAT_INTERNAL_H
#define PGSTAT_INTERNAL_H


#include "pgstat.h"


#define PGSTAT_STAT_INTERVAL	500 /* Minimum time between stats file
									 * updates; in milliseconds. */

/* ----------
 * The initial size hints for the hash tables used in the collector.
 * ----------
 */
#define PGSTAT_DB_HASH_SIZE		16
#define PGSTAT_TAB_HASH_SIZE	512
#define PGSTAT_FUNCTION_HASH_SIZE	512
#define PGSTAT_SUBSCRIPTION_HASH_SIZE	32
#define PGSTAT_REPLSLOT_HASH_SIZE	32


/*
 * Some stats changes are transactional. To maintain those, a stack of
 * PgStat_SubXactStatus entries is maintained, which contain data pertaining
 * to the current transaction and its active subtransactions.
 */
typedef struct PgStat_SubXactStatus
{
	int			nest_level;		/* subtransaction nest level */

	struct PgStat_SubXactStatus *prev;	/* higher-level subxact if any */

	/*
	 * Tuple insertion/deletion counts for an open transaction can't be
	 * propagated into PgStat_TableStatus counters until we know if it is
	 * going to commit or abort.  Hence, we keep these counts in per-subxact
	 * structs that live in TopTransactionContext.  This data structure is
	 * designed on the assumption that subxacts won't usually modify very many
	 * tables.
	 */
	PgStat_TableXactStatus *first;	/* head of list for this subxact */
} PgStat_SubXactStatus;


/*
 * List of SLRU names that we keep stats for.  There is no central registry of
 * SLRUs, so we use this fixed list instead.  The "other" entry is used for
 * all SLRUs without an explicit entry (e.g. SLRUs in extensions).
 */
static const char *const slru_names[] = {
	"CommitTs",
	"MultiXactMember",
	"MultiXactOffset",
	"Notify",
	"Serial",
	"Subtrans",
	"Xact",
	"other"						/* has to be last */
};

#define SLRU_NUM_ELEMENTS	lengthof(slru_names)


/*
 * Functions in pgstat.c
 */

extern void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype);
extern void pgstat_send(void *msg, int len);
#ifdef USE_ASSERT_CHECKING
extern void pgstat_assert_is_up(void);
#else
#define pgstat_assert_is_up() ((void)true)
#endif


/*
 * Functions in pgstat_database.c
 */

extern void AtEOXact_PgStat_Database(bool isCommit, bool parallel);
extern void pgstat_report_disconnect(Oid dboid);
extern void pgstat_update_dbstats(PgStat_MsgTabstat *tsmsg, TimestampTz now);


/*
 * Functions in pgstat_function.c
 */

extern void pgstat_send_funcstats(void);


/*
 * Functions in pgstat_relation.c
 */

extern void AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit);
extern void AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth);
extern void AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state);
extern void PostPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state);
extern void pgstat_send_tabstats(TimestampTz now, bool disconnect);


/*
 * Functions in pgstat_slru.c
 */

extern void pgstat_send_slru(void);


/*
 * Functions in pgstat_wal.c
 */

extern void pgstat_wal_initialize(void);
extern bool pgstat_wal_pending(void);


/*
 * Functions in pgstat_xact.c
 */

extern PgStat_SubXactStatus *pgstat_xact_stack_level_get(int nest_level);


/*
 * Variables in pgstat.c
 */

extern pgsocket pgStatSock;


/*
 * Variables in pgstat_database.c
 */

extern int	pgStatXactCommit;
extern int	pgStatXactRollback;


/*
 * Variables in pgstat_functions.c
 */

extern bool have_function_stats;


/*
 * Variables in pgstat_relation.c
 */

extern bool have_relation_stats;


#endif							/* PGSTAT_INTERNAL_H */