mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-15 12:40:27 +02:00
Fix vacuumdb --analyze-in-stages --all order
When running vacuumdb --analyze-in-stages --all, it needs to run the first stage across all databases before the second one, instead of running all stages in a database before processing the next one. Also respect the --quiet option with --analyze-in-stages.
This commit is contained in:
parent
022aea346d
commit
330bf85c49
@ -1,7 +1,7 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
use Test::More tests => 1;
|
use Test::More tests => 2;
|
||||||
|
|
||||||
my $tempdir = tempdir;
|
my $tempdir = tempdir;
|
||||||
start_test_server $tempdir;
|
start_test_server $tempdir;
|
||||||
@ -15,3 +15,20 @@ qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
|
|||||||
.*statement:\ RESET\ default_statistics_target;
|
.*statement:\ RESET\ default_statistics_target;
|
||||||
.*statement:\ ANALYZE/sx,
|
.*statement:\ ANALYZE/sx,
|
||||||
'analyze three times');
|
'analyze three times');
|
||||||
|
|
||||||
|
|
||||||
|
issues_sql_like(
|
||||||
|
[ 'vacuumdb', '--analyze-in-stages', '--all' ],
|
||||||
|
qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
|
||||||
|
.*statement:\ ANALYZE.*
|
||||||
|
.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
|
||||||
|
.*statement:\ ANALYZE.*
|
||||||
|
.*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay;
|
||||||
|
.*statement:\ ANALYZE.*
|
||||||
|
.*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay;
|
||||||
|
.*statement:\ ANALYZE.*
|
||||||
|
.*statement:\ RESET\ default_statistics_target;
|
||||||
|
.*statement:\ ANALYZE.*
|
||||||
|
.*statement:\ RESET\ default_statistics_target;
|
||||||
|
.*statement:\ ANALYZE/sx,
|
||||||
|
'analyze more than one database in stages');
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
|
|
||||||
static void vacuum_one_database(const char *dbname, bool full, bool verbose,
|
static void vacuum_one_database(const char *dbname, bool full, bool verbose,
|
||||||
bool and_analyze, bool analyze_only, bool analyze_in_stages, bool freeze,
|
bool and_analyze, bool analyze_only, bool analyze_in_stages, int stage, bool freeze,
|
||||||
const char *table, const char *host, const char *port,
|
const char *table, const char *host, const char *port,
|
||||||
const char *username, enum trivalue prompt_password,
|
const char *username, enum trivalue prompt_password,
|
||||||
const char *progname, bool echo);
|
const char *progname, bool echo, bool quiet);
|
||||||
static void vacuum_all_databases(bool full, bool verbose, bool and_analyze,
|
static void vacuum_all_databases(bool full, bool verbose, bool and_analyze,
|
||||||
bool analyze_only, bool analyze_in_stages, bool freeze,
|
bool analyze_only, bool analyze_in_stages, bool freeze,
|
||||||
const char *maintenance_db,
|
const char *maintenance_db,
|
||||||
@ -217,18 +217,18 @@ main(int argc, char *argv[])
|
|||||||
for (cell = tables.head; cell; cell = cell->next)
|
for (cell = tables.head; cell; cell = cell->next)
|
||||||
{
|
{
|
||||||
vacuum_one_database(dbname, full, verbose, and_analyze,
|
vacuum_one_database(dbname, full, verbose, and_analyze,
|
||||||
analyze_only, analyze_in_stages,
|
analyze_only, analyze_in_stages, -1,
|
||||||
freeze, cell->val,
|
freeze, cell->val,
|
||||||
host, port, username, prompt_password,
|
host, port, username, prompt_password,
|
||||||
progname, echo);
|
progname, echo, quiet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vacuum_one_database(dbname, full, verbose, and_analyze,
|
vacuum_one_database(dbname, full, verbose, and_analyze,
|
||||||
analyze_only, analyze_in_stages,
|
analyze_only, analyze_in_stages, -1,
|
||||||
freeze, NULL,
|
freeze, NULL,
|
||||||
host, port, username, prompt_password,
|
host, port, username, prompt_password,
|
||||||
progname, echo);
|
progname, echo, quiet);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -254,10 +254,10 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo, const char *dbname,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyze,
|
vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyze,
|
||||||
bool analyze_only, bool analyze_in_stages, bool freeze, const char *table,
|
bool analyze_only, bool analyze_in_stages, int stage, bool freeze, const char *table,
|
||||||
const char *host, const char *port,
|
const char *host, const char *port,
|
||||||
const char *username, enum trivalue prompt_password,
|
const char *username, enum trivalue prompt_password,
|
||||||
const char *progname, bool echo)
|
const char *progname, bool echo, bool quiet)
|
||||||
{
|
{
|
||||||
PQExpBufferData sql;
|
PQExpBufferData sql;
|
||||||
|
|
||||||
@ -334,14 +334,36 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
|
|||||||
gettext_noop("Generating medium optimizer statistics (10 targets)"),
|
gettext_noop("Generating medium optimizer statistics (10 targets)"),
|
||||||
gettext_noop("Generating default (full) optimizer statistics")
|
gettext_noop("Generating default (full) optimizer statistics")
|
||||||
};
|
};
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
if (stage == -1)
|
||||||
{
|
{
|
||||||
puts(gettext(stage_messages[i]));
|
int i;
|
||||||
executeCommand(conn, stage_commands[i], progname, echo);
|
|
||||||
|
/* Run all stages. */
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
if (!quiet)
|
||||||
|
{
|
||||||
|
puts(gettext(stage_messages[i]));
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
executeCommand(conn, stage_commands[i], progname, echo);
|
||||||
|
run_vacuum_command(conn, sql.data, echo, dbname, table, progname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Otherwise, we got a stage from vacuum_all_databases(), so run
|
||||||
|
* only that one. */
|
||||||
|
if (!quiet)
|
||||||
|
{
|
||||||
|
puts(gettext(stage_messages[stage]));
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
executeCommand(conn, stage_commands[stage], progname, echo);
|
||||||
run_vacuum_command(conn, sql.data, echo, dbname, table, progname);
|
run_vacuum_command(conn, sql.data, echo, dbname, table, progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
run_vacuum_command(conn, sql.data, echo, dbname, NULL, progname);
|
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
|
|||||||
{
|
{
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
PGresult *result;
|
PGresult *result;
|
||||||
int i;
|
int stage;
|
||||||
|
|
||||||
conn = connectMaintenanceDatabase(maintenance_db, host, port,
|
conn = connectMaintenanceDatabase(maintenance_db, host, port,
|
||||||
username, prompt_password, progname);
|
username, prompt_password, progname);
|
||||||
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
|
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
|
|
||||||
for (i = 0; i < PQntuples(result); i++)
|
/* If analyzing in stages, then run through all stages. Otherwise just
|
||||||
|
* run once, passing -1 as the stage. */
|
||||||
|
for (stage = (analyze_in_stages ? 0 : -1);
|
||||||
|
stage < (analyze_in_stages ? 3 : 0);
|
||||||
|
stage++)
|
||||||
{
|
{
|
||||||
char *dbname = PQgetvalue(result, i, 0);
|
int i;
|
||||||
|
|
||||||
if (!quiet)
|
for (i = 0; i < PQntuples(result); i++)
|
||||||
{
|
{
|
||||||
printf(_("%s: vacuuming database \"%s\"\n"), progname, dbname);
|
char *dbname = PQgetvalue(result, i, 0);
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
vacuum_one_database(dbname, full, verbose, and_analyze, analyze_only,
|
if (!quiet)
|
||||||
analyze_in_stages,
|
{
|
||||||
freeze, NULL, host, port, username, prompt_password,
|
printf(_("%s: vacuuming database \"%s\"\n"), progname, dbname);
|
||||||
progname, echo);
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
vacuum_one_database(dbname, full, verbose, and_analyze, analyze_only,
|
||||||
|
analyze_in_stages, stage,
|
||||||
|
freeze, NULL, host, port, username, prompt_password,
|
||||||
|
progname, echo, quiet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user