Add support for dry run -N (--dryrun)
This commit is contained in:
parent
53906c4f18
commit
bf277a4e5f
@ -226,6 +226,7 @@ static SimpleStringList r_index = {NULL, NULL};
|
|||||||
static bool only_indexes = false;
|
static bool only_indexes = false;
|
||||||
static int wait_timeout = 60; /* in seconds */
|
static int wait_timeout = 60; /* in seconds */
|
||||||
static int jobs = 0; /* number of concurrent worker conns. */
|
static int jobs = 0; /* number of concurrent worker conns. */
|
||||||
|
static bool dryrun = false;
|
||||||
|
|
||||||
/* buffer should have at least 11 bytes */
|
/* buffer should have at least 11 bytes */
|
||||||
static char *
|
static char *
|
||||||
@ -240,6 +241,7 @@ static pgut_option options[] =
|
|||||||
{ 'b', 'a', "all", &alldb },
|
{ 'b', 'a', "all", &alldb },
|
||||||
{ 'l', 't', "table", &table_list },
|
{ 'l', 't', "table", &table_list },
|
||||||
{ 'b', 'n', "no-order", &noorder },
|
{ 'b', 'n', "no-order", &noorder },
|
||||||
|
{ 'b', 'N', "dry-run", &dryrun },
|
||||||
{ 's', 'o', "order-by", &orderby },
|
{ 's', 'o', "order-by", &orderby },
|
||||||
{ 's', 's', "tablespace", &tablespace },
|
{ 's', 's', "tablespace", &tablespace },
|
||||||
{ 'b', 'S', "moveidx", &moveidx },
|
{ 'b', 'S', "moveidx", &moveidx },
|
||||||
@ -513,9 +515,12 @@ repack_all_databases(const char *orderby)
|
|||||||
dbname = PQgetvalue(result, i, 0);
|
dbname = PQgetvalue(result, i, 0);
|
||||||
|
|
||||||
elog(INFO, "repacking database \"%s\"", dbname);
|
elog(INFO, "repacking database \"%s\"", dbname);
|
||||||
ret = repack_one_database(orderby, errbuf, sizeof(errbuf));
|
if (!dryrun)
|
||||||
if (!ret)
|
{
|
||||||
elog(INFO, "database \"%s\" skipped: %s", dbname, errbuf);
|
ret = repack_one_database(orderby, errbuf, sizeof(errbuf));
|
||||||
|
if (!ret)
|
||||||
|
elog(INFO, "database \"%s\" skipped: %s", dbname, errbuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLEARPGRES(result);
|
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_update : %s", table->sql_update);
|
||||||
elog(DEBUG2, "sql_pop : %s", table->sql_pop);
|
elog(DEBUG2, "sql_pop : %s", table->sql_pop);
|
||||||
|
|
||||||
|
if (dryrun)
|
||||||
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. Setup advisory lock and trigger on main table.
|
* 1. Setup advisory lock and trigger on main table.
|
||||||
*/
|
*/
|
||||||
@ -1693,6 +1701,10 @@ repack_table_indexes(PGresult *index_details)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elog(INFO, "repacking index \"%s\".\"index_%u\"", schema_name, index);
|
||||||
|
if (dryrun)
|
||||||
|
continue;
|
||||||
|
|
||||||
params[0] = utoa(index, buffer[0]);
|
params[0] = utoa(index, buffer[0]);
|
||||||
res = execute("SELECT repack.repack_indexdef($1, $2, $3, true)", 3,
|
res = execute("SELECT repack.repack_indexdef($1, $2, $3, true)", 3,
|
||||||
params);
|
params);
|
||||||
@ -1731,6 +1743,9 @@ repack_table_indexes(PGresult *index_details)
|
|||||||
getstr(index_details, i, 0));
|
getstr(index_details, i, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dryrun)
|
||||||
|
return true;
|
||||||
|
|
||||||
/* If we did not successfully repack any indexes, e.g. because of some
|
/* If we did not successfully repack any indexes, e.g. because of some
|
||||||
* error affecting every CREATE INDEX attempt, don't waste time with
|
* error affecting every CREATE INDEX attempt, don't waste time with
|
||||||
* the ACCESS EXCLUSIVE lock on the table, and return false.
|
* 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(" -S, --moveidx move repacked indexes to TBLSPC too\n");
|
||||||
printf(" -o, --order-by=COLUMNS order by columns instead of cluster keys\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, --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(" -j, --jobs=NUM Use this many parallel jobs for each table\n");
|
||||||
printf(" -i, --index=INDEX move only the specified index\n");
|
printf(" -i, --index=INDEX move only the specified index\n");
|
||||||
printf(" -x, --only-indexes move only indexes of the specified table\n");
|
printf(" -x, --only-indexes move only indexes of the specified table\n");
|
||||||
|
@ -121,6 +121,7 @@ Options:
|
|||||||
-S, --moveidx move repacked indexes to *TBLSPC* too
|
-S, --moveidx move repacked indexes to *TBLSPC* too
|
||||||
-o, --order-by=COLUMNS order by columns instead of cluster keys
|
-o, --order-by=COLUMNS order by columns instead of cluster keys
|
||||||
-n, --no-order do vacuum full instead of cluster
|
-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
|
-j, --jobs=NUM Use this many parallel jobs for each table
|
||||||
-i, --index=INDEX move only the specified index
|
-i, --index=INDEX move only the specified index
|
||||||
-x, --only-indexes move only indexes of the specified table
|
-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
|
Perform an online VACUUM FULL. Since version 1.2 this is the default for
|
||||||
non-clustered tables.
|
non-clustered tables.
|
||||||
|
|
||||||
|
``-N``, ``--dry-run``
|
||||||
|
List what would be repacked and exit.
|
||||||
|
|
||||||
``-j``, ``--jobs``
|
``-j``, ``--jobs``
|
||||||
Create the specified number of extra connections to PostgreSQL, and
|
Create the specified number of extra connections to PostgreSQL, and
|
||||||
use these extra connections to parallelize the rebuild of indexes
|
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
|
* Bugfix: correctly handle key indexes with options such as DESC, NULL
|
||||||
FIRST/LAST, COLLATE (pg_repack issue #3).
|
FIRST/LAST, COLLATE (pg_repack issue #3).
|
||||||
* More helpful program output and error messages.
|
* More helpful program output and error messages.
|
||||||
|
* Added ``--dry-run`` to do a dry run.
|
||||||
|
|
||||||
* pg_repack 1.1.8
|
* pg_repack 1.1.8
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user