Oracle event triggers (system triggers) automatically fire on database or schema events such as LOGON, DDL, STARTUP, and SHUTDOWN.
Oracle event triggers—also called system triggers—execute PL/SQL blocks when specific database or schema events occur (e.g., LOGON, ALTER, DROP).
Use them for auditing DDL, enforcing security policies, initializing session settings, or capturing system-wide metrics without touching application code.
Write a CREATE TRIGGER statement, pick BEFORE/AFTER timing, list one or more events, scope it to DATABASE or SCHEMA, then add PL/SQL logic.
CREATE OR REPLACE TRIGGER trg_name
AFTER LOGON ON DATABASE
BEGIN
-- logic
END;
/
LOGON, LOGOFF, STARTUP, SHUTDOWN, CREATE, ALTER, DROP, GRANT, REVOKE, and many more. DDL events can be combined with OR.
CREATE TABLE ddl_audit (
username VARCHAR2(30),
action VARCHAR2(30),
object_name VARCHAR2(128),
action_time TIMESTAMP DEFAULT SYSTIMESTAMP
);
CREATE OR REPLACE TRIGGER trg_ddl_audit
AFTER CREATE OR ALTER OR DROP ON SCHEMA
DECLARE
BEGIN
IF ora_dict_obj_name = 'PRODUCTS' THEN
INSERT INTO ddl_audit(username, action, object_name)
VALUES (USER, ora_sysevent, ora_dict_obj_name);
END IF;
END;
/
Keep code lightweight, log errors, avoid COMMIT/ROLLBACK, and monitor performance. Always document trigger purpose and owner.
Using COMMIT inside a trigger—breaks atomicity. Remove COMMIT and let calling session commit.
Forgetting to limit scope—triggers that fire on every DDL hurt performance. Add IF filters or restrict to specific events.
Yes. Triggers run synchronously, so heavy logic slows the originating event. Keep work minimal or offload to background jobs.
ALTER TRIGGER trg_ddl_audit DISABLE;
ALTER TRIGGER trg_ddl_audit ENABLE;
DROP TRIGGER trg_ddl_audit;
1) Identify event and scope. 2) Create audit/support table if needed. 3) Write CREATE TRIGGER. 4) Test. 5) Document and monitor.
Yes—use ALTER TRIGGER trigger_name DISABLE, then ENABLE when done.
Query DBA_TRIGGERS or USER_TRIGGERS: SELECT trigger_name, triggering_event FROM user_triggers WHERE base_object_type IS NULL;
Only if they perform heavy work. Keep LOGON logic short—or push complex tasks to DBMS_SCHEDULER jobs.
Yes. Run ALTER TRIGGER trigger_name DISABLE to turn it off, and ALTER TRIGGER trigger_name ENABLE to restore it.
Query USER_SOURCE or use SQL Developer: SELECT text FROM user_source WHERE name='TRIGGER_NAME' ORDER BY line;
Yes. Triggers are data dictionary objects and are transferred to standby databases, but they only fire on the primary unless the standby is opened read-write.