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

Commit6497a7f

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Added GUC configuration options to control access statistics.
Jan
1 parent2f3bd9e commit6497a7f

File tree

4 files changed

+95
-25
lines changed

4 files changed

+95
-25
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
* thus an initdb and we might want to provide this as a
1515
* patch for 7.1.
1616
*
17-
*- Make the functions from contrib/pgstat_tmp builtin
18-
* and create the views on initdb.
19-
*
2017
*Copyright (c) 2001, PostgreSQL Global Development Group
2118
*
22-
*$Id: pgstat.c,v 1.3 2001/06/3019:01:27 petere Exp $
19+
*$Id: pgstat.c,v 1.4 2001/07/05 15:19:40 wieck Exp $
2320
* ----------
2421
*/
2522
#include"postgres.h"
@@ -56,7 +53,11 @@
5653
* Global data
5754
* ----------
5855
*/
59-
56+
boolpgstat_collect_startcollector= true;
57+
boolpgstat_collect_resetonpmstart= true;
58+
boolpgstat_collect_querystring= false;
59+
boolpgstat_collect_tuplelevel= false;
60+
boolpgstat_collect_blocklevel= false;
6061

6162
/* ----------
6263
* Local data
@@ -135,6 +136,13 @@ pgstat_init(void)
135136
{
136137
intalen;
137138

139+
/*
140+
* Force start of collector daemon if something to collect
141+
*/
142+
if (pgstat_collect_querystring||pgstat_collect_tuplelevel||
143+
pgstat_collect_blocklevel)
144+
pgstat_collect_startcollector= true;
145+
138146
/*
139147
* Initialize the filenames for the status reports.
140148
*/
@@ -143,6 +151,20 @@ pgstat_init(void)
143151
snprintf(pgStat_fname,MAXPGPATH,
144152
PGSTAT_STAT_FILENAME,DataDir);
145153

