Commit 3ccb97b2 authored by Bruce Momjian's avatar Bruce Momjian

pg_dump --only-analyze

Implement pg_dump --only-analyze for use by pg_migrator to only analyze
all databases.
parent 8cdb85b5
<!-- <!--
$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 PostgreSQL documentation
--> -->
...@@ -24,9 +24,10 @@ PostgreSQL documentation ...@@ -24,9 +24,10 @@ PostgreSQL documentation
<command>vacuumdb</command> <command>vacuumdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<group><arg>--full</arg><arg>-f</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>--verbose</arg><arg>-v</arg></group>
<group><arg>--analyze</arg><arg>-z</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>--table | -t <replaceable>table</replaceable>
<arg>( <replaceable class="parameter">column</replaceable> [,...] )</arg> <arg>( <replaceable class="parameter">column</replaceable> [,...] )</arg>
</arg> </arg>
...@@ -36,9 +37,10 @@ PostgreSQL documentation ...@@ -36,9 +37,10 @@ PostgreSQL documentation
<arg rep="repeat"><replaceable>connection-options</replaceable></arg> <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
<group><arg>--all</arg><arg>-a</arg></group> <group><arg>--all</arg><arg>-a</arg></group>
<group><arg>--full</arg><arg>-f</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>--verbose</arg><arg>-v</arg></group>
<group><arg>--analyze</arg><arg>-z</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> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -56,8 +58,9 @@ PostgreSQL documentation ...@@ -56,8 +58,9 @@ PostgreSQL documentation
<para> <para>
<application>vacuumdb</application> is a wrapper around the SQL <application>vacuumdb</application> is a wrapper around the SQL
command <xref linkend="SQL-VACUUM" endterm="SQL-VACUUM-title">. command <xref linkend="SQL-VACUUM" endterm="SQL-VACUUM-title">.
There is no effective difference between vacuuming databases via There is no effective difference between vacuuming and analyzing
this utility and via other methods for accessing the server. databases via this utility and via other methods for accessing the
server.
</para> </para>
</refsect1> </refsect1>
...@@ -116,6 +119,26 @@ PostgreSQL documentation ...@@ -116,6 +119,26 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </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> <varlistentry>
<term><option>-q</></term> <term><option>-q</></term>
<term><option>--quiet</></term> <term><option>--quiet</></term>
...@@ -133,7 +156,7 @@ PostgreSQL documentation ...@@ -133,7 +156,7 @@ PostgreSQL documentation
<para> <para>
Clean or analyze <replaceable class="parameter">table</replaceable> only. Clean or analyze <replaceable class="parameter">table</replaceable> only.
Column names can be specified only in conjunction with 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> </para>
<tip> <tip>
<para> <para>
...@@ -164,15 +187,6 @@ PostgreSQL documentation ...@@ -164,15 +187,6 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-F</option></term>
<term><option>--freeze</option></term>
<listitem>
<para>
Aggressively <quote>freeze</quote> tuples.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -14,12 +14,13 @@ ...@@ -14,12 +14,13 @@
#include "common.h" #include "common.h"
static void vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze, static void vacuum_one_database(const char *dbname, bool full, bool verbose,
bool freeze, const char *table, bool and_analyze, bool only_analyze, bool freeze,
const char *host, const char *port, const char *table, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo); 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 *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet); const char *progname, bool echo, bool quiet);
...@@ -40,6 +41,7 @@ main(int argc, char *argv[]) ...@@ -40,6 +41,7 @@ main(int argc, char *argv[])
{"quiet", no_argument, NULL, 'q'}, {"quiet", no_argument, NULL, 'q'},
{"dbname", required_argument, NULL, 'd'}, {"dbname", required_argument, NULL, 'd'},
{"analyze", no_argument, NULL, 'z'}, {"analyze", no_argument, NULL, 'z'},
{"only-analyze", no_argument, NULL, 'o'},
{"freeze", no_argument, NULL, 'F'}, {"freeze", no_argument, NULL, 'F'},
{"all", no_argument, NULL, 'a'}, {"all", no_argument, NULL, 'a'},
{"table", required_argument, NULL, 't'}, {"table", required_argument, NULL, 't'},
...@@ -59,7 +61,8 @@ main(int argc, char *argv[]) ...@@ -59,7 +61,8 @@ main(int argc, char *argv[])
enum trivalue prompt_password = TRI_DEFAULT; enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false; bool echo = false;
bool quiet = false; bool quiet = false;
bool analyze = false; bool and_analyze = false;
bool only_analyze = false;
bool freeze = false; bool freeze = false;
bool alldb = false; bool alldb = false;
char *table = NULL; char *table = NULL;
...@@ -100,7 +103,10 @@ main(int argc, char *argv[]) ...@@ -100,7 +103,10 @@ main(int argc, char *argv[])
dbname = optarg; dbname = optarg;
break; break;
case 'z': case 'z':
analyze = true; and_analyze = true;
break;
case 'o':
only_analyze = true;
break; break;
case 'F': case 'F':
freeze = true; freeze = true;
...@@ -139,6 +145,23 @@ main(int argc, char *argv[]) ...@@ -139,6 +145,23 @@ main(int argc, char *argv[])
setup_cancel_handler(); 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 (alldb)
{ {
if (dbname) if (dbname)
...@@ -154,7 +177,7 @@ main(int argc, char *argv[]) ...@@ -154,7 +177,7 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
vacuum_all_databases(full, verbose, analyze, freeze, vacuum_all_databases(full, verbose, and_analyze, only_analyze, freeze,
host, port, username, prompt_password, host, port, username, prompt_password,
progname, echo, quiet); progname, echo, quiet);
} }
...@@ -170,7 +193,8 @@ main(int argc, char *argv[]) ...@@ -170,7 +193,8 @@ main(int argc, char *argv[])
dbname = get_user_name(progname); 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, host, port, username, prompt_password,
progname, echo); progname, echo);
} }
...@@ -180,8 +204,8 @@ main(int argc, char *argv[]) ...@@ -180,8 +204,8 @@ main(int argc, char *argv[])
static void static void
vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze, vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyze,
bool freeze, const char *table, bool only_analyze, bool freeze, const char *table,
const char *host, const char *port, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo) const char *progname, bool echo)
...@@ -192,15 +216,20 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze, ...@@ -192,15 +216,20 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
initPQExpBuffer(&sql); initPQExpBuffer(&sql);
if (only_analyze)
appendPQExpBuffer(&sql, "ANALYZE");
else
{
appendPQExpBuffer(&sql, "VACUUM"); appendPQExpBuffer(&sql, "VACUUM");
if (full) if (full)
appendPQExpBuffer(&sql, " FULL"); appendPQExpBuffer(&sql, " FULL");
if (freeze) if (freeze)
appendPQExpBuffer(&sql, " FREEZE"); appendPQExpBuffer(&sql, " FREEZE");
if (and_analyze)
appendPQExpBuffer(&sql, " ANALYZE");
}
if (verbose) if (verbose)
appendPQExpBuffer(&sql, " VERBOSE"); appendPQExpBuffer(&sql, " VERBOSE");
if (analyze)
appendPQExpBuffer(&sql, " ANALYZE");
if (table) if (table)
appendPQExpBuffer(&sql, " %s", table); appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBuffer(&sql, ";\n");
...@@ -223,8 +252,8 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze, ...@@ -223,8 +252,8 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
static void static void
vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze, vacuum_all_databases(bool full, bool verbose, bool and_analyze, bool only_analyze,
const char *host, const char *port, bool freeze, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet) const char *progname, bool echo, bool quiet)
{ {
...@@ -246,8 +275,8 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze, ...@@ -246,8 +275,8 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
fflush(stdout); fflush(stdout);
} }
vacuum_one_database(dbname, full, verbose, analyze, freeze, NULL, vacuum_one_database(dbname, full, verbose, and_analyze, only_analyze,
host, port, username, prompt_password, freeze, NULL, host, port, username, prompt_password,
progname, echo); progname, echo);
} }
...@@ -267,6 +296,7 @@ help(const char *progname) ...@@ -267,6 +296,7 @@ help(const char *progname)
printf(_(" -e, --echo show the commands being sent to the server\n")); printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -f, --full do full vacuuming\n")); printf(_(" -f, --full do full vacuuming\n"));
printf(_(" -F, --freeze freeze row transaction information\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(_(" -q, --quiet don't write any messages\n"));
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table only\n")); printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table only\n"));
printf(_(" -v, --verbose write a lot of output\n")); printf(_(" -v, --verbose write a lot of output\n"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment