avoidEnableDisableTrigger

Diagnostic Category: lint/safety/avoidEnableDisableTrigger

Since: vnext

Sources: - Inspired from: pgfence/enable-disable-trigger

Description

Enabling or disabling a trigger acquires a SHARE ROW EXCLUSIVE lock.

ALTER TABLE ... ENABLE/DISABLE TRIGGER blocks concurrent writes while the lock is held. This can cause downtime on busy tables.

Examples

Invalid

alter table my_table enable trigger my_trigger;
code-block.sql:1:1 lint/safety/avoidEnableDisableTrigger ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! Enabling or disabling a trigger acquires a SHARE ROW EXCLUSIVE lock.

  > 1 │ alter table my_table enable trigger my_trigger;
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 

  i This blocks concurrent writes. Consider the impact on busy tables and use SET lock_timeout.


Valid

select 1;

How to configure


{
  "linter": {
    "rules": {
      "safety": {
        "avoidEnableDisableTrigger": "error"
      }
    }
  }
}