PostgreSQL triggers

From: Sebastian Ritter <sebastian(at)campbell-lange(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: software(at)campbell-lange(dot)net
Subject: PostgreSQL triggers
Date: 2010-07-01 10:29:56
Message-ID: 20100701102956.GA30265@campbell-lange.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi All,

I was hoping you could help with a few queries regarding row-wise
PostgreSQL triggers.

Is it possible to see triggers appearing in the postgresql-8.3-main.log?
I have "log_min_duration_statement" set to 0 (logs all statements) in my
postgresql.conf but I can't seem to find any reference to triggers being
executed.

My next questions are best illustrated by the following example:

A PostgreSQL PL/pgSQL function makes multiple consecutive inserts on a
table that has a ROW-WISE INSERT trigger. The INSERT trigger executes a
function to delete historical entries in the same table.

1. What is the order of execution between the multiple inserts and their
corresponding trigger invocations? Do the triggers run synchronously or
asynchronously from their respective inserts ?

Synchronously:
INSERT ROW
WAIT TO FINISH EXECUTION OF TRIGGER
INSERT NEXT ROW
WAIT TO FINISH EXECUTION OF TRIGGER
INSERT NEXT ROW ....

Asynchronously:
INSERT ROW -> INVOKE EXECUTION OF TRIGGER
INSERT NEXT ROW -> INVOKE EXECUTION AGAIN (first invocation of trigger may still be running)
INSERT NEXT ROW ....

I think I'm getting caught out by a trigger invocation not finishing
before a later insert is made, and thinking that the newly inserted row
is "historical", causing it to be deleted. Is this possible? If so, is
there a way of simulating the synchronous approach described above?

2. Does having cascading triggers influence the outcome in any way? Many
of our triggers (including the one above) manipulate rows in different
tables which in turn fire more triggers...

3. If I execute the PL/pgSQL function within Postgres with "\timing" set,
will the returned execution time include the duration of the invoked
triggers?

Kindest regads,
Sebastian

--
Sebastian Ritter
Software Manager
sebastian(at)campbell-lange(dot)net

Campbell-Lange Workshop
www.campbell-lange.net
0207 6311 555
3 Tottenham Street London W1T 2AF
Registered in England No. 04551928

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2010-07-01 11:26:38 Re: Find users that have ALL categories
Previous Message Craig Ringer 2010-07-01 06:53:18 Re: DBI::Oracle problems