Unix Technical Forum

ENABLE / DISABLE ALL TRIGGERS IN DATABASE

This is a discussion on ENABLE / DISABLE ALL TRIGGERS IN DATABASE within the Pgsql General forums, part of the PostgreSQL category; --> Hi, I think this has been asked before, but I can't find the answer from arcive nor google. How ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-29-2008, 09:59 AM
Teemu Juntunen
 
Posts: n/a
Default ENABLE / DISABLE ALL TRIGGERS IN DATABASE

Hi,

I think this has been asked before, but I can't find the answer from arcive nor google. How to disable/enable all the riggers in a database? I have problem with disabled triggers after database restore. If there is no simple way, could this be made in a function where you find the table names and construct the needed commands in strings. If so, how to get all the tablenames from database?

Best regards and thanks!
Teemu Juntunen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-29-2008, 09:59 AM
Teemu Juntunen
 
Posts: n/a
Default Re: ENABLE / DISABLE ALL TRIGGERS IN DATABASE

Hi,

I made the function myself. Here is it, if anyone else has a need for this.

Teemu

/* Enable/disable all the triggers in database */
CREATE OR REPLACE FUNCTION fn_triggerall(DoEnable boolean) RETURNS integer AS
$BODY$
DECLARE
mytables RECORD;
BEGIN
FOR mytables IN SELECT relname FROM pg_class WHERE reltriggers > 0 AND NOT relname LIKE 'pg_%'
LOOP
IF DoEnable THEN
EXECUTE 'ALTER TABLE ' || mytables.relname || ' ENABLE TRIGGER ALL';
ELSE
EXECUTE 'ALTER TABLE ' || mytables.relname || ' DISABLE TRIGGER ALL';
END IF;
END LOOP;

RETURN 1;

END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION fn_triggerall(DoEnable boolean) OWNER TO postgres;
COMMENT ON FUNCTION fn_triggerall(DoEnable boolean) IS 'Enable/disable all the triggers in database';
----- Original Message -----
From: Teemu Juntunen
To: PostgreSQL
Sent: Wednesday, August 27, 2008 11:24 AM
Subject: [GENERAL] ENABLE / DISABLE ALL TRIGGERS IN DATABASE


Hi,

I think this has been asked before, but I can't find the answer from arcive nor google. How to disable/enable all the riggers in a database? I have problem with disabled triggers after database restore. If there is no simple way, could this be made in a function where you find the table names and construct the needed commands in strings. If so, how to get all the tablenames from database?

Best regards and thanks!
Teemu Juntunen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-29-2008, 09:59 AM
Terry Lee Tucker
 
Posts: n/a
Default Re: ENABLE / DISABLE ALL TRIGGERS IN DATABASE

On Wednesday 27 August 2008 04:24, Teemu Juntunen wrote:
> Hi,
>
> I think this has been asked before, but I can't find the answer from arcive
> nor google. How to disable/enable all the riggers in a database? I have
> problem with disabled triggers after database restore. If there is no
> simple way, could this be made in a function where you find the table names
> and construct the needed commands in strings. If so, how to get all the
> tablenames from database?
>
> Best regards and thanks!
> Teemu Juntunen


You can accomplish this by manipulating the run time parameter,
session_replication_role. For example, from within your psql session:
SET SESSION session_replication_role = replica;
This will prevent all triggers from firing for the entire session except those
defined as "replica". We use this all the time.

HTH...
--
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@turbocorp.com
www.turbocorp.com

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads for: ENABLE / DISABLE ALL TRIGGERS IN DATABASE

Thread Thread Starter Forum Replies Last Post
Re: Commands to enable and disable DATABASE LOGGING Dattatreya Govindappanavar Informix 0 04-20-2008 04:18 PM
Re: Commands to enable and disable DATABASE LOGGING Dattatreya Govindappanavar Informix 0 04-20-2008 04:18 PM
Re: Commands to enable and disable DATABASE LOGGING Martin Fuerderer Informix 0 04-20-2008 04:18 PM
Commands to enable and disable DATABASE LOGGING Navaid Arif Informix 0 04-20-2008 04:18 PM
Re: Enable/Disable Triggers Tom Lane Pgsql General 0 04-09-2008 02:32 PM


All times are GMT. The time now is 10:43 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com