Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 72dd233

Browse files
committed
pg_event_trigger_dropped_objects: Add name/args output columns
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.
1 parent a676201 commit 72dd233

File tree

5 files changed

+60
-20
lines changed

5 files changed

+60
-20
lines changed

doc/src/sgml/func.sgml

+18
Original file line numberDiff line numberDiff line change
@@ -17835,6 +17835,24 @@ FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
1783517835
identifier present in the identity is quoted if necessary.
1783617836
</entry>
1783717837
</row>
17838+
<row>
17839+
<entry><literal>address_names</literal></entry>
17840+
<entry><type>text[]</type></entry>
17841+
<entry>
17842+
An array that, together with <literal>object_type</literal> and
17843+
<literal>address_args</literal>,
17844+
can be used by the <function>pg_get_object_address()</function> to
17845+
recreate the object address in a remote server containing an
17846+
identically named object of the same kind.
17847+
</entry>
17848+
</row>
17849+
<row>
17850+
<entry><literal>address_args</literal></entry>
17851+
<entry><type>text[]</type></entry>
17852+
<entry>
17853+
Complement for <literal>address_names</literal> above.
17854+
</entry>
17855+
</row>
1783817856
</tbody>
1783917857
</tgroup>
1784017858
</informaltable>

src/backend/commands/event_trigger.c

+24-5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ typedef struct SQLDropObject
117117
const char *objname;
118118
const char *objidentity;
119119
const char *objecttype;
120+
List *addrnames;
121+
List *addrargs;
120122
bool original;
121123
bool normal;
122124
slist_node next;
@@ -1324,10 +1326,11 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13241326
heap_close(catalog, AccessShareLock);
13251327
}
13261328

1327-
/* object identity */
1328-
obj->objidentity = getObjectIdentity(&obj->address);
1329+
/* object identity, objname and objargs */
1330+
obj->objidentity =
1331+
getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs);
13291332

1330-
/* and object type, too */
1333+
/* object type */
13311334
obj->objecttype = getObjectTypeDescription(&obj->address);
13321335

13331336
slist_push_head(&(currentEventTriggerState->SQLDropList), &obj->next);
@@ -1390,8 +1393,8 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
13901393
{
13911394
SQLDropObject *obj;
13921395
int i = 0;
1393-
Datum values[9];
1394-
bool nulls[9];
1396+
Datum values[11];
1397+
bool nulls[11];
13951398

13961399
obj = slist_container(SQLDropObject, next, iter.cur);
13971400

@@ -1434,6 +1437,22 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
14341437
else
14351438
nulls[i++] = true;
14361439

1440+
/* address_names and address_args */
1441+
if (obj->addrnames)
1442+
{
1443+
values[i++] = PointerGetDatum(strlist_to_textarray(obj->addrnames));
1444+
1445+
if (obj->addrargs)
1446+
values[i++] = PointerGetDatum(strlist_to_textarray(obj->addrargs));
1447+
else
1448+
values[i++] = PointerGetDatum(construct_empty_array(TEXTOID));
1449+
}
1450+
else
1451+
{
1452+
nulls[i++] = true;
1453+
nulls[i++] = true;
1454+
}
1455+
14371456
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
14381457
}
14391458

src/include/catalog/pg_proc.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -5081,7 +5081,8 @@ DATA(insert OID = 3785 ( pg_logical_slot_peek_binary_changes PGNSP PGUID 12 100
50815081
DESCR("peek at binary changes from replication slot");
50825082

50835083
/* event triggers */
5084-
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_ ));
5084+
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_ ));
5085+
50855086
DESCR("list objects dropped by the current command");
50865087
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_ ));
50875088
DESCR("return Oid of the table getting rewritten");

src/test/regress/expected/event_trigger.out

+13-12
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ BEGIN
305305
IF NOT r.normal AND NOT r.original THEN
306306
CONTINUE;
307307
END IF;
308-
RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
309-
r.original, r.normal, r.object_type, r.object_identity;
308+
RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=% name=% args=%',
309+
r.original, r.normal, r.object_type, r.object_identity,
310+
r.address_names, r.address_args;
310311
END LOOP;
311312
END; $$;
312313
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
@@ -316,23 +317,23 @@ CREATE SCHEMA evttrig
316317
CREATE INDEX one_idx ON one (col_b)
317318
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
318319
ALTER TABLE evttrig.two DROP COLUMN col_c;
319-
NOTICE: NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c
320-
NOTICE: NORMAL: orig=f normal=t type=table constraint identity=two_col_c_check on evttrig.two
320+
NOTICE: NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c name={evttrig,two,col_c} args={}
321+
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={}
321322
ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
322-
NOTICE: NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b
323+
NOTICE: NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b name={evttrig,one,col_b} args={}
323324
ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
324-
NOTICE: NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one
325+
NOTICE: NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one name={evttrig,one,one_pkey} args={}
325326
DROP INDEX evttrig.one_idx;
326-
NOTICE: NORMAL: orig=t normal=f type=index identity=evttrig.one_idx
327+
NOTICE: NORMAL: orig=t normal=f type=index identity=evttrig.one_idx name={evttrig,one_idx} args={}
327328
DROP SCHEMA evttrig CASCADE;
328329
NOTICE: drop cascades to 2 other objects
329330
DETAIL: drop cascades to table evttrig.one
330331
drop cascades to table evttrig.two
331-
NOTICE: NORMAL: orig=t normal=f type=schema identity=evttrig
332-
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.one
333-
NOTICE: NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq
334-
NOTICE: NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a
335-
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.two
332+
NOTICE: NORMAL: orig=t normal=f type=schema identity=evttrig name={evttrig} args={}
333+
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.one name={evttrig,one} args={}
334+
NOTICE: NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq name={evttrig,one_col_a_seq} args={}
335+
NOTICE: NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a name={evttrig,one,col_a} args={}
336+
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.two name={evttrig,two} args={}
336337
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
337338
-- only allowed from within an event trigger function, should fail
338339
select pg_event_trigger_table_rewrite_oid();

src/test/regress/sql/event_trigger.sql

+3-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ BEGIN
218218
IF NOT r.normal AND NOT r.original THEN
219219
CONTINUE;
220220
END IF;
221-
RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
222-
r.original, r.normal, r.object_type, r.object_identity;
221+
RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=% name=% args=%',
222+
r.original, r.normal, r.object_type, r.object_identity,
223+
r.address_names, r.address_args;
223224
END LOOP;
224225
END; $$;
225226
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop

0 commit comments

Comments
 (0)