Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ceeb4c

Browse files
committed
Adjust pgstat message definitions so that the target message size is
specified in just one place and adhered to exactly, rather than just moreor less. A side effect is to increase PGSTAT_ACTIVITY_SIZE (maximumreported query length) from 256 to nearly 1000.
1 parentb2ca707 commit0ceeb4c

File tree

2 files changed

+139
-149
lines changed

2 files changed

+139
-149
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.75 2004/06/14 18:08:18 tgl Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.76 2004/06/26 16:32:02 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -22,12 +22,10 @@
2222
#include<fcntl.h>
2323
#include<sys/param.h>
2424
#include<sys/time.h>
25-
#include<sys/types.h>
2625
#include<sys/socket.h>
2726
#include<netdb.h>
2827
#include<netinet/in.h>
2928
#include<arpa/inet.h>
30-
#include<errno.h>
3129
#include<signal.h>
3230
#include<time.h>
3331

@@ -55,6 +53,47 @@
5553
#include"utils/syscache.h"
5654

5755

56+
/* ----------
57+
* Paths for the statistics files. The %s is replaced with the
58+
* installation's $PGDATA.
59+
* ----------
60+
*/
61+
#definePGSTAT_STAT_FILENAME"%s/global/pgstat.stat"
62+
#definePGSTAT_STAT_TMPFILE"%s/global/pgstat.tmp.%d"
63+
64+
/* ----------
65+
* Timer definitions.
66+
* ----------
67+
*/
68+
#definePGSTAT_STAT_INTERVAL500/* How often to write the status
69+
* file; in milliseconds. */
70+
71+
#definePGSTAT_DESTROY_DELAY10000/* How long to keep destroyed
72+
* objects known, to give delayed
73+
* UDP packets time to arrive;
74+
* in milliseconds. */
75+
76+
#definePGSTAT_DESTROY_COUNT(PGSTAT_DESTROY_DELAY / PGSTAT_STAT_INTERVAL)
77+
78+
#definePGSTAT_RESTART_INTERVAL 60/* How often to attempt to restart
79+
* a failed statistics collector;
80+
* in seconds. */
81+
82+
/* ----------
83+
* Amount of space reserved in pgstat_recvbuffer().
84+
* ----------
85+
*/
86+
#definePGSTAT_RECVBUFFERSZ((int) (1024 * sizeof(PgStat_Msg)))
87+
88+
/* ----------
89+
* The initial size hints for the hash tables used in the collector.
90+
* ----------
91+
*/
92+
#definePGSTAT_DB_HASH_SIZE16
93+
#definePGSTAT_BE_HASH_SIZE512
94+
#definePGSTAT_TAB_HASH_SIZE512
95+
96+
5897
/* ----------
5998
* GUC parameters
6099
* ----------
@@ -2760,15 +2799,15 @@ pgstat_recv_activity(PgStat_MsgActivity *msg, int len)
27602799

27612800
/*
27622801
* Here we check explicitly for 0 return, since we don't want to
2763-
* mangle the activity of an active backend by a delayedpacked from a
2802+
* mangle the activity of an active backend by a delayedpacket from a
27642803
* dead one.
27652804
*/
27662805
if (pgstat_add_backend(&msg->m_hdr)!=0)
27672806
return;
27682807

27692808
entry=&(pgStatBeTable[msg->m_hdr.m_backendid-1]);
27702809

2771-
strncpy(entry->activity,msg->m_what,PGSTAT_ACTIVITY_SIZE);
2810+
StrNCpy(entry->activity,msg->m_what,PGSTAT_ACTIVITY_SIZE);
27722811

27732812
entry->activity_start_sec=
27742813
GetCurrentAbsoluteTimeUsec(&entry->activity_start_usec);

‎src/include/pgstat.h

