Skip to content

Commit b4d8a90

Browse files
committed
Don't perform repack_cleanup() if we haven't actually set up z_repack_trigger etc.
Fixes a regression introduced in master (by the multiple --tables changes, I think).
1 parent 0bdb4bb commit b4d8a90

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

bin/pg_repack.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,14 @@ repack_one_table(const repack_table *table, const char *orderby)
575575
StringInfoData sql;
576576
bool have_error = false;
577577

578+
/* Keep track of whether we have gotten through setup to install
579+
* the z_repack_trigger, log table, etc. ourselves. We don't want to
580+
* go through repack_cleanup() if we didnt' actually set up the
581+
* trigger ourselves, lest we be cleaning up another pg_repack's mess,
582+
* or worse, interfering with a still-running pg_repack.
583+
*/
584+
bool table_init = false;
585+
578586
initStringInfo(&sql);
579587

580588
elog(DEBUG2, "---- repack_one_table ----");
@@ -695,6 +703,12 @@ repack_one_table(const repack_table *table, const char *orderby)
695703
*/
696704
command("COMMIT", 0, NULL);
697705

706+
/* The main connection has now committed its z_repack_trigger,
707+
* log table, and temp. table. If any error occurs from this point
708+
* on and we bail out, we should try to clean those up.
709+
*/
710+
table_init = true;
711+
698712
/* Keep looping PQgetResult() calls until it returns NULL, indicating the
699713
* command is done and we have obtained our lock.
700714
*/
@@ -911,7 +925,7 @@ repack_one_table(const repack_table *table, const char *orderby)
911925
/* XXX: distinguish between fatal and non-fatal errors via the first
912926
* arg to repack_cleanup().
913927
*/
914-
if (have_error)
928+
if (have_error && table_init)
915929
repack_cleanup(false, table);
916930
}
917931

0 commit comments

Comments
 (0)