16
16
17
17
18
18
static void vacuum_one_database (const char * dbname ,bool full ,bool verbose ,
19
- bool and_analyze ,bool analyze_only ,bool analyze_in_stages ,bool freeze ,
19
+ bool and_analyze ,bool analyze_only ,bool analyze_in_stages ,int stage , bool freeze ,
20
20
const char * table ,const char * host ,const char * port ,
21
21
const char * username ,enum trivalue prompt_password ,
22
- const char * progname ,bool echo );
22
+ const char * progname ,bool echo , bool quiet );
23
23
static void vacuum_all_databases (bool full ,bool verbose ,bool and_analyze ,
24
24
bool analyze_only ,bool analyze_in_stages ,bool freeze ,
25
25
const char * maintenance_db ,
@@ -217,18 +217,18 @@ main(int argc, char *argv[])
217
217
for (cell = tables .head ;cell ;cell = cell -> next )
218
218
{
219
219
vacuum_one_database (dbname ,full ,verbose ,and_analyze ,
220
- analyze_only ,analyze_in_stages ,
220
+ analyze_only ,analyze_in_stages ,-1 ,
221
221
freeze ,cell -> val ,
222
222
host ,port ,username ,prompt_password ,
223
- progname ,echo );
223
+ progname ,echo , quiet );
224
224
}
225
225
}
226
226
else
227
227
vacuum_one_database (dbname ,full ,verbose ,and_analyze ,
228
- analyze_only ,analyze_in_stages ,
228
+ analyze_only ,analyze_in_stages ,-1 ,
229
229
freeze ,NULL ,
230
230
host ,port ,username ,prompt_password ,
231
- progname ,echo );
231
+ progname ,echo , quiet );
232
232
}
233
233
234
234
exit (0 );
@@ -254,10 +254,10 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo, const char *dbname,
254
254
255
255
static void
256
256
vacuum_one_database (const char * dbname ,bool full ,bool verbose ,bool and_analyze ,
257
- bool analyze_only ,bool analyze_in_stages ,bool freeze ,const char * table ,
257
+ bool analyze_only ,bool analyze_in_stages , int stage ,bool freeze ,const char * table ,
258
258
const char * host ,const char * port ,
259
259
const char * username ,enum trivalue prompt_password ,
260
- const char * progname ,bool echo )
260
+ const char * progname ,bool echo , bool quiet )
261
261
{
262
262
PQExpBufferData sql ;
263
263
@@ -334,14 +334,36 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
334
334
gettext_noop ("Generating medium optimizer statistics (10 targets)" ),
335
335
gettext_noop ("Generating default (full) optimizer statistics" )
336
336
};
337
- int i ;
338
337
339
- for (i = 0 ;i < 3 ;i ++ )
338
+ if (stage == -1 )
339
+ {
340
+ int i ;
341
+
342
+ /* Run all stages. */
343
+ for (i = 0 ;i < 3 ;i ++ )
344
+ {
345
+ if (!quiet )
346
+ {
347
+ puts (gettext (stage_messages [i ]));
348
+ fflush (stdout );
349
+ }
350
+ executeCommand (conn ,stage_commands [i ],progname ,echo );
351
+ run_vacuum_command (conn ,sql .data ,echo ,dbname ,table ,progname );
352
+ }
353
+ }
354
+ else
340
355
{
341
- puts (gettext (stage_messages [i ]));
342
- executeCommand (conn ,stage_commands [i ],progname ,echo );
356
+ /* Otherwise, we got a stage from vacuum_all_databases(), so run
357
+ * only that one. */
358
+ if (!quiet )
359
+ {
360
+ puts (gettext (stage_messages [stage ]));
361
+ fflush (stdout );
362
+ }
363
+ executeCommand (conn ,stage_commands [stage ],progname ,echo );
343
364
run_vacuum_command (conn ,sql .data ,echo ,dbname ,table ,progname );
344
365
}
366
+
345
367
}
346
368
else
347
369
run_vacuum_command (conn ,sql .data ,echo ,dbname ,NULL ,progname );
@@ -360,27 +382,36 @@ vacuum_all_databases(bool full, bool verbose, bool and_analyze, bool analyze_onl
360
382
{
361
383
PGconn * conn ;
362
384
PGresult * result ;
363
- int i ;
385
+ int stage ;
364
386
365
387
conn = connectMaintenanceDatabase (maintenance_db ,host ,port ,
366
388
username ,prompt_password ,progname );
367
389
result = executeQuery (conn ,"SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;" ,progname ,echo );
368
390
PQfinish (conn );
369
391
370
- for (i = 0 ;i < PQntuples (result );i ++ )
392
+ /* If analyzing in stages, then run through all stages. Otherwise just
393
+ * run once, passing -1 as the stage. */
394
+ for (stage = (analyze_in_stages ?0 :-1 );
395
+ stage < (analyze_in_stages ?3 :0 );
396
+ stage ++ )
371
397
{
372
- char * dbname = PQgetvalue ( result , i , 0 ) ;
398
+ int i ;
373
399
374
- if (! quiet )
400
+ for ( i = 0 ; i < PQntuples ( result ); i ++ )
375
401
{
376
- printf (_ ("%s: vacuuming database \"%s\"\n" ),progname ,dbname );
377
- fflush (stdout );
378
- }
402
+ char * dbname = PQgetvalue (result ,i ,0 );
379
403
380
- vacuum_one_database (dbname ,full ,verbose ,and_analyze ,analyze_only ,
381
- analyze_in_stages ,
382
- freeze ,NULL ,host ,port ,username ,prompt_password ,
383
- progname ,echo );
404
+ if (!quiet )
405
+ {
406
+ printf (_ ("%s: vacuuming database \"%s\"\n" ),progname ,dbname );
407
+ fflush (stdout );
408
+ }
409
+
410
+ vacuum_one_database (dbname ,full ,verbose ,and_analyze ,analyze_only ,
411
+ analyze_in_stages ,stage ,
412
+ freeze ,NULL ,host ,port ,username ,prompt_password ,
413
+ progname ,echo ,quiet );
414
+ }
384
415
}
385
416
386
417
PQclear (result );