4.55 avg. rating (90% score) - 11 votes
To temporarily disable all triggers in a PostgreSQL session, use this:
|
SET session_replication_role = replica; |
That disables all triggers for the current database session only. Useful for bulk operations, but remember to be careful to keep your database consistent.
To re-enable:
|
SET session_replication_role = DEFAULT; |
Disable a Single Trigger
To disable just a single trigger, use ALTER TABLE:
|
ALTER TABLE mytable DISABLE TRIGGER mytrigger; |
The difference to the previous method is that ALTER TABLE will globally disable the trigger, affecting all database sessions, not just the current one.
To disable all triggers for one table:
|
ALTER TABLE mytable DISABLE TRIGGER ALL; |
To re-enable:
|
ALTER TABLE mytable ENABLE TRIGGER ALL; |