@@ -575,6 +575,14 @@ repack_one_table(const repack_table *table, const char *orderby)
575
575
StringInfoData sql ;
576
576
bool have_error = false;
577
577
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
+
578
586
initStringInfo (& sql );
579
587
580
588
elog (DEBUG2 , "---- repack_one_table ----" );
@@ -695,6 +703,12 @@ repack_one_table(const repack_table *table, const char *orderby)
695
703
*/
696
704
command ("COMMIT" , 0 , NULL );
697
705
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
+
698
712
/* Keep looping PQgetResult() calls until it returns NULL, indicating the
699
713
* command is done and we have obtained our lock.
700
714
*/
@@ -911,7 +925,7 @@ repack_one_table(const repack_table *table, const char *orderby)
911
925
/* XXX: distinguish between fatal and non-fatal errors via the first
912
926
* arg to repack_cleanup().
913
927
*/
914
- if (have_error )
928
+ if (have_error && table_init )
915
929
repack_cleanup (false, table );
916
930
}
917
931
0 commit comments