Add support for dry run -N (--dryrun)

This commit is contained in:
Steeve Lennmark 2014-01-24 15:15:35 +01:00
parent 53906c4f18
commit bf277a4e5f
2 changed files with 24 additions and 3 deletions

View File

@ -226,6 +226,7 @@ static SimpleStringList r_index = {NULL, NULL};
static bool only_indexes = false;
static int wait_timeout = 60; /* in seconds */
static int jobs = 0; /* number of concurrent worker conns. */
static bool dryrun = false;
/* buffer should have at least 11 bytes */
static char *
@ -240,6 +241,7 @@ static pgut_option options[] =
{ 'b', 'a', "all", &alldb },
{ 'l', 't', "table", &table_list },
{ 'b', 'n', "no-order", &noorder },
{ 'b', 'N', "dry-run", &dryrun },
{ 's', 'o', "order-by", &orderby },
{ 's', 's', "tablespace", &tablespace },
{ 'b', 'S', "moveidx", &moveidx },
@ -513,9 +515,12 @@ repack_all_databases(const char *orderby)
dbname = PQgetvalue(result, i, 0);
elog(INFO, "repacking database \"%s\"", dbname);
ret = repack_one_database(orderby, errbuf, sizeof(errbuf));
if (!ret)
elog(INFO, "database \"%s\" skipped: %s", dbname, errbuf);
if (!dryrun)
{
ret = repack_one_database(orderby, errbuf, sizeof(errbuf));
if (!ret)
elog(INFO, "database \"%s\" skipped: %s", dbname, errbuf);
}
}
CLEARPGRES(result);
@ -1018,6 +1023,9 @@ repack_one_table(const repack_table *table, const char *orderby)
elog(DEBUG2, "sql_update : %s", table->sql_update);
elog(DEBUG2, "sql_pop : %s", table->sql_pop);
if (dryrun)
return;
/*
* 1. Setup advisory lock and trigger on main table.
*/
@ -1693,6 +1701,10 @@ repack_table_indexes(PGresult *index_details)
continue;
}
elog(INFO, "repacking index \"%s\".\"index_%u\"", schema_name, index);
if (dryrun)
continue;
params[0] = utoa(index, buffer[0]);
res = execute("SELECT repack.repack_indexdef($1, $2, $3, true)", 3,
params);
@ -1731,6 +1743,9 @@ repack_table_indexes(PGresult *index_details)
getstr(index_details, i, 0));
}
if (dryrun)
return true;
/* If we did not successfully repack any indexes, e.g. because of some
* error affecting every CREATE INDEX attempt, don't waste time with
* the ACCESS EXCLUSIVE lock on the table, and return false.
@ -1899,6 +1914,7 @@ pgut_help(bool details)
printf(" -S, --moveidx move repacked indexes to TBLSPC too\n");
printf(" -o, --order-by=COLUMNS order by columns instead of cluster keys\n");
printf(" -n, --no-order do vacuum full instead of cluster\n");
printf(" -N, --dry-run print what would have been repacked\n");
printf(" -j, --jobs=NUM Use this many parallel jobs for each table\n");
printf(" -i, --index=INDEX move only the specified index\n");
printf(" -x, --only-indexes move only indexes of the specified table\n");

View File

@ -121,6 +121,7 @@ Options:
-S, --moveidx move repacked indexes to *TBLSPC* too
-o, --order-by=COLUMNS order by columns instead of cluster keys
-n, --no-order do vacuum full instead of cluster
-N, --dry-run print what would have been repacked
-j, --jobs=NUM Use this many parallel jobs for each table
-i, --index=INDEX move only the specified index
-x, --only-indexes move only indexes of the specified table
@ -161,6 +162,9 @@ Reorg Options
Perform an online VACUUM FULL. Since version 1.2 this is the default for
non-clustered tables.
``-N``, ``--dry-run``
List what would be repacked and exit.
``-j``, ``--jobs``
Create the specified number of extra connections to PostgreSQL, and
use these extra connections to parallelize the rebuild of indexes
@ -443,6 +447,7 @@ Releases
* Bugfix: correctly handle key indexes with options such as DESC, NULL
FIRST/LAST, COLLATE (pg_repack issue #3).
* More helpful program output and error messages.
* Added ``--dry-run`` to do a dry run.
* pg_repack 1.1.8