PostgreSQL Source Code  git master
event_trigger.h File Reference
Include dependency graph for event_trigger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EventTriggerData
 

Macros

#define AT_REWRITE_ALTER_PERSISTENCE   0x01
 
#define AT_REWRITE_DEFAULT_VAL   0x02
 
#define AT_REWRITE_COLUMN_REWRITE   0x04
 
#define CALLED_AS_EVENT_TRIGGER(fcinfo)   ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))
 

Typedefs

typedef struct EventTriggerData EventTriggerData
 

Functions

Oid CreateEventTrigger (CreateEventTrigStmt *stmt)
 
Oid get_event_trigger_oid (const char *trigname, bool missing_ok)
 
Oid AlterEventTrigger (AlterEventTrigStmt *stmt)
 
ObjectAddress AlterEventTriggerOwner (const char *name, Oid newOwnerId)
 
void AlterEventTriggerOwner_oid (Oid, Oid newOwnerId)
 
bool EventTriggerSupportsObjectType (ObjectType obtype)
 
bool EventTriggerSupportsObjectClass (ObjectClass objclass)
 
void EventTriggerDDLCommandStart (Node *parsetree)
 
void EventTriggerDDLCommandEnd (Node *parsetree)
 
void EventTriggerSQLDrop (Node *parsetree)
 
void EventTriggerTableRewrite (Node *parsetree, Oid tableOid, int reason)
 
bool EventTriggerBeginCompleteQuery (void)
 
void EventTriggerEndCompleteQuery (void)
 
bool trackDroppedObjectsNeeded (void)
 
void EventTriggerSQLDropAddObject (const ObjectAddress *object, bool original, bool normal)
 
void EventTriggerInhibitCommandCollection (void)
 
void EventTriggerUndoInhibitCommandCollection (void)
 
void EventTriggerCollectSimpleCommand (ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
 
void EventTriggerAlterTableStart (Node *parsetree)
 
void EventTriggerAlterTableRelid (Oid objectId)
 
void EventTriggerCollectAlterTableSubcmd (Node *subcmd, ObjectAddress address)
 
void EventTriggerAlterTableEnd (void)
 
void EventTriggerCollectGrant (InternalGrant *istmt)
 
void EventTriggerCollectAlterOpFam (AlterOpFamilyStmt *stmt, Oid opfamoid, List *operators, List *procedures)
 
void EventTriggerCollectCreateOpClass (CreateOpClassStmt *stmt, Oid opcoid, List *operators, List *procedures)
 
void EventTriggerCollectAlterTSConfig (AlterTSConfigurationStmt *stmt, Oid cfgId, Oid *dictIds, int ndicts)
 
void EventTriggerCollectAlterDefPrivs (AlterDefaultPrivilegesStmt *stmt)
 

Macro Definition Documentation

◆ AT_REWRITE_ALTER_PERSISTENCE

#define AT_REWRITE_ALTER_PERSISTENCE   0x01

Definition at line 32 of file event_trigger.h.

Referenced by ATPrepCmd().

◆ AT_REWRITE_COLUMN_REWRITE

#define AT_REWRITE_COLUMN_REWRITE   0x04

Definition at line 34 of file event_trigger.h.

Referenced by ATPrepAlterColumnType().

◆ AT_REWRITE_DEFAULT_VAL

#define AT_REWRITE_DEFAULT_VAL   0x02

Definition at line 33 of file event_trigger.h.

Referenced by ATExecAddColumn().

◆ CALLED_AS_EVENT_TRIGGER

#define CALLED_AS_EVENT_TRIGGER (   fcinfo)    ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))

Typedef Documentation

◆ EventTriggerData

Function Documentation

◆ AlterEventTrigger()

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 362 of file event_trigger.c.

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, EVENTTRIGGERNAME, GETSTRUCT, GetUserId(), heap_freetuple(), HeapTupleIsValid, InvokeObjectPostAlterHook, OBJECT_EVENT_TRIGGER, pg_event_trigger_ownercheck(), RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), table_open(), AlterEventTrigStmt::tgenabled, and AlterEventTrigStmt::trigname.

Referenced by standard_ProcessUtility().

363 {
364  Relation tgrel;
365  HeapTuple tup;
366  Oid trigoid;
367  Form_pg_event_trigger evtForm;
368  char tgenabled = stmt->tgenabled;
369 
370  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
371 
373  CStringGetDatum(stmt->trigname));
374  if (!HeapTupleIsValid(tup))
375  ereport(ERROR,
376  (errcode(ERRCODE_UNDEFINED_OBJECT),
377  errmsg("event trigger \"%s\" does not exist",
378  stmt->trigname)));
379 
380  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
381  trigoid = evtForm->oid;
382 
383  if (!pg_event_trigger_ownercheck(trigoid, GetUserId()))
385  stmt->trigname);
386 
387  /* tuple is a copy, so we can modify it below */
388  evtForm->evtenabled = tgenabled;
389 
390  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
391 
392  InvokeObjectPostAlterHook(EventTriggerRelationId,
393  trigoid, 0);
394 
395  /* clean up */
396  heap_freetuple(tup);
398 
399  return trigoid;
400 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Oid GetUserId(void)
Definition: miscinit.c:450
int errcode(int sqlerrcode)
Definition: elog.c:610
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5078
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:175
#define ereport(elevel,...)
Definition: elog.h:144
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
int errmsg(const char *fmt,...)
Definition: elog.c:824
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 406 of file event_trigger.c.

References AlterEventTriggerOwner_internal(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, EVENTTRIGGERNAME, GETSTRUCT, heap_freetuple(), HeapTupleIsValid, ObjectAddressSet, RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().

Referenced by ExecAlterOwnerStmt().

407 {
408  Oid evtOid;
409  HeapTuple tup;
410  Form_pg_event_trigger evtForm;
411  Relation rel;
412  ObjectAddress address;
413 
414  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
415 
417 
418  if (!HeapTupleIsValid(tup))
419  ereport(ERROR,
420  (errcode(ERRCODE_UNDEFINED_OBJECT),
421  errmsg("event trigger \"%s\" does not exist", name)));
422 
423  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
424  evtOid = evtForm->oid;
425 
426  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
427 
428  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
429 
430  heap_freetuple(tup);
431 
433 
434  return address;
435 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
int errcode(int sqlerrcode)
Definition: elog.c:610
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel,...)
Definition: elog.h:144
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
const char * name
Definition: encode.c:561
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
int errmsg(const char *fmt,...)
Definition: elog.c:824
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  ,
Oid  newOwnerId 
)

Definition at line 441 of file event_trigger.c.

References AlterEventTriggerOwner_internal(), ereport, errcode(), errmsg(), ERROR, EVENTTRIGGEROID, heap_freetuple(), HeapTupleIsValid, ObjectIdGetDatum, RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().

Referenced by shdepReassignOwned().

442 {
443  HeapTuple tup;
444  Relation rel;
445 
446  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
447 
449 
450  if (!HeapTupleIsValid(tup))
451  ereport(ERROR,
452  (errcode(ERRCODE_UNDEFINED_OBJECT),
453  errmsg("event trigger with OID %u does not exist", trigOid)));
454 
455  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
456 
457  heap_freetuple(tup);
458 
460 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
int errcode(int sqlerrcode)
Definition: elog.c:610
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
int errmsg(const char *fmt,...)
Definition: elog.c:824
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 108 of file event_trigger.c.

References DefElem::arg, CStringGetDatum, DefElem::defname, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg(), ERROR, error_duplicate_filter_variable(), CreateEventTrigStmt::eventname, EVENTTRIGGERNAME, CreateEventTrigStmt::funcname, get_func_rettype(), GetUserId(), HeapTupleIsValid, insert_event_trigger_tuple(), lfirst, LookupFuncName(), NameListToString(), SearchSysCache1(), superuser(), CreateEventTrigStmt::trigname, validate_ddl_tags(), validate_table_rewrite_tags(), and CreateEventTrigStmt::whenclause.

Referenced by standard_ProcessUtility().

109 {
110  HeapTuple tuple;
111  Oid funcoid;
112  Oid funcrettype;
113  Oid evtowner = GetUserId();
114  ListCell *lc;
115  List *tags = NULL;
116 
117  /*
118  * It would be nice to allow database owners or even regular users to do
119  * this, but there are obvious privilege escalation risks which would have
120  * to somehow be plugged first.
121  */
122  if (!superuser())
123  ereport(ERROR,
124  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
125  errmsg("permission denied to create event trigger \"%s\"",
126  stmt->trigname),
127  errhint("Must be superuser to create an event trigger.")));
128 
129  /* Validate event name. */
130  if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
131  strcmp(stmt->eventname, "ddl_command_end") != 0 &&
132  strcmp(stmt->eventname, "sql_drop") != 0 &&
133  strcmp(stmt->eventname, "table_rewrite") != 0)
134  ereport(ERROR,
135  (errcode(ERRCODE_SYNTAX_ERROR),
136  errmsg("unrecognized event name \"%s\"",
137  stmt->eventname)));
138 
139  /* Validate filter conditions. */
140  foreach(lc, stmt->whenclause)
141  {
142  DefElem *def = (DefElem *) lfirst(lc);
143 
144  if (strcmp(def->defname, "tag") == 0)
145  {
146  if (tags != NULL)
148  tags = (List *) def->arg;
149  }
150  else
151  ereport(ERROR,
152  (errcode(ERRCODE_SYNTAX_ERROR),
153  errmsg("unrecognized filter variable \"%s\"", def->defname)));
154  }
155 
156  /* Validate tag list, if any. */
157  if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
158  strcmp(stmt->eventname, "ddl_command_end") == 0 ||
159  strcmp(stmt->eventname, "sql_drop") == 0)
160  && tags != NULL)
161  validate_ddl_tags("tag", tags);
162  else if (strcmp(stmt->eventname, "table_rewrite") == 0
163  && tags != NULL)
164  validate_table_rewrite_tags("tag", tags);
165 
166  /*
167  * Give user a nice error message if an event trigger of the same name
168  * already exists.
169  */
171  if (HeapTupleIsValid(tuple))
172  ereport(ERROR,
174  errmsg("event trigger \"%s\" already exists",
175  stmt->trigname)));
176 
177  /* Find and validate the trigger function. */
178  funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
179  funcrettype = get_func_rettype(funcoid);
180  if (funcrettype != EVTTRIGGEROID)
181  ereport(ERROR,
182  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
183  errmsg("function %s must return type %s",
184  NameListToString(stmt->funcname), "event_trigger")));
185 
186  /* Insert catalog entries. */
187  return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
188  evtowner, funcoid, tags);
189 }
static void validate_ddl_tags(const char *filtervar, List *taglist)
int errhint(const char *fmt,...)
Definition: elog.c:1071
Oid GetUserId(void)
Definition: miscinit.c:450
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1567
#define ERROR
Definition: elog.h:43
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Definition: parse_func.c:2103
static void error_duplicate_filter_variable(const char *defname)
#define CStringGetDatum(X)
Definition: postgres.h:578
Node * arg
Definition: parsenodes.h:733
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3102
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *tags)
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define lfirst(lc)
Definition: pg_list.h:190
int errmsg(const char *fmt,...)
Definition: elog.c:824
char * defname
Definition: parsenodes.h:732
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:31
Definition: pg_list.h:50

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1635 of file event_trigger.c.

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, EventTriggerQueryState::currentCommand, CollectedCommand::d, lappend(), list_length(), CollectedCommand::parent, and pfree().

Referenced by AlterTableMoveAll(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

1636 {
1637  CollectedCommand *parent;
1638 
1639  /* ignore if event trigger context not set, or collection disabled */
1640  if (!currentEventTriggerState ||
1642  return;
1643 
1645 
1646  /* If no subcommands, don't collect */
1648  {
1652  }
1653  else
1655 
1657 }
struct CollectedCommand::@109::@111 alterTable
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
void pfree(void *pointer)
Definition: mcxt.c:1056
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct CollectedCommand * parent
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
static int list_length(const List *l)
Definition: pg_list.h:169

◆ EventTriggerAlterTableRelid()

void EventTriggerAlterTableRelid ( Oid  objectId)

Definition at line 1582 of file event_trigger.c.

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::currentCommand, and CollectedCommand::d.

Referenced by AlterTableInternal(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

1583 {
1584  if (!currentEventTriggerState ||
1586  return;
1587 
1588  currentEventTriggerState->currentCommand->d.alterTable.objectId = objectId;
1589 }
struct CollectedCommand::@109::@111 alterTable
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
union CollectedCommand::@109 d

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1548 of file event_trigger.c.

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, copyObject, creating_extension, EventTriggerQueryState::currentCommand, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::in_extension, InvalidOid, MemoryContextSwitchTo(), NIL, palloc(), CollectedCommand::parent, CollectedCommand::parsetree, SCT_AlterTable, and CollectedCommand::type.

Referenced by AlterTableMoveAll(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

1549 {
1550  MemoryContext oldcxt;
1551  CollectedCommand *command;
1552 
1553  /* ignore if event trigger context not set, or collection disabled */
1554  if (!currentEventTriggerState ||
1556  return;
1557 
1559 
1560  command = palloc(sizeof(CollectedCommand));
1561 
1562  command->type = SCT_AlterTable;
1563  command->in_extension = creating_extension;
1564 
1565  command->d.alterTable.classId = RelationRelationId;
1566  command->d.alterTable.objectId = InvalidOid;
1567  command->d.alterTable.subcmds = NIL;
1568  command->parsetree = copyObject(parsetree);
1569 
1572 
1573  MemoryContextSwitchTo(oldcxt);
1574 }
#define NIL
Definition: pg_list.h:65
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct CollectedCommand::@109::@111 alterTable
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct CollectedCommand * parent
union CollectedCommand::@109 d
#define InvalidOid
Definition: postgres_ext.h:36
bool creating_extension
Definition: extension.c:71
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1075 of file event_trigger.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, EventTriggerQueryState::currentCommand, currentEventTriggerState, EventTriggerQueryState::cxt, EventTriggerQueryState::in_sql_drop, InvalidOid, MemoryContextAlloc(), NIL, EventTriggerQueryState::previous, slist_init(), EventTriggerQueryState::SQLDropList, EventTriggerQueryState::table_rewrite_oid, TopMemoryContext, and trackDroppedObjectsNeeded().

Referenced by ProcessUtilitySlow().

1076 {
1078  MemoryContext cxt;
1079 
1080  /*
1081  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1082  * reason to have event trigger state at all; so if there are none, don't
1083  * install one.
1084  */
1086  return false;
1087 
1089  "event trigger state",
1091  state = MemoryContextAlloc(cxt, sizeof(EventTriggerQueryState));
1092  state->cxt = cxt;
1093  slist_init(&(state->SQLDropList));
1094  state->in_sql_drop = false;
1095  state->table_rewrite_oid = InvalidOid;
1096 
1099  state->currentCommand = NULL;
1100  state->commandList = NIL;
1102  currentEventTriggerState = state;
1103 
1104  return true;
1105 }
#define NIL
Definition: pg_list.h:65
#define AllocSetContextCreate
Definition: memutils.h:170
bool trackDroppedObjectsNeeded(void)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static void slist_init(slist_head *head)
Definition: ilist.h:554
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct EventTriggerQueryState * previous
Definition: event_trigger.c:70
MemoryContext TopMemoryContext
Definition: mcxt.c:44
#define InvalidOid
Definition: postgres_ext.h:36
Definition: regguts.h:298
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796

◆ EventTriggerCollectAlterDefPrivs()

void EventTriggerCollectAlterDefPrivs ( AlterDefaultPrivilegesStmt stmt)

Definition at line 1813 of file event_trigger.c.

References AlterDefaultPrivilegesStmt::action, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::defprivs, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), GrantStmt::objtype, palloc0(), CollectedCommand::parsetree, SCT_AlterDefaultPrivileges, and CollectedCommand::type.

Referenced by ProcessUtilitySlow().

1814 {
1815  MemoryContext oldcxt;
1816  CollectedCommand *command;
1817 
1818  /* ignore if event trigger context not set, or collection disabled */
1819  if (!currentEventTriggerState ||
1821  return;
1822 
1824 
1825  command = palloc0(sizeof(CollectedCommand));
1826  command->type = SCT_AlterDefaultPrivileges;
1827  command->d.defprivs.objtype = stmt->action->objtype;
1828  command->in_extension = creating_extension;
1829  command->parsetree = (Node *) copyObject(stmt);
1830 
1833  MemoryContextSwitchTo(oldcxt);
1834 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:529
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
void * palloc0(Size size)
Definition: mcxt.c:980
bool creating_extension
Definition: extension.c:71
struct CollectedCommand::@109::@116 defprivs
ObjectType objtype
Definition: parsenodes.h:1929
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerCollectAlterOpFam()

void EventTriggerCollectAlterOpFam ( AlterOpFamilyStmt stmt,
Oid  opfamoid,
List operators,
List procedures 
)

Definition at line 1711 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), ObjectAddressSet, CollectedCommand::opfam, palloc(), CollectedCommand::parsetree, SCT_AlterOpFamily, and CollectedCommand::type.

Referenced by AlterOpFamilyAdd(), and AlterOpFamilyDrop().

1713 {
1714  MemoryContext oldcxt;
1715  CollectedCommand *command;
1716 
1717  /* ignore if event trigger context not set, or collection disabled */
1718  if (!currentEventTriggerState ||
1720  return;
1721 
1723 
1724  command = palloc(sizeof(CollectedCommand));
1725  command->type = SCT_AlterOpFamily;
1726  command->in_extension = creating_extension;
1727  ObjectAddressSet(command->d.opfam.address,
1728  OperatorFamilyRelationId, opfamoid);
1729  command->d.opfam.operators = operators;
1730  command->d.opfam.procedures = procedures;
1731  command->parsetree = (Node *) copyObject(stmt);
1732 
1735 
1736  MemoryContextSwitchTo(oldcxt);
1737 }
struct CollectedCommand::@109::@113 opfam
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:529
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
bool creating_extension
Definition: extension.c:71
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

Definition at line 1600 of file event_trigger.c.

References CollectedATSubcmd::address, CollectedCommand::alterTable, Assert, EventTriggerQueryState::commandCollectionInhibited, copyObject, EventTriggerQueryState::currentCommand, EventTriggerQueryState::cxt, CollectedCommand::d, IsA, lappend(), MemoryContextSwitchTo(), newsub(), OidIsValid, palloc(), and CollectedATSubcmd::parsetree.

Referenced by ATExecCmd().

1601 {
1602  MemoryContext oldcxt;
1604 
1605  /* ignore if event trigger context not set, or collection disabled */
1606  if (!currentEventTriggerState ||
1608  return;
1609 
1610  Assert(IsA(subcmd, AlterTableCmd));
1613 
1615 
1616  newsub = palloc(sizeof(CollectedATSubcmd));
1617  newsub->address = address;
1618  newsub->parsetree = copyObject(subcmd);
1619 
1622 
1623  MemoryContextSwitchTo(oldcxt);
1624 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct CollectedCommand::@109::@111 alterTable
#define OidIsValid(objectId)
Definition: c.h:651
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
#define Assert(condition)
Definition: c.h:745
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645
static color newsub(struct colormap *cm, color co)
Definition: regc_color.c:389
ObjectAddress address

◆ EventTriggerCollectAlterTSConfig()

void EventTriggerCollectAlterTSConfig ( AlterTSConfigurationStmt stmt,
Oid  cfgId,
Oid dictIds,
int  ndicts 
)

Definition at line 1778 of file event_trigger.c.

References CollectedCommand::atscfg, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), ObjectAddressSet, palloc(), palloc0(), CollectedCommand::parsetree, SCT_AlterTSConfig, and CollectedCommand::type.

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

1780 {
1781  MemoryContext oldcxt;
1782  CollectedCommand *command;
1783 
1784  /* ignore if event trigger context not set, or collection disabled */
1785  if (!currentEventTriggerState ||
1787  return;
1788 
1790 
1791  command = palloc0(sizeof(CollectedCommand));
1792  command->type = SCT_AlterTSConfig;
1793  command->in_extension = creating_extension;
1794  ObjectAddressSet(command->d.atscfg.address,
1795  TSConfigRelationId, cfgId);
1796  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1797  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1798  command->d.atscfg.ndicts = ndicts;
1799  command->parsetree = (Node *) copyObject(stmt);
1800 
1803 
1804  MemoryContextSwitchTo(oldcxt);
1805 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:529
CollectedCommandType type
unsigned int Oid
Definition: postgres_ext.h:31
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
void * palloc0(Size size)
Definition: mcxt.c:980
bool creating_extension
Definition: extension.c:71
struct CollectedCommand::@109::@115 atscfg
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerCollectCreateOpClass()

void EventTriggerCollectCreateOpClass ( CreateOpClassStmt stmt,
Oid  opcoid,
List operators,
List procedures 
)

Definition at line 1744 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, CollectedCommand::createopc, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), ObjectAddressSet, palloc0(), CollectedCommand::parsetree, SCT_CreateOpClass, and CollectedCommand::type.

Referenced by DefineOpClass().

1746 {
1747  MemoryContext oldcxt;
1748  CollectedCommand *command;
1749 
1750  /* ignore if event trigger context not set, or collection disabled */
1751  if (!currentEventTriggerState ||
1753  return;
1754 
1756 
1757  command = palloc0(sizeof(CollectedCommand));
1758  command->type = SCT_CreateOpClass;
1759  command->in_extension = creating_extension;
1760  ObjectAddressSet(command->d.createopc.address,
1761  OperatorClassRelationId, opcoid);
1762  command->d.createopc.operators = operators;
1763  command->d.createopc.procedures = procedures;
1764  command->parsetree = (Node *) copyObject(stmt);
1765 
1768 
1769  MemoryContextSwitchTo(oldcxt);
1770 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:529
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
void * palloc0(Size size)
Definition: mcxt.c:980
bool creating_extension
Definition: extension.c:71
struct CollectedCommand::@109::@114 createopc
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1667 of file event_trigger.c.

References InternalGrant::col_privs, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::grant, InternalGrant::grantees, CollectedCommand::in_extension, lappend(), lfirst, list_copy(), MemoryContextSwitchTo(), NIL, InternalGrant::objects, palloc(), CollectedCommand::parsetree, SCT_Grant, and CollectedCommand::type.

Referenced by ExecGrantStmt_oids().

1668 {
1669  MemoryContext oldcxt;
1670  CollectedCommand *command;
1671  InternalGrant *icopy;
1672  ListCell *cell;
1673 
1674  /* ignore if event trigger context not set, or collection disabled */
1675  if (!currentEventTriggerState ||
1677  return;
1678 
1680 
1681  /*
1682  * This is tedious, but necessary.
1683  */
1684  icopy = palloc(sizeof(InternalGrant));
1685  memcpy(icopy, istmt, sizeof(InternalGrant));
1686  icopy->objects = list_copy(istmt->objects);
1687  icopy->grantees = list_copy(istmt->grantees);
1688  icopy->col_privs = NIL;
1689  foreach(cell, istmt->col_privs)
1690  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1691 
1692  /* Now collect it, using the copied InternalGrant */
1693  command = palloc(sizeof(CollectedCommand));
1694  command->type = SCT_Grant;
1695  command->in_extension = creating_extension;
1696  command->d.grant.istmt = icopy;
1697  command->parsetree = NULL;
1698 
1701 
1702  MemoryContextSwitchTo(oldcxt);
1703 }
#define NIL
Definition: pg_list.h:65
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
List * list_copy(const List *oldlist)
Definition: list.c:1403
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct CollectedCommand::@109::@112 grant
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:321
bool creating_extension
Definition: extension.c:71
#define lfirst(lc)
Definition: pg_list.h:190
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerCollectSimpleCommand()

void EventTriggerCollectSimpleCommand ( ObjectAddress  address,
ObjectAddress  secondaryObject,
Node parsetree 
)

Definition at line 1510 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), palloc(), CollectedCommand::parsetree, SCT_Simple, CollectedCommand::simple, and CollectedCommand::type.

Referenced by AlterPublicationOptions(), CreateSchemaCommand(), ProcessUtilitySlow(), and PublicationAddTables().

1513 {
1514  MemoryContext oldcxt;
1515  CollectedCommand *command;
1516 
1517  /* ignore if event trigger context not set, or collection disabled */
1518  if (!currentEventTriggerState ||
1520  return;
1521 
1523 
1524  command = palloc(sizeof(CollectedCommand));
1525 
1526  command->type = SCT_Simple;
1527  command->in_extension = creating_extension;
1528 
1529  command->d.simple.address = address;
1530  command->d.simple.secondaryObject = secondaryObject;
1531  command->parsetree = copyObject(parsetree);
1532 
1534  command);
1535 
1536  MemoryContextSwitchTo(oldcxt);
1537 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
struct CollectedCommand::@109::@110 simple
List * lappend(List *list, void *datum)
Definition: list.c:321
bool creating_extension
Definition: extension.c:71
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 689 of file event_trigger.c.

References CommandCounterIncrement(), EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_DDLCommandEnd, IsUnderPostmaster, list_free(), and NIL.

Referenced by ProcessUtilitySlow().

690 {
691  List *runlist;
692  EventTriggerData trigdata;
693 
694  /*
695  * See EventTriggerDDLCommandStart for a discussion about why event
696  * triggers are disabled in single user mode.
697  */
698  if (!IsUnderPostmaster)
699  return;
700 
701  /*
702  * Also do nothing if our state isn't set up, which it won't be if there
703  * weren't any relevant event triggers at the start of the current DDL
704  * command. This test might therefore seem optional, but it's important
705  * because EventTriggerCommonSetup might find triggers that didn't exist
706  * at the time the command started. Although this function itself
707  * wouldn't crash, the event trigger functions would presumably call
708  * pg_event_trigger_ddl_commands which would fail. Better to do nothing
709  * until the next command.
710  */
712  return;
713 
714  runlist = EventTriggerCommonSetup(parsetree,
715  EVT_DDLCommandEnd, "ddl_command_end",
716  &trigdata);
717  if (runlist == NIL)
718  return;
719 
720  /*
721  * Make sure anything the main command did will be visible to the event
722  * triggers.
723  */
725 
726  /* Run the triggers. */
727  EventTriggerInvoke(runlist, &trigdata);
728 
729  /* Cleanup. */
730  list_free(runlist);
731 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:109
void CommandCounterIncrement(void)
Definition: xact.c:1021
void list_free(List *list)
Definition: list.c:1376
Definition: pg_list.h:50

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 641 of file event_trigger.c.

References CommandCounterIncrement(), EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_DDLCommandStart, IsUnderPostmaster, list_free(), and NIL.

Referenced by ProcessUtilitySlow().

642 {
643  List *runlist;
644  EventTriggerData trigdata;
645 
646  /*
647  * Event Triggers are completely disabled in standalone mode. There are
648  * (at least) two reasons for this:
649  *
650  * 1. A sufficiently broken event trigger might not only render the
651  * database unusable, but prevent disabling itself to fix the situation.
652  * In this scenario, restarting in standalone mode provides an escape
653  * hatch.
654  *
655  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
656  * therefore will malfunction if pg_event_trigger's indexes are damaged.
657  * To allow recovery from a damaged index, we need some operating mode
658  * wherein event triggers are disabled. (Or we could implement
659  * heapscan-and-sort logic for that case, but having disaster recovery
660  * scenarios depend on code that's otherwise untested isn't appetizing.)
661  */
662  if (!IsUnderPostmaster)
663  return;
664 
665  runlist = EventTriggerCommonSetup(parsetree,
667  "ddl_command_start",
668  &trigdata);
669  if (runlist == NIL)
670  return;
671 
672  /* Run the triggers. */
673  EventTriggerInvoke(runlist, &trigdata);
674 
675  /* Cleanup. */
676  list_free(runlist);
677 
678  /*
679  * Make sure anything the event triggers did will be visible to the main
680  * command.
681  */
683 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:109
void CommandCounterIncrement(void)
Definition: xact.c:1021
void list_free(List *list)
Definition: list.c:1376
Definition: pg_list.h:50

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1119 of file event_trigger.c.

References EventTriggerQueryState::cxt, MemoryContextDelete(), and EventTriggerQueryState::previous.

Referenced by ProcessUtilitySlow().

1120 {
1121  EventTriggerQueryState *prevstate;
1122 
1123  prevstate = currentEventTriggerState->previous;
1124 
1125  /* this avoids the need for retail pfree of SQLDropList items: */
1127 
1128  currentEventTriggerState = prevstate;
1129 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct EventTriggerQueryState * previous
Definition: event_trigger.c:70

◆ EventTriggerInhibitCommandCollection()

void EventTriggerInhibitCommandCollection ( void  )

Definition at line 1476 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1477 {
1479  return;
1480 
1482 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 737 of file event_trigger.c.

References CommandCounterIncrement(), EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_SQLDrop, EventTriggerQueryState::in_sql_drop, IsUnderPostmaster, list_free(), NIL, PG_END_TRY, PG_FINALLY, PG_TRY, slist_is_empty(), and EventTriggerQueryState::SQLDropList.

Referenced by ProcessUtilitySlow().

738 {
739  List *runlist;
740  EventTriggerData trigdata;
741 
742  /*
743  * See EventTriggerDDLCommandStart for a discussion about why event
744  * triggers are disabled in single user mode.
745  */
746  if (!IsUnderPostmaster)
747  return;
748 
749  /*
750  * Use current state to determine whether this event fires at all. If
751  * there are no triggers for the sql_drop event, then we don't have
752  * anything to do here. Note that dropped object collection is disabled
753  * if this is the case, so even if we were to try to run, the list would
754  * be empty.
755  */
758  return;
759 
760  runlist = EventTriggerCommonSetup(parsetree,
761  EVT_SQLDrop, "sql_drop",
762  &trigdata);
763 
764  /*
765  * Nothing to do if run list is empty. Note this typically can't happen,
766  * because if there are no sql_drop events, then objects-to-drop wouldn't
767  * have been collected in the first place and we would have quit above.
768  * But it could occur if event triggers were dropped partway through.
769  */
770  if (runlist == NIL)
771  return;
772 
773  /*
774  * Make sure anything the main command did will be visible to the event
775  * triggers.
776  */
778 
779  /*
780  * Make sure pg_event_trigger_dropped_objects only works when running
781  * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
782  * one trigger fails. (This is perhaps not necessary, as the currentState
783  * variable will be removed shortly by our caller, but it seems better to
784  * play safe.)
785  */
787 
788  /* Run the triggers. */
789  PG_TRY();
790  {
791  EventTriggerInvoke(runlist, &trigdata);
792  }
793  PG_FINALLY();
794  {
796  }
797  PG_END_TRY();
798 
799  /* Cleanup. */
800  list_free(runlist);
801 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:109
static bool slist_is_empty(slist_head *head)
Definition: ilist.h:563
#define PG_FINALLY()
Definition: elog.h:312
void CommandCounterIncrement(void)
Definition: xact.c:1021
void list_free(List *list)
Definition: list.c:1376
#define PG_TRY()
Definition: elog.h:295
Definition: pg_list.h:50
#define PG_END_TRY()
Definition: elog.h:320

◆ EventTriggerSQLDropAddObject()

void EventTriggerSQLDropAddObject ( const ObjectAddress object,
bool  original,
bool  normal 
)

Definition at line 1169 of file event_trigger.c.

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert, attnum, ObjectAddress::classId, EventTriggerQueryState::cxt, DatumGetName, DatumGetObjectId, EventTriggerSupportsObjectClass(), get_catalog_object_by_oid(), get_namespace_name(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_namensp_unique(), getObjectClass(), getObjectIdentityParts(), getObjectTypeDescription(), heap_getattr, InvalidAttrNumber, is_objectclass_supported(), isAnyTempNamespace(), SQLDropObject::istemp, isTempNamespace(), MemoryContextSwitchTo(), NameStr, SQLDropObject::next, SQLDropObject::normal, ObjectAddress::objectId, ObjectAddress::objectSubId, SQLDropObject::objecttype, SQLDropObject::objidentity, SQLDropObject::objname, SQLDropObject::original, palloc0(), pfree(), pstrdup(), RelationGetDescr, SQLDropObject::schemaname, slist_push_head(), EventTriggerQueryState::SQLDropList, table_close(), and table_open().

Referenced by deleteObjectsInList(), and DropSubscription().

1170 {
1171  SQLDropObject *obj;
1172  MemoryContext oldcxt;
1173 
1175  return;
1176 
1178 
1179  /* don't report temp schemas except my own */
1180  if (object->classId == NamespaceRelationId &&
1181  (isAnyTempNamespace(object->objectId) &&
1182  !isTempNamespace(object->objectId)))
1183  return;
1184 
1186 
1187  obj = palloc0(sizeof(SQLDropObject));
1188  obj->address = *object;
1189  obj->original = original;
1190  obj->normal = normal;
1191 
1192  /*
1193  * Obtain schema names from the object's catalog tuple, if one exists;
1194  * this lets us skip objects in temp schemas. We trust that
1195  * ObjectProperty contains all object classes that can be
1196  * schema-qualified.
1197  */
1198  if (is_objectclass_supported(object->classId))
1199  {
1200  Relation catalog;
1201  HeapTuple tuple;
1202 
1203  catalog = table_open(obj->address.classId, AccessShareLock);
1204  tuple = get_catalog_object_by_oid(catalog,
1205  get_object_attnum_oid(object->classId),
1206  obj->address.objectId);
1207 
1208  if (tuple)
1209  {
1211  Datum datum;
1212  bool isnull;
1213 
1215  if (attnum != InvalidAttrNumber)
1216  {
1217  datum = heap_getattr(tuple, attnum,
1218  RelationGetDescr(catalog), &isnull);
1219  if (!isnull)
1220  {
1221  Oid namespaceId;
1222 
1223  namespaceId = DatumGetObjectId(datum);
1224  /* temp objects are only reported if they are my own */
1225  if (isTempNamespace(namespaceId))
1226  {
1227  obj->schemaname = "pg_temp";
1228  obj->istemp = true;
1229  }
1230  else if (isAnyTempNamespace(namespaceId))
1231  {
1232  pfree(obj);
1233  table_close(catalog, AccessShareLock);
1234  MemoryContextSwitchTo(oldcxt);
1235  return;
1236  }
1237  else
1238  {
1239  obj->schemaname = get_namespace_name(namespaceId);
1240  obj->istemp = false;
1241  }
1242  }
1243  }
1244 
1246  obj->address.objectSubId == 0)
1247  {
1248  attnum = get_object_attnum_name(obj->address.classId);
1249  if (attnum != InvalidAttrNumber)
1250  {
1251  datum = heap_getattr(tuple, attnum,
1252  RelationGetDescr(catalog), &isnull);
1253  if (!isnull)
1254  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1255  }
1256  }
1257  }
1258 
1259  table_close(catalog, AccessShareLock);
1260  }
1261  else
1262  {
1263  if (object->classId == NamespaceRelationId &&
1264  isTempNamespace(object->objectId))
1265  obj->istemp = true;
1266  }
1267 
1268  /* object identity, objname and objargs */
1269  obj->objidentity =
1270  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
1271  false);
1272 
1273  /* object type */
1274  obj->objecttype = getObjectTypeDescription(&obj->address, false);
1275 
1277 
1278  MemoryContextSwitchTo(oldcxt);
1279 }
bool get_object_namensp_unique(Oid class_id)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
slist_node next
Definition: event_trigger.c:88
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
ObjectAddress address
Definition: event_trigger.c:78
AttrNumber get_object_attnum_oid(Oid class_id)
#define RelationGetDescr(relation)
Definition: rel.h:482
const char * objname
Definition: event_trigger.c:80
#define DatumGetObjectId(X)
Definition: postgres.h:500
char * pstrdup(const char *in)
Definition: mcxt.c:1186
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AccessShareLock
Definition: lockdefs.h:36
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:574
List * addrnames
Definition: event_trigger.c:83
AttrNumber get_object_attnum_namespace(Oid class_id)
const char * objidentity
Definition: event_trigger.c:81
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2722
const char * objecttype
Definition: event_trigger.c:82
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
#define DatumGetName(X)
Definition: postgres.h:585
void pfree(void *pointer)
Definition: mcxt.c:1056
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3157
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
const char * schemaname
Definition: event_trigger.c:79
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:762
AttrNumber get_object_attnum_name(Oid class_id)
void * palloc0(Size size)
Definition: mcxt.c:980
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
uintptr_t Datum
Definition: postgres.h:367
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:745
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:622
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3195
bool is_objectclass_supported(Oid class_id)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
int16 AttrNumber
Definition: attnum.h:21

◆ EventTriggerSupportsObjectClass()

bool EventTriggerSupportsObjectClass ( ObjectClass  objclass)

Definition at line 1010 of file event_trigger.c.

References OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, and OCLASS_USER_MAPPING.

Referenced by deleteObjectsInList(), and EventTriggerSQLDropAddObject().

1011 {
1012  switch (objclass)
1013  {
1014  case OCLASS_DATABASE:
1015  case OCLASS_TBLSPACE:
1016  case OCLASS_ROLE:
1017  /* no support for global objects */
1018  return false;
1019  case OCLASS_EVENT_TRIGGER:
1020  /* no support for event triggers on event triggers */
1021  return false;
1022  case OCLASS_CLASS:
1023  case OCLASS_PROC:
1024  case OCLASS_TYPE:
1025  case OCLASS_CAST:
1026  case OCLASS_COLLATION:
1027  case OCLASS_CONSTRAINT:
1028  case OCLASS_CONVERSION:
1029  case OCLASS_DEFAULT:
1030  case OCLASS_LANGUAGE:
1031  case OCLASS_LARGEOBJECT:
1032  case OCLASS_OPERATOR:
1033  case OCLASS_OPCLASS:
1034  case OCLASS_OPFAMILY:
1035  case OCLASS_AM:
1036  case OCLASS_AMOP:
1037  case OCLASS_AMPROC:
1038  case OCLASS_REWRITE:
1039  case OCLASS_TRIGGER:
1040  case OCLASS_SCHEMA:
1041  case OCLASS_STATISTIC_EXT:
1042  case OCLASS_TSPARSER:
1043  case OCLASS_TSDICT:
1044  case OCLASS_TSTEMPLATE:
1045  case OCLASS_TSCONFIG:
1046  case OCLASS_FDW:
1047  case OCLASS_FOREIGN_SERVER:
1048  case OCLASS_USER_MAPPING:
1049  case OCLASS_DEFACL:
1050  case OCLASS_EXTENSION:
1051  case OCLASS_POLICY:
1052  case OCLASS_PUBLICATION:
1054  case OCLASS_SUBSCRIPTION:
1055  case OCLASS_TRANSFORM:
1056  return true;
1057 
1058  /*
1059  * There's intentionally no default: case here; we want the
1060  * compiler to warn if a new OCLASS hasn't been handled above.
1061  */
1062  }
1063 
1064  /* Shouldn't get here, but if we do, say "no support" */
1065  return false;
1066 }

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 936 of file event_trigger.c.

References OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, and OBJECT_VIEW.

Referenced by ExecGrantStmt_oids(), and standard_ProcessUtility().

937 {
938  switch (obtype)
939  {
940  case OBJECT_DATABASE:
941  case OBJECT_TABLESPACE:
942  case OBJECT_ROLE:
943  /* no support for global objects */
944  return false;
946  /* no support for event triggers on event triggers */
947  return false;
949  case OBJECT_AGGREGATE:
950  case OBJECT_AMOP:
951  case OBJECT_AMPROC:
952  case OBJECT_ATTRIBUTE:
953  case OBJECT_CAST:
954  case OBJECT_COLUMN:
955  case OBJECT_COLLATION:
956  case OBJECT_CONVERSION:
957  case OBJECT_DEFACL:
958  case OBJECT_DEFAULT:
959  case OBJECT_DOMAIN:
961  case OBJECT_EXTENSION:
962  case OBJECT_FDW:
965  case OBJECT_FUNCTION:
966  case OBJECT_INDEX:
967  case OBJECT_LANGUAGE:
968  case OBJECT_LARGEOBJECT:
969  case OBJECT_MATVIEW:
970  case OBJECT_OPCLASS:
971  case OBJECT_OPERATOR:
972  case OBJECT_OPFAMILY:
973  case OBJECT_POLICY:
974  case OBJECT_PROCEDURE:
975  case OBJECT_PUBLICATION:
977  case OBJECT_ROUTINE:
978  case OBJECT_RULE:
979  case OBJECT_SCHEMA:
980  case OBJECT_SEQUENCE:
981  case OBJECT_SUBSCRIPTION:
984  case OBJECT_TABLE:
985  case OBJECT_TRANSFORM:
986  case OBJECT_TRIGGER:
988  case OBJECT_TSDICTIONARY:
989  case OBJECT_TSPARSER:
990  case OBJECT_TSTEMPLATE:
991  case OBJECT_TYPE:
992  case OBJECT_USER_MAPPING:
993  case OBJECT_VIEW:
994  return true;
995 
996  /*
997  * There's intentionally no default: case here; we want the
998  * compiler to warn if a new ObjectType hasn't been handled above.
999  */
1000  }
1001 
1002  /* Shouldn't get here, but if we do, say "no support" */
1003  return false;
1004 }

◆ EventTriggerTableRewrite()

void EventTriggerTableRewrite ( Node parsetree,
Oid  tableOid,
int  reason 
)

Definition at line 808 of file event_trigger.c.

References CommandCounterIncrement(), EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_TableRewrite, InvalidOid, IsUnderPostmaster, list_free(), NIL, PG_END_TRY, PG_FINALLY, PG_TRY, EventTriggerQueryState::table_rewrite_oid, and EventTriggerQueryState::table_rewrite_reason.

Referenced by ATRewriteTables().

809 {
810  List *runlist;
811  EventTriggerData trigdata;
812 
813  /*
814  * See EventTriggerDDLCommandStart for a discussion about why event
815  * triggers are disabled in single user mode.
816  */
817  if (!IsUnderPostmaster)
818  return;
819 
820  /*
821  * Also do nothing if our state isn't set up, which it won't be if there
822  * weren't any relevant event triggers at the start of the current DDL
823  * command. This test might therefore seem optional, but it's
824  * *necessary*, because EventTriggerCommonSetup might find triggers that
825  * didn't exist at the time the command started.
826  */
828  return;
829 
830  runlist = EventTriggerCommonSetup(parsetree,
832  "table_rewrite",
833  &trigdata);
834  if (runlist == NIL)
835  return;
836 
837  /*
838  * Make sure pg_event_trigger_table_rewrite_oid only works when running
839  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
840  * when one trigger fails. (This is perhaps not necessary, as the
841  * currentState variable will be removed shortly by our caller, but it
842  * seems better to play safe.)
843  */
846 
847  /* Run the triggers. */
848  PG_TRY();
849  {
850  EventTriggerInvoke(runlist, &trigdata);
851  }
852  PG_FINALLY();
853  {
856  }
857  PG_END_TRY();
858 
859  /* Cleanup. */
860  list_free(runlist);
861 
862  /*
863  * Make sure anything the event triggers did will be visible to the main
864  * command.
865  */
867 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:109
#define PG_FINALLY()
Definition: elog.h:312
void CommandCounterIncrement(void)
Definition: xact.c:1021
#define InvalidOid
Definition: postgres_ext.h:36
void list_free(List *list)
Definition: list.c:1376
#define PG_TRY()
Definition: elog.h:295
Definition: pg_list.h:50
#define PG_END_TRY()
Definition: elog.h:320

◆ EventTriggerUndoInhibitCommandCollection()

void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1488 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1489 {
1491  return;
1492 
1494 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73

◆ get_event_trigger_oid()

Oid get_event_trigger_oid ( const char *  trigname,
bool  missing_ok 
)

Definition at line 506 of file event_trigger.c.

References CStringGetDatum, ereport, errcode(), errmsg(), ERROR, EVENTTRIGGERNAME, GetSysCacheOid1, and OidIsValid.

Referenced by get_object_address_unqualified().

507 {
508  Oid oid;
509 
510  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
511  CStringGetDatum(trigname));
512  if (!OidIsValid(oid) && !missing_ok)
513  ereport(ERROR,
514  (errcode(ERRCODE_UNDEFINED_OBJECT),
515  errmsg("event trigger \"%s\" does not exist", trigname)));
516  return oid;
517 }
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:192
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1137 of file event_trigger.c.

References EventCacheLookup(), EVT_DDLCommandEnd, EVT_SQLDrop, EVT_TableRewrite, and list_length().

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

1138 {
1139  /*
1140  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1141  * exists
1142  */
1143  return list_length(EventCacheLookup(EVT_SQLDrop)) > 0 ||
1146 }
static int list_length(const List *l)
Definition: pg_list.h:169
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:65