From 3ccb97b2e453cfba479dbbc48a91c6eff58b443e Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 6 Jan 2010 02:59:46 +0000 Subject: [PATCH] pg_dump --only-analyze Implement pg_dump --only-analyze for use by pg_migrator to only analyze all databases. --- doc/src/sgml/ref/vacuumdb.sgml | 44 +++++++++++++------- src/bin/scripts/vacuumdb.c | 74 ++++++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 37 deletions(-) diff --git a/doc/src/sgml/ref/vacuumdb.sgml b/doc/src/sgml/ref/vacuumdb.sgml index 9fcdb4d2bb..ad6f3a8cf3 100644 --- a/doc/src/sgml/ref/vacuumdb.sgml +++ b/doc/src/sgml/ref/vacuumdb.sgml @@ -1,5 +1,5 @@ @@ -24,9 +24,10 @@ PostgreSQL documentation vacuumdb connection-option --full-f + --freeze-F --verbose-v --analyze-z - --freeze-F + --only-analyze-o --table | -t table ( column [,...] ) @@ -36,9 +37,10 @@ PostgreSQL documentation connection-options --all-a --full-f + --freeze-F --verbose-v --analyze-z - --freeze-F + --only-analyze-o @@ -56,8 +58,9 @@ PostgreSQL documentation vacuumdb is a wrapper around the SQL command . - 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. @@ -116,6 +119,26 @@ PostgreSQL documentation + + + + + + Aggressively freeze tuples. + + + + + + + + + + Only calculate statistics for use by the optimizer (no vacuum). + + + + @@ -133,7 +156,7 @@ PostgreSQL documentation Clean or analyze table only. Column names can be specified only in conjunction with - the option. + the or options. @@ -164,15 +187,6 @@ PostgreSQL documentation - - - - - - Aggressively freeze tuples. - - - diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 2b2398a321..658284da86 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -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 $ * *------------------------------------------------------------------------- */ @@ -14,12 +14,13 @@ #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"));