154+
/*
155+
* If we don't have to start a collector or should reset the
156+
* collected statistics on postmaster start, simply remove the
157+
* file.
158+
*/
159+
if (!pgstat_collect_startcollector||pgstat_collect_resetonpmstart)
160+
unlink(pgStat_fname);
161+
162+
/*
163+
* Nothing else required if collector will not get started
164+
*/
165+
if (!pgstat_collect_startcollector)
166+
return0;
167+
146168
/*
147169
* Create the UDP socket for receiving statistic messages
148170
*/
@@ -211,6 +233,12 @@ pgstat_init(void)
211233
int
212234
pgstat_start(void)
213235
{
236+
/*
237+
* Do nothing if no collector needed
238+
*/
239+
if (!pgstat_collect_startcollector)
240+
return0;
241+
214242
/*
215243
* Check that the socket at least is there
216244
*/
@@ -275,6 +303,9 @@ pgstat_beterm(int pid)
275303
{
276304
PgStat_MsgBetermmsg;
277305

306+
if (!pgstat_collect_startcollector)
307+
return;
308+
278309
msg.m_hdr.m_type=PGSTAT_MTYPE_BETERM;
279310
msg.m_hdr.m_backendid=0;
280311
msg.m_hdr.m_procpid=pid;
@@ -302,7 +333,7 @@ pgstat_bestart(void)
302333
{
303334
PgStat_MsgBestartmsg;
304335

305-
if (pgStatSock<0)
336+
if (!pgstat_collect_startcollector||pgStatSock<0)
306337
return;
307338

308339
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_BESTART);
@@ -324,7 +355,7 @@ pgstat_report_activity(char *what)
324355
PgStat_MsgActivitymsg;
325356
intlen;
326357

327-
if (pgStatSock<0)
358+
if (!pgstat_collect_querystring||pgStatSock<0)
328359
return;
329360

330361
len=strlen(what);
@@ -354,6 +385,10 @@ pgstat_report_tabstat(void)
354385
intn;
355386
intlen;
356387

388+
if (!pgstat_collect_querystring&& !pgstat_collect_tuplelevel&&
389+
!pgstat_collect_blocklevel)
390+
return;
391+
357392
if (pgStatSock<0)
358393
return;
359394

@@ -654,7 +689,7 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
654689
stats->heap_scan_counted= FALSE;
655690
stats->index_scan_counted= FALSE;
656691

657-
if (pgStatSock<0)
692+
if (!pgstat_collect_startcollector||pgStatSock<0)
658693
{
659694
stats->no_stats= TRUE;
660695
return;
@@ -764,6 +799,10 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
764799
void
765800
pgstat_count_xact_commit(void)
766801
{
802+
if (!pgstat_collect_querystring&& !pgstat_collect_tuplelevel&&
803+
!pgstat_collect_blocklevel)
804+
return;
805+
767806
pgStatXactCommit++;
768807

769808
/*
@@ -791,6 +830,10 @@ pgstat_count_xact_commit(void)
791830
void
792831
pgstat_count_xact_rollback(void)
793832
{
833+
if (!pgstat_collect_querystring&& !pgstat_collect_tuplelevel&&
834+
!pgstat_collect_blocklevel)
835+
return;
836+
794837
pgStatXactRollback++;
795838

796839
/*

‎src/backend/utils/misc/guc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Support for grand unified configuration scheme, including SET
55
* command, configuration file, and command line options.
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.44 2001/06/30 22:03:26 petere Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.45 2001/07/05 15:19:40 wieck Exp $
88
*
99
* Copyright 2000 by PostgreSQL Global Development Group
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -36,6 +36,7 @@
3636
#include"storage/proc.h"
3737
#include"tcop/tcopprot.h"
3838
#include"utils/datetime.h"
39+
#include"pgstat.h"
3940

4041

4142
/* XXX these should be in other modules' header files */
@@ -225,6 +226,12 @@ static struct config_bool
225226
{"show_btree_build_stats",PGC_SUSET,&Show_btree_build_stats, false,NULL},
226227
#endif
227228

229+
{"collect_startcollector",PGC_POSTMASTER,&pgstat_collect_startcollector, true,NULL},
230+
{"collect_resetonpmstart",PGC_POSTMASTER,&pgstat_collect_resetonpmstart, true,NULL},
231+
{"collect_querystring",PGC_SUSET,&pgstat_collect_querystring, false,NULL},
232+
{"collect_tuplelevel",PGC_SUSET,&pgstat_collect_tuplelevel, false,NULL},
233+
{"collect_blocklevel",PGC_SUSET,&pgstat_collect_blocklevel, false,NULL},
234+
228235
{"trace_notify",PGC_USERSET,&Trace_notify, false,NULL},
229236

230237
#ifdefLOCK_DEBUG

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@
149149
#endif
150150

151151

152+
#
153+
#Access statistics collection
154+
#
155+
#collect_startcollector = true
156+
#collect_resetonpmstart = true
157+
#collect_querystring = false
158+
#collect_tuplelevel = false
159+
#collect_blocklevel = false
160+
161+
152162
#
153163
#Lock Tracing
154164
#

‎src/include/pgstat.h

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001, PostgreSQL Global Development Group
77
*
8-
* $Id: pgstat.h,v 1.3 2001/06/29 23:03:02 tgl Exp $
8+
* $Id: pgstat.h,v 1.4 2001/07/05 15:19:40 wieck Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -321,7 +321,15 @@ typedef unionPgStat_Msg
321321
}PgStat_Msg;
322322

323323

324-
324+
/* ----------
325+
* Global variables
326+
* ----------
327+
*/
328+
externboolpgstat_collect_startcollector;
329+
externboolpgstat_collect_resetonpmstart;
330+
externboolpgstat_collect_querystring;
331+
externboolpgstat_collect_tuplelevel;
332+
externboolpgstat_collect_blocklevel;
325333

326334
/* ----------
327335
* Functions called from postmaster
@@ -350,64 +358,66 @@ extern voidpgstat_initstats(PgStat_Info *stats, Relation rel);
350358

351359
#definepgstat_reset_heap_scan(s)\
352360
do {\
353-
if ((s)->tabentry != NULL)\
361+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
354362
(s)->heap_scan_counted = FALSE;\
355363
} while (0)
356364
#definepgstat_count_heap_scan(s)\
357365
do {\
358-
if ((s)->tabentry != NULL && !(s)->heap_scan_counted) {\
366+
if (pgstat_collect_tuplelevel && (s)->tabentry != NULL && \
367+
!(s)->heap_scan_counted) {\
359368
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++;\
360369
(s)->heap_scan_counted = TRUE;\
361370
}\
362371
} while (0)
363372
#definepgstat_count_heap_getnext(s)\
364373
do {\
365-
if ((s)->tabentry != NULL)\
374+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
366375
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++; \
367376
} while (0)
368377
#definepgstat_count_heap_fetch(s)\
369378
do {\
370-
if ((s)->tabentry != NULL)\
379+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
371380
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_fetched++;\
372381
} while (0)
373382
#definepgstat_count_heap_insert(s)\
374383
do {\
375-
if ((s)->tabentry != NULL)\
384+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
376385
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_inserted++; \
377386
} while (0)
378387
#definepgstat_count_heap_update(s)\
379388
do {\
380-
if ((s)->tabentry != NULL)\
389+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
381390
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_updated++;\
382391
} while (0)
383392
#definepgstat_count_heap_delete(s)\
384393
do {\
385-
if ((s)->tabentry != NULL)\
394+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
386395
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_deleted++;\
387396
} while (0)
388397
#definepgstat_reset_index_scan(s)\
389398
do {\
390-
if ((s)->tabentry != NULL)\
399+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
391400
(s)->index_scan_counted = FALSE;\
392401
} while (0)
393402
#definepgstat_count_index_scan(s)\
394403
do {\
395-
if ((s)->tabentry != NULL && !(s)->index_scan_counted) {\
404+
if (pgstat_collect_tuplelevel && (s)->tabentry != NULL && \
405+
!(s)->index_scan_counted) {\
396406
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++;\
397407
(s)->index_scan_counted = TRUE;\
398408
}\
399409
} while (0)
400410
#definepgstat_count_index_getnext(s)\
401411
do {\
402-
if ((s)->tabentry != NULL)\
412+
if (pgstat_collect_tuplelevel &&(s)->tabentry != NULL)\
403413
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++; \
404414
} while (0)
405415
#definepgstat_count_buffer_read(s,r)\
406416
do {\
407-
if ((s)->tabentry != NULL)\
417+
if (pgstat_collect_blocklevel &&(s)->tabentry != NULL)\
408418
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++;\
409419
else {\
410-
if (!(s)->no_stats) {\
420+
if (pgstat_collect_blocklevel &&!(s)->no_stats) {\
411421
pgstat_initstats((s), (r));\
412422
if ((s)->tabentry != NULL)\
413423
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
@@ -416,10 +426,10 @@ extern voidpgstat_initstats(PgStat_Info *stats, Relation rel);
416426
} while (0)
417427
#definepgstat_count_buffer_hit(s,r)\
418428
do {\
419-
if ((s)->tabentry != NULL)\
429+
if (pgstat_collect_blocklevel &&(s)->tabentry != NULL)\
420430
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++;\
421431
else {\
422-
if (!(s)->no_stats) {\
432+
if (pgstat_collect_blocklevel &&!(s)->no_stats) {\
423433
pgstat_initstats((s), (r));\
424434
if ((s)->tabentry != NULL)\
425435
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++; \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp