Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9a077c

Browse files
committed
pg_event_trigger_dropped_objects: add is_temp column
It now also reports temporary objects dropped that are local to thebackend. Previously we weren't reporting any temp objects because itwas deemed unnecessary; but as it turns out, it is necessary if we wantto keep close track of DDL command execution inside one session. Tempobjects are reported as living in schema pg_temp, which works becausesuch a schema-qualification always refers to the temp objects of thecurrent session.
1 parent70dc2db commite9a077c

File tree

11 files changed

+87
-41
lines changed

11 files changed

+87
-41
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17877,6 +17877,13 @@ FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
1787717877
in the dependency graph leading to this object
1787817878
</entry>
1787917879
</row>
17880+
<row>
17881+
<entry><literal>is_temporary</literal></entry>
17882+
<entry><type>bool</type></entry>
17883+
<entry>
17884+
Flag indicating that the object was a temporary object.
17885+
</entry>
17886+
</row>
1788017887
<row>
1788117888
<entry><literal>object_type</literal></entry>
1788217889
<entry><type>text</type></entry>

‎src/backend/catalog/objectaddress.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,7 @@ getObjectIdentityParts(const ObjectAddress *object,
36873687
elog(ERROR,"cache lookup failed for collation %u",
36883688
object->objectId);
36893689
coll= (Form_pg_collation)GETSTRUCT(collTup);
3690-
schema=get_namespace_name(coll->collnamespace);
3690+
schema=get_namespace_name_or_temp(coll->collnamespace);
36913691
appendStringInfoString(&buffer,
36923692
quote_qualified_identifier(schema,
36933693
NameStr(coll->collname)));
@@ -3751,7 +3751,7 @@ getObjectIdentityParts(const ObjectAddress *object,
37513751
elog(ERROR,"cache lookup failed for conversion %u",
37523752
object->objectId);
37533753
conForm= (Form_pg_conversion)GETSTRUCT(conTup);
3754-
schema=get_namespace_name(conForm->connamespace);
3754+
schema=get_namespace_name_or_temp(conForm->connamespace);
37553755
appendStringInfoString(&buffer,
37563756
quote_qualified_identifier(schema,
37573757
NameStr(conForm->conname)));
@@ -3849,7 +3849,7 @@ getObjectIdentityParts(const ObjectAddress *object,
38493849
elog(ERROR,"cache lookup failed for opclass %u",
38503850
object->objectId);
38513851
opcForm= (Form_pg_opclass)GETSTRUCT(opcTup);
3852-
schema=get_namespace_name(opcForm->opcnamespace);
3852+
schema=get_namespace_name_or_temp(opcForm->opcnamespace);
38533853

38543854
amTup=SearchSysCache1(AMOID,
38553855
ObjectIdGetDatum(opcForm->opcmethod));
@@ -4066,7 +4066,7 @@ getObjectIdentityParts(const ObjectAddress *object,
40664066
{
40674067
char*nspname;
40684068

4069-
nspname=get_namespace_name(object->objectId);
4069+
nspname=get_namespace_name_or_temp(object->objectId);
40704070
if (!nspname)
40714071
elog(ERROR,"cache lookup failed for namespace %u",
40724072
object->objectId);
@@ -4089,7 +4089,7 @@ getObjectIdentityParts(const ObjectAddress *object,
40894089
elog(ERROR,"cache lookup failed for text search parser %u",
40904090
object->objectId);
40914091
formParser= (Form_pg_ts_parser)GETSTRUCT(tup);
4092-
schema=get_namespace_name(formParser->prsnamespace);
4092+
schema=get_namespace_name_or_temp(formParser->prsnamespace);
40934093
appendStringInfoString(&buffer,
40944094
quote_qualified_identifier(schema,
40954095
NameStr(formParser->prsname)));
@@ -4112,7 +4112,7 @@ getObjectIdentityParts(const ObjectAddress *object,
41124112
elog(ERROR,"cache lookup failed for text search dictionary %u",
41134113
object->objectId);
41144114
formDict= (Form_pg_ts_dict)GETSTRUCT(tup);
4115-
schema=get_namespace_name(formDict->dictnamespace);
4115+
schema=get_namespace_name_or_temp(formDict->dictnamespace);
41164116
appendStringInfoString(&buffer,
41174117
quote_qualified_identifier(schema,
41184118
NameStr(formDict->dictname)));
@@ -4135,7 +4135,7 @@ getObjectIdentityParts(const ObjectAddress *object,
41354135
elog(ERROR,"cache lookup failed for text search template %u",
41364136
object->objectId);
41374137
formTmpl= (Form_pg_ts_template)GETSTRUCT(tup);
4138-
schema=get_namespace_name(formTmpl->tmplnamespace);
4138+
schema=get_namespace_name_or_temp(formTmpl->tmplnamespace);
41394139
appendStringInfoString(&buffer,
41404140
quote_qualified_identifier(schema,
41414141
NameStr(formTmpl->tmplname)));
@@ -4158,7 +4158,7 @@ getObjectIdentityParts(const ObjectAddress *object,
41584158
elog(ERROR,"cache lookup failed for text search configuration %u",
41594159
object->objectId);
41604160
formCfg= (Form_pg_ts_config)GETSTRUCT(tup);
4161-
schema=get_namespace_name(formCfg->cfgnamespace);
4161+
schema=get_namespace_name_or_temp(formCfg->cfgnamespace);
41624162
appendStringInfoString(&buffer,
41634163
quote_qualified_identifier(schema,
41644164
NameStr(formCfg->cfgname)));
@@ -4305,7 +4305,7 @@ getObjectIdentityParts(const ObjectAddress *object,
43054305

43064306
if (OidIsValid(defacl->defaclnamespace))
43074307
{
4308-
schema=get_namespace_name(defacl->defaclnamespace);
4308+
schema=get_namespace_name_or_temp(defacl->defaclnamespace);
43094309
appendStringInfo(&buffer,
43104310
" in schema %s",
43114311
quote_identifier(schema));
@@ -4421,7 +4421,7 @@ getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **objname)
44214421
opfForm->opfmethod);
44224422
amForm= (Form_pg_am)GETSTRUCT(amTup);
44234423

4424-
schema=get_namespace_name(opfForm->opfnamespace);
4424+
schema=get_namespace_name_or_temp(opfForm->opfnamespace);
44254425
appendStringInfo(buffer,"%s USING %s",
44264426
quote_qualified_identifier(schema,
44274427
NameStr(opfForm->opfname)),
@@ -4453,7 +4453,7 @@ getRelationIdentity(StringInfo buffer, Oid relid, List **objname)
44534453
elog(ERROR,"cache lookup failed for relation %u",relid);
44544454
relForm= (Form_pg_class)GETSTRUCT(relTup);
44554455

4456-
schema=get_namespace_name(relForm->relnamespace);
4456+
schema=get_namespace_name_or_temp(relForm->relnamespace);
44574457
appendStringInfoString(buffer,
44584458
quote_qualified_identifier(schema,
44594459
NameStr(relForm->relname)));

‎src/backend/commands/event_trigger.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ typedef struct SQLDropObject
121121
List*addrargs;
122122
booloriginal;
123123
boolnormal;
124+
boolistemp;
124125
slist_nodenext;
125126
}SQLDropObject;
126127

@@ -1294,9 +1295,10 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
12941295

12951296
Assert(EventTriggerSupportsObjectClass(getObjectClass(object)));
12961297

1297-
/* don't report temp schemas */
1298+
/* don't report temp schemasexcept my own*/
12981299
if (object->classId==NamespaceRelationId&&
1299-
isAnyTempNamespace(object->objectId))
1300+
(isAnyTempNamespace(object->objectId)&&
1301+
!isTempNamespace(object->objectId)))
13001302
return;
13011303

13021304
oldcxt=MemoryContextSwitchTo(currentEventTriggerState->cxt);
@@ -1336,16 +1338,24 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13361338
OidnamespaceId;
13371339

13381340
namespaceId=DatumGetObjectId(datum);
1339-
/* Don't report objects in temp namespaces */
1340-
if (isAnyTempNamespace(namespaceId))
1341+
/* temp objects are only reported if they are my own */
1342+
if (isTempNamespace(namespaceId))
1343+
{
1344+
obj->schemaname="pg_temp";
1345+
obj->istemp= true;
1346+
}
1347+
elseif (isAnyTempNamespace(namespaceId))
13411348
{
13421349
pfree(obj);
13431350
heap_close(catalog,AccessShareLock);
13441351
MemoryContextSwitchTo(oldcxt);
13451352
return;
13461353
}
1347-
1348-
obj->schemaname=get_namespace_name(namespaceId);
1354+
else
1355+
{
1356+
obj->schemaname=get_namespace_name(namespaceId);
1357+
obj->istemp= false;
1358+
}
13491359
}
13501360
}
13511361

@@ -1365,6 +1375,12 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13651375

13661376
heap_close(catalog,AccessShareLock);
13671377
}
1378+
else
1379+
{
1380+
if (object->classId==NamespaceRelationId&&
1381+
isTempNamespace(object->objectId))
1382+
obj->istemp= true;
1383+
}
13681384

13691385
/* object identity, objname and objargs */
13701386
obj->objidentity=
@@ -1433,8 +1449,8 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
14331449
{
14341450
SQLDropObject*obj;
14351451
inti=0;
1436-
Datumvalues[11];
1437-
boolnulls[11];
1452+
Datumvalues[12];
1453+
boolnulls[12];
14381454

14391455
obj=slist_container(SQLDropObject,next,iter.cur);
14401456

@@ -1456,6 +1472,9 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
14561472
/* normal */
14571473
values[i++]=BoolGetDatum(obj->normal);
14581474

1475+
/* is_temporary */
1476+
values[i++]=BoolGetDatum(obj->istemp);
1477+
14591478
/* object_type */
14601479
values[i++]=CStringGetTextDatum(obj->objecttype);
14611480

‎src/backend/utils/adt/format_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ format_type_internal(Oid type_oid, int32 typemod,
305305
if (!force_qualify&&TypeIsVisible(type_oid))
306306
nspname=NULL;
307307
else
308-
nspname=get_namespace_name(typeform->typnamespace);
308+
nspname=get_namespace_name_or_temp(typeform->typnamespace);
309309

310310
typname=NameStr(typeform->typname);
311311

‎src/backend/utils/adt/regproc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs)
460460
procform= (Form_pg_proc)GETSTRUCT(proctup);
461461
nargs=procform->pronargs;
462462

463-
*objnames=list_make2(get_namespace_name(procform->pronamespace),
463+
*objnames=list_make2(get_namespace_name_or_temp(procform->pronamespace),
464464
pstrdup(NameStr(procform->proname)));
465465
*objargs=NIL;
466466
for (i=0;i<nargs;i++)
@@ -922,7 +922,7 @@ format_operator_parts(Oid operator_oid, List **objnames, List **objargs)
922922
operator_oid);
923923

924924
oprForm= (Form_pg_operator)GETSTRUCT(opertup);
925-
*objnames=list_make2(get_namespace_name(oprForm->oprnamespace),
925+
*objnames=list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
926926
pstrdup(NameStr(oprForm->oprname)));
927927
*objargs=NIL;
928928
if (oprForm->oprleft)

‎src/backend/utils/cache/lsyscache.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include"access/htup_details.h"
2020
#include"access/nbtree.h"
2121
#include"bootstrap/bootstrap.h"
22+
#include"catalog/namespace.h"
2223
#include"catalog/pg_amop.h"
2324
#include"catalog/pg_amproc.h"
2425
#include"catalog/pg_collation.h"
@@ -2884,6 +2885,20 @@ get_namespace_name(Oid nspid)
28842885
returnNULL;
28852886
}
28862887

2888+
/*
2889+
* get_namespace_name_or_temp
2890+
*As above, but if it is this backend's temporary namespace, return
2891+
*"pg_temp" instead.
2892+
*/
2893+
char*
2894+
get_namespace_name_or_temp(Oidnspid)
2895+
{
2896+
if (isTempNamespace(nspid))
2897+
return"pg_temp";
2898+
else
2899+
returnget_namespace_name(nspid);
2900+
}
2901+
28872902
/*---------- PG_RANGE CACHE ---------- */
28882903

28892904
/*

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201504021
56+
#defineCATALOG_VERSION_NO201504061
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,8 +5120,7 @@ DATA(insert OID = 3785 ( pg_logical_slot_peek_binary_changes PGNSP PGUID 12 100
51205120
DESCR("peek at binary changes from replication slot");
51215121

51225122
/* event triggers */
5123-
DATA(insert OID = 3566 ( pg_event_trigger_dropped_objectsPGNSP 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_ ));
5124-
5123+
DATA(insert OID = 3566 ( pg_event_trigger_dropped_objectsPGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{26,26,23,16,16,16,25,25,25,25,1009,1009}" "{o,o,o,o,o,o,o,o,o,o,o,o}" "{classid, objid, objsubid, original, normal, is_temporary, object_type, schema_name, object_name, object_identity, address_names, address_args}" _null_ pg_event_trigger_dropped_objects _null_ _null_ _null_ ));
51255124
DESCR("list objects dropped by the current command");
51265125
DATA(insert OID = 4566 ( pg_event_trigger_table_rewrite_oidPGNSP 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_ ));
51275126
DESCR("return Oid of the table getting rewritten");

‎src/include/utils/lsyscache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ extern void free_attstatsslot(Oid atttype,
151151
Datum*values,intnvalues,
152152
float4*numbers,intnnumbers);
153153
externchar*get_namespace_name(Oidnspid);
154+
externchar*get_namespace_name_or_temp(Oidnspid);
154155
externOidget_range_subtype(OidrangeOid);
155156

156157
#definetype_is_array(typid) (get_element_type(typid) != InvalidOid)

‎src/test/regress/expected/event_trigger.out

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ drop event trigger regress_event_trigger_end;
151151
CREATE SCHEMA schema_one authorization regression_bob;
152152
CREATE SCHEMA schema_two authorization regression_bob;
153153
CREATE SCHEMA audit_tbls authorization regression_bob;
154+
CREATE TEMP TABLE a_temp_tbl ();
154155
SET SESSION AUTHORIZATION regression_bob;
155156
CREATE TABLE schema_one.table_one(a int);
156157
CREATE TABLE schema_one."table two"(a int);
@@ -352,9 +353,9 @@ BEGIN
352353
IF NOT r.normal AND NOT r.original THEN
353354
CONTINUE;
354355
END IF;
355-
RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=% name=% args=%',
356-
r.original, r.normal, r.object_type, r.object_identity,
357-
r.address_names, r.address_args;
356+
RAISE NOTICE 'NORMAL: orig=% normal=%istemp=%type=% identity=% name=% args=%',
357+
r.original, r.normal, r.is_temporary, r.object_type,
358+
r.object_identity,r.address_names, r.address_args;
358359
END LOOP;
359360
END; $$;
360361
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
@@ -364,23 +365,25 @@ CREATE SCHEMA evttrig
364365
CREATE INDEX one_idx ON one (col_b)
365366
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
366367
ALTER TABLE evttrig.two DROP COLUMN col_c;
367-
NOTICE: NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c name={evttrig,two,col_c} args={}
368-
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={}
368+
NOTICE: NORMAL: orig=t normal=fistemp=ftype=table column identity=evttrig.two.col_c name={evttrig,two,col_c} args={}
369+
NOTICE: NORMAL: orig=f normal=tistemp=ftype=table constraint identity=two_col_c_check on evttrig.two name={evttrig,two,two_col_c_check} args={}
369370
ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
370-
NOTICE: NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b name={evttrig,one,col_b} args={}
371+
NOTICE: NORMAL: orig=t normal=fistemp=ftype=default value identity=for evttrig.one.col_b name={evttrig,one,col_b} args={}
371372
ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
372-
NOTICE: NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one name={evttrig,one,one_pkey} args={}
373+
NOTICE: NORMAL: orig=t normal=fistemp=ftype=table constraint identity=one_pkey on evttrig.one name={evttrig,one,one_pkey} args={}
373374
DROP INDEX evttrig.one_idx;
374-
NOTICE: NORMAL: orig=t normal=f type=index identity=evttrig.one_idx name={evttrig,one_idx} args={}
375+
NOTICE: NORMAL: orig=t normal=fistemp=ftype=index identity=evttrig.one_idx name={evttrig,one_idx} args={}
375376
DROP SCHEMA evttrig CASCADE;
376377
NOTICE: drop cascades to 2 other objects
377378
DETAIL: drop cascades to table evttrig.one
378379
drop cascades to table evttrig.two
379-
NOTICE: NORMAL: orig=t normal=f type=schema identity=evttrig name={evttrig} args={}
380-
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.one name={evttrig,one} args={}
381-
NOTICE: NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq name={evttrig,one_col_a_seq} args={}
382-
NOTICE: NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a name={evttrig,one,col_a} args={}
383-
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.two name={evttrig,two} args={}
380+
NOTICE: NORMAL: orig=t normal=f istemp=f type=schema identity=evttrig name={evttrig} args={}
381+
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.one name={evttrig,one} args={}
382+
NOTICE: NORMAL: orig=f normal=t istemp=f type=sequence identity=evttrig.one_col_a_seq name={evttrig,one_col_a_seq} args={}
383+
NOTICE: NORMAL: orig=f normal=t istemp=f type=default value identity=for evttrig.one.col_a name={evttrig,one,col_a} args={}
384+
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.two name={evttrig,two} args={}
385+
DROP TABLE a_temp_tbl;
386+
NOTICE: NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
384387
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
385388
-- only allowed from within an event trigger function, should fail
386389
select pg_event_trigger_table_rewrite_oid();

‎src/test/regress/sql/event_trigger.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ drop event trigger regress_event_trigger_end;
143143
CREATESCHEMAschema_one authorization regression_bob;
144144
CREATESCHEMAschema_two authorization regression_bob;
145145
CREATESCHEMAaudit_tbls authorization regression_bob;
146+
CREATE TEMP TABLE a_temp_tbl ();
146147
SET SESSION AUTHORIZATION regression_bob;
147148

148149
CREATETABLEschema_one.table_one(aint);
@@ -253,9 +254,9 @@ BEGIN
253254
IF NOTr.normalAND NOTr.original THEN
254255
CONTINUE;
255256
END IF;
256-
RAISE NOTICE'NORMAL: orig=% normal=% type=% identity=% name=% args=%',
257-
r.original,r.normal,r.object_type,r.object_identity,
258-
r.address_names,r.address_args;
257+
RAISE NOTICE'NORMAL: orig=% normal=%istemp=%type=% identity=% name=% args=%',
258+
r.original,r.normal,r.is_temporary,r.object_type,
259+
r.object_identity,r.address_names,r.address_args;
259260
END LOOP;
260261
END; $$;
261262
CREATE EVENT TRIGGER regress_event_trigger_report_droppedON sql_drop
@@ -270,6 +271,7 @@ ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
270271
ALTERTABLEevttrig.one DROPCONSTRAINT one_pkey;
271272
DROPINDEXevttrig.one_idx;
272273
DROPSCHEMA evttrig CASCADE;
274+
DROPTABLE a_temp_tbl;
273275

274276
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
275277

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp