How do I temporarily disable triggers in PostgreSQL?

David Schmitt picture David Schmitt · Oct 15, 2010 · Viewed 124.6k times · Source

I'm bulk loading data and can re-calculate all trigger modifications much more cheaply after the fact than on a row-by-row basis.

How can I temporarily disable all triggers in PostgreSQL?

Answer

zyzof picture zyzof · Sep 10, 2013

Alternatively, if you are wanting to disable all triggers, not just those on the USER table, you can use:

SET session_replication_role = replica;

This disables triggers for the current session.

To re-enable for the same session:

SET session_replication_role = DEFAULT;

Source: http://koo.fi/blog/2013/01/08/disable-postgresql-triggers-temporarily/