# man > CREATE_EVENT_TRIGGER(7)

---
type: CommandReference
command: CREATE EVENT TRIGGER
mode: man
section: 7
source: man-pages
---

## Quick Reference
- Forbid all DDL commands:  
  ```sql
  CREATE OR REPLACE FUNCTION abort_any_command()
    RETURNS event_trigger
   LANGUAGE plpgsql
    AS $$
  BEGIN
    RAISE EXCEPTION 'command % is disabled', tg_tag;
  END;
  $$;

  CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
     EXECUTE FUNCTION abort_any_command();
  
- Restrict trigger to specific command tags:  
  ```sql
  CREATE EVENT TRIGGER drop_filter ON ddl_command_start
     WHEN TAG IN ('DROP TABLE', 'DROP FUNCTION')
     EXECUTE FUNCTION my_event_func();
  
## Name
CREATE EVENT TRIGGER — define a new event trigger

## Synopsis
sql
CREATE EVENT TRIGGER name
    ON event
    [ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
    EXECUTE { FUNCTION | PROCEDURE } function_name()
## Options
- **`name`** — The name of the trigger, unique within the database.
- **`event`** — The event that fires the trigger (e.g., `ddl_command_start`, `ddl_command_end`, `sql_drop`, `table_rewrite`).
- **`WHEN filter_variable IN (filter_value [, ...])`** — Optional filter clause. Currently only `TAG` is supported as `filter_variable`, filtering by command tag strings (e.g., `'DROP FUNCTION'`).
- **`function_name`** — A user-supplied function that takes no arguments and returns `event_trigger`. The keywords `FUNCTION` and `PROCEDURE` are equivalent, but a function (not a procedure) must be provided. `PROCEDURE` is deprecated.

> **Note:** Only superusers can create event triggers. Event triggers are disabled in single-user mode.

## Examples
Forbid the execution of any DDL command:
sql
CREATE OR REPLACE FUNCTION abort_any_command()
  RETURNS event_trigger
 LANGUAGE plpgsql
  AS $$
BEGIN
  RAISE EXCEPTION 'command % is disabled', tg_tag;
END;
$$;

CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
   EXECUTE FUNCTION abort_any_command();
## See Also
- [ALTER EVENT TRIGGER](https://www.postgresql.org/docs/14/sql-altereventtrigger.html)
- [DROP EVENT TRIGGER](https://www.postgresql.org/docs/14/sql-dropeventtrigger.html)
- [CREATE FUNCTION](https://www.postgresql.org/docs/14/sql-createfunction.html)