The following bug has been logged on the website:
Bug reference: 15883
Logged by: Jeremy Smith
Email address: jeremy@musicsmith.net
PostgreSQL version: 11.4
Operating system: All
Description:
The event trigger firing matrix table in the documentation:
https://www.postgresql.org/docs/11/event-trigger-matrix.html#EVENT-TRIGGER-BY-COMMAND-TAG
claims to list all commands for which event triggers are supported.
However, there are several triggers in the source code
(https://github.com/postgres/postgres/blob/REL_11_STABLE/src/backend/commands/event_trigger.c#L290)
that are not listed in this table.
They are:
- REFRESH MATERIALIZED VIEW
- ALTER DEFAULT PRIVILEGES
- ALTER LARGE OBJECT
- DROP OWNED
- IMPORT FOREIGN SCHEMA
I have tried creating a trigger on refresh materialized view, which seems to
work, so I believe this is a documentation issue:
CREATE TABLE public.mview_refresh_log(
mview regclass PRIMARY KEY,
last_refresh timestamp without time zone
);
CREATE OR REPLACE FUNCTION public.log_mview_refresh()
RETURNS event_trigger AS
$$
BEGIN
INSERT INTO mview_refresh(mview, last_refresh)
SELECT objid, now()
FROM pg_event_trigger_ddl_commands()
ON CONFLICT (mview) DO UPDATE SET last_refresh = EXCLUDED.last_refresh;
END;
$$ LANGUAGE plpgsql;
CREATE EVENT TRIGGER log_mview_refresh_trig
ON ddl_command_end
WHEN TAG IN ('REFRESH MATERIALIZED VIEW')
EXECUTE FUNCTION log_mview_refresh();