Added GUC configuration options to control access statistics.
authorJan Wieck <[email protected]>
Thu, 5 Jul 2001 15:19:40 +0000 (15:19 +0000)
committerJan Wieck <[email protected]>
Thu, 5 Jul 2001 15:19:40 +0000 (15:19 +0000)
Jan

src/backend/postmaster/pgstat.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/include/pgstat.h

index 9332b7368ec8446000ba493e0b1f8b8e08a67870..8efda5c90ff04c4a91d60753682ed1c90243c42a 100644 (file)
  *                       thus an initdb and we might want to provide this as a
  *                       patch for 7.1.
  *
- *                     - Make the functions from contrib/pgstat_tmp builtin
- *                       and create the views on initdb.
- *
  *     Copyright (c) 2001, PostgreSQL Global Development Group
  *
- *     $Id: pgstat.c,v 1.3 2001/06/30 19:01:27 petere Exp $
+ *     $Id: pgstat.c,v 1.4 2001/07/05 15:19:40 wieck Exp $
  * ----------
  */
 #include "postgres.h"
  * Global data
  * ----------
  */
-
+bool   pgstat_collect_startcollector   = true;
+bool   pgstat_collect_resetonpmstart   = true;
+bool   pgstat_collect_querystring              = false;
+bool   pgstat_collect_tuplelevel               = false;
+bool   pgstat_collect_blocklevel               = false;
 
 /* ----------
  * Local data
@@ -135,6 +136,13 @@ pgstat_init(void)
 {
        int                     alen;
 
+       /*
+        * Force start of collector daemon if something to collect
+        */
+       if (pgstat_collect_querystring || pgstat_collect_tuplelevel ||
+                               pgstat_collect_blocklevel)
+               pgstat_collect_startcollector = true;
+
        /*
         * Initialize the filenames for the status reports.
         */
@@ -143,6 +151,20 @@ pgstat_init(void)
        snprintf(pgStat_fname, MAXPGPATH, 
                                PGSTAT_STAT_FILENAME, DataDir);
 
+       /*
+        * If we don't have to start a collector or should reset the
+        * collected statistics on postmaster start, simply remove the
+        * file.
+        */
+       if (!pgstat_collect_startcollector || pgstat_collect_resetonpmstart)
+               unlink(pgStat_fname);
+
+       /*
+        * Nothing else required if collector will not get started
+        */
+       if (!pgstat_collect_startcollector)
+               return 0;
+
        /*
         * Create the UDP socket for receiving statistic messages
         */
