]> granicus.if.org Git - postgresql/commitdiff
pg_dump --only-analyze
authorBruce Momjian <bruce@momjian.us>
Wed, 6 Jan 2010 02:59:46 +0000 (02:59 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 6 Jan 2010 02:59:46 +0000 (02:59 +0000)
Implement pg_dump --only-analyze for use by pg_migrator to only analyze
all databases.

doc/src/sgml/ref/vacuumdb.sgml
src/bin/scripts/vacuumdb.c

index 9fcdb4d2bba3451f8dde1063686e8364bda72f9e..ad6f3a8cf3d29a155c36375d7c2af46003cede24 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.45 2009/11/27 17:41:26 momjian Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.46 2010/01/06 02:59:44 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -24,9 +24,10 @@ PostgreSQL documentation
    <command>vacuumdb</command>
    <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
    <group><arg>--full</arg><arg>-f</arg></group>
+   <group><arg>--freeze</arg><arg>-F</arg></group>
    <group><arg>--verbose</arg><arg>-v</arg></group>
    <group><arg>--analyze</arg><arg>-z</arg></group>
-   <group><arg>--freeze</arg><arg>-F</arg></group>
+   <group><arg>--only-analyze</arg><arg>-o</arg></group>
    <arg>--table | -t <replaceable>table</replaceable>
     <arg>( <replaceable class="parameter">column</replaceable> [,...] )</arg>
    </arg>
@@ -36,9 +37,10 @@ PostgreSQL documentation
    <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
    <group><arg>--all</arg><arg>-a</arg></group>
    <group><arg>--full</arg><arg>-f</arg></group>
+   <group><arg>--freeze</arg><arg>-F</arg></group>
    <group><arg>--verbose</arg><arg>-v</arg></group>
    <group><arg>--analyze</arg><arg>-z</arg></group>
-   <group><arg>--freeze</arg><arg>-F</arg></group>
+   <group><arg>--only-analyze</arg><arg>-o</arg></group>
   </cmdsynopsis>
  </refsynopsisdiv>
  
@@ -56,8 +58,9 @@ PostgreSQL documentation
   <para>
    <application>vacuumdb</application> is a wrapper around the SQL
    command <xref linkend="SQL-VACUUM" endterm="SQL-VACUUM-title">.
-   There is no effective difference between vacuuming databases via
-   this utility and via other methods for accessing the server.
+   There is no effective difference between vacuuming and analyzing 
+   databases via this utility and via other methods for accessing the 
+   server.
   </para>
 
  </refsect1>
@@ -116,6 +119,26 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-F</option></term>
+      <term><option>--freeze</option></term>
+      <listitem>
+       <para>
+        Aggressively <quote>freeze</quote> tuples.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
+      <term><option>-o</option></term>
+      <term><option>--only-analyze</option></term>
+      <listitem>
+       <para>
+        Only calculate statistics for use by the optimizer (no vacuum).
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-q</></term>
       <term><option>--quiet</></term>
@@ -133,7 +156,7 @@ PostgreSQL documentation
        <para>
         Clean or analyze <replaceable class="parameter">table</replaceable> only.
         Column names can be specified only in conjunction with
-        the <option>--analyze</option> option.
+        the <option>--analyze</option> or <option>--only-analyze</option> options.
        </para>
        <tip>
         <para>
@@ -164,15 +187,6 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
-     <varlistentry>
-      <term><option>-F</option></term>
-      <term><option>--freeze</option></term>
-      <listitem>
-       <para>
-        Aggressively <quote>freeze</quote> tuples.
-       </para>
-      </listitem>
-     </varlistentry>
     </variablelist>
    </para>
 
index 2b2398a3210e898ebfa2c3ef3a1b5bb41f3bb0cf..658284da8608a3c43dc189ed27f0f7be0bb544f8 100644 (file)
@@ -5,7 +5,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.28 2010/01/02 16:58:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.29 2010/01/06 02:59:46 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "common.h"
 
 
-static void vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
-                                       bool freeze, const char *table,
-                                       const char *host, const char *port,
+static void vacuum_one_database(const char *dbname, bool full, bool verbose,
+                                       bool and_analyze, bool only_analyze, bool freeze,
+                                       const char *table, const char *host, const char *port,
                                        const char *username, enum trivalue prompt_password,
                                        const char *progname, bool echo);
-static void vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
+static void vacuum_all_databases(bool full, bool verbose, bool and_analyze,
+                                        bool only_analyze, bool freeze,
                                         const char *host, const char *port,
                                         const char *username, enum trivalue prompt_password,
                                         const char *progname, bool echo, bool quiet);
@@ -40,6 +41,7 @@ main(int argc, char *argv[])
                {"quiet", no_argument, NULL, 'q'},
                {"dbname", required_argument, NULL, 'd'},
                {"analyze", no_argument, NULL, 'z'},
+               {"only-analyze", no_argument, NULL, 'o'},
                {"freeze", no_argument, NULL, 'F'},
                {"all", no_argument, NULL, 'a'},
                {"table", required_argument, NULL, 't'},
@@ -59,7 +61,8 @@ main(int argc, char *argv[])
        enum trivalue prompt_password = TRI_DEFAULT;
        bool            echo = false;
        bool            quiet = false;
-       bool            analyze = false;
+       bool            and_analyze = false;
+       bool            only_analyze = false;
        bool            freeze = false;
        bool            alldb = false;
        char       *table = NULL;
@@ -100,7 +103,10 @@ main(int argc, char *argv[])
                                dbname = optarg;
                                break;
                        case 'z':
-                               analyze = true;
+                               and_analyze = true;
+                               break;
+                       case 'o':
+                               only_analyze = true;
                                break;
                        case 'F':
                                freeze = true;
@@ -139,6 +145,23 @@ main(int argc, char *argv[])
 
        setup_cancel_handler();
 
+       if (only_analyze)
+       {
+               if (full)
+               {
+                       fprintf(stderr, _("%s: cannot use the \"full\" option when performing only analyze\n"),
+                                       progname);
+                       exit(1);
+               }
+               if (freeze)
+               {
+                       fprintf(stderr, _("%s: cannot use the \"freeze\" option when performing only analyze\n"),
+                                       progname);
+                       exit(1);
+               }
+               /* ignore 'and_analyze' */
+       }
+
        if (alldb)
        {
                if (dbname)
@@ -154,7 +177,7 @@ main(int argc, char *argv[])
                        exit(1);
                }
 
-               vacuum_all_databases(full, verbose, analyze, freeze,
+               vacuum_all_databases(full, verbose, and_analyze, only_analyze, freeze,
                                                         host, port, username, prompt_password,
                                                         progname, echo, quiet);
        }
@@ -170,7 +193,8 @@ main(int argc, char *argv[])
                                dbname = get_user_name(progname);
                }
 
