Re: COMMIT TRIGGERs, take n, implemented with CONSTRAINT TRIGGERS

From: Nico Williams <nico(at)cryptonector(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: COMMIT TRIGGERs, take n, implemented with CONSTRAINT TRIGGERS
Date: 2017-09-15 19:42:04
Message-ID: 20170915194202.GB26093@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 15, 2017 at 02:19:29PM -0500, Nico Williams wrote:
> On Fri, Sep 15, 2017 at 11:26:08AM -0700, Andres Freund wrote:
> > I think you should also explain why that's a desirable set of
> > semantics.

Note that DEFERRED CONSTRAINT TRIGGERs already have these semantics,
except of course that an unprivileged user can force them to run
IMMEDIATEly rather than DEFERRED.

Now, why is this desirable: atomicity.

The client/user can no longer add statements to the transaction,
therefore now (commit-time) is a good time to run a procedure that
can *atomically* examine the totatility of the changes made by the
user.

This allows one to perform consistency checks across the entire DB.
One might speed them up by examining deltas recorded by for-each-row
triggers, but logically one could check the entire state of the DB.

Commit triggers also allow one to record transaction boundaries, and
NOTIFY listeners less frequently than if one did a NOTIFY in normal
for-each-row/statement triggers.

These are all good things -- or at least they aren't bad things.

For NOTIFY, it would be nice to have a post-commit trigger, though such
a thing could do nothing more than NOTIFY!

(A "post-commit" trigger could certainly not write to the DB unless it
did so in a new transaction that itself could not invoke post-commit
triggers that could write more... Such a thing would be very strange!
But I'm not asking for a post-commit trigger feature.)

Nico
--

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2017-09-15 19:50:33 Re: POC: Sharing record typmods between backends
Previous Message Tom Lane 2017-09-15 19:39:49 Re: POC: Sharing record typmods between backends