| From: | "Teemu Juntunen" <teemu(dot)juntunen(at)e-ngine(dot)fi> |
|---|---|
| To: | "PostgreSQL" <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: ENABLE / DISABLE ALL TRIGGERS IN DATABASE |
| Date: | 2008-08-27 09:21:12 |
| Message-ID: | 9CEBD523D1CD4916AE46EC487323B524@eng02 |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Terry Lee Tucker | 2008-08-27 09:36:44 | Re: ENABLE / DISABLE ALL TRIGGERS IN DATABASE |
| Previous Message | Pavel Stehule | 2008-08-27 08:42:54 | Re: update and group by/aggregate |