55 *
66 * Copyright (c) 2001-2003, PostgreSQL Global Development Group
77 *
8- * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.24 2004/06/14 18:08:19 tgl Exp $
8+ * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.25 2004/06/26 16:32:04 tgl Exp $
99 * ----------
1010 */
1111#ifndef PGSTAT_H
1616#include "utils/rel.h"
1717
1818
19- /* ----------
20- * Paths for the statistics files. The %s is replaced with the
21- * installations $PGDATA.
22- * ----------
23- */
24- #define PGSTAT_STAT_FILENAME "%s/global/pgstat.stat"
25- #define PGSTAT_STAT_TMPFILE "%s/global/pgstat.tmp.%d"
26-
27- /* ----------
28- * Timer definitions.
29- * ----------
30- */
31- #define PGSTAT_STAT_INTERVAL 500 /* How often to write the status */
32- /* file; in milliseconds. */
33-
34- #define PGSTAT_DESTROY_DELAY 10000 /* How long to keep destroyed */
35- /* objects known, to give delayed */
36- /* UDP packets time to arrive; */
37- /* in milliseconds. */
38-
39- #define PGSTAT_DESTROY_COUNT (PGSTAT_DESTROY_DELAY / PGSTAT_STAT_INTERVAL)
40-
41- #define PGSTAT_RESTART_INTERVAL 60 /* How often to attempt to restart */
42- /* a failed statistics collector; in seconds. */
43-
44- /* ----------
45- * How much of the actual query string to send to the collector.
46- * ----------
47- */
48- #define PGSTAT_ACTIVITY_SIZE 256
49-
50-
5119/* ----------
5220 * The types of backend/postmaster -> collector messages
5321 * ----------
6129#define PGSTAT_MTYPE_DROPDB 6
6230#define PGSTAT_MTYPE_RESETCOUNTER 7
6331
64- /* ----------
65- * Amount of space reserved in pgstat_recvbuffer().
66- * ----------
67- */
68- #define PGSTAT_RECVBUFFERSZ ((int) (1024 * sizeof(PgStat_Msg)))
69-
70-
71- /* ----------
72- * The initial size hints for the hash tables used in the collector.
73- * ----------
74- */
75- #define PGSTAT_DB_HASH_SIZE 16
76- #define PGSTAT_BE_HASH_SIZE 512
77- #define PGSTAT_TAB_HASH_SIZE 512
78-
79-
8032/* ----------
8133 * The data type used for counters.
8234 * ----------
8335 */
8436typedef int64 PgStat_Counter ;
8537
8638
87- /* ------------------------------------------------------------
88- * Statistic collector data structures follow
89- * ------------------------------------------------------------
90- */
91- /* ----------
92- * PgStat_StatDBEntry The collectors data per database
93- * ----------
94- */
95- typedef struct PgStat_StatDBEntry
96- {
97- Oid databaseid ;
98- HTAB * tables ;
99- int n_backends ;
100- PgStat_Counter n_connects ;
101- PgStat_Counter n_xact_commit ;
102- PgStat_Counter n_xact_rollback ;
103- PgStat_Counter n_blocks_fetched ;
104- PgStat_Counter n_blocks_hit ;
105- int destroy ;
106- } PgStat_StatDBEntry ;
107-
108-
109- /* ----------
110- * PgStat_StatBeEntry The collectors data per backend
111- * ----------
112- */
113- typedef struct PgStat_StatBeEntry
114- {
115- Oid databaseid ;
116- Oid userid ;
117- int procpid ;
118- char activity [PGSTAT_ACTIVITY_SIZE ];
119- AbsoluteTime activity_start_sec ;
120- int activity_start_usec ;
121- } PgStat_StatBeEntry ;
122-
123-
124- /* ----------
125- * PgStat_StatBeDead Because UDP packets can arrive out of
126- * order, we need to keep some information
127- * about backends that are known to be
128- * dead for some seconds. This info is held
129- * in a hash table of these structs.
130- * ----------
131- */
132- typedef struct PgStat_StatBeDead
133- {
134- int procpid ;
135- int backendid ;
136- int destroy ;
137- } PgStat_StatBeDead ;
138-
139-
140- /* ----------
141- * PgStat_StatTabEntry The collectors data table data
142- * ----------
143- */
144- typedef struct PgStat_StatTabEntry
145- {
146- Oid tableid ;
147-
148- PgStat_Counter numscans ;
149-
150- PgStat_Counter tuples_returned ;
151- PgStat_Counter tuples_fetched ;
152- PgStat_Counter tuples_inserted ;
153- PgStat_Counter tuples_updated ;
154- PgStat_Counter tuples_deleted ;
155-
156- PgStat_Counter blocks_fetched ;
157- PgStat_Counter blocks_hit ;
158-
159- int destroy ;
160- } PgStat_StatTabEntry ;
161-
162-
16339/* ------------------------------------------------------------
16440 * Message formats follow
16541 * ------------------------------------------------------------
@@ -181,7 +57,15 @@ typedef struct PgStat_MsgHdr
18157} PgStat_MsgHdr ;
18258
18359/* ----------
184- * PgStat_TabEntry A table slot in a MsgTabstat
60+ * Space available in a message. This will keep the UDP packets below 1K,
61+ * which should fit unfragmented into the MTU of the lo interface on most
62+ * platforms. Does anybody care for platforms where it doesn't?
63+ * ----------
64+ */
65+ #define PGSTAT_MSG_PAYLOAD (1000 - sizeof(PgStat_MsgHdr))
66+
67+ /* ----------
68+ * PgStat_TableEntry Per-table info in a MsgTabstat
18569 * ----------
18670 */
18771typedef struct PgStat_TableEntry
@@ -234,27 +118,22 @@ typedef struct PgStat_MsgBeterm
234118 * to parse a query.
235119 * ----------
236120 */
121+ #define PGSTAT_ACTIVITY_SIZE PGSTAT_MSG_PAYLOAD
122+
237123typedef struct PgStat_MsgActivity
238124{
239125 PgStat_MsgHdr m_hdr ;
240126 char m_what [PGSTAT_ACTIVITY_SIZE ];
241127} PgStat_MsgActivity ;
242128
243- /* ----------
244- * How many table entries fit into a MsgTabstat. Actually,
245- * this will keep the UDP packets below 1K, what should fit
246- * unfragmented into the MTU of the lo interface on most
247- * platforms. Does anybody care for platforms where it doesn't?
248- * ----------
249- */
250- #define PGSTAT_NUM_TABENTRIES ((1000 - sizeof(PgStat_MsgHdr)) \
251- / sizeof(PgStat_TableEntry))
252-
253129/* ----------
254130 * PgStat_MsgTabstat Sent by the backend to report table
255131 * and buffer access statistics.
256132 * ----------
257133 */
134+ #define PGSTAT_NUM_TABENTRIES ((PGSTAT_MSG_PAYLOAD - 3 * sizeof(int)) \
135+ / sizeof(PgStat_TableEntry))
136+
258137typedef struct PgStat_MsgTabstat
259138{
260139 PgStat_MsgHdr m_hdr ;
@@ -264,19 +143,14 @@ typedef struct PgStat_MsgTabstat
264143 PgStat_TableEntry m_entry [PGSTAT_NUM_TABENTRIES ];
265144} PgStat_MsgTabstat ;
266145
267-
268- /* ----------
269- * How many Oid entries fit into a MsgTabpurge.
270- * ----------
271- */
272- #define PGSTAT_NUM_TABPURGE ((1000 - sizeof(PgStat_MsgHdr)) \
273- / sizeof(Oid))
274-
275146/* ----------
276147 * PgStat_MsgTabpurge Sent by the backend to tell the collector
277148 * about dead tables.
278149 * ----------
279150 */
151+ #define PGSTAT_NUM_TABPURGE ((PGSTAT_MSG_PAYLOAD - sizeof(int)) \
152+ / sizeof(Oid))
153+
280154typedef struct PgStat_MsgTabpurge
281155{
282156 PgStat_MsgHdr m_hdr ;
@@ -325,6 +199,83 @@ typedef union PgStat_Msg
325199} PgStat_Msg ;
326200
327201
202+ /* ------------------------------------------------------------
203+ * Statistic collector data structures follow
204+ * ------------------------------------------------------------
205+ */
206+
207+ /* ----------
208+ * PgStat_StatDBEntry The collectors data per database
209+ * ----------
210+ */
211+ typedef struct PgStat_StatDBEntry
212+ {
213+ Oid databaseid ;
214+ HTAB * tables ;
215+ int n_backends ;
216+ PgStat_Counter n_connects ;
217+ PgStat_Counter n_xact_commit ;
218+ PgStat_Counter n_xact_rollback ;
219+ PgStat_Counter n_blocks_fetched ;
220+ PgStat_Counter n_blocks_hit ;
221+ int destroy ;
222+ } PgStat_StatDBEntry ;
223+
224+
225+ /* ----------
226+ * PgStat_StatBeEntry The collectors data per backend
227+ * ----------
228+ */
229+ typedef struct PgStat_StatBeEntry
230+ {
231+ Oid databaseid ;
232+ Oid userid ;
233+ int procpid ;
234+ AbsoluteTime activity_start_sec ;
235+ int activity_start_usec ;
236+ char activity [PGSTAT_ACTIVITY_SIZE ];
237+ } PgStat_StatBeEntry ;
238+
239+
240+ /* ----------
241+ * PgStat_StatBeDead Because UDP packets can arrive out of
242+ * order, we need to keep some information
243+ * about backends that are known to be
244+ * dead for some seconds. This info is held
245+ * in a hash table of these structs.
246+ * ----------
247+ */
248+ typedef struct PgStat_StatBeDead
249+ {
250+ int procpid ;
251+ int backendid ;
252+ int destroy ;
253+ } PgStat_StatBeDead ;
254+
255+
256+ /* ----------
257+ * PgStat_StatTabEntry The collectors data table data
258+ * ----------
259+ */
260+ typedef struct PgStat_StatTabEntry
261+ {
262+ Oid tableid ;
263+
264+ PgStat_Counter numscans ;
265+
266+ PgStat_Counter tuples_returned ;
267+ PgStat_Counter tuples_fetched ;
268+ PgStat_Counter tuples_inserted ;
269+ PgStat_Counter tuples_updated ;
270+ PgStat_Counter tuples_deleted ;
271+
272+ PgStat_Counter blocks_fetched ;
273+ PgStat_Counter blocks_hit ;
274+
275+ int destroy ;
276+ } PgStat_StatTabEntry ;
277+
278+
328279/* ----------
329280 * GUC parameters
330281 * ----------
0 commit comments