Lines changed: 95 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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
#ifndefPGSTAT_H
@@ -16,38 +16,6 @@
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-
#definePGSTAT_STAT_FILENAME"%s/global/pgstat.stat"
25-
#definePGSTAT_STAT_TMPFILE"%s/global/pgstat.tmp.%d"
26-
27-
/* ----------
28-
* Timer definitions.
29-
* ----------
30-
*/
31-
#definePGSTAT_STAT_INTERVAL500/* How often to write the status*/
32-
/* file; in milliseconds. */
33-
34-
#definePGSTAT_DESTROY_DELAY10000/* How long to keep destroyed*/
35-
/* objects known, to give delayed */
36-
/* UDP packets time to arrive; */
37-
/* in milliseconds. */
38-
39-
#definePGSTAT_DESTROY_COUNT(PGSTAT_DESTROY_DELAY / PGSTAT_STAT_INTERVAL)
40-
41-
#definePGSTAT_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-
#definePGSTAT_ACTIVITY_SIZE256
49-
50-
5119
/* ----------
5220
* The types of backend/postmaster -> collector messages
5321
* ----------
@@ -61,105 +29,13 @@
6129
#definePGSTAT_MTYPE_DROPDB6
6230
#definePGSTAT_MTYPE_RESETCOUNTER7
6331

64-
/* ----------
65-
* Amount of space reserved in pgstat_recvbuffer().
66-
* ----------
67-
*/
68-
#definePGSTAT_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-
#definePGSTAT_DB_HASH_SIZE16
76-
#definePGSTAT_BE_HASH_SIZE512
77-
#definePGSTAT_TAB_HASH_SIZE512
78-
79-
8032
/* ----------
8133
* The data type used for counters.
8234
* ----------
8335
*/
8436
typedefint64PgStat_Counter;
8537

8638

87-
/* ------------------------------------------------------------
88-
* Statistic collector data structures follow
89-
* ------------------------------------------------------------
90-
*/
91-
/* ----------
92-
* PgStat_StatDBEntryThe collectors data per database
93-
* ----------
94-
*/
95-
typedefstructPgStat_StatDBEntry
96-
{
97-
Oiddatabaseid;
98-
HTAB*tables;
99-
intn_backends;
100-
PgStat_Countern_connects;
101-
PgStat_Countern_xact_commit;
102-
PgStat_Countern_xact_rollback;
103-
PgStat_Countern_blocks_fetched;
104-
PgStat_Countern_blocks_hit;
105-
intdestroy;
106-
}PgStat_StatDBEntry;
107-
108-
109-
/* ----------
110-
* PgStat_StatBeEntryThe collectors data per backend
111-
* ----------
112-
*/
113-
typedefstructPgStat_StatBeEntry
114-
{
115-
Oiddatabaseid;
116-
Oiduserid;
117-
intprocpid;
118-
charactivity[PGSTAT_ACTIVITY_SIZE];
119-
AbsoluteTimeactivity_start_sec;
120-
intactivity_start_usec;
121-
}PgStat_StatBeEntry;
122-
123-
124-
/* ----------
125-
* PgStat_StatBeDeadBecause 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-
typedefstructPgStat_StatBeDead
133-
{
134-
intprocpid;
135-
intbackendid;
136-
intdestroy;
137-
}PgStat_StatBeDead;
138-
139-
140-
/* ----------
141-
* PgStat_StatTabEntryThe collectors data table data
142-
* ----------
143-
*/
144-
typedefstructPgStat_StatTabEntry
145-
{
146-
Oidtableid;
147-
148-
PgStat_Counternumscans;
149-
150-
PgStat_Countertuples_returned;
151-
PgStat_Countertuples_fetched;
152-
PgStat_Countertuples_inserted;
153-
PgStat_Countertuples_updated;
154-
PgStat_Countertuples_deleted;
155-
156-
PgStat_Counterblocks_fetched;
157-
PgStat_Counterblocks_hit;
158-
159-
intdestroy;
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_TabEntryA 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+
#definePGSTAT_MSG_PAYLOAD(1000 - sizeof(PgStat_MsgHdr))
66+
67+
/* ----------
68+
* PgStat_TableEntryPer-table info in a MsgTabstat
18569
* ----------
18670
*/
18771
typedefstructPgStat_TableEntry
@@ -234,27 +118,22 @@ typedef struct PgStat_MsgBeterm
234118
*to parse a query.
235119
* ----------
236120
*/
121+
#definePGSTAT_ACTIVITY_SIZEPGSTAT_MSG_PAYLOAD
122+
237123
typedefstructPgStat_MsgActivity
238124
{
239125
PgStat_MsgHdrm_hdr;
240126
charm_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-
#definePGSTAT_NUM_TABENTRIES((1000 - sizeof(PgStat_MsgHdr))\
251-
/ sizeof(PgStat_TableEntry))
252-
253129
/* ----------
254130
* PgStat_MsgTabstatSent by the backend to report table
255131
*and buffer access statistics.
256132
* ----------
257133
*/
134+
#definePGSTAT_NUM_TABENTRIES((PGSTAT_MSG_PAYLOAD - 3 * sizeof(int))\
135+
/ sizeof(PgStat_TableEntry))
136+
258137
typedefstructPgStat_MsgTabstat
259138
{
260139
PgStat_MsgHdrm_hdr;
@@ -264,19 +143,14 @@ typedef struct PgStat_MsgTabstat
264143
PgStat_TableEntrym_entry[PGSTAT_NUM_TABENTRIES];
265144
}PgStat_MsgTabstat;
266145

