Event triggers automatically run a user-defined function when specified DDL events occur in ParadeDB.
Event triggers let you react instantly to DDL changes—such as CREATE TABLE or ALTER FUNCTION—without polling or manual scripts. They help enforce standards, capture audit logs, or regenerate dependent objects.
Regular triggers fire on data changes in a single table, while event triggers fire on global catalog events.They operate at the database level and can inspect multiple affected objects through helper functions.
Use them to: (1) log every schema change to an audit_ddl
table; (2) block unapproved DROP TABLE on critical tables like Orders
; (3) refresh materialized views after bulk DDL migrations.
First, create a SECURITY DEFINER function returning event_trigger
. Then attach it with CREATE EVENT TRIGGER
.The trigger fires on events you specify, such as ddl_command_end
or sql_drop
.
CREATE EVENT TRIGGER
needs a name, event, optional filters, and the function to call. ParadeDB inherits PostgreSQL options like WHEN TAG IN (...)
for granular filtering.
Query pg_event_trigger
or run \dy
in psql/Galaxy.This shows trigger names, events, and attached functions, enabling quick audits of active hooks.
Disable with ALTER EVENT TRIGGER trigger_name DISABLE;
or remove entirely using DROP EVENT TRIGGER trigger_name;
. Always test in staging to avoid accidental production outages.
1. Keep functions lightweight—write to an async queue if heavy work is needed. 2. Use SECURITY DEFINER
and set proper ownership. 3.Version-control both trigger and function DDL.
See dedicated section below for typical pitfalls like forgetting catalog helper calls and mis-scoping filters.
Event triggers are powerful automation hooks. When used carefully, they improve auditability and governance in ParadeDB-backed applications while reducing manual overhead.
.
No. They only respond to DDL events. Use table triggers for INSERT/UPDATE/DELETE operations.
Yes. If the surrounding transaction rolls back, changes made inside the trigger also roll back unless you use autonomous transactions via dblink or background workers.
Triggers themselves are schema objects and replicate via logical replication. Their side effects execute on the subscriber if the function exists there.