Skip to content

Commit

Permalink
Add "-X" option to avoid waiting for other transactions
Browse files Browse the repository at this point in the history
There was a conservative wait[1] for all existing transaction to
finish before repacking a table. This may not be desired on a busy
database on which you have long running transaction, which may block
pg_repack to do the job. This option will display a warning message,
but continues the process in such cases.

[1] http://lists.pgfoundry.org/pipermail/reorg-general/2015-October/000318.html
  • Loading branch information
farrokhi committed Mar 24, 2023
1 parent 7eaa988 commit eb1b54c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit eb1b54c

Please sign in to comment.