From b4d8a904373675913764fa691046360cbf542901 Mon Sep 17 00:00:00 2001 From: Josh Kupershmidt Date: Thu, 13 Dec 2012 18:55:19 -0700 Subject: [PATCH] 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). --- bin/pg_repack.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 3b384a8..c6ec6ef 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -575,6 +575,14 @@ repack_one_table(const repack_table *table, const char *orderby) StringInfoData sql; bool have_error = false; + /* Keep track of whether we have gotten through setup to install + * the z_repack_trigger, log table, etc. ourselves. We don't want to + * go through repack_cleanup() if we didnt' actually set up the + * trigger ourselves, lest we be cleaning up another pg_repack's mess, + * or worse, interfering with a still-running pg_repack. + */ + bool table_init = false; + initStringInfo(&sql); elog(DEBUG2, "---- repack_one_table ----"); @@ -695,6 +703,12 @@ repack_one_table(const repack_table *table, const char *orderby) */ command("COMMIT", 0, NULL); + /* The main connection has now committed its z_repack_trigger, + * log table, and temp. table. If any error occurs from this point + * on and we bail out, we should try to clean those up. + */ + table_init = true; + /* Keep looping PQgetResult() calls until it returns NULL, indicating the * command is done and we have obtained our lock. */ @@ -911,7 +925,7 @@ cleanup: /* XXX: distinguish between fatal and non-fatal errors via the first * arg to repack_cleanup(). */ - if (have_error) + if (have_error && table_init) repack_cleanup(false, table); }