5
5
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
6
6
* Portions Copyright (c) 1994, Regents of the University of California
7
7
*
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 $
9
9
*
10
10
*-------------------------------------------------------------------------
11
11
*/
14
14
#include "common.h"
15
15
16
16
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 ,
20
20
const char * username , enum trivalue prompt_password ,
21
21
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 ,
23
24
const char * host , const char * port ,
24
25
const char * username , enum trivalue prompt_password ,
25
26
const char * progname , bool echo , bool quiet );
@@ -40,6 +41,7 @@ main(int argc, char *argv[])
40
41
{"quiet" , no_argument , NULL , 'q' },
41
42
{"dbname" , required_argument , NULL , 'd' },
42
43
{"analyze" , no_argument , NULL , 'z' },
44
+ {"only-analyze" , no_argument , NULL , 'o' },
43
45
{"freeze" , no_argument , NULL , 'F' },
44
46
{"all" , no_argument , NULL , 'a' },
45
47
{"table" , required_argument , NULL , 't' },
@@ -59,7 +61,8 @@ main(int argc, char *argv[])
59
61
enum trivalue prompt_password = TRI_DEFAULT ;
60
62
bool echo = false;
61
63
bool quiet = false;
62
- bool analyze = false;
64
+ bool and_analyze = false;
65
+ bool only_analyze = false;
63
66
bool freeze = false;
64
67
bool alldb = false;
65
68
char * table = NULL ;
@@ -100,7 +103,10 @@ main(int argc, char *argv[])
100
103
dbname = optarg ;
101
104
break ;
102
105
case 'z' :
103
- analyze = true;
106
+ and_analyze = true;
107
+ break ;
108
+ case 'o' :
109
+ only_analyze = true;
104
110
break ;
105
111
case 'F' :
106
112
freeze = true;
@@ -139,6 +145,23 @@ main(int argc, char *argv[])
139
145
140
146
setup_cancel_handler ();
141
147
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
+
142
165
if (alldb )
143
166
{
144
167
if (dbname )
@@ -154,7 +177,7 @@ main(int argc, char *argv[])
154
177
exit (1 );
155
178
}
156
179
157
- vacuum_all_databases (full , verbose , analyze , freeze ,
180
+ vacuum_all_databases (full , verbose , and_analyze , only_analyze , freeze ,
158
181
host , port , username , prompt_password ,
159
182
progname , echo , quiet );
160
183
}
@@ -170,7 +193,8 @@ main(int argc, char *argv[])
170
193
dbname = get_user_name (progname );
171
194
}
172
195
173
- vacuum_one_database (dbname , full , verbose , analyze , freeze , table ,
196
+ vacuum_one_database (dbname , full , verbose , and_analyze , only_analyze ,
197
+ freeze , table ,
174
198
host , port , username , prompt_password ,
175
199
progname , echo );
176
200
}
@@ -180,8 +204,8 @@ main(int argc, char *argv[])
180
204
181
205
182
206
static 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 ,
185
209
const char * host , const char * port ,
186
210
const char * username , enum trivalue prompt_password ,
187
211
const char * progname , bool echo )
@@ -192,15 +216,20 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
192
216
193
217
initPQExpBuffer (& sql );
194
218
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
+ }
200
231
if (verbose )
201
232
appendPQExpBuffer (& sql , " VERBOSE" );
202
- if (analyze )
203
- appendPQExpBuffer (& sql , " ANALYZE" );
204
233
if (table )
205
234
appendPQExpBuffer (& sql , " %s" , table );
206
235
appendPQExpBuffer (& sql , ";\n" );
@@ -223,8 +252,8 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
223
252
224
253
225
254
static 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 ,
228
257
const char * username , enum trivalue prompt_password ,
229
258
const char * progname , bool echo , bool quiet )
230
259
{
@@ -246,8 +275,8 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
246
275
fflush (stdout );
247
276
}
248
277
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 ,
251
280
progname , echo );
252
281
}
253
282
@@ -267,6 +296,7 @@ help(const char *progname)
267
296
printf (_ (" -e, --echo show the commands being sent to the server\n" ));
268
297
printf (_ (" -f, --full do full vacuuming\n" ));
269
298
printf (_ (" -F, --freeze freeze row transaction information\n" ));
299
+ printf (_ (" -o, --only-analyze only update optimizer hints\n" ));
270
300
printf (_ (" -q, --quiet don't write any messages\n" ));
271
301
printf (_ (" -t, --table='TABLE[(COLUMNS)]' vacuum specific table only\n" ));
272
302
printf (_ (" -v, --verbose write a lot of output\n" ));
0 commit comments