My googling-fu is failing me. How to know if a PostgreSQL trigger is disabled or not?
To enable a trigger or all triggers associated with a table, you use the ALTER TABLE ENABLE TRIGGER statement: ALTER TABLE table_name ENABLE TRIGGER trigger_name | ALL; In this syntax: First, specify the name of the table of the trigger that you want to enable.
PostgreSQL Triggers are database callback functions, which are automatically performed/invoked when a specified database event occurs. A trigger that is marked FOR EACH ROW is called once for every row that the operation modifies.
A constraint trigger can only be specified as AFTER . One of INSERT , UPDATE , DELETE , or TRUNCATE ; this specifies the event that will fire the trigger. Multiple events can be specified using OR , except when transition relations are requested.
The SQL below will do the work. It displays all triggers in your current database.
SELECT pg_namespace.nspname, pg_class.relname, pg_trigger.*
FROM pg_trigger
JOIN pg_class ON pg_trigger.tgrelid = pg_class.oid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
If tgenabled is 'D', the trigger is disabled. All other values (documented here) indicate, that it is enabled in some way.
BTW. If you want to check the triggers for a specific table, the query is a bit shorter:
SELECT * FROM pg_trigger
WHERE tgrelid = 'your_schema.your_table'::regclass
The cast to the regclass type gets you from qualified table name to OID (object id) the easy way.
It's my first day with postresql, but I think you can check the trigger state via pg_trigger system table: http://www.postgresql.org/docs/current/static/catalog-pg-trigger.html
The columns you will need are tgrelid
and tgenabled
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With