How can you tell if a trigger is enabled in PostgreSQL?

Hao picture Hao · Apr 1, 2009 · Viewed 14.2k times · Source

My googling-fu is failing me. How to know if a PostgreSQL trigger is disabled or not?

Answer

tolgayilmaz picture tolgayilmaz · Apr 14, 2015

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.