ddl_command_end not firing DROP events

From: Demitri Muna <postgresql(at)demitri(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: ddl_command_end not firing DROP events
Date: 2018-07-08 17:46:25
Message-ID: E73C07B3-2E50-43A4-94BE-DEF6277AA5AB@demitri.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I’ve created a trigger where I want to capture schema-changing events. I’m finding that DROP events are not being triggered when using “ddl_command_end". The test case below demonstrates this. I am running PostgreSQL 10.4. The trigger is fired for the CREATE event, but not DROP TYPE or DROP TABLE.

I came across the same question on the mailing list, but the solution was to use the “sql_drop” trigger instead.

https://www.postgresql.org/message-id/CAHE3wgjX-N%3DX9mccp4Bs-y-%3DHE%3DqayHEpXpCs1jMT%3DW0ZsYc5A%40mail.gmail.com

The documentation suggests that one should be able to use “ddl_command_end” instead of creating two triggers (i.e. one for DROPs, another for everything else).

Test:

CREATE FUNCTION test_event_trigger_for_drops()
RETURNS event_trigger LANGUAGE plpgsql AS $$
DECLARE
obj record;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
LOOP
RAISE NOTICE 'caught % event on ''%''',
obj.command_tag,
obj.object_identity;
END LOOP;
END
$$;
CREATE EVENT TRIGGER test_event_trigger_for_drops
ON ddl_command_end
EXECUTE PROCEDURE test_event_trigger_for_drops();

CREATE TYPE foo AS (f1 int, f2 text);
DROP TYPE foo;
CREATE TABLE drop_test ( pk int ) WITH ( OIDS = FALSE );
DROP TABLE drop_test;

-- for ease of copy/paste to delete the above
DROP EVENT TRIGGER test_event_trigger_for_drops;
DROP FUNCTION test_event_trigger_for_drops;

Cheers,
Demitri

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2018-07-08 18:19:29 Re: ddl_command_end not firing DROP events
Previous Message Matt Dee 2018-07-08 13:51:47 Specifying WAL Location in Streaming Replication