pg_event_trigger_dropped_objects: Add name/args output columns
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 30 Dec 2014 20:41:46 +0000 (17:41 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 30 Dec 2014 20:41:46 +0000 (17:41 -0300)
These columns can be passed to pg_get_object_address() and used to
reconstruct the dropped objects identities in a remote server containing
similar objects, so that the drop can be replicated.

Reviewed by Stephen Frost, Heikki Linnakangas, Abhijit Menon-Sen, Andres
Freund.

doc/src/sgml/func.sgml
src/backend/commands/event_trigger.c
src/include/catalog/pg_proc.h
src/test/regress/expected/event_trigger.out
src/test/regress/sql/event_trigger.sql

index 53aeb12f9a51e53dcd950de198971ffa133ce7b8..2016c5a8b062a019abc89b4ffe94ff71cfdb7154 100644 (file)
@@ -17835,6 +17835,24 @@ FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
          identifier present in the identity is quoted if necessary.
         </entry>
        </row>
+       <row>
+        <entry><literal>address_names</literal></entry>
+        <entry><type>text[]</type></entry>
+        <entry>
+         An array that, together with <literal>object_type</literal> and
+         <literal>address_args</literal>,
+         can be used by the <function>pg_get_object_address()</function> to
+         recreate the object address in a remote server containing an
+         identically named object of the same kind.
+        </entry>
+       </row>
+       <row>
+        <entry><literal>address_args</literal></entry>
+        <entry><type>text[]</type></entry>
+        <entry>
+         Complement for <literal>address_names</literal> above.
+        </entry>
+       </row>
       </tbody>
      </tgroup>
     </informaltable>
index 34dd3c01ad1f7a00d52c0a4b560cfa1d6bd660af..7563ae51503d2669da43d116e514bfbf84415e4e 100644 (file)
@@ -117,6 +117,8 @@ typedef struct SQLDropObject
    const char *objname;
    const char *objidentity;
    const char *objecttype;
+   List       *addrnames;
+   List       *addrargs;
    bool        original;
    bool        normal;
    slist_node  next;
@@ -1324,10 +1326,11 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
        heap_close(catalog, AccessShareLock);
    }
 
-   /* object identity */
-   obj->objidentity = getObjectIdentity(&obj->address);
+   /* object identity, objname and objargs */
+   obj->objidentity =
+       getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs);
 
-   /* and object type, too */
+   /* object type */
    obj->objecttype = getObjectTypeDescription(&obj->address);
 
    slist_push_head(&(currentEventTriggerState->SQLDropList), &obj->next);
@@ -1390,8 +1393,8 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
    {
        SQLDropObject *obj;
        int         i = 0;
-       Datum       values[9];
-       bool        nulls[9];
+       Datum       values[11];
+       bool        nulls[11];
 
        obj = slist_container(SQLDropObject, next, iter.cur);
 
@@ -1434,6 +1437,22 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
        else
            nulls[i++] = true;
 
+       /* address_names and address_args */
+       if (obj->addrnames)
+       {
+           values[i++] = PointerGetDatum(strlist_to_textarray(obj->addrnames));
+
+           if (obj->addrargs)
+               values[i++] = PointerGetDatum(strlist_to_textarray(obj->addrargs));
+           else
+               values[i++] = PointerGetDatum(construct_empty_array(TEXTOID));
+       }
+       else
+       {
+           nulls[i++] = true;
+           nulls[i++] = true;
+       }
+
        tuplestore_putvalues(tupstore, tupdesc, values, nulls);
    }
 
index 5c10d96ce293c72e99396cebde63fbc3574fb12c..54d1f2ec978ae1b49356b762b5ca79e707b38b73 100644 (file)
@@ -5081,7 +5081,8 @@ DATA(insert OID = 3785 (  pg_logical_slot_peek_binary_changes PGNSP PGUID 12 100
 DESCR("peek at binary changes from replication slot");
 
 /* event triggers */
-DATA(insert OID = 3566 (  pg_event_trigger_dropped_objects     PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{26,26,23,16,16,25,25,25,25}" "{o,o,o,o,o,o,o,o,o}" "{classid, objid, objsubid, original, normal, object_type, schema_name, object_name, object_identity}" _null_ pg_event_trigger_dropped_objects _null_ _null_ _null_ ));
+DATA(insert OID = 3566 (  pg_event_trigger_dropped_objects     PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{26,26,23,16,16,25,25,25,25,1009,1009}" "{o,o,o,o,o,o,o,o,o,o,o}" "{classid, objid, objsubid, original, normal, object_type, schema_name, object_name, object_identity, address_names, address_args}" _null_ pg_event_trigger_dropped_objects _null_ _null_ _null_ ));
+
 DESCR("list objects dropped by the current command");
 DATA(insert OID = 4566 (  pg_event_trigger_table_rewrite_oid   PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 26 "" "{26}" "{o}" "{oid}" _null_ pg_event_trigger_table_rewrite_oid _null_ _null_ _null_ ));
 DESCR("return Oid of the table getting rewritten");
index 72e1660d6b9e5e419e186b0b21523e8816ce0b1b..869d713f5b7c03d4666a43f1b699bba0c44f0668 100644 (file)
@@ -305,8 +305,9 @@ BEGIN
     IF NOT r.normal AND NOT r.original THEN
         CONTINUE;
     END IF;
-    RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
-        r.original, r.normal, r.object_type, r.object_identity;
+    RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=% name=% args=%',
+        r.original, r.normal, r.object_type, r.object_identity,
+       r.address_names, r.address_args;
     END LOOP;
 END; $$;
 CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
@@ -316,23 +317,23 @@ CREATE SCHEMA evttrig
    CREATE INDEX one_idx ON one (col_b)
    CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
 ALTER TABLE evttrig.two DROP COLUMN col_c;
-NOTICE:  NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c
-NOTICE:  NORMAL: orig=f normal=t type=table constraint identity=two_col_c_check on evttrig.two
+NOTICE:  NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c name={evttrig,two,col_c} args={}
+NOTICE:  NORMAL: orig=f normal=t type=table constraint identity=two_col_c_check on evttrig.two name={evttrig,two,two_col_c_check} args={}
 ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
-NOTICE:  NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b
+NOTICE:  NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b name={evttrig,one,col_b} args={}
 ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
-NOTICE:  NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one
+NOTICE:  NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one name={evttrig,one,one_pkey} args={}
 DROP INDEX evttrig.one_idx;
-NOTICE:  NORMAL: orig=t normal=f type=index identity=evttrig.one_idx
+NOTICE:  NORMAL: orig=t normal=f type=index identity=evttrig.one_idx name={evttrig,one_idx} args={}
 DROP SCHEMA evttrig CASCADE;
 NOTICE:  drop cascades to 2 other objects
 DETAIL:  drop cascades to table evttrig.one
 drop cascades to table evttrig.two
-NOTICE:  NORMAL: orig=t normal=f type=schema identity=evttrig
-NOTICE:  NORMAL: orig=f normal=t type=table identity=evttrig.one
-NOTICE:  NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq
-NOTICE:  NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a
-NOTICE:  NORMAL: orig=f normal=t type=table identity=evttrig.two
+NOTICE:  NORMAL: orig=t normal=f type=schema identity=evttrig name={evttrig} args={}
+NOTICE:  NORMAL: orig=f normal=t type=table identity=evttrig.one name={evttrig,one} args={}
+NOTICE:  NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq name={evttrig,one_col_a_seq} args={}
+NOTICE:  NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a name={evttrig,one,col_a} args={}
+NOTICE:  NORMAL: orig=f normal=t type=table identity=evttrig.two name={evttrig,two} args={}
 DROP EVENT TRIGGER regress_event_trigger_report_dropped;
 -- only allowed from within an event trigger function, should fail
 select pg_event_trigger_table_rewrite_oid();
index 7987fde50b9f293f06cfd667e64cc98c4a01319d..b2c89315fcdc2e9ce3515f21e1061d0e42aa4f87 100644 (file)
@@ -218,8 +218,9 @@ BEGIN
     IF NOT r.normal AND NOT r.original THEN
         CONTINUE;
     END IF;
-    RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
-        r.original, r.normal, r.object_type, r.object_identity;
+    RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=% name=% args=%',
+        r.original, r.normal, r.object_type, r.object_identity,
+       r.address_names, r.address_args;
     END LOOP;
 END; $$;
 CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop