pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Vik Fearing <vik@2ndquadrant.fr>
Cc: benjie@jemjie.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14431: ERROR: XX000: relation 5022917 has no triggers ("should not happen")
Date: Thu, 24 Nov 2016 11:41:25 -0500
Message-ID: <17845.1480005685@sss.pgh.pa.us> (raw)
In-Reply-To: <680a86c6-b9f1-09f6-02de-ed6b15fff6e8@2ndquadrant.fr>
References: <20161124114911.6530.31200@wrigleys.postgresql.org>
	<680a86c6-b9f1-09f6-02de-ed6b15fff6e8@2ndquadrant.fr>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Vik Fearing <vik@2ndquadrant.fr> writes:
> For the archives, the test case at that link is:

Thanks for copying that into the archives.

The "bar" trigger is actually irrelevant and can be dropped from the
example.  The problem is that because the FK constraint on "b" is
deferred, there is an FK-check trigger event waiting to be fired
at the end of the transaction, and we're deleting the pg_trigger
row out from under it.

Ordinarily, we'd prevent you from dropping a trigger that has
unfired events, but the code in tablecmds.c is only checking the
"b" table, and the event in question is for "a"'s trigger.

With the attached patch, you get

ERROR:  cannot ALTER TABLE "a" because it has pending trigger events

which I think is a sane behavior, although maybe the precise wording
of the error could be quibbled with.  (But improving that would
require fooling with the API of CheckTableNotInUse, which does not
seem worthwhile.)

The other approach we could take is to allow the DROP CONSTRAINT and
silently ignore queued trigger events if we can't find their pg_trigger
row ... but that seems pretty scary in terms of its ability to mask bugs,
and it's not consistent with past choices.

Barring objection, I'll add a test case to this and push it.

			regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

disallow-activity-on-referenced-table.patch (text/x-diff, 1.1K) download diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f97bee5..6322fa7 100644 *** a/src/backend/commands/tablecmds.c --- b/src/backend/commands/tablecmds.c *************** ATExecDropConstraint(Relation rel, const *** 7723,7728 **** --- 7723,7746 ---- is_no_inherit_constraint = con->connoinherit; /* + * If it's a foreign-key constraint, we'd better lock the referenced + * table and check that that's not in use, just as we've already done + * for the constrained table (else we might, eg, be dropping a trigger + * that has unfired events). But we can/must skip that in the + * self-referential case. + */ + if (con->contype == CONSTRAINT_FOREIGN && + con->confrelid != RelationGetRelid(rel)) + { + Relation frel; + + /* Must match lock taken by RemoveTriggerById: */ + frel = heap_open(con->confrelid, AccessExclusiveLock); + CheckTableNotInUse(frel, "ALTER TABLE"); + heap_close(frel, NoLock); + } + + /* * Perform the actual constraint deletion */ conobj.classId = ConstraintRelationId;

view thread (3+ messages)

Message-ID: <17845.1480005685@sss.pgh.pa.us>
Permalink:  ../17845.1480005685@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17845.1480005685@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, vik@2ndquadrant.fr, benjie@jemjie.com
  Subject: Re: BUG #14431: ERROR: XX000: relation 5022917 has no triggers ("should not happen")
  In-Reply-To: <17845.1480005685@sss.pgh.pa.us>
  References: <20161124114911.6530.31200@wrigleys.postgresql.org> <680a86c6-b9f1-09f6-02de-ed6b15fff6e8@2ndquadrant.fr> <17845.1480005685@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox