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_event_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++)
408 if (!db->dathasloginevt)
410 db->dathasloginevt =
true;
429 char tgenabled =
stmt->tgenabled;
437 (
errcode(ERRCODE_UNDEFINED_OBJECT),
438 errmsg(
"event trigger \"%s\" does not exist",
442 trigoid = evtForm->oid;
449 evtForm->evtenabled = tgenabled;
457 if (
namestrcmp(&evtForm->evtevent,
"login") == 0 &&
489 (
errcode(ERRCODE_UNDEFINED_OBJECT),
490 errmsg(
"event trigger \"%s\" does not exist",
name)));
493 evtOid = evtForm->oid;
521 (
errcode(ERRCODE_UNDEFINED_OBJECT),
522 errmsg(
"event trigger with OID %u does not exist", trigOid)));
541 if (form->evtowner == newOwnerId)
551 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
552 errmsg(
"permission denied to change owner of event trigger \"%s\"",
554 errhint(
"The owner of an event trigger must be a superuser.")));
556 form->evtowner = newOwnerId;
583 (
errcode(ERRCODE_UNDEFINED_OBJECT),
584 errmsg(
"event trigger \"%s\" does not exist", trigname)));
657#ifdef USE_ASSERT_CHECKING
681 if (cachelist ==
NIL)
694 foreach(lc, cachelist)
709 trigdata->
type = T_EventTriggerData;
710 trigdata->
event = eventstr;
958 Anum_pg_database_oid,
969 if (db->dathasloginevt)
971 db->dathasloginevt =
false;
1079 "event trigger context",
1084 foreach(lc, fn_oid_list)
1091 elog(
DEBUG1,
"EventTriggerInvoke %u", fnoid);
1157 case DatabaseRelationId:
1158 case TableSpaceRelationId:
1159 case AuthIdRelationId:
1160 case AuthMemRelationId:
1161 case ParameterAclRelationId:
1164 case EventTriggerRelationId:
1193 "event trigger state",
1198 state->in_sql_drop =
false;
1203 state->currentCommand = NULL;
1284 if (object->
classId == NamespaceRelationId &&
1367 if (object->
classId == NamespaceRelationId &&
1403 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1404 errmsg(
"%s can only be called in a sql_drop event trigger function",
1405 "pg_event_trigger_dropped_objects()")));
1415 bool nulls[12] = {0};
1496 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1497 errmsg(
"%s can only be called in a table_rewrite event trigger function",
1498 "pg_event_trigger_table_rewrite_oid()")));
1517 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1518 errmsg(
"%s can only be called in a table_rewrite event trigger function",
1519 "pg_event_trigger_table_rewrite_reason()")));
1690 newsub->address = address;
1807 OperatorFamilyRelationId, opfamoid);
1840 OperatorClassRelationId, opcoid);
1858 Oid *dictIds,
int ndicts)
1874 TSConfigRelationId, cfgId);
1930 (
errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1931 errmsg(
"%s can only be called in an event trigger function",
1932 "pg_event_trigger_ddl_commands()")));
1941 bool nulls[9] = {0};
1969 char *schema = NULL;
1992 if (identity == NULL)
2021 elog(
ERROR,
"cache lookup failed for object %u/%u",
2028 "invalid null namespace in object %u/%u/%d",
2090 "GRANT" :
"REVOKE");
2131 return "FOREIGN DATA WRAPPER";
2133 return "FOREIGN SERVER";
2139 return "LARGE OBJECT";
2149 return "TABLESPACE";
2189 elog(
ERROR,
"unsupported object type: %d", (
int) objtype);
2216 return "FOREIGN DATA WRAPPERS";
2218 return "FOREIGN SERVERS";
2224 return "LARGE OBJECTS";
2228 return "PROCEDURES";
2232 return "TABLESPACES";
2273 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_empty_array(Oid elmtype)
ArrayType * construct_array_builtin(Datum *elems, int nelems, 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)
const char * GetCommandTagName(CommandTag commandTag)
CommandTag GetCommandTagEnum(const char *commandname)
bool command_tag_event_trigger_ok(CommandTag commandTag)
bool command_tag_table_rewrite_ok(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)
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)
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata, bool unfiltered)
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_inplace_update_cancel(void *state)
void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)
void systable_inplace_update_finish(void *state, HeapTuple tuple)
bool MyDatabaseHasLoginEventTriggers
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 * list_copy(const List *oldlist)
List * lappend_oid(List *list, Oid datum)
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)
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
#define AccessExclusiveLock
#define InplaceUpdateTupleLock
char * get_namespace_name_or_temp(Oid nspid)
char * get_namespace_name(Oid nspid)
Oid get_func_rettype(Oid funcid)
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext TopMemoryContext
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
int namestrcmp(Name name, const char *str)
void namestrcpy(Name name, const char *str)
char * NameListToString(const List *names)
bool isTempNamespace(Oid namespaceId)
bool isAnyTempNamespace(Oid namespaceId)
#define IsA(nodeptr, _type_)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
ArrayType * strlist_to_textarray(List *list)
bool get_object_namensp_unique(Oid class_id)
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)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
AttrNumber get_object_attnum_name(Oid class_id)
char * getObjectIdentity(const ObjectAddress *object, 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)
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)
void check_stack_depth(void)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
CollectedCommandType type
struct CollectedCommand::@124::@128 opfam
struct CollectedCommand::@124::@131 defprivs
union CollectedCommand::@124 d
struct CollectedCommand::@124::@127 grant
struct CollectedCommand::@124::@126 alterTable
struct CollectedCommand::@124::@130 atscfg
struct CollectedCommand * parent
struct CollectedCommand::@124::@125 simple
ObjectAddress secondaryObject
struct CollectedCommand::@124::@129 createopc
struct EventTriggerQueryState * previous
CollectedCommand * currentCommand
bool commandCollectionInhibited
Tuplestorestate * setResult
bool superuser_arg(Oid roleid)
HeapTuple SearchSysCacheLockedCopy1(int cacheId, Datum key1)
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)