diff --git a/README.md b/README.md index 5c4c9a4..abe9e1e 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Generate Series Of Numbers](postgres/generate-series-of-numbers.md) - [Limit Execution Time Of Statements](postgres/limit-execution-time-of-statements.md) - [String Contains Another String](postgres/string-contains-another-string.md) +- [Temporarily Disable Triggers](postgres/temporarily-disable-triggers.md) - [Timestamp Functions](postgres/timestamp-functions.md) - [Toggling The Pager In PSQL](postgres/toggling-the-pager-in-psql.md) - [Turning Timing On](postgres/turning-timing-on.md) diff --git a/postgres/temporarily-disable-triggers.md b/postgres/temporarily-disable-triggers.md new file mode 100644 index 0000000..9bc9248 --- /dev/null +++ b/postgres/temporarily-disable-triggers.md @@ -0,0 +1,25 @@ +# Temporarily Disable Triggers + +In general, you are always going to want your triggers to fire. That's why +they are there. Though special circumstances may arise where you need to +temporarily disable them. Use + +```sql +> set session_replication_role = 'replica'; +SET +``` + +By changing the +[replication role](http://www.postgresql.org/docs/9.4/static/runtime-config-client.html#GUC-SESSION-REPLICATION-ROLE) +from `origin` to +`replica` you are essentially disabling all non-replica triggers across the +database (for that session). When you are done, you can simply set the +replication role back so that normal trigger behavior can resume + +```sql +> set session_replication_role = 'origin'; +SET +``` + +A more direct and fine-grained approach to disabling triggers is to use an +`alter table` command that targets a specific trigger.