@@ -211,6 +233,12 @@ pgstat_init(void)
 int
 pgstat_start(void)
 {
+       /*
+        * Do nothing if no collector needed
+        */
+       if (!pgstat_collect_startcollector)
+               return 0;
+
        /*
         * Check that the socket at least is there
         */
@@ -275,6 +303,9 @@ pgstat_beterm(int pid)
 {
        PgStat_MsgBeterm                msg;
 
+       if (!pgstat_collect_startcollector)
+               return;
+
        msg.m_hdr.m_type                = PGSTAT_MTYPE_BETERM;
        msg.m_hdr.m_backendid   = 0;
        msg.m_hdr.m_procpid             = pid;
@@ -302,7 +333,7 @@ pgstat_bestart(void)
 {
        PgStat_MsgBestart               msg;
 
-       if (pgStatSock < 0)
+       if (!pgstat_collect_startcollector || pgStatSock < 0)
                return;
 
        pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
@@ -324,7 +355,7 @@ pgstat_report_activity(char *what)
        PgStat_MsgActivity      msg;
        int                                             len;
 
-       if (pgStatSock < 0)
+       if (!pgstat_collect_querystring || pgStatSock < 0)
                return;
 
        len = strlen(what);
@@ -354,6 +385,10 @@ pgstat_report_tabstat(void)
        int                             n;
        int                             len;
 
+       if (!pgstat_collect_querystring && !pgstat_collect_tuplelevel &&
+                       !pgstat_collect_blocklevel)
+               return;
+
        if (pgStatSock < 0)
                return;
 
@@ -654,7 +689,7 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
        stats->heap_scan_counted        = FALSE;
        stats->index_scan_counted       = FALSE;
 
-       if (pgStatSock < 0)
+       if (!pgstat_collect_startcollector || pgStatSock < 0)
        {
                stats->no_stats = TRUE;
                return;
@@ -764,6 +799,10 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
 void
 pgstat_count_xact_commit(void)
 {
+       if (!pgstat_collect_querystring && !pgstat_collect_tuplelevel &&
+                       !pgstat_collect_blocklevel)
+               return;
+
        pgStatXactCommit++;
 
        /*
@@ -791,6 +830,10 @@ pgstat_count_xact_commit(void)
 void
 pgstat_count_xact_rollback(void)
 {
+       if (!pgstat_collect_querystring && !pgstat_collect_tuplelevel &&
+                       !pgstat_collect_blocklevel)
+               return;
+
        pgStatXactRollback++;
 
        /*
index 96dc8399e1c4fce51444c9cb6198d1cb65346c14..cc666047815b10dc82d19c279e7fb1598f0709ae 100644 (file)
@@ -4,7 +4,7 @@
  * Support for grand unified configuration scheme, including SET
  * command, configuration file, and command line options.
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.44 2001/06/30 22:03:26 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.45 2001/07/05 15:19:40 wieck Exp $
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  * Written by Peter Eisentraut <[email protected]>.
@@ -36,6 +36,7 @@
 #include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/datetime.h"
+#include "pgstat.h"
 
 
 /* XXX these should be in other modules' header files */
@@ -225,6 +226,12 @@ static struct config_bool
        {"show_btree_build_stats", PGC_SUSET, &Show_btree_build_stats, false, NULL},
 #endif
 
+       {"collect_startcollector", PGC_POSTMASTER, &pgstat_collect_startcollector, true, NULL},
+       {"collect_resetonpmstart", PGC_POSTMASTER, &pgstat_collect_resetonpmstart, true, NULL},
+       {"collect_querystring", PGC_SUSET, &pgstat_collect_querystring, false, NULL},
+       {"collect_tuplelevel", PGC_SUSET, &pgstat_collect_tuplelevel, false, NULL},
+       {"collect_blocklevel", PGC_SUSET, &pgstat_collect_blocklevel, false, NULL},
+
        {"trace_notify", PGC_USERSET, &Trace_notify, false, NULL},
 
 #ifdef LOCK_DEBUG
index fad01e7f32efd2c8d6a28018f25c00f5a9acd8ec..6b25bbca6c6160a5d3f01c68cd89767a8e357896 100644 (file)
 #endif
 
 
+#
+#      Access statistics collection
+#
+#collect_startcollector = true
+#collect_resetonpmstart = true
+#collect_querystring = false
+#collect_tuplelevel = false
+#collect_blocklevel = false
+
+
 #
 #      Lock Tracing
 #
index 5bea15c4577cc53e7169497f375e472069605e0f..51bb00dc16bf3112591e4ba747d02239c8243060 100644 (file)
@@ -5,7 +5,7 @@
  *
  *     Copyright (c) 2001, PostgreSQL Global Development Group
  *
- *  $Id: pgstat.h,v 1.3 2001/06/29 23:03:02 tgl Exp $
+ *  $Id: pgstat.h,v 1.4 2001/07/05 15:19:40 wieck Exp $
  * ----------
  */
 #ifndef PGSTAT_H
@@ -321,7 +321,15 @@ typedef union      PgStat_Msg
 } PgStat_Msg;
 
 
-
+/* ----------
+ * Global variables
+ * ----------
+ */
+extern bool            pgstat_collect_startcollector;
+extern bool            pgstat_collect_resetonpmstart;
+extern bool            pgstat_collect_querystring;
+extern bool            pgstat_collect_tuplelevel;
+extern bool            pgstat_collect_blocklevel;
 
 /* ----------
  * Functions called from postmaster
@@ -350,64 +358,66 @@ extern void               pgstat_initstats(PgStat_Info *stats, Relation rel);
 
 #define pgstat_reset_heap_scan(s)                                                                              \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        (s)->heap_scan_counted = FALSE;                                                         \
        } while (0)
 #define pgstat_count_heap_scan(s)                                                                              \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL && !(s)->heap_scan_counted) {                 \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL &&               \
+                               !(s)->heap_scan_counted) {                                                              \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_numscans++;           \
                        (s)->heap_scan_counted = TRUE;                                                          \
                }                                                                                                                               \
        } while (0)
 #define pgstat_count_heap_getnext(s)                                                                   \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++; \
        } while (0)
 #define pgstat_count_heap_fetch(s)                                                                             \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_tuples_fetched++;     \
        } while (0)
 #define pgstat_count_heap_insert(s)                                                                            \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_tuples_inserted++; \
        } while (0)
 #define pgstat_count_heap_update(s)                                                                            \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_tuples_updated++;     \
        } while (0)
 #define pgstat_count_heap_delete(s)                                                                            \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_tuples_deleted++;     \
        } while (0)
 #define pgstat_reset_index_scan(s)                                                                             \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        (s)->index_scan_counted = FALSE;                                                        \
        } while (0)
 #define pgstat_count_index_scan(s)                                                                             \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL && !(s)->index_scan_counted) {                \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL &&               \
+                               !(s)->index_scan_counted) {                                                             \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_numscans++;           \
                        (s)->index_scan_counted = TRUE;                                                         \
                }                                                                                                                               \
        } while (0)
 #define pgstat_count_index_getnext(s)                                                                  \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_tuplelevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++; \
        } while (0)
 #define pgstat_count_buffer_read(s,r)                                                                  \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_blocklevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++;     \
                else {                                                                                                                  \
-                       if (!(s)->no_stats) {                                                                           \
+                       if (pgstat_collect_blocklevel && !(s)->no_stats) {                      \
                                pgstat_initstats((s), (r));                                                             \
                                if ((s)->tabentry != NULL)                                                              \
                                        ((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
@@ -416,10 +426,10 @@ extern void               pgstat_initstats(PgStat_Info *stats, Relation rel);
        } while (0)
 #define pgstat_count_buffer_hit(s,r)                                                                   \
        do {                                                                                                                            \
-               if ((s)->tabentry != NULL)                                                                              \
+               if (pgstat_collect_blocklevel && (s)->tabentry != NULL)                 \
                        ((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++;         \
                else {                                                                                                                  \
-                       if (!(s)->no_stats) {                                                                           \
+                       if (pgstat_collect_blocklevel && !(s)->no_stats) {                      \
                                pgstat_initstats((s), (r));                                                             \
                                if ((s)->tabentry != NULL)                                                              \
                                        ((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++; \