Skip to content

Commit 1d62d8d

Browse files
committed
More helpful error messages in case of conflicting triggers
Closes issue #5.
1 parent 127d5cb commit 1d62d8d

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

bin/pg_repack.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,35 @@ repack_one_table(const repack_table *table, const char *orderby)
886886
res = execute("SELECT repack.conflicted_triggers($1)", 1, params);
887887
if (PQntuples(res) > 0)
888888
{
889-
ereport(WARNING,
890-
(errcode(E_PG_COMMAND),
891-
errmsg("trigger %s conflicted for %s",
889+
if (0 == strcmp("z_repack_trigger", PQgetvalue(res, 0, 0)))
890+
{
891+
ereport(WARNING,
892+
(errcode(E_PG_COMMAND),
893+
errmsg("the table \"%s\" has already a trigger called \"%s\"",
894+
table->target_name, PQgetvalue(res, 0, 0)),
895+
errdetail(
896+
"The trigger was probably installed during a previous"
897+
" attempt to run pg_repack on the table which was"
898+
" interrupted and for some reason failed to clean up"
899+
" the temporary objects. Please drop the trigger or drop"
900+
" and recreate the pg_repack extension altogether"
901+
" to remove all the temporary objects left over.")));
902+
}
903+
else
904+
{
905+
ereport(WARNING,
906+
(errcode(E_PG_COMMAND),
907+
errmsg("trigger \"%s\" conflicting on table \"%s\"",
908+
PQgetvalue(res, 0, 0), table->target_name),
909+
errdetail(
910+
"The trigger \"z_repack_trigger\" must be the last of the"
911+
" BEFORE triggers to fire on the table (triggers fire in"
912+
" alphabetical order). Please rename the trigger so that"
913+
" it sorts before \"z_repack_trigger\": you can use"
914+
" \"ALTER TRIGGER %s ON %s RENAME TO newname\".",
892915
PQgetvalue(res, 0, 0), table->target_name)));
916+
}
917+
893918
have_error = true;
894919
goto cleanup;
895920
}

doc/pg_repack.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,23 @@ ERROR: permission denied for schema repack
329329

330330
pg_repack must be executed by a superuser.
331331

332-
pg_repack: query failed: ERROR: trigger "z_repack_trigger" for relation "tbl" already exists
333-
The target table has already a trigger named ``z_repack_trigger``. This
334-
is probably caused by a previous failed attempt to run pg_repack on the
335-
table, which for some reason failed to clean up the temporary object.
332+
WARNING: the table "tbl" has already a trigger called z_repack_trigger
333+
The trigger was probably installed during a previous attempt to run
334+
pg_repack on the table which was interrupted and for some reason failed
335+
to clean up the temporary objects.
336336

337337
You can remove all the temporary objects by dropping and re-creating the
338338
extension: see the installation_ section for the details.
339339

340-
pg_repack: trigger conflicted for tbl
340+
WARNING: trigger "trg" conflicting on table "tbl"
341341
The target table has a trigger whose name follows ``z_repack_trigger``
342342
in alphabetical order.
343343

344344
The ``z_repack_trigger`` should be the last BEFORE trigger to fire.
345345
Please rename your trigger to that it sorts alphabetically before
346-
pg_repack's one.
346+
pg_repack's one; you can use::
347+
348+
ALTER TRIGGER zzz_my_trigger ON sometable RENAME TO yyy_my_trigger;
347349

348350

349351
Restrictions
@@ -402,6 +404,7 @@ Releases
402404
* pg_repack 1.2
403405

404406
* Added --jobs option for parallel operation.
407+
* More helpful error messages.
405408
* Bugfix: correctly handle key indexes with options such as DESC, NULL
406409
FIRST/LAST, COLLATE (pg_repack issue #3).
407410

lib/pg_repack.sql.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ CREATE FUNCTION repack.conflicted_triggers(oid) RETURNS SETOF name AS
217217
$$
218218
SELECT tgname FROM pg_trigger
219219
WHERE tgrelid = $1 AND tgname >= 'z_repack_trigger'
220+
ORDER BY tgname;
220221
$$
221222
LANGUAGE sql STABLE STRICT;
222223

0 commit comments

Comments
 (0)