Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda24813

Browse files
committed
Fix vacuumdb --analyze-in-stages --all order
When running vacuumdb --analyze-in-stages --all, it needs to run thefirst stage across all databases before the second one, instead ofrunning all stages in a database before processing the next one.Also respect the --quiet option with --analyze-in-stages.
1 parent95d737f commitda24813

File tree

2 files changed

+72
-24
lines changed

2 files changed

+72
-24
lines changed

‎src/bin/scripts/t/102_vacuumdb_stages.pl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33
use TestLib;
4-
use Test::Moretests=>1;
4+
use Test::Moretests=>2;
55

66
my$tempdir = tempdir;
77
start_test_server$tempdir;
@@ -15,3 +15,20 @@
1515
.*statement:\RESET\default_statistics_target;
1616
.*statement:\ANALYZE/sx,
1717
'analyze three times');
18+
19+
20+
issues_sql_like(
21+
['vacuumdb','--analyze-in-stages','--all' ],
22+
qr/.*statement:\SET\default_statistics_target=1;\SET\vacuum_cost_delay=0;
23+
.*statement:\ANALYZE.*
24+
.*statement:\SET\default_statistics_target=1;\SET\vacuum_cost_delay=0;
25+
.*statement:\ANALYZE.*
26+
.*statement:\SET\default_statistics_target=10;\RESET\vacuum_cost_delay;
27+
.*statement:\ANALYZE.*
28+
.*statement:\SET\default_statistics_target=10;\RESET\vacuum_cost_delay;
29+
.*statement:\ANALYZE.*
30+
.*statement:\RESET\default_statistics_target;
31+
.*statement:\ANALYZE.*
32+
.*statement:\RESET\default_statistics_target;
33+
.*statement:\ANALYZE/sx,
34+
'analyze more than one database in stages');

‎src/bin/scripts/vacuumdb.c

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717

1818
staticvoidvacuum_one_database(constchar*dbname,boolfull,boolverbose,
19-
booland_analyze,boolanalyze_only,boolanalyze_in_stages,boolfreeze,
19+
booland_analyze,boolanalyze_only,boolanalyze_in_stages,intstage,boolfreeze,
2020
constchar*table,constchar*host,constchar*port,
2121
constchar*username,enumtrivalueprompt_password,
22-
constchar*progname,boolecho);
22+
constchar*progname,boolecho,boolquiet);
2323
staticvoidvacuum_all_databases(boolfull,boolverbose,booland_analyze,
2424
boolanalyze_only,boolanalyze_in_stages,boolfreeze,
2525
constchar*maintenance_db,
@@ -217,18 +217,18 @@ main(int argc, char *argv[])
217217
for (cell=tables.head;cell;cell=cell->next)
218218
{
219219
vacuum_one_database(dbname,full,verbose,and_analyze,
220-
analyze_only,analyze_in_stages,
220+
analyze_only,analyze_in_stages,-1,
221221
freeze,cell->val,
222222
host,port,username,prompt_password,
223-
progname,echo);
223+
progname,echo,quiet);
224224
}
225225
}
226226
else
227227
vacuum_one_database(dbname,full,verbose,and_analyze,
228-
analyze_only,analyze_in_stages,
228+
analyze_only,analyze_in_stages,-1,
229229
freeze,NULL,
230230
host,port,username,prompt_password,
231-
progname,echo);
231+
progname,echo,quiet);
232232
}
233233

234234
exit(0);
@@ -254,10 +254,10 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo, const char *dbname,
254254

255255
staticvoid
256256
vacuum_one_database(constchar*dbname,boolfull,boolverbose,booland_analyze,
257-
boolanalyze_only,boolanalyze_in_stages,boolfreeze,constchar*table,
257+
boolanalyze_only,boolanalyze_in_stages,intstage,boolfreeze,constchar*table,
258258
constchar*host,constchar*port,
259259
constchar*username,enumtrivalueprompt_password,
260-
constchar*progname,boolecho)
260+
constchar*progname,boolecho,boolquiet)
261261
{
262262
PQExpBufferDatasql;
263263

@@ -334,14 +334,36 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
334334
gettext_noop("Generating medium optimizer statistics (10 targets)"),
335335
gettext_noop("Generating default (full) optimizer statistics")
336336
};
337-
inti;
338337

339-
for (i=0;i<3;i++)
338+
if (stage==-1)
339+
{
340+
inti;
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
340355
{
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);
343364
run_vacuum_command(conn,sql.data,echo,dbname,table,progname);
344365
}
366+
345367
}
346368
else
347369
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
360382
{
361383
PGconn*conn;
362384
PGresult*result;
363-
inti;
385+
intstage;
364386

365387
conn=connectMaintenanceDatabase(maintenance_db,host,port,
366388
username,prompt_password,progname);
367389
result=executeQuery(conn,"SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;",progname,echo);
368390
PQfinish(conn);
369391

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++)
371397
{
372-
char*dbname=PQgetvalue(result,i,0);
398+
inti;
373399

374-
if (!quiet)
400+
for (i=0;i<PQntuples(result);i++)
375401
{
376-
printf(_("%s: vacuuming database \"%s\"\n"),progname,dbname);
377-
fflush(stdout);
378-
}
402+
char*dbname=PQgetvalue(result,i,0);
379403

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+
}
384415
}
385416

386417
PQclear(result);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp