Proper Way to Disable Triggers

Lists: pgsql-general
From: Terry Lee Tucker <terry(at)chosen-ones(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Proper Way to Disable Triggers
Date: 2008-04-02 23:47:51
Message-ID: 200804021947.51540.terry@chosen-ones.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Greetings:

I am in the process of converting our 7.4.19 database to 8.3.1. We have
various scenarios where we need to disable all triggers for a given table
except for the Slony replication triggers. I'm looking for advice for the
"proper" way to do this. I have a function, disable_triggers(table), which
worked in 7.4.19 by retrieving the value of reltriggers from pg_trigger,
saving the value in another table, and then setting reltriggers to zero. Once
the work was done, we then call enable_triggers(table) which restores the
value of reltriggers. Keep in mind, all of this is in a transaction, and
thus, the action is only visible to the connection doing the work. Of course,
this also disabled the Slony trigger, which is not what we want. Now that we
are porting to 8.3.1, I'm looking for advice as to which is the best way to
disable triggers for a given table. Should I simply alter disable_triggers to
set tgenabled in pg_trigger to "D" for all the triggers I want to disable for
a given operation, and then code enable_triggers to restore the value to "O"
for said triggers?

Thanks in advance for any insight you can give...
--
Terry Lee Tucker
Turbo's IT Manager
Turbo, division of Ozburn-Hessey Logistics
2251 Jesse Jewell Pkwy NE
Gainesville, GA 30501
Tel: (336) 372-6812 Fax: (336) 372-6812 Cell: (336) 404-6987
terry(at)turbocorp(dot)com
www.turbocorp.com


From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Proper Way to Disable Triggers
Date: 2008-04-03 00:22:30
Message-ID: 90ddaf175ecc5e11f778904961818988@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

> I am in the process of converting our 7.4.19 database to 8.3.1. We have
> various scenarios where we need to disable all triggers for a given table
> except for the Slony replication triggers. I'm looking for advice for the
> "proper" way to do this.

See the new new session_replication option:

http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-SESSION-REPLICATION-ROLE

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200804022021
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAkf0IxwACgkQvJuQZxSWSsjt/gCgk+57cVz9IO6J3bSeka9jEiuB
W60An2QKLR87/Rer+gfnO9LBqIU4S5jj
=ZOcE
-----END PGP SIGNATURE-----