{"id":1719,"date":"2025-01-14T20:48:48","date_gmt":"2025-01-14T13:48:48","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=1719"},"modified":"2025-01-15T07:54:11","modified_gmt":"2025-01-15T00:54:11","slug":"postgresql-disable-triggers","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/","title":{"rendered":"PostgreSQL Disable Triggers"},"content":{"rendered":"\n<p><strong>Summary<\/strong>:  In this tutorial, you&#8217;ll learn how to use the PostgreSQL <code>ALTER TABLE ... DISABLE TRIGGER<\/code> statement to disable a trigger.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='how-to-disable-triggers'>How to disable triggers <a href=\"#how-to-disable-triggers\" class=\"anchor\" id=\"how-to-disable-triggers\" title=\"Anchor for How to disable triggers\">#<\/a><\/h2>\n\n\n\n<p>Sometimes, you may want to turn off a <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-triggers\/\">trigger<\/a>. For example, triggers may cause significant overhead when performing bulk inserts due to additional operations for each inserted row.<\/p>\n\n\n\n<p>To disable a trigger, you can use the <code>ALTER TABLE DISABLE TRIGGER<\/code> statement with the following syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-built_in\">table_name<\/span>\n<span class=\"hljs-keyword\">DISABLE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> trigger_name | <span class=\"hljs-keyword\">ALL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, specify the table name to which the trigger belongs in the <code>ALTER TABLE<\/code> clause.<\/li>\n\n\n\n<li>Second, provide the trigger name you want to disable in the <code>DISABLE TRIGGER<\/code> clause. If you want to turn off all table triggers, you can use the <code>ALL<\/code> keyword instead of disabling the trigger individually.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='disabling-trigger-example'>Disabling Trigger Example <a href=\"#disabling-trigger-example\" class=\"anchor\" id=\"disabling-trigger-example\" title=\"Anchor for Disabling Trigger Example\">#<\/a><\/h2>\n\n\n\n<p>First, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-create-table\/\">create a table<\/a> to log the price change in the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> price_change_logs (\n    id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> <span class=\"hljs-keyword\">PRIMARY KEY<\/span>,\n    product_id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\n    old_price <span class=\"hljs-type\">DECIMAL<\/span>(<span class=\"hljs-number\">11<\/span>,<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\n    new_price <span class=\"hljs-type\">DECIMAL<\/span>(<span class=\"hljs-number\">11<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\n    changed_at <span class=\"hljs-type\">TIMESTAMPTZ<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> NOW(),\n    <span class=\"hljs-keyword\">FOREIGN KEY<\/span> (product_id) <span class=\"hljs-keyword\">REFERENCES<\/span> products (product_id) <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=Q1JFQVRFIFRBQkxFIHByaWNlX2NoYW5nZV9sb2dzICggaWQgSU5UIEdFTkVSQVRFRCBBTFdBWVMgQVMgSURFTlRJVFkgUFJJTUFSWSBLRVksIHByb2R1Y3RfaWQgSU5UIE5PVCBOVUxMLCBvbGRfcHJpY2UgREVDSU1BTCgxMSwyKSBOT1QgTlVMTCwgbmV3X3ByaWNlIERFQ0lNQUwoMTEsIDIpIE5PVCBOVUxMLCBjaGFuZ2VkX2F0IFRJTUVTVEFNUFRaIERFRkFVTFQgTk9XKCksIEZPUkVJR04gS0VZIChwcm9kdWN0X2lkKSBSRUZFUkVOQ0VTIHByb2R1Y3RzIChwcm9kdWN0X2lkKSBPTiBERUxFVEUgQ0FTQ0FERSApOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Second, create a trigger function that logs the price changes into the <code>price_change_logs<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">OR REPLACE<\/span> <span class=\"hljs-keyword\">FUNCTION<\/span> log_price_changes()\n<span class=\"hljs-keyword\">RETURNS<\/span> <span class=\"hljs-type\">TRIGGER<\/span> \n<span class=\"hljs-keyword\">AS<\/span> \n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-keyword\">IF<\/span> <span class=\"hljs-built_in\">NEW<\/span>.price &lt;&gt; <span class=\"hljs-built_in\">OLD<\/span>.price <span class=\"hljs-keyword\">THEN<\/span>\n        <span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> price_change_logs (product_id, old_price, new_price)\n        <span class=\"hljs-keyword\">VALUES<\/span> (<span class=\"hljs-built_in\">OLD<\/span>.product_id, <span class=\"hljs-built_in\">OLD<\/span>.price, <span class=\"hljs-built_in\">NEW<\/span>.price);\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n    <span class=\"hljs-keyword\">RETURN<\/span> <span class=\"hljs-built_in\">NEW<\/span>;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span> <span class=\"hljs-keyword\">LANGUAGE<\/span> plpgsql;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=Q1JFQVRFIE9SIFJFUExBQ0UgRlVOQ1RJT04gbG9nX3ByaWNlX2NoYW5nZXMoKQpSRVRVUk5TIFRSSUdHRVIgCkFTIAokJApCRUdJTgogICAgSUYgTkVXLnByaWNlIDw%2BIE9MRC5wcmljZSBUSEVOCiAgICAgICAgSU5TRVJUIElOVE8gcHJpY2VfY2hhbmdlX2xvZ3MgKHByb2R1Y3RfaWQsIG9sZF9wcmljZSwgbmV3X3ByaWNlKQogICAgICAgIFZBTFVFUyAoT0xELnByb2R1Y3RfaWQsIE9MRC5wcmljZSwgTkVXLnByaWNlKTsKICAgIEVORCBJRjsKICAgIFJFVFVSTiBORVc7CkVORDsKJCQgTEFOR1VBR0UgcGxwZ3NxbDs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Third, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-triggers\/\">create a trigger<\/a> that executes the <code>log_price_changes<\/code> function after updating the price in the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> price_update_trigger\n<span class=\"hljs-keyword\">AFTER<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">OF<\/span> price <span class=\"hljs-keyword\">ON<\/span> products\n<span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-keyword\">EACH<\/span> <span class=\"hljs-keyword\">ROW<\/span>\n<span class=\"hljs-keyword\">EXECUTE<\/span> <span class=\"hljs-keyword\">FUNCTION<\/span> log_price_changes();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=Q1JFQVRFIFRSSUdHRVIgcHJpY2VfdXBkYXRlX3RyaWdnZXIKQUZURVIgVVBEQVRFIE9GIHByaWNlIE9OIHByb2R1Y3RzCkZPUiBFQUNIIFJPVwpFWEVDVVRFIEZVTkNUSU9OIGxvZ19wcmljZV9jaGFuZ2VzKCk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Fourth, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-update\/\">update<\/a> the price of the product with id 1 to 799.99:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">UPDATE<\/span> products\n<span class=\"hljs-keyword\">SET<\/span> price = <span class=\"hljs-number\">799.99<\/span>\n<span class=\"hljs-keyword\">WHERE<\/span> product_id = <span class=\"hljs-number\">1<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=VVBEQVRFIHByb2R1Y3RzIFNFVCBwcmljZSA9IDc5OS45OSBXSEVSRSBwcm9kdWN0X2lkID0gMTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>The update statement causes the trigger <code>price_update_trigger<\/code> to fire, which executes the <code>log_price_changes<\/code> function. The function logs the price change into the <code>price_change_logs<\/code> table.<\/p>\n\n\n\n<p>Fifth, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-select\/\">retrieve the data<\/a> from the <code>price_change_logs<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_id,\n  old_price,\n  new_price\n<span class=\"hljs-keyword\">FROM<\/span>\n  price_change_logs;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfaWQsIG9sZF9wcmljZSwgbmV3X3ByaWNlIEZST00gcHJpY2VfY2hhbmdlX2xvZ3M7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> product_id | old_price | new_price\n------------+-----------+-----------\n          1 |    999.99 |    799.99<\/code><\/span><\/pre>\n\n\n<p>Sixth, disable the trigger <code>price_update_trigger<\/code> of the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> products\n<span class=\"hljs-keyword\">DISABLE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> price_update_trigger;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=QUxURVIgVEFCTEUgcHJvZHVjdHMgRElTQUJMRSBUUklHR0VSIHByaWNlX3VwZGF0ZV90cmlnZ2VyOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Seventh, update the price of product id 2 to 999.99:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">UPDATE<\/span> products\n<span class=\"hljs-keyword\">SET<\/span> price = <span class=\"hljs-number\">999.99<\/span>\n<span class=\"hljs-keyword\">WHERE<\/span> product_id = <span class=\"hljs-number\">2<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Eighth, retrieve data from the <code>price_change_logs<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_id,\n  old_price,\n  new_price\n<span class=\"hljs-keyword\">FROM<\/span>\n  price_change_logs\n<span class=\"hljs-keyword\">WHERE<\/span>\n  product_id = <span class=\"hljs-number\">2<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfaWQsIG9sZF9wcmljZSwgbmV3X3ByaWNlIEZST00gcHJpY2VfY2hhbmdlX2xvZ3MgV0hFUkUgcHJvZHVjdF9pZCA9IDI7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>It does not have log for the product id 2 because the trigger was disable.<\/p>\n\n\n\n<p>Finally, disable all triggers of the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> products \n<span class=\"hljs-keyword\">DISABLE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> <span class=\"hljs-keyword\">ALL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=QUxURVIgVEFCTEUgcHJvZHVjdHMgRElTQUJMRSBUUklHR0VSIEFMTDs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='enabling-triggers'>Enabling triggers <a href=\"#enabling-triggers\" class=\"anchor\" id=\"enabling-triggers\" title=\"Anchor for Enabling triggers\">#<\/a><\/h2>\n\n\n\n<p>To enable a trigger, you use the <code>ALTER TABLE ... ENABLE TRIGGER<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-built_in\">table_name<\/span>\n<span class=\"hljs-keyword\">ENABLE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> trigger_name | <span class=\"hljs-keyword\">ALL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, provide the table name to which the trigger belongs in the <code>ALTER TABLE<\/code> clause.<\/li>\n\n\n\n<li>Second, specify the trigger name you want to enable in the <code>ENABLE TRIGGER<\/code> clause. You can use the <code>ALL<\/code> keyword to enable all triggers of a table.<\/li>\n<\/ul>\n\n\n\n<p>For example, the following statement enables the trigger <code>price_update_trigger<\/code> of the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> products\n<span class=\"hljs-keyword\">ENABLE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> price_update_trigger;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=QUxURVIgVEFCTEUgcHJvZHVjdHMgRU5BQkxFIFRSSUdHRVIgcHJpY2VfdXBkYXRlX3RyaWdnZXI7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>The following example enables all triggers of the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> products\n<span class=\"hljs-keyword\">ENABLE<\/span> <span class=\"hljs-keyword\">TRIGGER<\/span> price_update_trigger;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=QUxURVIgVEFCTEUgcHJvZHVjdHMgRU5BQkxFIFRSSUdHRVIgcHJpY2VfdXBkYXRlX3RyaWdnZXI7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the PostgreSQL <code>ALTER TABLE ... DISABLE TRIGGER<\/code> statement to disable a trigger.<\/li>\n\n\n\n<li>Use the PostgreSQL <code>ALTER TABLE ... ENABLE TRIGGER<\/code> statement to enable a trigger.<br><\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1719\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Disable Triggers\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1719\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Disable Triggers\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: In this tutorial, you&#8217;ll learn how to use the PostgreSQL ALTER TABLE &#8230; DISABLE TRIGGER statement to disable a trigger. How to disable triggers # Sometimes, you may want to turn off a trigger. For example, triggers may cause significant overhead when performing bulk inserts due to additional operations for each inserted row. To [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":13,"menu_order":99,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1719","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Disable Triggers in PostgreSQL<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to use the PostgreSQL ALTER TABLE ... DISABLE TRIGGER statement to disable a trigger.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Disable Triggers in PostgreSQL\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to use the PostgreSQL ALTER TABLE ... DISABLE TRIGGER statement to disable a trigger.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-15T00:54:11+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-disable-triggers\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-disable-triggers\\\/\",\"name\":\"How to Disable Triggers in PostgreSQL\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2025-01-14T13:48:48+00:00\",\"dateModified\":\"2025-01-15T00:54:11+00:00\",\"description\":\"In this tutorial, you'll learn how to use the PostgreSQL ALTER TABLE ... DISABLE TRIGGER statement to disable a trigger.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-disable-triggers\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-disable-triggers\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-disable-triggers\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Tutorial\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL Disable Triggers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Disable Triggers in PostgreSQL","description":"In this tutorial, you'll learn how to use the PostgreSQL ALTER TABLE ... DISABLE TRIGGER statement to disable a trigger.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/","og_locale":"en_US","og_type":"article","og_title":"How to Disable Triggers in PostgreSQL","og_description":"In this tutorial, you'll learn how to use the PostgreSQL ALTER TABLE ... DISABLE TRIGGER statement to disable a trigger.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-01-15T00:54:11+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/","url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/","name":"How to Disable Triggers in PostgreSQL","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2025-01-14T13:48:48+00:00","dateModified":"2025-01-15T00:54:11+00:00","description":"In this tutorial, you'll learn how to use the PostgreSQL ALTER TABLE ... DISABLE TRIGGER statement to disable a trigger.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-disable-triggers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Tutorial","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL Disable Triggers"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=1719"}],"version-history":[{"count":6,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1719\/revisions"}],"predecessor-version":[{"id":1728,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1719\/revisions\/1728"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/13"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=1719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}