Home > Archive > PostgreSQL Discussion > December 2005 > Trigger Behavior in Transactions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Trigger Behavior in Transactions
Joshua Kramer

2005-12-24, 1:23 pm


Greetings,

Where in the documentation can I find information on the low-level
behavior of triggers that fire as a result of insert/update statements
inside of transactions?

Do the triggers fire at the point the transaction is COMMITted? Or as
soon as the statements are encountered? (If this is the case, how are
rollbacks done - does the trigger also fire for the rollback?)

I am creating a mechanism for updating PG databases remotely (from another
PG database) for a magazine article I'm writing, and I need to figure out
how to engineer the trigger mechamisms so they work properly.

Thanks,
-Josh


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Bruce Momjian

2005-12-26, 11:23 am

Joshua Kramer wrote:
>
> Greetings,
>
> Where in the documentation can I find information on the low-level
> behavior of triggers that fire as a result of insert/update statements
> inside of transactions?
>
> Do the triggers fire at the point the transaction is COMMITted? Or as
> soon as the statements are encountered? (If this is the case, how are
> rollbacks done - does the trigger also fire for the rollback?)
>
> I am creating a mechanism for updating PG databases remotely (from another
> PG database) for a magazine article I'm writing, and I need to figure out
> how to engineer the trigger mechamisms so they work properly.


These are complex questions. Triggers fire at the end of the statement,
unless they are DEFERRRED (look that up). I recommend you look up MVCC
to see how triggers fired on statement end are automatically rolled back
on abort, meaning we don't re-run the triggers on abort, the changes
the trigger made are ignored by other backends.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com