267-
268-
/* ----------
269-
* How many Oid entries fit into a MsgTabpurge.
270-
* ----------
271-
*/
272-
#definePGSTAT_NUM_TABPURGE((1000 - sizeof(PgStat_MsgHdr))\
273-
/ sizeof(Oid))
274-
275146
/* ----------
276147
* PgStat_MsgTabpurgeSent by the backend to tell the collector
277148
*about dead tables.
278149
* ----------
279150
*/
151+
#definePGSTAT_NUM_TABPURGE((PGSTAT_MSG_PAYLOAD - sizeof(int))\
152+
/ sizeof(Oid))
153+
280154
typedefstructPgStat_MsgTabpurge
281155
{
282156
PgStat_MsgHdrm_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_StatDBEntryThe collectors data per database
209+
* ----------
210+
*/
211+
typedefstructPgStat_StatDBEntry
212+
{
213+
Oiddatabaseid;
214+
HTAB*tables;
215+
intn_backends;
216+
PgStat_Countern_connects;
217+
PgStat_Countern_xact_commit;
218+
PgStat_Countern_xact_rollback;
219+
PgStat_Countern_blocks_fetched;
220+
PgStat_Countern_blocks_hit;
221+
intdestroy;
222+
}PgStat_StatDBEntry;
223+
224+
225+
/* ----------
226+
* PgStat_StatBeEntryThe collectors data per backend
227+
* ----------
228+
*/
229+
typedefstructPgStat_StatBeEntry
230+
{
231+
Oiddatabaseid;
232+
Oiduserid;
233+
intprocpid;
234+
AbsoluteTimeactivity_start_sec;
235+
intactivity_start_usec;
236+
charactivity[PGSTAT_ACTIVITY_SIZE];
237+
}PgStat_StatBeEntry;
238+
239+
240+
/* ----------
241+
* PgStat_StatBeDeadBecause 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+
typedefstructPgStat_StatBeDead
249+
{
250+
intprocpid;
251+
intbackendid;
252+
intdestroy;
253+
}PgStat_StatBeDead;
254+
255+
256+
/* ----------
257+
* PgStat_StatTabEntryThe collectors data table data
258+
* ----------
259+
*/
260+
typedefstructPgStat_StatTabEntry
261+
{
262+
Oidtableid;
263+
264+
PgStat_Counternumscans;
265+
266+
PgStat_Countertuples_returned;
267+
PgStat_Countertuples_fetched;
268+
PgStat_Countertuples_inserted;
269+
PgStat_Countertuples_updated;
270+
PgStat_Countertuples_deleted;
271+
272+
PgStat_Counterblocks_fetched;
273+
PgStat_Counterblocks_hit;
274+
275+
intdestroy;
276+
}PgStat_StatTabEntry;
277+
278+
328279
/* ----------
329280
* GUC parameters
330281
* ----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp