bdr: allow ALTER TABLE ... DISABLE/ENABLE TRIGGER commands
authorPetr Jelinek <pjmodos@pjmodos.net>
Wed, 20 Aug 2014 16:35:49 +0000 (18:35 +0200)
committerAndres Freund <andres@anarazel.de>
Mon, 8 Sep 2014 15:49:58 +0000 (17:49 +0200)
bdr_commandfilter.c
expected/ddl/function.out
sql/ddl/function.sql

index 7d9f413c8be75272e7478e0b088cdd8700274d2f..c62a22d9799cf5b657f9641343ce394ac575228f 100644 (file)
@@ -251,6 +251,16 @@ filter_AlterTableStmt(Node *parsetree,
                case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */
                    break;
 
+               case AT_EnableTrig:
+               case AT_EnableAlwaysTrig:
+               case AT_EnableReplicaTrig:
+               case AT_DisableTrig:
+               case AT_EnableTrigAll:
+               case AT_DisableTrigAll:
+               case AT_EnableTrigUser:
+               case AT_DisableTrigUser:
+                   break;
+
                default:
                    hasInvalid = true;
                    break;
index abe64aa7182208a14d13054020088e1d1d7b3d91..d50c1c1d5c8e2082d8d3f9d61c4185b8bd5cafab 100644 (file)
@@ -147,6 +147,13 @@ Triggers:
     truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
 
 ALTER TRIGGER test_trigger_fn_trg1 ON test_trigger_table RENAME TO test_trigger_fn_trg;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
 \d+ test_trigger_table
                   Table "public.test_trigger_table"
  Column |  Type   | Modifiers | Storage  | Stats target | Description 
@@ -170,7 +177,14 @@ Triggers:
     test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
     truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
 
-DROP TRIGGER test_trigger_fn_trg2 ON test_trigger_table;
+ALTER TABLE test_trigger_table DISABLE TRIGGER test_trigger_fn_trg;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
 \d+ test_trigger_table
                   Table "public.test_trigger_table"
  Column |  Type   | Modifiers | Storage  | Stats target | Description 
@@ -178,10 +192,96 @@ DROP TRIGGER test_trigger_fn_trg2 ON test_trigger_table;
  f1     | integer |           | plain    |              | 
  f2     | text    |           | extended |              | 
 Triggers:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Disabled user triggers:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+
+\c regression
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Disabled user triggers:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+
+ALTER TABLE test_trigger_table DISABLE TRIGGER ALL;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Disabled user triggers:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+
+\c postgres
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Disabled user triggers:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+
+ALTER TABLE test_trigger_table ENABLE TRIGGER test_trigger_fn_trg2;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+Disabled user triggers:
     test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
     truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
 
 \c regression
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+Disabled user triggers:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+
+ALTER TABLE test_trigger_table ENABLE TRIGGER USER;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
 \d+ test_trigger_table
                   Table "public.test_trigger_table"
  Column |  Type   | Modifiers | Storage  | Stats target | Description 
@@ -190,8 +290,120 @@ Triggers:
  f2     | text    |           | extended |              | 
 Triggers:
     test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
     truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
 
+\c postgres
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+
+ALTER TABLE test_trigger_table ENABLE ALWAYS TRIGGER test_trigger_fn_trg;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Triggers firing always:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+
+\c regression
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Triggers firing always:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+
+ALTER TABLE test_trigger_table ENABLE REPLICA TRIGGER test_trigger_fn_trg2;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Triggers firing always:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+Triggers firing on replica only:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+
+\c postgres
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Triggers firing always:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+Triggers firing on replica only:
+    test_trigger_fn_trg2 AFTER UPDATE OF f1 ON test_trigger_table FOR EACH ROW EXECUTE PROCEDURE test_trigger_fn()
+
+DROP TRIGGER test_trigger_fn_trg2 ON test_trigger_table;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Triggers firing always:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+
+\c regression
+\d+ test_trigger_table
+                  Table "public.test_trigger_table"
+ Column |  Type   | Modifiers | Storage  | Stats target | Description 
+--------+---------+-----------+----------+--------------+-------------
+ f1     | integer |           | plain    |              | 
+ f2     | text    |           | extended |              | 
+Triggers:
+    truncate_trigger AFTER TRUNCATE ON test_trigger_table FOR EACH STATEMENT EXECUTE PROCEDURE bdr.queue_truncate()
+Triggers firing always:
+    test_trigger_fn_trg BEFORE INSERT OR DELETE ON test_trigger_table FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE test_trigger_fn()
+
 -- should fail (for test to be useful it should be called on different node than CREATE FUNCTION)
 DROP FUNCTION test_trigger_fn();
 ERROR:  cannot drop function test_trigger_fn() because other objects depend on it
@@ -199,6 +411,13 @@ DETAIL:  trigger test_trigger_fn_trg on table test_trigger_table depends on func
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 DROP TABLE test_trigger_table;
 DROP FUNCTION test_trigger_fn();
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+ pg_xlog_wait_remote_apply 
+---------------------------
+(2 rows)
+
 \d+ test_trigger_table
 \c postgres
 \d+ test_trigger_table
index d41afb16f766bf9c87dbcffe5a6ee34761088f51..5f749a605b5c70399655c2ab63f924aa5fe8ed1e 100644 (file)
@@ -47,11 +47,49 @@ SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_r
 \d+ test_trigger_table
 
 ALTER TRIGGER test_trigger_fn_trg1 ON test_trigger_table RENAME TO test_trigger_fn_trg;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+\d+ test_trigger_table
+\c postgres
+\d+ test_trigger_table
+
+ALTER TABLE test_trigger_table DISABLE TRIGGER test_trigger_fn_trg;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+\d+ test_trigger_table
+\c regression
+\d+ test_trigger_table
+
+ALTER TABLE test_trigger_table DISABLE TRIGGER ALL;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+\d+ test_trigger_table
+\c postgres
+\d+ test_trigger_table
+
+ALTER TABLE test_trigger_table ENABLE TRIGGER test_trigger_fn_trg2;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+\d+ test_trigger_table
+\c regression
+\d+ test_trigger_table
+
+ALTER TABLE test_trigger_table ENABLE TRIGGER USER;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+\d+ test_trigger_table
+\c postgres
+\d+ test_trigger_table
+
+ALTER TABLE test_trigger_table ENABLE ALWAYS TRIGGER test_trigger_fn_trg;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
+\d+ test_trigger_table
+\c regression
+\d+ test_trigger_table
+
+ALTER TABLE test_trigger_table ENABLE REPLICA TRIGGER test_trigger_fn_trg2;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
 \d+ test_trigger_table
 \c postgres
 \d+ test_trigger_table
 
 DROP TRIGGER test_trigger_fn_trg2 ON test_trigger_table;
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
 \d+ test_trigger_table
 \c regression
 \d+ test_trigger_table
@@ -61,6 +99,7 @@ DROP FUNCTION test_trigger_fn();
 
 DROP TABLE test_trigger_table;
 DROP FUNCTION test_trigger_fn();
+SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), pid) FROM pg_stat_replication;
 \d+ test_trigger_table
 \c postgres
 \d+ test_trigger_table