add-trigger
warningCREATE TRIGGER
Why it's unsafe
CREATE TRIGGER takes a SHARE ROW EXCLUSIVE lock (blocking writes and other DDL, though not reads) and changes behavior for every subsequent write to the table.
Safe rewrite
Create the trigger during a low-traffic window; its lock conflicts with concurrent writes on the table.
Example
Try it in the playground →Unsafe
CREATE TRIGGER trg_audit AFTER INSERT ON users FOR EACH ROW EXECUTE FUNCTION audit();