Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "-X" option to avoid waiting for other transactions #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bin/pg_repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ static bool sqlstate_equals(PGresult *res, const char *state)

static bool analyze = true;
static bool alldb = false;
static bool ignore_transactions = false;
static bool noorder = false;
static SimpleStringList parent_table_list = {NULL, NULL};
static SimpleStringList table_list = {NULL, NULL};
Expand Down Expand Up @@ -269,6 +270,7 @@ utoa(unsigned int value, char *buffer)
static pgut_option options[] =
{
{ 'b', 'a', "all", &alldb },
{ 'b', 'X', "ignore-transactions", &ignore_transactions },
{ 'l', 't', "table", &table_list },
{ 'l', 'I', "parent-table", &parent_table_list },
{ 'l', 'c', "schema", &schema_list },
Expand Down Expand Up @@ -1565,6 +1567,15 @@ repack_one_table(repack_table *table, const char *orderby)
res = execute(SQL_XID_ALIVE, 1, params);
num = PQntuples(res);

/* display a warning if there are still one or more transactions
* alive, but continue
*/
if (ignore_transactions)
{
elog(NOTICE, "There are %d transactions waiting to finish, but skipping.", num);
break;
}

if (num > 0)
{
/* Wait for old transactions.
Expand Down Expand Up @@ -2355,4 +2366,5 @@ pgut_help(bool details)
printf(" -Z, --no-analyze don't analyze at end\n");
printf(" -k, --no-superuser-check skip superuser checks in client\n");
printf(" -C, --exclude-extension don't repack tables which belong to specific extension\n");
printf(" -X, --ignore-transactions don't wait for running transactions (use with care)\n");
}
7 changes: 7 additions & 0 deletions doc/pg_repack.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Options:
-Z, --no-analyze don't analyze at end
-k, --no-superuser-check skip superuser checks in client
-C, --exclude-extension don't repack tables which belong to specific extension
-X, --ignore-transactions don't wait for running transactions (use with care)

Connection options:
-d, --dbname=DBNAME database to connect
Expand Down Expand Up @@ -224,6 +225,12 @@ Reorg Options
Skip tables that belong to the specified extension(s). Some extensions
may heavily depend on such tables at planning time etc.

``-X``, ``--ignore-transactions``
Proceed without waiting for running transactions to finish.
Default behavior might not be desired on busy databases with
long-running transactions


Connection Options
^^^^^^^^^^^^^^^^^^

Expand Down