2012-07-18 16:16:16 +02:00
|
|
|
-- should fail, return type mismatch
|
|
|
|
create event trigger regress_event_trigger
|
|
|
|
on ddl_command_start
|
|
|
|
execute procedure pg_backend_pid();
|
2016-04-01 18:35:48 +02:00
|
|
|
ERROR: function pg_backend_pid must return type event_trigger
|
2012-07-20 17:38:47 +02:00
|
|
|
-- OK
|
|
|
|
create function test_event_trigger() returns event_trigger as $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE 'test_event_trigger: % %', tg_event, tg_tag;
|
|
|
|
END
|
|
|
|
$$ language plpgsql;
|
Fix confusion about event trigger vs. plain function in plpgsql.
The function hash table keys made by compute_function_hashkey() failed
to distinguish event-trigger call context from regular call context.
This meant that once we'd successfully made a hash entry for an event
trigger (either by validation, or by normal use as an event trigger),
an attempt to call the trigger function as a plain function would
find this hash entry and thereby bypass the you-can't-do-that check in
do_compile(). Thus we'd attempt to execute the function, leading to
strange errors or even crashes, depending on function contents and
server version.
To fix, add an isEventTrigger field to PLpgSQL_func_hashkey,
paralleling the longstanding infrastructure for regular triggers.
This fits into what had been pad space, so there's no risk of an ABI
break, even assuming that any third-party code is looking at these
hash keys. (I considered replacing isTrigger with a PLpgSQL_trigtype
enum field, but felt that that carried some API/ABI risk. Maybe we
should change it in HEAD though.)
Per bug #16266 from Alexander Lakhin. This has been broken since
event triggers were invented, so back-patch to all supported branches.
Discussion: https://postgr.es/m/16266-fcd7f838e97ba5d4@postgresql.org
2020-02-19 20:44:58 +01:00
|
|
|
-- should fail, can't call it as a plain function
|
|
|
|
SELECT test_event_trigger();
|
|
|
|
ERROR: trigger functions can only be called as triggers
|
|
|
|
CONTEXT: compilation of PL/pgSQL function "test_event_trigger" near line 1
|
2015-03-06 23:14:28 +01:00
|
|
|
-- should fail, event triggers cannot have declared arguments
|
|
|
|
create function test_event_trigger_arg(name text)
|
|
|
|
returns event_trigger as $$ BEGIN RETURN 1; END $$ language plpgsql;
|
|
|
|
ERROR: event trigger functions cannot have declared arguments
|
|
|
|
CONTEXT: compilation of PL/pgSQL function "test_event_trigger_arg" near line 1
|
|
|
|
-- should fail, SQL functions cannot be event triggers
|
|
|
|
create function test_event_trigger_sql() returns event_trigger as $$
|
|
|
|
SELECT 1 $$ language sql;
|
|
|
|
ERROR: SQL functions cannot return type event_trigger
|
2012-07-18 16:16:16 +02:00
|
|
|
-- should fail, no elephant_bootstrap entry point
|
|
|
|
create event trigger regress_event_trigger on elephant_bootstrap
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
ERROR: unrecognized event name "elephant_bootstrap"
|
|
|
|
-- OK
|
|
|
|
create event trigger regress_event_trigger on ddl_command_start
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2013-01-23 12:46:27 +01:00
|
|
|
-- OK
|
2013-01-22 00:00:24 +01:00
|
|
|
create event trigger regress_event_trigger_end on ddl_command_end
|
2018-10-01 23:02:55 +02:00
|
|
|
execute function test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
-- should fail, food is not a valid filter variable
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
2016-06-03 16:13:36 +02:00
|
|
|
when food in ('sandwich')
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
ERROR: unrecognized filter variable "food"
|
2016-06-03 16:13:36 +02:00
|
|
|
-- should fail, sandwich is not a valid command tag
|
2012-07-18 16:16:16 +02:00
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
2016-06-03 16:13:36 +02:00
|
|
|
when tag in ('sandwich')
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2016-06-03 16:13:36 +02:00
|
|
|
ERROR: filter value "sandwich" not recognized for filter variable "tag"
|
2015-05-17 14:57:30 +02:00
|
|
|
-- should fail, create skunkcabbage is not a valid command tag
|
2012-07-18 16:16:16 +02:00
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('create table', 'create skunkcabbage')
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
ERROR: filter value "create skunkcabbage" not recognized for filter variable "tag"
|
|
|
|
-- should fail, can't have event triggers on event triggers
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('DROP EVENT TRIGGER')
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2013-04-11 17:00:09 +02:00
|
|
|
ERROR: event triggers are not supported for DROP EVENT TRIGGER
|
2015-03-06 23:14:28 +01:00
|
|
|
-- should fail, can't have event triggers on global objects
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('CREATE ROLE')
|
|
|
|
execute procedure test_event_trigger();
|
|
|
|
ERROR: event triggers are not supported for CREATE ROLE
|
|
|
|
-- should fail, can't have event triggers on global objects
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('CREATE DATABASE')
|
|
|
|
execute procedure test_event_trigger();
|
|
|
|
ERROR: event triggers are not supported for CREATE DATABASE
|
|
|
|
-- should fail, can't have event triggers on global objects
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('CREATE TABLESPACE')
|
|
|
|
execute procedure test_event_trigger();
|
|
|
|
ERROR: event triggers are not supported for CREATE TABLESPACE
|
2012-07-18 16:16:16 +02:00
|
|
|
-- should fail, can't have same filter variable twice
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('create table') and tag in ('CREATE FUNCTION')
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
ERROR: filter variable "tag" specified more than once
|
2015-03-06 23:14:28 +01:00
|
|
|
-- should fail, can't have arguments
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
execute procedure test_event_trigger('argument not allowed');
|
|
|
|
ERROR: syntax error at or near "'argument not allowed'"
|
|
|
|
LINE 2: execute procedure test_event_trigger('argument not allowe...
|
|
|
|
^
|
2012-07-18 16:16:16 +02:00
|
|
|
-- OK
|
|
|
|
create event trigger regress_event_trigger2 on ddl_command_start
|
|
|
|
when tag in ('create table', 'CREATE FUNCTION')
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
-- OK
|
|
|
|
comment on event trigger regress_event_trigger is 'test comment';
|
|
|
|
-- drop as non-superuser should fail
|
2016-07-18 00:42:31 +02:00
|
|
|
create role regress_evt_user;
|
|
|
|
set role regress_evt_user;
|
2012-07-18 16:16:16 +02:00
|
|
|
create event trigger regress_event_trigger_noperms on ddl_command_start
|
2012-07-20 17:38:47 +02:00
|
|
|
execute procedure test_event_trigger();
|
2012-07-18 16:16:16 +02:00
|
|
|
ERROR: permission denied to create event trigger "regress_event_trigger_noperms"
|
|
|
|
HINT: Must be superuser to create an event trigger.
|
|
|
|
reset role;
|
2018-01-18 17:24:07 +01:00
|
|
|
-- test enabling and disabling
|
2012-07-20 17:38:47 +02:00
|
|
|
alter event trigger regress_event_trigger disable;
|
2018-01-18 17:24:07 +01:00
|
|
|
-- fires _trigger2 and _trigger_end should fire, but not _trigger
|
2012-07-20 17:38:47 +02:00
|
|
|
create table event_trigger_fire1 (a int);
|
2013-01-23 12:46:27 +01:00
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
2013-01-22 00:00:24 +01:00
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE TABLE
|
2018-01-18 17:24:07 +01:00
|
|
|
alter event trigger regress_event_trigger enable;
|
|
|
|
set session_replication_role = replica;
|
|
|
|
-- fires nothing
|
|
|
|
create table event_trigger_fire2 (a int);
|
|
|
|
alter event trigger regress_event_trigger enable replica;
|
|
|
|
-- fires only _trigger
|
|
|
|
create table event_trigger_fire3 (a int);
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
alter event trigger regress_event_trigger enable always;
|
|
|
|
-- fires only _trigger
|
|
|
|
create table event_trigger_fire4 (a int);
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
reset session_replication_role;
|
|
|
|
-- fires all three
|
|
|
|
create table event_trigger_fire5 (a int);
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE TABLE
|
2018-10-05 15:20:01 +02:00
|
|
|
-- non-top-level command
|
|
|
|
create function f1() returns int
|
|
|
|
language plpgsql
|
|
|
|
as $$
|
|
|
|
begin
|
|
|
|
create table event_trigger_fire6 (a int);
|
|
|
|
return 0;
|
|
|
|
end $$;
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE FUNCTION
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE FUNCTION
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE FUNCTION
|
|
|
|
select f1();
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE TABLE
|
|
|
|
f1
|
|
|
|
----
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- non-top-level command
|
|
|
|
create procedure p1()
|
|
|
|
language plpgsql
|
|
|
|
as $$
|
|
|
|
begin
|
|
|
|
create table event_trigger_fire7 (a int);
|
|
|
|
end $$;
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE PROCEDURE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE PROCEDURE
|
|
|
|
call p1();
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE TABLE
|
2018-01-18 17:24:07 +01:00
|
|
|
-- clean up
|
|
|
|
alter event trigger regress_event_trigger disable;
|
2018-10-05 15:20:01 +02:00
|
|
|
drop table event_trigger_fire2, event_trigger_fire3, event_trigger_fire4, event_trigger_fire5, event_trigger_fire6, event_trigger_fire7;
|
2018-01-18 17:24:07 +01:00
|
|
|
NOTICE: test_event_trigger: ddl_command_end DROP TABLE
|
2018-10-05 15:20:01 +02:00
|
|
|
drop routine f1(), p1();
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end DROP ROUTINE
|
2015-03-06 23:14:28 +01:00
|
|
|
-- regress_event_trigger_end should fire on these commands
|
|
|
|
grant all on table event_trigger_fire1 to public;
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end GRANT
|
|
|
|
comment on table event_trigger_fire1 is 'here is a comment';
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end COMMENT
|
|
|
|
revoke all on table event_trigger_fire1 from public;
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end REVOKE
|
2012-07-20 17:38:47 +02:00
|
|
|
drop table event_trigger_fire1;
|
2013-01-22 00:00:24 +01:00
|
|
|
NOTICE: test_event_trigger: ddl_command_end DROP TABLE
|
2015-03-11 21:01:13 +01:00
|
|
|
create foreign data wrapper useless;
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE FOREIGN DATA WRAPPER
|
|
|
|
create server useless_server foreign data wrapper useless;
|
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE SERVER
|
2016-07-18 00:42:31 +02:00
|
|
|
create user mapping for regress_evt_user server useless_server;
|
2015-03-11 21:01:13 +01:00
|
|
|
NOTICE: test_event_trigger: ddl_command_end CREATE USER MAPPING
|
2016-07-18 00:42:31 +02:00
|
|
|
alter default privileges for role regress_evt_user
|
|
|
|
revoke delete on tables from regress_evt_user;
|
2015-03-11 23:23:47 +01:00
|
|
|
NOTICE: test_event_trigger: ddl_command_end ALTER DEFAULT PRIVILEGES
|
2012-07-18 16:16:16 +02:00
|
|
|
-- alter owner to non-superuser should fail
|
2016-07-18 00:42:31 +02:00
|
|
|
alter event trigger regress_event_trigger owner to regress_evt_user;
|
2012-07-18 16:16:16 +02:00
|
|
|
ERROR: permission denied to change owner of event trigger "regress_event_trigger"
|
|
|
|
HINT: The owner of an event trigger must be a superuser.
|
|
|
|
-- alter owner to superuser should work
|
2016-07-18 00:42:31 +02:00
|
|
|
alter role regress_evt_user superuser;
|
|
|
|
alter event trigger regress_event_trigger owner to regress_evt_user;
|
2012-07-18 16:16:16 +02:00
|
|
|
-- should fail, name collision
|
|
|
|
alter event trigger regress_event_trigger rename to regress_event_trigger2;
|
|
|
|
ERROR: event trigger "regress_event_trigger2" already exists
|
|
|
|
-- OK
|
|
|
|
alter event trigger regress_event_trigger rename to regress_event_trigger3;
|
|
|
|
-- should fail, doesn't exist any more
|
|
|
|
drop event trigger regress_event_trigger;
|
|
|
|
ERROR: event trigger "regress_event_trigger" does not exist
|
2016-07-18 00:42:31 +02:00
|
|
|
-- should fail, regress_evt_user owns some objects
|
|
|
|
drop role regress_evt_user;
|
|
|
|
ERROR: role "regress_evt_user" cannot be dropped because some objects depend on it
|
2019-03-25 00:15:37 +01:00
|
|
|
DETAIL: owner of event trigger regress_event_trigger3
|
|
|
|
owner of user mapping for regress_evt_user on server useless_server
|
|
|
|
owner of default privileges on new relations belonging to role regress_evt_user
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
-- cleanup before next test
|
2012-07-18 16:16:16 +02:00
|
|
|
-- these are all OK; the second one should emit a NOTICE
|
|
|
|
drop event trigger if exists regress_event_trigger2;
|
|
|
|
drop event trigger if exists regress_event_trigger2;
|
|
|
|
NOTICE: event trigger "regress_event_trigger2" does not exist, skipping
|
|
|
|
drop event trigger regress_event_trigger3;
|
2013-01-22 00:00:24 +01:00
|
|
|
drop event trigger regress_event_trigger_end;
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
-- test support for dropped objects
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE SCHEMA schema_one authorization regress_evt_user;
|
|
|
|
CREATE SCHEMA schema_two authorization regress_evt_user;
|
|
|
|
CREATE SCHEMA audit_tbls authorization regress_evt_user;
|
2015-04-06 16:40:55 +02:00
|
|
|
CREATE TEMP TABLE a_temp_tbl ();
|
2016-07-18 00:42:31 +02:00
|
|
|
SET SESSION AUTHORIZATION regress_evt_user;
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
CREATE TABLE schema_one.table_one(a int);
|
|
|
|
CREATE TABLE schema_one."table two"(a int);
|
|
|
|
CREATE TABLE schema_one.table_three(a int);
|
|
|
|
CREATE TABLE audit_tbls.schema_one_table_two(the_value text);
|
|
|
|
CREATE TABLE schema_two.table_two(a int);
|
|
|
|
CREATE TABLE schema_two.table_three(a int, b text);
|
|
|
|
CREATE TABLE audit_tbls.schema_two_table_three(the_value text);
|
|
|
|
CREATE OR REPLACE FUNCTION schema_two.add(int, int) RETURNS int LANGUAGE plpgsql
|
|
|
|
CALLED ON NULL INPUT
|
|
|
|
AS $$ BEGIN RETURN coalesce($1,0) + coalesce($2,0); END; $$;
|
|
|
|
CREATE AGGREGATE schema_two.newton
|
|
|
|
(BASETYPE = int, SFUNC = schema_two.add, STYPE = int);
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
CREATE TABLE undroppable_objs (
|
|
|
|
object_type text,
|
|
|
|
object_identity text
|
|
|
|
);
|
|
|
|
INSERT INTO undroppable_objs VALUES
|
|
|
|
('table', 'schema_one.table_three'),
|
|
|
|
('table', 'audit_tbls.schema_two_table_three');
|
|
|
|
CREATE TABLE dropped_objects (
|
|
|
|
type text,
|
|
|
|
schema text,
|
|
|
|
object text
|
|
|
|
);
|
|
|
|
-- This tests errors raised within event triggers; the one in audit_tbls
|
|
|
|
-- uses 2nd-level recursive invocation via test_evtrig_dropped_objects().
|
|
|
|
CREATE OR REPLACE FUNCTION undroppable() RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql AS $$
|
|
|
|
DECLARE
|
|
|
|
obj record;
|
|
|
|
BEGIN
|
|
|
|
PERFORM 1 FROM pg_tables WHERE tablename = 'undroppable_objs';
|
|
|
|
IF NOT FOUND THEN
|
|
|
|
RAISE NOTICE 'table undroppable_objs not found, skipping';
|
|
|
|
RETURN;
|
|
|
|
END IF;
|
|
|
|
FOR obj IN
|
|
|
|
SELECT * FROM pg_event_trigger_dropped_objects() JOIN
|
|
|
|
undroppable_objs USING (object_type, object_identity)
|
|
|
|
LOOP
|
|
|
|
RAISE EXCEPTION 'object % of type % cannot be dropped',
|
|
|
|
obj.object_identity, obj.object_type;
|
|
|
|
END LOOP;
|
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
CREATE EVENT TRIGGER undroppable ON sql_drop
|
|
|
|
EXECUTE PROCEDURE undroppable();
|
|
|
|
CREATE OR REPLACE FUNCTION test_evtrig_dropped_objects() RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql AS $$
|
|
|
|
DECLARE
|
|
|
|
obj record;
|
|
|
|
BEGIN
|
|
|
|
FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
|
|
|
|
LOOP
|
|
|
|
IF obj.object_type = 'table' THEN
|
|
|
|
EXECUTE format('DROP TABLE IF EXISTS audit_tbls.%I',
|
|
|
|
format('%s_%s', obj.schema_name, obj.object_name));
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
INSERT INTO dropped_objects
|
|
|
|
(type, schema, object) VALUES
|
|
|
|
(obj.object_type, obj.schema_name, obj.object_identity);
|
|
|
|
END LOOP;
|
|
|
|
END
|
|
|
|
$$;
|
|
|
|
CREATE EVENT TRIGGER regress_event_trigger_drop_objects ON sql_drop
|
|
|
|
WHEN TAG IN ('drop table', 'drop function', 'drop view',
|
|
|
|
'drop owned', 'drop schema', 'alter table')
|
|
|
|
EXECUTE PROCEDURE test_evtrig_dropped_objects();
|
|
|
|
ALTER TABLE schema_one.table_one DROP COLUMN a;
|
|
|
|
DROP SCHEMA schema_one, schema_two CASCADE;
|
|
|
|
NOTICE: drop cascades to 7 other objects
|
|
|
|
DETAIL: drop cascades to table schema_two.table_two
|
|
|
|
drop cascades to table schema_two.table_three
|
|
|
|
drop cascades to function schema_two.add(integer,integer)
|
|
|
|
drop cascades to function schema_two.newton(integer)
|
|
|
|
drop cascades to table schema_one.table_one
|
|
|
|
drop cascades to table schema_one."table two"
|
|
|
|
drop cascades to table schema_one.table_three
|
|
|
|
NOTICE: table "schema_two_table_two" does not exist, skipping
|
|
|
|
NOTICE: table "audit_tbls_schema_two_table_three" does not exist, skipping
|
|
|
|
ERROR: object audit_tbls.schema_two_table_three of type table cannot be dropped
|
2015-09-05 17:58:20 +02:00
|
|
|
CONTEXT: PL/pgSQL function undroppable() line 14 at RAISE
|
|
|
|
SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_three"
|
2015-08-19 01:22:37 +02:00
|
|
|
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
DELETE FROM undroppable_objs WHERE object_identity = 'audit_tbls.schema_two_table_three';
|
|
|
|
DROP SCHEMA schema_one, schema_two CASCADE;
|
|
|
|
NOTICE: drop cascades to 7 other objects
|
|
|
|
DETAIL: drop cascades to table schema_two.table_two
|
|
|
|
drop cascades to table schema_two.table_three
|
|
|
|
drop cascades to function schema_two.add(integer,integer)
|
|
|
|
drop cascades to function schema_two.newton(integer)
|
|
|
|
drop cascades to table schema_one.table_one
|
|
|
|
drop cascades to table schema_one."table two"
|
|
|
|
drop cascades to table schema_one.table_three
|
|
|
|
NOTICE: table "schema_two_table_two" does not exist, skipping
|
|
|
|
NOTICE: table "audit_tbls_schema_two_table_three" does not exist, skipping
|
|
|
|
NOTICE: table "schema_one_table_one" does not exist, skipping
|
|
|
|
NOTICE: table "schema_one_table two" does not exist, skipping
|
|
|
|
NOTICE: table "schema_one_table_three" does not exist, skipping
|
|
|
|
ERROR: object schema_one.table_three of type table cannot be dropped
|
2015-09-05 17:58:20 +02:00
|
|
|
CONTEXT: PL/pgSQL function undroppable() line 14 at RAISE
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
DELETE FROM undroppable_objs WHERE object_identity = 'schema_one.table_three';
|
|
|
|
DROP SCHEMA schema_one, schema_two CASCADE;
|
|
|
|
NOTICE: drop cascades to 7 other objects
|
|
|
|
DETAIL: drop cascades to table schema_two.table_two
|
|
|
|
drop cascades to table schema_two.table_three
|
|
|
|
drop cascades to function schema_two.add(integer,integer)
|
|
|
|
drop cascades to function schema_two.newton(integer)
|
|
|
|
drop cascades to table schema_one.table_one
|
|
|
|
drop cascades to table schema_one."table two"
|
|
|
|
drop cascades to table schema_one.table_three
|
|
|
|
NOTICE: table "schema_two_table_two" does not exist, skipping
|
|
|
|
NOTICE: table "audit_tbls_schema_two_table_three" does not exist, skipping
|
|
|
|
NOTICE: table "schema_one_table_one" does not exist, skipping
|
|
|
|
NOTICE: table "schema_one_table two" does not exist, skipping
|
|
|
|
NOTICE: table "schema_one_table_three" does not exist, skipping
|
|
|
|
SELECT * FROM dropped_objects WHERE schema IS NULL OR schema <> 'pg_toast';
|
|
|
|
type | schema | object
|
|
|
|
--------------+------------+-------------------------------------
|
|
|
|
table column | schema_one | schema_one.table_one.a
|
|
|
|
schema | | schema_two
|
|
|
|
table | schema_two | schema_two.table_two
|
|
|
|
type | schema_two | schema_two.table_two
|
|
|
|
type | schema_two | schema_two.table_two[]
|
|
|
|
table | audit_tbls | audit_tbls.schema_two_table_three
|
|
|
|
type | audit_tbls | audit_tbls.schema_two_table_three
|
|
|
|
type | audit_tbls | audit_tbls.schema_two_table_three[]
|
|
|
|
table | schema_two | schema_two.table_three
|
|
|
|
type | schema_two | schema_two.table_three
|
|
|
|
type | schema_two | schema_two.table_three[]
|
|
|
|
function | schema_two | schema_two.add(integer,integer)
|
|
|
|
aggregate | schema_two | schema_two.newton(integer)
|
|
|
|
schema | | schema_one
|
|
|
|
table | schema_one | schema_one.table_one
|
|
|
|
type | schema_one | schema_one.table_one
|
|
|
|
type | schema_one | schema_one.table_one[]
|
|
|
|
table | schema_one | schema_one."table two"
|
|
|
|
type | schema_one | schema_one."table two"
|
|
|
|
type | schema_one | schema_one."table two"[]
|
|
|
|
table | schema_one | schema_one.table_three
|
|
|
|
type | schema_one | schema_one.table_three
|
|
|
|
type | schema_one | schema_one.table_three[]
|
|
|
|
(23 rows)
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP OWNED BY regress_evt_user;
|
2014-01-23 18:40:29 +01:00
|
|
|
NOTICE: schema "audit_tbls" does not exist, skipping
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
SELECT * FROM dropped_objects WHERE type = 'schema';
|
|
|
|
type | schema | object
|
|
|
|
--------+--------+------------
|
|
|
|
schema | | schema_two
|
|
|
|
schema | | schema_one
|
|
|
|
schema | | audit_tbls
|
|
|
|
(3 rows)
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP ROLE regress_evt_user;
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
|
|
|
|
DROP EVENT TRIGGER undroppable;
|
2021-06-14 07:57:22 +02:00
|
|
|
-- Event triggers on relations.
|
2014-12-19 19:00:45 +01:00
|
|
|
CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
|
|
|
|
RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql
|
|
|
|
AS $$
|
|
|
|
DECLARE r record;
|
|
|
|
BEGIN
|
|
|
|
FOR r IN SELECT * from pg_event_trigger_dropped_objects()
|
|
|
|
LOOP
|
|
|
|
IF NOT r.normal AND NOT r.original THEN
|
|
|
|
CONTINUE;
|
|
|
|
END IF;
|
2015-04-06 16:40:55 +02:00
|
|
|
RAISE NOTICE 'NORMAL: orig=% normal=% istemp=% type=% identity=% name=% args=%',
|
|
|
|
r.original, r.normal, r.is_temporary, r.object_type,
|
|
|
|
r.object_identity, r.address_names, r.address_args;
|
2014-12-19 19:00:45 +01:00
|
|
|
END LOOP;
|
|
|
|
END; $$;
|
|
|
|
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
|
|
|
|
EXECUTE PROCEDURE event_trigger_report_dropped();
|
2021-06-14 07:57:22 +02:00
|
|
|
CREATE OR REPLACE FUNCTION event_trigger_report_end()
|
|
|
|
RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql
|
|
|
|
AS $$
|
|
|
|
DECLARE r RECORD;
|
|
|
|
BEGIN
|
|
|
|
FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
|
|
|
|
LOOP
|
|
|
|
RAISE NOTICE 'END: command_tag=% type=% identity=%',
|
|
|
|
r.command_tag, r.object_type, r.object_identity;
|
|
|
|
END LOOP;
|
|
|
|
END; $$;
|
|
|
|
CREATE EVENT TRIGGER regress_event_trigger_report_end ON ddl_command_end
|
|
|
|
EXECUTE PROCEDURE event_trigger_report_end();
|
2014-12-19 19:00:45 +01:00
|
|
|
CREATE SCHEMA evttrig
|
2021-06-14 07:57:22 +02:00
|
|
|
CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two', col_c SERIAL)
|
2014-12-19 19:00:45 +01:00
|
|
|
CREATE INDEX one_idx ON one (col_b)
|
2021-06-14 07:57:22 +02:00
|
|
|
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42)
|
|
|
|
CREATE TABLE id (col_d int NOT NULL GENERATED ALWAYS AS IDENTITY);
|
|
|
|
NOTICE: END: command_tag=CREATE SCHEMA type=schema identity=evttrig
|
|
|
|
NOTICE: END: command_tag=CREATE SEQUENCE type=sequence identity=evttrig.one_col_a_seq
|
|
|
|
NOTICE: END: command_tag=CREATE SEQUENCE type=sequence identity=evttrig.one_col_c_seq
|
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.one
|
Catalog not-null constraints
We now create contype='n' pg_constraint rows for not-null constraints.
We propagate these constraints to other tables during operations such as
adding inheritance relationships, creating and attaching partitions and
creating tables LIKE other tables. We also spawn not-null constraints
for inheritance child tables when their parents have primary keys.
These related constraints mostly follow the well-known rules of
conislocal and coninhcount that we have for CHECK constraints, with some
adaptations: for example, as opposed to CHECK constraints, we don't
match not-null ones by name when descending a hierarchy to alter it,
instead matching by column name that they apply to. This means we don't
require the constraint names to be identical across a hierarchy.
For now, we omit them for system catalogs. Maybe this is worth
reconsidering. We don't support NOT VALID nor DEFERRABLE clauses
either; these can be added as separate features later (this patch is
already large and complicated enough.)
psql shows these constraints in \d+.
pg_dump requires some ad-hoc hacks, particularly when dumping a primary
key. We now create one "throwaway" not-null constraint for each column
in the PK together with the CREATE TABLE command, and once the PK is
created, all those throwaway constraints are removed. This avoids
having to check each tuple for nullness when the dump restores the
primary key creation.
pg_upgrading from an older release requires a somewhat brittle procedure
to create a constraint state that matches what would be created if the
database were being created fresh in Postgres 17. I have tested all the
scenarios I could think of, and it works correctly as far as I can tell,
but I could have neglected weird cases.
This patch has been very long in the making. The first patch was
written by Bernd Helmle in 2010 to add a new pg_constraint.contype value
('n'), which I (Álvaro) then hijacked in 2011 and 2012, until that one
was killed by the realization that we ought to use contype='c' instead:
manufactured CHECK constraints. However, later SQL standard
development, as well as nonobvious emergent properties of that design
(mostly, failure to distinguish them from "normal" CHECK constraints as
well as the performance implication of having to test the CHECK
expression) led us to reconsider this choice, so now the current
implementation uses contype='n' again. During Postgres 16 this had
already been introduced by commit e056c557aef4, but there were some
problems mainly with the pg_upgrade procedure that couldn't be fixed in
reasonable time, so it was reverted.
In 2016 Vitaly Burovoy also worked on this feature[1] but found no
consensus for his proposed approach, which was claimed to be closer to
the letter of the standard, requiring an additional pg_attribute column
to track the OID of the not-null constraint for that column.
[1] https://postgr.es/m/CAKOSWNkN6HSyatuys8xZxzRCR-KL1OkHS5-b9qd9bf1Rad3PLA@mail.gmail.com
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Author: Bernd Helmle <mailings@oopsware.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
2023-08-25 13:31:24 +02:00
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE INDEX type=index identity=evttrig.one_pkey
|
|
|
|
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.one_col_a_seq
|
|
|
|
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.one_col_c_seq
|
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.two
|
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.two
|
|
|
|
NOTICE: END: command_tag=CREATE SEQUENCE type=sequence identity=evttrig.id_col_d_seq
|
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.id
|
|
|
|
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.id_col_d_seq
|
|
|
|
NOTICE: END: command_tag=CREATE INDEX type=index identity=evttrig.one_idx
|
2018-10-07 00:17:46 +02:00
|
|
|
-- Partitioned tables with a partitioned index
|
|
|
|
CREATE TABLE evttrig.parted (
|
|
|
|
id int PRIMARY KEY)
|
|
|
|
PARTITION BY RANGE (id);
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.parted
|
Catalog not-null constraints
We now create contype='n' pg_constraint rows for not-null constraints.
We propagate these constraints to other tables during operations such as
adding inheritance relationships, creating and attaching partitions and
creating tables LIKE other tables. We also spawn not-null constraints
for inheritance child tables when their parents have primary keys.
These related constraints mostly follow the well-known rules of
conislocal and coninhcount that we have for CHECK constraints, with some
adaptations: for example, as opposed to CHECK constraints, we don't
match not-null ones by name when descending a hierarchy to alter it,
instead matching by column name that they apply to. This means we don't
require the constraint names to be identical across a hierarchy.
For now, we omit them for system catalogs. Maybe this is worth
reconsidering. We don't support NOT VALID nor DEFERRABLE clauses
either; these can be added as separate features later (this patch is
already large and complicated enough.)
psql shows these constraints in \d+.
pg_dump requires some ad-hoc hacks, particularly when dumping a primary
key. We now create one "throwaway" not-null constraint for each column
in the PK together with the CREATE TABLE command, and once the PK is
created, all those throwaway constraints are removed. This avoids
having to check each tuple for nullness when the dump restores the
primary key creation.
pg_upgrading from an older release requires a somewhat brittle procedure
to create a constraint state that matches what would be created if the
database were being created fresh in Postgres 17. I have tested all the
scenarios I could think of, and it works correctly as far as I can tell,
but I could have neglected weird cases.
This patch has been very long in the making. The first patch was
written by Bernd Helmle in 2010 to add a new pg_constraint.contype value
('n'), which I (Álvaro) then hijacked in 2011 and 2012, until that one
was killed by the realization that we ought to use contype='c' instead:
manufactured CHECK constraints. However, later SQL standard
development, as well as nonobvious emergent properties of that design
(mostly, failure to distinguish them from "normal" CHECK constraints as
well as the performance implication of having to test the CHECK
expression) led us to reconsider this choice, so now the current
implementation uses contype='n' again. During Postgres 16 this had
already been introduced by commit e056c557aef4, but there were some
problems mainly with the pg_upgrade procedure that couldn't be fixed in
reasonable time, so it was reverted.
In 2016 Vitaly Burovoy also worked on this feature[1] but found no
consensus for his proposed approach, which was claimed to be closer to
the letter of the standard, requiring an additional pg_attribute column
to track the OID of the not-null constraint for that column.
[1] https://postgr.es/m/CAKOSWNkN6HSyatuys8xZxzRCR-KL1OkHS5-b9qd9bf1Rad3PLA@mail.gmail.com
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Author: Bernd Helmle <mailings@oopsware.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
2023-08-25 13:31:24 +02:00
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.parted
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE INDEX type=index identity=evttrig.parted_pkey
|
2018-10-07 00:17:46 +02:00
|
|
|
CREATE TABLE evttrig.part_1_10 PARTITION OF evttrig.parted (id)
|
|
|
|
FOR VALUES FROM (1) TO (10);
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_1_10
|
2018-10-07 00:17:46 +02:00
|
|
|
CREATE TABLE evttrig.part_10_20 PARTITION OF evttrig.parted (id)
|
|
|
|
FOR VALUES FROM (10) TO (20) PARTITION BY RANGE (id);
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_10_20
|
2018-10-07 00:17:46 +02:00
|
|
|
CREATE TABLE evttrig.part_10_15 PARTITION OF evttrig.part_10_20 (id)
|
|
|
|
FOR VALUES FROM (10) TO (15);
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_10_15
|
2018-10-07 00:17:46 +02:00
|
|
|
CREATE TABLE evttrig.part_15_20 PARTITION OF evttrig.part_10_20 (id)
|
|
|
|
FOR VALUES FROM (15) TO (20);
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_15_20
|
2014-12-19 19:00:45 +01:00
|
|
|
ALTER TABLE evttrig.two DROP COLUMN col_c;
|
2015-04-06 16:40:55 +02:00
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=f type=table column identity=evttrig.two.col_c name={evttrig,two,col_c} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table constraint identity=two_col_c_check on evttrig.two name={evttrig,two,two_col_c_check} args={}
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.two
|
2014-12-19 19:00:45 +01:00
|
|
|
ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
|
2015-04-06 16:40:55 +02:00
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=f type=default value identity=for evttrig.one.col_b name={evttrig,one,col_b} args={}
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
|
2014-12-19 19:00:45 +01:00
|
|
|
ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
|
2015-04-06 16:40:55 +02:00
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=f type=table constraint identity=one_pkey on evttrig.one name={evttrig,one,one_pkey} args={}
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
|
|
|
|
ALTER TABLE evttrig.one DROP COLUMN col_c;
|
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=f type=table column identity=evttrig.one.col_c name={evttrig,one,col_c} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=default value identity=for evttrig.one.col_c name={evttrig,one,col_c} args={}
|
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
|
|
|
|
ALTER TABLE evttrig.id ALTER COLUMN col_d SET DATA TYPE bigint;
|
|
|
|
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.id_col_d_seq
|
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.id
|
|
|
|
ALTER TABLE evttrig.id ALTER COLUMN col_d DROP IDENTITY,
|
|
|
|
ALTER COLUMN col_d SET DATA TYPE int;
|
|
|
|
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.id
|
2014-12-19 19:00:45 +01:00
|
|
|
DROP INDEX evttrig.one_idx;
|
2015-04-06 16:40:55 +02:00
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=f type=index identity=evttrig.one_idx name={evttrig,one_idx} args={}
|
2014-12-19 19:00:45 +01:00
|
|
|
DROP SCHEMA evttrig CASCADE;
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: drop cascades to 4 other objects
|
2014-12-19 19:00:45 +01:00
|
|
|
DETAIL: drop cascades to table evttrig.one
|
|
|
|
drop cascades to table evttrig.two
|
2021-06-14 07:57:22 +02:00
|
|
|
drop cascades to table evttrig.id
|
2018-10-07 00:17:46 +02:00
|
|
|
drop cascades to table evttrig.parted
|
2015-04-06 16:40:55 +02:00
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=f type=schema identity=evttrig name={evttrig} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.one name={evttrig,one} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=sequence identity=evttrig.one_col_a_seq name={evttrig,one_col_a_seq} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=default value identity=for evttrig.one.col_a name={evttrig,one,col_a} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.two name={evttrig,two} args={}
|
2021-06-14 07:57:22 +02:00
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.id name={evttrig,id} args={}
|
2018-10-07 00:17:46 +02:00
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.parted name={evttrig,parted} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_1_10 name={evttrig,part_1_10} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_20 name={evttrig,part_10_20} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_15 name={evttrig,part_10_15} args={}
|
|
|
|
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_15_20 name={evttrig,part_15_20} args={}
|
2015-04-06 16:40:55 +02:00
|
|
|
DROP TABLE a_temp_tbl;
|
|
|
|
NOTICE: NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
|
2022-05-20 18:52:55 +02:00
|
|
|
-- CREATE OPERATOR CLASS without FAMILY clause should report
|
|
|
|
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
|
|
|
|
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
|
|
|
|
NOTICE: END: command_tag=CREATE OPERATOR FAMILY type=operator family identity=public.evttrigopclass USING btree
|
|
|
|
NOTICE: END: command_tag=CREATE OPERATOR CLASS type=operator class identity=public.evttrigopclass USING btree
|
2014-12-19 19:00:45 +01:00
|
|
|
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
|
2021-06-14 07:57:22 +02:00
|
|
|
DROP EVENT TRIGGER regress_event_trigger_report_end;
|
2014-12-07 16:55:28 +01:00
|
|
|
-- only allowed from within an event trigger function, should fail
|
|
|
|
select pg_event_trigger_table_rewrite_oid();
|
|
|
|
ERROR: pg_event_trigger_table_rewrite_oid() can only be called in a table_rewrite event trigger function
|
|
|
|
-- test Table Rewrite Event Trigger
|
|
|
|
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql AS $$
|
|
|
|
BEGIN
|
2015-09-05 17:58:20 +02:00
|
|
|
RAISE EXCEPTION 'rewrites not allowed';
|
2014-12-07 16:55:28 +01:00
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
create event trigger no_rewrite_allowed on table_rewrite
|
|
|
|
execute procedure test_evtrig_no_rewrite();
|
2019-03-09 05:16:27 +01:00
|
|
|
create table rewriteme (id serial primary key, foo float, bar timestamptz);
|
2014-12-07 16:55:28 +01:00
|
|
|
insert into rewriteme
|
|
|
|
select x * 1.001 from generate_series(1, 500) as t(x);
|
|
|
|
alter table rewriteme alter column foo type numeric;
|
2015-09-05 17:58:20 +02:00
|
|
|
ERROR: rewrites not allowed
|
|
|
|
CONTEXT: PL/pgSQL function test_evtrig_no_rewrite() line 3 at RAISE
|
2014-12-07 16:55:28 +01:00
|
|
|
alter table rewriteme add column baz int default 0;
|
|
|
|
-- test with more than one reason to rewrite a single table
|
|
|
|
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)',
|
|
|
|
pg_event_trigger_table_rewrite_oid()::regclass,
|
|
|
|
pg_event_trigger_table_rewrite_reason();
|
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
alter table rewriteme
|
|
|
|
add column onemore int default 0,
|
|
|
|
add column another int default -1,
|
|
|
|
alter column foo type numeric(10,4);
|
2018-03-28 02:13:52 +02:00
|
|
|
NOTICE: Table 'rewriteme' is being rewritten (reason = 4)
|
2022-08-17 07:55:20 +02:00
|
|
|
-- matview rewrite when changing access method
|
|
|
|
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT 1 AS a;
|
|
|
|
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap2;
|
|
|
|
NOTICE: Table 'heapmv' is being rewritten (reason = 8)
|
|
|
|
DROP MATERIALIZED VIEW heapmv;
|
2014-12-07 16:55:28 +01:00
|
|
|
-- shouldn't trigger a table_rewrite event
|
|
|
|
alter table rewriteme alter column foo type numeric(12,4);
|
2019-03-09 05:16:27 +01:00
|
|
|
begin;
|
|
|
|
set timezone to 'UTC';
|
|
|
|
alter table rewriteme alter column bar type timestamp;
|
|
|
|
set timezone to '0';
|
|
|
|
alter table rewriteme alter column bar type timestamptz;
|
|
|
|
set timezone to 'Europe/London';
|
|
|
|
alter table rewriteme alter column bar type timestamp; -- does rewrite
|
|
|
|
NOTICE: Table 'rewriteme' is being rewritten (reason = 4)
|
|
|
|
rollback;
|
2015-03-01 15:58:07 +01:00
|
|
|
-- typed tables are rewritten when their type changes. Don't emit table
|
|
|
|
-- name, because firing order is not stable.
|
|
|
|
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE 'Table is being rewritten (reason = %)',
|
|
|
|
pg_event_trigger_table_rewrite_reason();
|
|
|
|
END;
|
|
|
|
$$;
|
2015-02-27 22:38:33 +01:00
|
|
|
create type rewritetype as (a int);
|
|
|
|
create table rewritemetoo1 of rewritetype;
|
|
|
|
create table rewritemetoo2 of rewritetype;
|
|
|
|
alter type rewritetype alter attribute a type text cascade;
|
2015-03-01 15:58:07 +01:00
|
|
|
NOTICE: Table is being rewritten (reason = 4)
|
|
|
|
NOTICE: Table is being rewritten (reason = 4)
|
2015-02-27 22:38:33 +01:00
|
|
|
-- but this doesn't work
|
|
|
|
create table rewritemetoo3 (a rewritetype);
|
|
|
|
alter type rewritetype alter attribute a type varchar cascade;
|
|
|
|
ERROR: cannot alter type "rewritetype" because column "rewritemetoo3.a" uses it
|
2014-12-07 16:55:28 +01:00
|
|
|
drop table rewriteme;
|
|
|
|
drop event trigger no_rewrite_allowed;
|
|
|
|
drop function test_evtrig_no_rewrite();
|
2023-12-04 01:53:49 +01:00
|
|
|
-- Tests for REINDEX
|
|
|
|
CREATE OR REPLACE FUNCTION reindex_start_command()
|
|
|
|
RETURNS event_trigger AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE 'REINDEX START: % %', tg_event, tg_tag;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE EVENT TRIGGER regress_reindex_start ON ddl_command_start
|
|
|
|
WHEN TAG IN ('REINDEX')
|
|
|
|
EXECUTE PROCEDURE reindex_start_command();
|
|
|
|
CREATE FUNCTION reindex_end_command()
|
|
|
|
RETURNS event_trigger AS $$
|
|
|
|
DECLARE
|
|
|
|
obj record;
|
|
|
|
BEGIN
|
|
|
|
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
|
|
|
|
LOOP
|
|
|
|
RAISE NOTICE 'REINDEX END: command_tag=% type=% identity=%',
|
|
|
|
obj.command_tag, obj.object_type, obj.object_identity;
|
|
|
|
END LOOP;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE EVENT TRIGGER regress_reindex_end ON ddl_command_end
|
|
|
|
WHEN TAG IN ('REINDEX')
|
|
|
|
EXECUTE PROCEDURE reindex_end_command();
|
2023-12-07 00:31:02 +01:00
|
|
|
-- Extra event to force the use of a snapshot.
|
|
|
|
CREATE FUNCTION reindex_end_command_snap() RETURNS EVENT_TRIGGER
|
|
|
|
AS $$ BEGIN PERFORM 1; END $$ LANGUAGE plpgsql;
|
|
|
|
CREATE EVENT TRIGGER regress_reindex_end_snap ON ddl_command_end
|
|
|
|
EXECUTE FUNCTION reindex_end_command_snap();
|
|
|
|
-- With simple relation
|
2023-12-04 01:53:49 +01:00
|
|
|
CREATE TABLE concur_reindex_tab (c1 int);
|
|
|
|
CREATE INDEX concur_reindex_ind ON concur_reindex_tab (c1);
|
|
|
|
-- Both start and end triggers enabled.
|
|
|
|
REINDEX INDEX concur_reindex_ind;
|
|
|
|
NOTICE: REINDEX START: ddl_command_start REINDEX
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_ind
|
|
|
|
REINDEX TABLE concur_reindex_tab;
|
|
|
|
NOTICE: REINDEX START: ddl_command_start REINDEX
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_ind
|
|
|
|
REINDEX INDEX CONCURRENTLY concur_reindex_ind;
|
|
|
|
NOTICE: REINDEX START: ddl_command_start REINDEX
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_ind
|
|
|
|
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
|
|
|
|
NOTICE: REINDEX START: ddl_command_start REINDEX
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_ind
|
|
|
|
-- with start trigger disabled.
|
|
|
|
ALTER EVENT TRIGGER regress_reindex_start DISABLE;
|
|
|
|
REINDEX INDEX concur_reindex_ind;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_ind
|
|
|
|
REINDEX INDEX CONCURRENTLY concur_reindex_ind;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_ind
|
2023-12-07 00:31:02 +01:00
|
|
|
-- without an index
|
|
|
|
DROP INDEX concur_reindex_ind;
|
|
|
|
REINDEX TABLE concur_reindex_tab;
|
|
|
|
NOTICE: table "concur_reindex_tab" has no indexes to reindex
|
|
|
|
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
|
|
|
|
NOTICE: table "concur_reindex_tab" has no indexes that can be reindexed concurrently
|
|
|
|
-- With a Schema
|
|
|
|
CREATE SCHEMA concur_reindex_schema;
|
|
|
|
-- No indexes
|
|
|
|
REINDEX SCHEMA concur_reindex_schema;
|
|
|
|
REINDEX SCHEMA CONCURRENTLY concur_reindex_schema;
|
|
|
|
CREATE TABLE concur_reindex_schema.tab (a int);
|
|
|
|
CREATE INDEX ind ON concur_reindex_schema.tab (a);
|
|
|
|
-- One index reported
|
|
|
|
REINDEX SCHEMA concur_reindex_schema;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=concur_reindex_schema.ind
|
|
|
|
REINDEX SCHEMA CONCURRENTLY concur_reindex_schema;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=concur_reindex_schema.ind
|
|
|
|
-- One table on schema but no indexes
|
|
|
|
DROP INDEX concur_reindex_schema.ind;
|
|
|
|
REINDEX SCHEMA concur_reindex_schema;
|
|
|
|
REINDEX SCHEMA CONCURRENTLY concur_reindex_schema;
|
|
|
|
DROP SCHEMA concur_reindex_schema CASCADE;
|
|
|
|
NOTICE: drop cascades to table concur_reindex_schema.tab
|
|
|
|
-- With a partitioned table, and nothing else.
|
|
|
|
CREATE TABLE concur_reindex_part (id int) PARTITION BY RANGE (id);
|
|
|
|
REINDEX TABLE concur_reindex_part;
|
|
|
|
REINDEX TABLE CONCURRENTLY concur_reindex_part;
|
|
|
|
-- Partition that would be reindexed, still nothing.
|
|
|
|
CREATE TABLE concur_reindex_child PARTITION OF concur_reindex_part
|
|
|
|
FOR VALUES FROM (0) TO (10);
|
|
|
|
REINDEX TABLE concur_reindex_part;
|
|
|
|
REINDEX TABLE CONCURRENTLY concur_reindex_part;
|
|
|
|
-- Now add some indexes.
|
|
|
|
CREATE INDEX concur_reindex_partidx ON concur_reindex_part (id);
|
|
|
|
REINDEX INDEX concur_reindex_partidx;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_child_id_idx
|
|
|
|
REINDEX INDEX CONCURRENTLY concur_reindex_partidx;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_child_id_idx
|
|
|
|
REINDEX TABLE concur_reindex_part;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_child_id_idx
|
|
|
|
REINDEX TABLE CONCURRENTLY concur_reindex_part;
|
|
|
|
NOTICE: REINDEX END: command_tag=REINDEX type=index identity=public.concur_reindex_child_id_idx
|
|
|
|
DROP TABLE concur_reindex_part;
|
2023-12-04 01:53:49 +01:00
|
|
|
-- Clean up
|
|
|
|
DROP EVENT TRIGGER regress_reindex_start;
|
|
|
|
DROP EVENT TRIGGER regress_reindex_end;
|
2023-12-07 00:31:02 +01:00
|
|
|
DROP EVENT TRIGGER regress_reindex_end_snap;
|
2023-12-04 01:53:49 +01:00
|
|
|
DROP FUNCTION reindex_end_command();
|
2023-12-07 00:31:02 +01:00
|
|
|
DROP FUNCTION reindex_end_command_snap();
|
2023-12-04 01:53:49 +01:00
|
|
|
DROP FUNCTION reindex_start_command();
|
|
|
|
DROP TABLE concur_reindex_tab;
|
2015-01-02 21:09:39 +01:00
|
|
|
-- test Row Security Event Trigger
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
CREATE TABLE event_trigger_test (a integer, b text);
|
|
|
|
CREATE OR REPLACE FUNCTION start_command()
|
|
|
|
RETURNS event_trigger AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE '% - ddl_command_start', tg_tag;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE OR REPLACE FUNCTION end_command()
|
|
|
|
RETURNS event_trigger AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE '% - ddl_command_end', tg_tag;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE OR REPLACE FUNCTION drop_sql_command()
|
|
|
|
RETURNS event_trigger AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE '% - sql_drop', tg_tag;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE EVENT TRIGGER start_rls_command ON ddl_command_start
|
|
|
|
WHEN TAG IN ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') EXECUTE PROCEDURE start_command();
|
|
|
|
CREATE EVENT TRIGGER end_rls_command ON ddl_command_end
|
|
|
|
WHEN TAG IN ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') EXECUTE PROCEDURE end_command();
|
|
|
|
CREATE EVENT TRIGGER sql_drop_command ON sql_drop
|
|
|
|
WHEN TAG IN ('DROP POLICY') EXECUTE PROCEDURE drop_sql_command();
|
|
|
|
CREATE POLICY p1 ON event_trigger_test USING (FALSE);
|
|
|
|
NOTICE: CREATE POLICY - ddl_command_start
|
|
|
|
NOTICE: CREATE POLICY - ddl_command_end
|
|
|
|
ALTER POLICY p1 ON event_trigger_test USING (TRUE);
|
|
|
|
NOTICE: ALTER POLICY - ddl_command_start
|
|
|
|
NOTICE: ALTER POLICY - ddl_command_end
|
|
|
|
ALTER POLICY p1 ON event_trigger_test RENAME TO p2;
|
|
|
|
NOTICE: ALTER POLICY - ddl_command_start
|
|
|
|
NOTICE: ALTER POLICY - ddl_command_end
|
|
|
|
DROP POLICY p2 ON event_trigger_test;
|
|
|
|
NOTICE: DROP POLICY - ddl_command_start
|
|
|
|
NOTICE: DROP POLICY - sql_drop
|
|
|
|
NOTICE: DROP POLICY - ddl_command_end
|
2021-04-28 04:17:58 +02:00
|
|
|
-- Check the object addresses of all the event triggers.
|
|
|
|
SELECT
|
|
|
|
e.evtname,
|
|
|
|
pg_describe_object('pg_event_trigger'::regclass, e.oid, 0) as descr,
|
|
|
|
b.type, b.object_names, b.object_args,
|
|
|
|
pg_identify_object(a.classid, a.objid, a.objsubid) as ident
|
|
|
|
FROM pg_event_trigger as e,
|
|
|
|
LATERAL pg_identify_object_as_address('pg_event_trigger'::regclass, e.oid, 0) as b,
|
|
|
|
LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a
|
|
|
|
ORDER BY e.evtname;
|
|
|
|
evtname | descr | type | object_names | object_args | ident
|
|
|
|
-------------------+---------------------------------+---------------+---------------------+-------------+--------------------------------------------------------
|
|
|
|
end_rls_command | event trigger end_rls_command | event trigger | {end_rls_command} | {} | ("event trigger",,end_rls_command,end_rls_command)
|
|
|
|
sql_drop_command | event trigger sql_drop_command | event trigger | {sql_drop_command} | {} | ("event trigger",,sql_drop_command,sql_drop_command)
|
|
|
|
start_rls_command | event trigger start_rls_command | event trigger | {start_rls_command} | {} | ("event trigger",,start_rls_command,start_rls_command)
|
|
|
|
(3 rows)
|
|
|
|
|
2015-01-02 21:09:39 +01:00
|
|
|
DROP EVENT TRIGGER start_rls_command;
|
|
|
|
DROP EVENT TRIGGER end_rls_command;
|
|
|
|
DROP EVENT TRIGGER sql_drop_command;
|
2023-09-25 12:41:49 +02:00
|
|
|
-- Check the GUC for disabling event triggers
|
|
|
|
CREATE FUNCTION test_event_trigger_guc() RETURNS event_trigger
|
|
|
|
LANGUAGE plpgsql AS $$
|
|
|
|
DECLARE
|
|
|
|
obj record;
|
|
|
|
BEGIN
|
|
|
|
FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
|
|
|
|
LOOP
|
|
|
|
RAISE NOTICE '% dropped %', tg_tag, obj.object_type;
|
|
|
|
END LOOP;
|
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
CREATE EVENT TRIGGER test_event_trigger_guc
|
|
|
|
ON sql_drop
|
|
|
|
WHEN TAG IN ('DROP POLICY') EXECUTE FUNCTION test_event_trigger_guc();
|
|
|
|
SET event_triggers = 'on';
|
|
|
|
CREATE POLICY pguc ON event_trigger_test USING (FALSE);
|
|
|
|
DROP POLICY pguc ON event_trigger_test;
|
|
|
|
NOTICE: DROP POLICY dropped policy
|
|
|
|
CREATE POLICY pguc ON event_trigger_test USING (FALSE);
|
|
|
|
SET event_triggers = 'off';
|
|
|
|
DROP POLICY pguc ON event_trigger_test;
|