mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
pg_event_trigger_dropped_objects: add is_temp column
It now also reports temporary objects dropped that are local to the backend. Previously we weren't reporting any temp objects because it was deemed unnecessary; but as it turns out, it is necessary if we want to keep close track of DDL command execution inside one session. Temp objects are reported as living in schema pg_temp, which works because such a schema-qualification always refers to the temp objects of the current session.
This commit is contained in:
@ -121,6 +121,7 @@ typedef struct SQLDropObject
|
||||
List *addrargs;
|
||||
bool original;
|
||||
bool normal;
|
||||
bool istemp;
|
||||
slist_node next;
|
||||
} SQLDropObject;
|
||||
|
||||
@ -1294,9 +1295,10 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
|
||||
|
||||
Assert(EventTriggerSupportsObjectClass(getObjectClass(object)));
|
||||
|
||||
/* don't report temp schemas */
|
||||
/* don't report temp schemas except my own */
|
||||
if (object->classId == NamespaceRelationId &&
|
||||
isAnyTempNamespace(object->objectId))
|
||||
(isAnyTempNamespace(object->objectId) &&
|
||||
!isTempNamespace(object->objectId)))
|
||||
return;
|
||||
|
||||
oldcxt = MemoryContextSwitchTo(currentEventTriggerState->cxt);
|
||||
@ -1336,16 +1338,24 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
|
||||
Oid namespaceId;
|
||||
|
||||
namespaceId = DatumGetObjectId(datum);
|
||||
/* Don't report objects in temp namespaces */
|
||||
if (isAnyTempNamespace(namespaceId))
|
||||
/* temp objects are only reported if they are my own */
|
||||
if (isTempNamespace(namespaceId))
|
||||
{
|
||||
obj->schemaname = "pg_temp";
|
||||
obj->istemp = true;
|
||||
}
|
||||
else if (isAnyTempNamespace(namespaceId))
|
||||
{
|
||||
pfree(obj);
|
||||
heap_close(catalog, AccessShareLock);
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
return;
|
||||
}
|
||||
|
||||
obj->schemaname = get_namespace_name(namespaceId);
|
||||
else
|
||||
{
|
||||
obj->schemaname = get_namespace_name(namespaceId);
|
||||
obj->istemp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1365,6 +1375,12 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
|
||||
|
||||
heap_close(catalog, AccessShareLock);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (object->classId == NamespaceRelationId &&
|
||||
isTempNamespace(object->objectId))
|
||||
obj->istemp = true;
|
||||
}
|
||||
|
||||
/* object identity, objname and objargs */
|
||||
obj->objidentity =
|
||||
@ -1433,8 +1449,8 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
|
||||
{
|
||||
SQLDropObject *obj;
|
||||
int i = 0;
|
||||
Datum values[11];
|
||||
bool nulls[11];
|
||||
Datum values[12];
|
||||
bool nulls[12];
|
||||
|
||||
obj = slist_container(SQLDropObject, next, iter.cur);
|
||||
|
||||
@ -1456,6 +1472,9 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
|
||||
/* normal */
|
||||
values[i++] = BoolGetDatum(obj->normal);
|
||||
|
||||
/* is_temporary */
|
||||
values[i++] = BoolGetDatum(obj->istemp);
|
||||
|
||||
/* object_type */
|
||||
values[i++] = CStringGetTextDatum(obj->objecttype);
|
||||
|
||||
|
Reference in New Issue
Block a user