New pg_dump patch, --no-stats flag, disables sending to statistics collector - Mailing list pgsql-hackers

From Bryce Nesbitt
Subject New pg_dump patch, --no-stats flag, disables sending to statistics collector
Date
Msg-id 49763C47.7070400@obviously.com
Whole thread Raw
In response to Re: [PATCHES] GIN improvements  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: New pg_dump patch, --no-stats flag, disables sending to statistics collector  ("Jaime Casanova" <jcasanov@systemguards.com.ec>)
Re: New pg_dump patch, --no-stats flag, disables sending to statistics collector  (Greg Smith <gsmith@gregsmith.com>)
List pgsql-hackers
This patch adds another flag to pg_dump, this time to disable statistics
collection.  This is useful if your don't want pg_dump activity to show
(or clutter) your normal statistics.  This may be appropriate for an
organization that regularly dumps a database for backup purposes, but
wants to analyze only the application's database use.

This is patched against CVS HEAD from today, though the code is quite
version independent.  This patch is unsolicited, and as far as I know
has not been discussed on the list prior to now.

Comments?

Index: pg_dump.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.514
diff -c -2 -r1.514 pg_dump.c
*** pg_dump.c    18 Jan 2009 20:44:45 -0000    1.514
--- pg_dump.c    20 Jan 2009 20:47:25 -0000
***************
*** 236,239 ****
--- 236,240 ----
      static int  outputNoTablespaces = 0;
      static int    use_setsessauth = 0;
+     static int  noStatsCollection = 0;

      static struct option long_options[] = {
***************
*** 278,281 ****
--- 279,283 ----
          {"role", required_argument, NULL, 3},
          {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+         {"no-stats", no_argument, &noStatsCollection, 1},

          {NULL, 0, NULL, 0}
***************
*** 430,433 ****
--- 432,437 ----
                  else if (strcmp(optarg, "no-tablespaces") == 0)
                      outputNoTablespaces = 1;
+                 else if (strcmp(optarg, "no-stats") == 0)
+                     noStatsCollection = 1;
                  else if (strcmp(optarg, "use-set-session-authorization") == 0)
                      use_setsessauth = 1;
***************
*** 613,616 ****
--- 617,629 ----
          do_sql_command(g_conn, "SET statement_timeout = 0");

+    /*
+     * Disable collection of statistics.  pg_dump's activity may be very different
+     * from what you are trying to analyze in the stats tables.
+     */
+     if( noStatsCollection ) {
+         do_sql_command(g_conn, "SET stats_block_level = false");
+         do_sql_command(g_conn, "SET stats_row_level   = false");
+     }
+
      /*
       * Start serializable transaction to dump consistent data.
***************
*** 833,836 ****
--- 846,850 ----
      printf(_("  -U, --username=NAME      connect as specified database user\n"));
      printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+     printf(_("  --no-stats               disable statistics collection (superuser only)\n"));

      printf(_("\nIf no database name is supplied, then the PGDATABASE environment\n"

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Visibility map and freezing
Next
From: "Jaime Casanova"
Date:
Subject: Re: New pg_dump patch, --no-stats flag, disables sending to statistics collector