Skip to main content
Version: 2.0.0 (latest)

3.16. Event triggers

Event triggers work like ordinary triggers in the way they are fired: when a specific event occurs. But their similarity ends here. Instead of being activated when an event occurs on a table, the event triggers are fired whenever an event happens on the database level. In other words, event triggers are fired when a DDL command or other database-level command is issued on the server. One practical usage for event triggers is when the system administrator needs to audit commands executed on the database server or even deny certain DDL commands to be performed on it. Details about event triggers are displayed below.

ch3.eventtrigger-dialog.attributes123

Attributes
#FieldDescription
1Event

Defines the event that fires the trigger. Four events are valid: ddl_command_start, ddl_command_end, sql_drop, and table_rewrite.

The ddl_command_start event occurs just before the execution of a CREATE, ALTER, or DROP command.

The ddl_command_end event occurs just after the execution of the same commands that raise the ddl_command_start event.

The sql_drop event is sent just before the ddl_command_end event for any operation that drops database objects.

The table_rewrite event occurs just before a table is rewritten by some actions of the commands ALTER TABLE and ALTER TYPE.

2Function

The function executed by the trigger when it is activated. The function must return event_trigger and take no arguments.

3Filtered tag commands

The commands (tags) that fire the trigger, used to filter it. The complete list of commands can be found in the PostgreSQL documentation. More than one tag can be specified.

References​

Event trigger DDL
https://www.postgresql.org/docs/current/static/sql-createeventtrigger.html

Event trigger matrix
https://www.postgresql.org/docs/current/static/event-trigger-matrix.html