-               vacuum_one_database(dbname, full, verbose, analyze, freeze, table,
+               vacuum_one_database(dbname, full, verbose, and_analyze, only_analyze,
+                                                       freeze, table,
                                                        host, port, username, prompt_password,
                                                        progname, echo);
        }
@@ -180,8 +204,8 @@ main(int argc, char *argv[])
 
 
 static void
-vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
-                                       bool freeze, const char *table,
+vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyze,
+                                       bool only_analyze, bool freeze, const char *table,
                                        const char *host, const char *port,
                                        const char *username, enum trivalue prompt_password,
                                        const char *progname, bool echo)
@@ -192,15 +216,20 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
 
        initPQExpBuffer(&sql);
 
-       appendPQExpBuffer(&sql, "VACUUM");
-       if (full)
-               appendPQExpBuffer(&sql, " FULL");
-       if (freeze)
-               appendPQExpBuffer(&sql, " FREEZE");
+       if (only_analyze)
+               appendPQExpBuffer(&sql, "ANALYZE");
+       else
+       {
+               appendPQExpBuffer(&sql, "VACUUM");
+               if (full)
+                       appendPQExpBuffer(&sql, " FULL");
+               if (freeze)
+                       appendPQExpBuffer(&sql, " FREEZE");
+               if (and_analyze)
+                       appendPQExpBuffer(&sql, " ANALYZE");
+       }
        if (verbose)
                appendPQExpBuffer(&sql, " VERBOSE");
-       if (analyze)
-               appendPQExpBuffer(&sql, " ANALYZE");
        if (table)
                appendPQExpBuffer(&sql, " %s", table);
        appendPQExpBuffer(&sql, ";\n");
@@ -223,8 +252,8 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
 
 
 static void
-vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
-                                        const char *host, const char *port,
+vacuum_all_databases(bool full, bool verbose, bool and_analyze, bool only_analyze,
+                                        bool freeze, const char *host, const char *port,
                                         const char *username, enum trivalue prompt_password,
                                         const char *progname, bool echo, bool quiet)
 {
@@ -246,8 +275,8 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
                        fflush(stdout);
                }
 
-               vacuum_one_database(dbname, full, verbose, analyze, freeze, NULL,
-                                                       host, port, username, prompt_password,
+               vacuum_one_database(dbname, full, verbose, and_analyze, only_analyze,
+                                                       freeze, NULL, host, port, username, prompt_password,
                                                        progname, echo);
        }
 
@@ -267,6 +296,7 @@ help(const char *progname)
        printf(_("  -e, --echo                      show the commands being sent to the server\n"));
        printf(_("  -f, --full                      do full vacuuming\n"));
        printf(_("  -F, --freeze                    freeze row transaction information\n"));
+       printf(_("  -o, --only-analyze              only update optimizer hints\n"));
        printf(_("  -q, --quiet                     don't write any messages\n"));
        printf(_("  -t, --table='TABLE[(COLUMNS)]'  vacuum specific table only\n"));
        printf(_("  -v, --verbose                   write a lot of output\n"));