55 * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
8- * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.28 2010/01/02 16:58:00 momjian Exp $
8+ * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.29 2010/01/06 02:59:46 momjian Exp $
99 *
1010 *-------------------------------------------------------------------------
1111 */
1414#include "common.h"
1515
1616
17- static void vacuum_one_database (const char * dbname , bool full , bool verbose , bool analyze ,
18- bool freeze , const char * table ,
19- const char * host , const char * port ,
17+ static void vacuum_one_database (const char * dbname , bool full , bool verbose ,
18+ bool and_analyze , bool only_analyze , bool freeze ,
19+ const char * table , const char * host , const char * port ,
2020 const char * username , enum trivalue prompt_password ,
2121 const char * progname , bool echo );
22- static void vacuum_all_databases (bool full , bool verbose , bool analyze , bool freeze ,
22+ static void vacuum_all_databases (bool full , bool verbose , bool and_analyze ,
23+ bool only_analyze , bool freeze ,
2324 const char * host , const char * port ,
2425 const char * username , enum trivalue prompt_password ,
2526 const char * progname , bool echo , bool quiet );
@@ -40,6 +41,7 @@ main(int argc, char *argv[])
4041 {"quiet" , no_argument , NULL , 'q' },
4142 {"dbname" , required_argument , NULL , 'd' },
4243 {"analyze" , no_argument , NULL , 'z' },
44+ {"only-analyze" , no_argument , NULL , 'o' },
4345 {"freeze" , no_argument , NULL , 'F' },
4446 {"all" , no_argument , NULL , 'a' },
4547 {"table" , required_argument , NULL , 't' },
@@ -59,7 +61,8 @@ main(int argc, char *argv[])
5961 enum trivalue prompt_password = TRI_DEFAULT ;
6062 bool echo = false;
6163 bool quiet = false;
62- bool analyze = false;
64+ bool and_analyze = false;
65+ bool only_analyze = false;
6366 bool freeze = false;
6467 bool alldb = false;
6568 char * table = NULL ;
@@ -100,7 +103,10 @@ main(int argc, char *argv[])
100103 dbname = optarg ;
101104 break ;
102105 case 'z' :
103- analyze = true;
106+ and_analyze = true;
107+ break ;
108+ case 'o' :
109+ only_analyze = true;
104110 break ;
105111 case 'F' :
106112 freeze = true;
@@ -139,6 +145,23 @@ main(int argc, char *argv[])
139145
140146 setup_cancel_handler ();
141147
148+ if (only_analyze )
149+ {
150+ if (full )
151+ {
152+ fprintf (stderr , _ ("%s: cannot use the \"full\" option when performing only analyze\n" ),
153+ progname );
154+ exit (1 );
155+ }
156+ if (freeze )
157+ {
158+ fprintf (stderr , _ ("%s: cannot use the \"freeze\" option when performing only analyze\n" ),
159+ progname );
160+ exit (1 );
161+ }
162+ /* ignore 'and_analyze' */
163+ }
164+
142165 if (alldb )
143166 {
144167 if (dbname )
@@ -154,7 +177,7 @@ main(int argc, char *argv[])
154177 exit (1 );
155178 }
156179
157- vacuum_all_databases (full , verbose , analyze , freeze ,
180+ vacuum_all_databases (full , verbose , and_analyze , only_analyze , freeze ,
158181 host , port , username , prompt_password ,
159182 progname , echo , quiet );
160183 }
@@ -170,7 +193,8 @@ main(int argc, char *argv[])
170193 dbname = get_user_name (progname );
171194 }
172195
173- vacuum_one_database (dbname , full , verbose , analyze , freeze , table ,
196+ vacuum_one_database (dbname , full , verbose , and_analyze , only_analyze ,
197+ freeze , table ,
174198 host , port , username , prompt_password ,
175199 progname , echo );
176200 }
@@ -180,8 +204,8 @@ main(int argc, char *argv[])
180204
181205
182206static void
183- vacuum_one_database (const char * dbname , bool full , bool verbose , bool analyze ,
184- bool freeze , const char * table ,
207+ vacuum_one_database (const char * dbname , bool full , bool verbose , bool and_analyze ,
208+ bool only_analyze , bool freeze , const char * table ,
185209 const char * host , const char * port ,
186210 const char * username , enum trivalue prompt_password ,
187211 const char * progname , bool echo )
@@ -192,15 +216,20 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
192216
193217 initPQExpBuffer (& sql );
194218
195- appendPQExpBuffer (& sql , "VACUUM" );
196- if (full )
197- appendPQExpBuffer (& sql , " FULL" );
198- if (freeze )
199- appendPQExpBuffer (& sql , " FREEZE" );
219+ if (only_analyze )
220+ appendPQExpBuffer (& sql , "ANALYZE" );
221+ else
222+ {
223+ appendPQExpBuffer (& sql , "VACUUM" );
224+ if (full )
225+ appendPQExpBuffer (& sql , " FULL" );
226+ if (freeze )
227+ appendPQExpBuffer (& sql , " FREEZE" );
228+ if (and_analyze )
229+ appendPQExpBuffer (& sql , " ANALYZE" );
230+ }
200231 if (verbose )
201232 appendPQExpBuffer (& sql , " VERBOSE" );
202- if (analyze )
203- appendPQExpBuffer (& sql , " ANALYZE" );
204233 if (table )
205234 appendPQExpBuffer (& sql , " %s" , table );
206235 appendPQExpBuffer (& sql , ";\n" );
@@ -223,8 +252,8 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
223252
224253
225254static void
226- vacuum_all_databases (bool full , bool verbose , bool analyze , bool freeze ,
227- const char * host , const char * port ,
255+ vacuum_all_databases (bool full , bool verbose , bool and_analyze , bool only_analyze ,
256+ bool freeze , const char * host , const char * port ,
228257 const char * username , enum trivalue prompt_password ,
229258 const char * progname , bool echo , bool quiet )
230259{
@@ -246,8 +275,8 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
246275 fflush (stdout );
247276 }
248277
249- vacuum_one_database (dbname , full , verbose , analyze , freeze , NULL ,
250- host , port , username , prompt_password ,
278+ vacuum_one_database (dbname , full , verbose , and_analyze , only_analyze ,
279+ freeze , NULL , host , port , username , prompt_password ,
251280 progname , echo );
252281 }
253282
@@ -267,6 +296,7 @@ help(const char *progname)
267296 printf (_ (" -e, --echo show the commands being sent to the server\n" ));
268297 printf (_ (" -f, --full do full vacuuming\n" ));
269298 printf (_ (" -F, --freeze freeze row transaction information\n" ));
299+ printf (_ (" -o, --only-analyze only update optimizer hints\n" ));
270300 printf (_ (" -q, --quiet don't write any messages\n" ));
271301 printf (_ (" -t, --table='TABLE[(COLUMNS)]' vacuum specific table only\n" ));
272302 printf (_ (" -v, --verbose write a lot of output\n" ));
0 commit comments