51 #include "utils/fmgroids.h"
52 #include "utils/fmgrprotos.h"
136 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
137 errmsg(
"permission denied to create event trigger \"%s\"",
139 errhint(
"Must be superuser to create an event trigger.")));
142 if (strcmp(
stmt->eventname,
"ddl_command_start") != 0 &&
143 strcmp(
stmt->eventname,
"ddl_command_end") != 0 &&
144 strcmp(
stmt->eventname,
"sql_drop") != 0 &&
145 strcmp(
stmt->eventname,
"login") != 0 &&
146 strcmp(
stmt->eventname,
"table_rewrite") != 0)
148 (
errcode(ERRCODE_SYNTAX_ERROR),
149 errmsg(
"unrecognized event name \"%s\"",
153 foreach(lc,
stmt->whenclause)
157 if (strcmp(def->
defname,
"tag") == 0)
165 (
errcode(ERRCODE_SYNTAX_ERROR),
166 errmsg(
"unrecognized filter variable \"%s\"", def->
defname)));
170 if ((strcmp(
stmt->eventname,
"ddl_command_start") == 0 ||
171 strcmp(
stmt->eventname,
"ddl_command_end") == 0 ||
172 strcmp(
stmt->eventname,
"sql_drop") == 0)
175 else if (strcmp(
stmt->eventname,
"table_rewrite") == 0
178 else if (strcmp(
stmt->eventname,
"login") == 0 && tags != NULL)
180 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
181 errmsg(
"tag filtering is not supported for login event triggers")));
191 errmsg(
"event trigger \"%s\" already exists",
197 if (funcrettype != EVENT_TRIGGEROID)
199 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
200 errmsg(
"function %s must return type %s",
205 evtowner, funcoid, tags);
221 if (commandTag == CMDTAG_UNKNOWN)
223 (
errcode(ERRCODE_SYNTAX_ERROR),
224 errmsg(
"filter value \"%s\" not recognized for filter variable \"%s\"",
225 tagstr, filtervar)));
228 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
230 errmsg(
"event triggers are not supported for %s",
250 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
252 errmsg(
"event triggers are not supported for %s",
264 (
errcode(ERRCODE_SYNTAX_ERROR),
265 errmsg(
"filter variable \"%s\" specified more than once",
280 bool nulls[Natts_pg_trigger];
291 Anum_pg_event_trigger_oid);
293 memset(nulls,
false,
sizeof(nulls));
300 values[Anum_pg_event_trigger_evtenabled - 1] =
303 nulls[Anum_pg_event_trigger_evttags - 1] =
true;
305 values[Anum_pg_event_trigger_evttags - 1] =
317 if (strcmp(eventname,
"login") == 0)
324 myself.
classId = EventTriggerRelationId;
327 referenced.
classId = ProcedureRelationId;
365 foreach(lc, filterlist)
372 for (p = result; *p; p++)
406 if (!db->dathasloginevt)
408 db->dathasloginevt =
true;
426 char tgenabled =
stmt->tgenabled;
434 (
errcode(ERRCODE_UNDEFINED_OBJECT),
435 errmsg(
"event trigger \"%s\" does not exist",
439 trigoid = evtForm->oid;
446 evtForm->evtenabled = tgenabled;
454 if (
namestrcmp(&evtForm->evtevent,
"login") == 0 &&
486 (
errcode(ERRCODE_UNDEFINED_OBJECT),
487 errmsg(
"event trigger \"%s\" does not exist",
name)));
490 evtOid = evtForm->oid;
518 (
errcode(ERRCODE_UNDEFINED_OBJECT),
519 errmsg(
"event trigger with OID %u does not exist", trigOid)));
538 if (form->evtowner == newOwnerId)
548 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
549 errmsg(
"permission denied to change owner of event trigger \"%s\"",
551 errhint(
"The owner of an event trigger must be a superuser.")));
553 form->evtowner = newOwnerId;
580 (
errcode(ERRCODE_UNDEFINED_OBJECT),
581 errmsg(
"event trigger \"%s\" does not exist", trigname)));
654 #ifdef USE_ASSERT_CHECKING
678 if (cachelist ==
NIL)
691 foreach(lc, cachelist)
706 trigdata->
type = T_EventTriggerData;
707 trigdata->
event = eventstr;
959 Anum_pg_database_oid,
973 if (db->dathasloginevt)
975 db->dathasloginevt =
false;
1086 "event trigger context",
1091 foreach(lc, fn_oid_list)
1098 elog(
DEBUG1,
"EventTriggerInvoke %u", fnoid);
1164 case DatabaseRelationId:
1165 case TableSpaceRelationId:
1166 case AuthIdRelationId:
1167 case AuthMemRelationId:
1168 case ParameterAclRelationId:
1171 case EventTriggerRelationId:
1200 "event trigger state",
1205 state->in_sql_drop =
false;
1210 state->currentCommand = NULL;
1291 if (object->
classId == NamespaceRelationId &&
1374 if (object->
classId == NamespaceRelationId &&
1410 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1411 errmsg(
"%s can only be called in a sql_drop event trigger function",
1412 "pg_event_trigger_dropped_objects()")));
1422 bool nulls[12] = {0};
1503 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1504 errmsg(
"%s can only be called in a table_rewrite event trigger function",
1505 "pg_event_trigger_table_rewrite_oid()")));
1524 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1525 errmsg(
"%s can only be called in a table_rewrite event trigger function",
1526 "pg_event_trigger_table_rewrite_reason()")));
1609 command->
d.
simple.address = address;
1610 command->
d.
simple.secondaryObject = secondaryObject;
1645 command->
d.
alterTable.classId = RelationRelationId;
1697 newsub->address = address;
1782 command->
d.
grant.istmt = icopy;
1814 OperatorFamilyRelationId, opfamoid);
1815 command->
d.
opfam.operators = operators;
1816 command->
d.
opfam.procedures = procedures;
1847 OperatorClassRelationId, opcoid);
1849 command->
d.
createopc.procedures = procedures;
1865 Oid *dictIds,
int ndicts)
1881 TSConfigRelationId, cfgId);
1883 memcpy(command->
d.
atscfg.dictIds, dictIds,
sizeof(
Oid) * ndicts);
1884 command->
d.
atscfg.ndicts = ndicts;
1937 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1938 errmsg(
"%s can only be called in an event trigger function",
1939 "pg_event_trigger_ddl_commands()")));
1948 bool nulls[9] = {0};
1976 char *schema = NULL;
1985 addr = cmd->
d.
opfam.address;
1999 if (identity == NULL)
2028 elog(
ERROR,
"cache lookup failed for object %u/%u",
2035 "invalid null namespace in object %u/%u/%d",
2097 "GRANT" :
"REVOKE");
2138 return "FOREIGN DATA WRAPPER";
2140 return "FOREIGN SERVER";
2146 return "LARGE OBJECT";
2156 return "TABLESPACE";
2196 elog(
ERROR,
"unsupported object type: %d", (
int) objtype);
2223 return "FOREIGN DATA WRAPPERS";
2225 return "FOREIGN SERVERS";
2231 return "LARGE OBJECTS";
2235 return "PROCEDURES";
2239 return "TABLESPACES";
2280 elog(
ERROR,
"unsupported object type: %d", (
int) objtype);
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
ArrayType * construct_empty_array(Oid elmtype)
#define InvalidAttrNumber
bool bms_is_member(int x, const Bitmapset *a)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define Assert(condition)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
CommandTag GetCommandTagEnum(const char *commandname)
bool command_tag_event_trigger_ok(CommandTag commandTag)
bool command_tag_table_rewrite_ok(CommandTag commandTag)
const char * GetCommandTagName(CommandTag commandTag)
@ SCT_AlterDefaultPrivileges
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void EventTriggerUndoInhibitCommandCollection(void)
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerOnLogin(void)
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
bool trackDroppedObjectsNeeded(void)
Datum pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
void EventTriggerDDLCommandStart(Node *parsetree)
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata, bool unfiltered)
void EventTriggerInhibitCommandCollection(void)
bool EventTriggerBeginCompleteQuery(void)
static bool filter_event_trigger(CommandTag tag, EventTriggerCacheItem *item)
void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
bool EventTriggerSupportsObject(const ObjectAddress *object)
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
static const char * stringify_adefprivs_objtype(ObjectType objtype)
void EventTriggerCollectGrant(InternalGrant *istmt)
struct EventTriggerQueryState EventTriggerQueryState
Datum pg_event_trigger_table_rewrite_reason(PG_FUNCTION_ARGS)
void EventTriggerSQLDrop(Node *parsetree)
Datum pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
static CommandTag EventTriggerGetTag(Node *parsetree, EventTriggerEvent event)
void EventTriggerEndCompleteQuery(void)
Datum pg_event_trigger_table_rewrite_oid(PG_FUNCTION_ARGS)
static void validate_ddl_tags(const char *filtervar, List *taglist)
void AlterEventTriggerOwner_oid(Oid trigOid, Oid newOwnerId)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerCollectAlterTSConfig(AlterTSConfigurationStmt *stmt, Oid cfgId, Oid *dictIds, int ndicts)
static EventTriggerQueryState * currentEventTriggerState
struct SQLDropObject SQLDropObject
void EventTriggerAlterTableEnd(void)
void EventTriggerCollectAlterOpFam(AlterOpFamilyStmt *stmt, Oid opfamoid, List *operators, List *procedures)
static void SetDatabaseHasLoginEventTriggers(void)
void EventTriggerCollectCreateOpClass(CreateOpClassStmt *stmt, Oid opcoid, List *operators, List *procedures)
static void error_duplicate_filter_variable(const char *defname)
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
static const char * stringify_grant_objtype(ObjectType objtype)
void EventTriggerDDLCommandEnd(Node *parsetree)
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *taglist)
void EventTriggerCollectAlterTableSubcmd(Node *subcmd, ObjectAddress address)
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static Datum filter_list_to_array(List *filterlist)
List * EventCacheLookup(EventTriggerEvent event)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define LOCAL_FCINFO(name, nargs)
#define FunctionCallInvoke(fcinfo)
#define PG_RETURN_INT32(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
bool MyDatabaseHasLoginEventTriggers
void heap_inplace_update(Relation relation, HeapTuple tuple)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static void slist_init(slist_head *head)
static bool slist_is_empty(const slist_head *head)
static void slist_push_head(slist_head *head, slist_node *node)
#define slist_container(type, membername, ptr)
#define slist_foreach(iter, lhead)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
void list_free(List *list)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
#define AccessExclusiveLock
char * get_namespace_name_or_temp(Oid nspid)
char * get_namespace_name(Oid nspid)
Oid get_func_rettype(Oid funcid)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
int namestrcmp(Name name, const char *str)
void namestrcpy(Name name, const char *str)
bool isTempNamespace(Oid namespaceId)
bool isAnyTempNamespace(Oid namespaceId)
char * NameListToString(const List *names)
#define IsA(nodeptr, _type_)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
bool get_object_namensp_unique(Oid class_id)
ArrayType * strlist_to_textarray(List *list)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
char * getObjectIdentity(const ObjectAddress *object, bool missing_ok)
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
bool is_objectclass_supported(Oid class_id)
#define ObjectAddressSet(addr, class_id, object_id)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
@ OBJECT_PUBLICATION_NAMESPACE
FormData_pg_database * Form_pg_database
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
FormData_pg_event_trigger * Form_pg_event_trigger
static int list_length(const List *l)
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
unsigned char pg_ascii_toupper(unsigned char ch)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
static Name DatumGetName(Datum X)
static Oid DatumGetObjectId(Datum X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
MemoryContextSwitchTo(old_ctx)
static color newsub(struct colormap *cm, color co)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
struct CollectedCommand::@120::@127 defprivs
struct CollectedCommand::@120::@121 simple
CollectedCommandType type
struct CollectedCommand::@120::@125 createopc
struct CollectedCommand * parent
struct CollectedCommand::@120::@124 opfam
union CollectedCommand::@120 d
struct CollectedCommand::@120::@126 atscfg
struct CollectedCommand::@120::@122 alterTable
struct CollectedCommand::@120::@123 grant
struct EventTriggerQueryState * previous
CollectedCommand * currentCommand
bool commandCollectionInhibited
Tuplestorestate * setResult
bool superuser_arg(Oid roleid)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define SearchSysCacheCopy1(cacheId, key1)
#define GetSysCacheOid1(cacheId, oidcol, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
int SessionReplicationRole
#define SESSION_REPLICATION_ROLE_REPLICA
#define TRIGGER_FIRES_ON_ORIGIN
#define TRIGGER_FIRES_ON_REPLICA
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
CommandTag CreateCommandTag(Node *parsetree)
static const char * CreateCommandName(Node *parsetree)
text * cstring_to_text(const char *s)
void CommandCounterIncrement(void)
void StartTransactionCommand(void)
void CommitTransactionCommand(void)