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 AT_REWRITE_ACCESS_METHOD   0x08
 
#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_ACCESS_METHOD

#define AT_REWRITE_ACCESS_METHOD   0x08

Definition at line 35 of file event_trigger.h.

◆ AT_REWRITE_ALTER_PERSISTENCE

#define AT_REWRITE_ALTER_PERSISTENCE   0x01

Definition at line 32 of file event_trigger.h.

◆ AT_REWRITE_COLUMN_REWRITE

#define AT_REWRITE_COLUMN_REWRITE   0x04

Definition at line 34 of file event_trigger.h.

◆ AT_REWRITE_DEFAULT_VAL

#define AT_REWRITE_DEFAULT_VAL   0x02

Definition at line 33 of file event_trigger.h.

◆ CALLED_AS_EVENT_TRIGGER

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

Definition at line 41 of file event_trigger.h.

Typedef Documentation

◆ EventTriggerData

Function Documentation

◆ AlterEventTrigger()

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 361 of file event_trigger.c.

362 {
363  Relation tgrel;
364  HeapTuple tup;
365  Oid trigoid;
366  Form_pg_event_trigger evtForm;
367  char tgenabled = stmt->tgenabled;
368 
369  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
370 
372  CStringGetDatum(stmt->trigname));
373  if (!HeapTupleIsValid(tup))
374  ereport(ERROR,
375  (errcode(ERRCODE_UNDEFINED_OBJECT),
376  errmsg("event trigger \"%s\" does not exist",
377  stmt->trigname)));
378 
379  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
380  trigoid = evtForm->oid;
381 
382  if (!object_ownercheck(EventTriggerRelationId, trigoid, GetUserId()))
384  stmt->trigname);
385 
386  /* tuple is a copy, so we can modify it below */
387  evtForm->evtenabled = tgenabled;
388 
389  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
390 
391  InvokeObjectPostAlterHook(EventTriggerRelationId,
392  trigoid, 0);
393 
394  /* clean up */
395  heap_freetuple(tup);
397 
398  return trigoid;
399 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2679
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:3984
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:502
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:197
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1983
FormData_pg_event_trigger * Form_pg_event_trigger
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
unsigned int Oid
Definition: postgres_ext.h:31
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:179
@ EVENTTRIGGERNAME
Definition: syscache.h:59
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

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

Referenced by standard_ProcessUtility().

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 405 of file event_trigger.c.

406 {
407  Oid evtOid;
408  HeapTuple tup;
409  Form_pg_event_trigger evtForm;
410  Relation rel;
411  ObjectAddress address;
412 
413  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
414 
416 
417  if (!HeapTupleIsValid(tup))
418  ereport(ERROR,
419  (errcode(ERRCODE_UNDEFINED_OBJECT),
420  errmsg("event trigger \"%s\" does not exist", name)));
421 
422  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
423  evtOid = evtForm->oid;
424 
425  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
426 
427  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
428 
429  heap_freetuple(tup);
430 
432 
433  return address;
434 }
const char * name
Definition: encode.c:571
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40

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

Referenced by ExecAlterOwnerStmt().

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  trigOid,
Oid  newOwnerId 
)

Definition at line 440 of file event_trigger.c.

441 {
442  HeapTuple tup;
443  Relation rel;
444 
445  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
446 
448 
449  if (!HeapTupleIsValid(tup))
450  ereport(ERROR,
451  (errcode(ERRCODE_UNDEFINED_OBJECT),
452  errmsg("event trigger with OID %u does not exist", trigOid)));
453 
454  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
455 
456  heap_freetuple(tup);
457 
459 }
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
@ EVENTTRIGGEROID
Definition: syscache.h:60

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

Referenced by shdepReassignOwned().

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 108 of file event_trigger.c.

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 != EVENT_TRIGGEROID)
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 }
int errhint(const char *fmt,...)
Definition: elog.c:1316
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
static void validate_ddl_tags(const char *filtervar, List *taglist)
static void error_duplicate_filter_variable(const char *defname)
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *taglist)
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1637
char * NameListToString(List *names)
Definition: namespace.c:3145
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Definition: parse_func.c:2146
#define lfirst(lc)
Definition: pg_list.h:172
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
char * defname
Definition: parsenodes.h:810
Node * arg
Definition: parsenodes.h:811
Definition: pg_list.h:54
bool superuser(void)
Definition: superuser.c:46
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:817

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().

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1608 of file event_trigger.c.

1609 {
1610  CollectedCommand *parent;
1611 
1612  /* ignore if event trigger context not set, or collection disabled */
1613  if (!currentEventTriggerState ||
1615  return;
1616 
1618 
1619  /* If no subcommands, don't collect */
1621  {
1622  MemoryContext oldcxt;
1623 
1625 
1629 
1630  MemoryContextSwitchTo(oldcxt);
1631  }
1632  else
1634 
1636 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
List * lappend(List *list, void *datum)
Definition: list.c:338
void pfree(void *pointer)
Definition: mcxt.c:1436
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define NIL
Definition: pg_list.h:68
union CollectedCommand::@107 d
struct CollectedCommand::@107::@109 alterTable
struct CollectedCommand * parent
CollectedCommand * currentCommand
Definition: event_trigger.c:67

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, EventTriggerQueryState::currentCommand, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, lappend(), MemoryContextSwitchTo(), NIL, CollectedCommand::parent, and pfree().

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

◆ EventTriggerAlterTableRelid()

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1521 of file event_trigger.c.

1522 {
1523  MemoryContext oldcxt;
1524  CollectedCommand *command;
1525 
1526  /* ignore if event trigger context not set, or collection disabled */
1527  if (!currentEventTriggerState ||
1529  return;
1530 
1532 
1533  command = palloc(sizeof(CollectedCommand));
1534 
1535  command->type = SCT_AlterTable;
1536  command->in_extension = creating_extension;
1537 
1538  command->d.alterTable.classId = RelationRelationId;
1539  command->d.alterTable.objectId = InvalidOid;
1540  command->d.alterTable.subcmds = NIL;
1541  command->parsetree = copyObject(parsetree);
1542 
1545 
1546  MemoryContextSwitchTo(oldcxt);
1547 }
@ SCT_AlterTable
bool creating_extension
Definition: extension.c:73
void * palloc(Size size)
Definition: mcxt.c:1210
#define copyObject(obj)
Definition: nodes.h:244
#define InvalidOid
Definition: postgres_ext.h:36
CollectedCommandType type

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, copyObject, creating_extension, EventTriggerQueryState::currentCommand, currentEventTriggerState, 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().

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1079 of file event_trigger.c.

1080 {
1082  MemoryContext cxt;
1083 
1084  /*
1085  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1086  * reason to have event trigger state at all; so if there are none, don't
1087  * install one.
1088  */
1090  return false;
1091 
1093  "event trigger state",
1096  state->cxt = cxt;
1097  slist_init(&(state->SQLDropList));
1098  state->in_sql_drop = false;
1099  state->table_rewrite_oid = InvalidOid;
1100 
1101  state->commandCollectionInhibited = currentEventTriggerState ?
1103  state->currentCommand = NULL;
1104  state->commandList = NIL;
1105  state->previous = currentEventTriggerState;
1107 
1108  return true;
1109 }
bool trackDroppedObjectsNeeded(void)
static void slist_init(slist_head *head)
Definition: ilist.h:986
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1005
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
Definition: regguts.h:318

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, EventTriggerQueryState::commandCollectionInhibited, currentEventTriggerState, InvalidOid, MemoryContextAlloc(), NIL, slist_init(), TopMemoryContext, and trackDroppedObjectsNeeded().

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterDefPrivs()

void EventTriggerCollectAlterDefPrivs ( AlterDefaultPrivilegesStmt stmt)

Definition at line 1792 of file event_trigger.c.

1793 {
1794  MemoryContext oldcxt;
1795  CollectedCommand *command;
1796 
1797  /* ignore if event trigger context not set, or collection disabled */
1798  if (!currentEventTriggerState ||
1800  return;
1801 
1803 
1804  command = palloc0(sizeof(CollectedCommand));
1805  command->type = SCT_AlterDefaultPrivileges;
1806  command->d.defprivs.objtype = stmt->action->objtype;
1807  command->in_extension = creating_extension;
1808  command->parsetree = (Node *) copyObject(stmt);
1809 
1812  MemoryContextSwitchTo(oldcxt);
1813 }
@ SCT_AlterDefaultPrivileges
void * palloc0(Size size)
Definition: mcxt.c:1241
struct CollectedCommand::@107::@114 defprivs
ObjectType objtype
Definition: parsenodes.h:2206
Definition: nodes.h:129

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterOpFam()

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

Definition at line 1690 of file event_trigger.c.

1692 {
1693  MemoryContext oldcxt;
1694  CollectedCommand *command;
1695 
1696  /* ignore if event trigger context not set, or collection disabled */
1697  if (!currentEventTriggerState ||
1699  return;
1700 
1702 
1703  command = palloc(sizeof(CollectedCommand));
1704  command->type = SCT_AlterOpFamily;
1705  command->in_extension = creating_extension;
1706  ObjectAddressSet(command->d.opfam.address,
1707  OperatorFamilyRelationId, opfamoid);
1708  command->d.opfam.operators = operators;
1709  command->d.opfam.procedures = procedures;
1710  command->parsetree = (Node *) copyObject(stmt);
1711 
1714 
1715  MemoryContextSwitchTo(oldcxt);
1716 }
@ SCT_AlterOpFamily
struct CollectedCommand::@107::@111 opfam

References EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, 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().

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

Definition at line 1573 of file event_trigger.c.

1574 {
1575  MemoryContext oldcxt;
1577 
1578  /* ignore if event trigger context not set, or collection disabled */
1579  if (!currentEventTriggerState ||
1581  return;
1582 
1583  Assert(IsA(subcmd, AlterTableCmd));
1586 
1588 
1589  newsub = palloc(sizeof(CollectedATSubcmd));
1590  newsub->address = address;
1591  newsub->parsetree = copyObject(subcmd);
1592 
1595 
1596  MemoryContextSwitchTo(oldcxt);
1597 }
#define OidIsValid(objectId)
Definition: c.h:759
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
static color newsub(struct colormap *cm, color co)
Definition: regc_color.c:389

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

Referenced by ATExecCmd().

◆ EventTriggerCollectAlterTSConfig()

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

Definition at line 1757 of file event_trigger.c.

1759 {
1760  MemoryContext oldcxt;
1761  CollectedCommand *command;
1762 
1763  /* ignore if event trigger context not set, or collection disabled */
1764  if (!currentEventTriggerState ||
1766  return;
1767 
1769 
1770  command = palloc0(sizeof(CollectedCommand));
1771  command->type = SCT_AlterTSConfig;
1772  command->in_extension = creating_extension;
1773  ObjectAddressSet(command->d.atscfg.address,
1774  TSConfigRelationId, cfgId);
1775  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1776  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1777  command->d.atscfg.ndicts = ndicts;
1778  command->parsetree = (Node *) copyObject(stmt);
1779 
1782 
1783  MemoryContextSwitchTo(oldcxt);
1784 }
@ SCT_AlterTSConfig
struct CollectedCommand::@107::@113 atscfg

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

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

◆ EventTriggerCollectCreateOpClass()

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

Definition at line 1723 of file event_trigger.c.

1725 {
1726  MemoryContext oldcxt;
1727  CollectedCommand *command;
1728 
1729  /* ignore if event trigger context not set, or collection disabled */
1730  if (!currentEventTriggerState ||
1732  return;
1733 
1735 
1736  command = palloc0(sizeof(CollectedCommand));
1737  command->type = SCT_CreateOpClass;
1738  command->in_extension = creating_extension;
1739  ObjectAddressSet(command->d.createopc.address,
1740  OperatorClassRelationId, opcoid);
1741  command->d.createopc.operators = operators;
1742  command->d.createopc.procedures = procedures;
1743  command->parsetree = (Node *) copyObject(stmt);
1744 
1747 
1748  MemoryContextSwitchTo(oldcxt);
1749 }
@ SCT_CreateOpClass
struct CollectedCommand::@107::@112 createopc

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

Referenced by DefineOpClass().

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1646 of file event_trigger.c.

1647 {
1648  MemoryContext oldcxt;
1649  CollectedCommand *command;
1650  InternalGrant *icopy;
1651  ListCell *cell;
1652 
1653  /* ignore if event trigger context not set, or collection disabled */
1654  if (!currentEventTriggerState ||
1656  return;
1657 
1659 
1660  /*
1661  * This is tedious, but necessary.
1662  */
1663  icopy = palloc(sizeof(InternalGrant));
1664  memcpy(icopy, istmt, sizeof(InternalGrant));
1665  icopy->objects = list_copy(istmt->objects);
1666  icopy->grantees = list_copy(istmt->grantees);
1667  icopy->col_privs = NIL;
1668  foreach(cell, istmt->col_privs)
1669  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1670 
1671  /* Now collect it, using the copied InternalGrant */
1672  command = palloc(sizeof(CollectedCommand));
1673  command->type = SCT_Grant;
1674  command->in_extension = creating_extension;
1675  command->d.grant.istmt = icopy;
1676  command->parsetree = NULL;
1677 
1680 
1681  MemoryContextSwitchTo(oldcxt);
1682 }
@ SCT_Grant
List * list_copy(const List *oldlist)
Definition: list.c:1572
struct CollectedCommand::@107::@110 grant

References InternalGrant::col_privs, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, 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().

◆ EventTriggerCollectSimpleCommand()

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

Definition at line 1483 of file event_trigger.c.

1486 {
1487  MemoryContext oldcxt;
1488  CollectedCommand *command;
1489 
1490  /* ignore if event trigger context not set, or collection disabled */
1491  if (!currentEventTriggerState ||
1493  return;
1494 
1496 
1497  command = palloc(sizeof(CollectedCommand));
1498 
1499  command->type = SCT_Simple;
1500  command->in_extension = creating_extension;
1501 
1502  command->d.simple.address = address;
1503  command->d.simple.secondaryObject = secondaryObject;
1504  command->parsetree = copyObject(parsetree);
1505 
1507  command);
1508 
1509  MemoryContextSwitchTo(oldcxt);
1510 }
@ SCT_Simple
struct CollectedCommand::@107::@108 simple

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

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

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 688 of file event_trigger.c.

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

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 640 of file event_trigger.c.

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

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1123 of file event_trigger.c.

1124 {
1125  EventTriggerQueryState *prevstate;
1126 
1127  prevstate = currentEventTriggerState->previous;
1128 
1129  /* this avoids the need for retail pfree of SQLDropList items: */
1131 
1132  currentEventTriggerState = prevstate;
1133 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:387
struct EventTriggerQueryState * previous
Definition: event_trigger.c:70

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerInhibitCommandCollection()

void EventTriggerInhibitCommandCollection ( void  )

Definition at line 1449 of file event_trigger.c.

1450 {
1452  return;
1453 
1455 }

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 736 of file event_trigger.c.

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

References CommandCounterIncrement(), currentEventTriggerState, 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().

◆ EventTriggerSQLDropAddObject()

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

Definition at line 1173 of file event_trigger.c.

1174 {
1175  SQLDropObject *obj;
1176  MemoryContext oldcxt;
1177 
1179  return;
1180 
1182 
1183  /* don't report temp schemas except my own */
1184  if (object->classId == NamespaceRelationId &&
1185  (isAnyTempNamespace(object->objectId) &&
1186  !isTempNamespace(object->objectId)))
1187  return;
1188 
1190 
1191  obj = palloc0(sizeof(SQLDropObject));
1192  obj->address = *object;
1193  obj->original = original;
1194  obj->normal = normal;
1195 
1196  /*
1197  * Obtain schema names from the object's catalog tuple, if one exists;
1198  * this lets us skip objects in temp schemas. We trust that
1199  * ObjectProperty contains all object classes that can be
1200  * schema-qualified.
1201  */
1202  if (is_objectclass_supported(object->classId))
1203  {
1204  Relation catalog;
1205  HeapTuple tuple;
1206 
1207  catalog = table_open(obj->address.classId, AccessShareLock);
1208  tuple = get_catalog_object_by_oid(catalog,
1209  get_object_attnum_oid(object->classId),
1210  obj->address.objectId);
1211 
1212  if (tuple)
1213  {
1215  Datum datum;
1216  bool isnull;
1217 
1219  if (attnum != InvalidAttrNumber)
1220  {
1221  datum = heap_getattr(tuple, attnum,
1222  RelationGetDescr(catalog), &isnull);
1223  if (!isnull)
1224  {
1225  Oid namespaceId;
1226 
1227  namespaceId = DatumGetObjectId(datum);
1228  /* temp objects are only reported if they are my own */
1229  if (isTempNamespace(namespaceId))
1230  {
1231  obj->schemaname = "pg_temp";
1232  obj->istemp = true;
1233  }
1234  else if (isAnyTempNamespace(namespaceId))
1235  {
1236  pfree(obj);
1237  table_close(catalog, AccessShareLock);
1238  MemoryContextSwitchTo(oldcxt);
1239  return;
1240  }
1241  else
1242  {
1243  obj->schemaname = get_namespace_name(namespaceId);
1244  obj->istemp = false;
1245  }
1246  }
1247  }
1248 
1250  obj->address.objectSubId == 0)
1251  {
1253  if (attnum != InvalidAttrNumber)
1254  {
1255  datum = heap_getattr(tuple, attnum,
1256  RelationGetDescr(catalog), &isnull);
1257  if (!isnull)
1258  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1259  }
1260  }
1261  }
1262 
1263  table_close(catalog, AccessShareLock);
1264  }
1265  else
1266  {
1267  if (object->classId == NamespaceRelationId &&
1268  isTempNamespace(object->objectId))
1269  obj->istemp = true;
1270  }
1271 
1272  /* object identity, objname and objargs */
1273  obj->objidentity =
1274  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
1275  false);
1276 
1277  /* object type */
1278  obj->objecttype = getObjectTypeDescription(&obj->address, false);
1279 
1281 
1282  MemoryContextSwitchTo(oldcxt);
1283 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:730
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2836
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:1006
#define AccessShareLock
Definition: lockdefs.h:36
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3331
char * pstrdup(const char *in)
Definition: mcxt.c:1624
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3200
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3238
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)
AttrNumber get_object_attnum_name(Oid class_id)
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)
int16 attnum
Definition: pg_attribute.h:83
static Name DatumGetName(Datum X)
Definition: postgres.h:360
uintptr_t Datum
Definition: postgres.h:64
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
#define RelationGetDescr(relation)
Definition: rel.h:527
ObjectAddress address
Definition: event_trigger.c:78
const char * schemaname
Definition: event_trigger.c:79
slist_node next
Definition: event_trigger.c:88
const char * objidentity
Definition: event_trigger.c:81
const char * objecttype
Definition: event_trigger.c:82
List * addrnames
Definition: event_trigger.c:83
const char * objname
Definition: event_trigger.c:80

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert(), attnum, ObjectAddress::classId, currentEventTriggerState, 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().

◆ EventTriggerSupportsObjectClass()

bool EventTriggerSupportsObjectClass ( ObjectClass  objclass)

Definition at line 1011 of file event_trigger.c.

1012 {
1013  switch (objclass)
1014  {
1015  case OCLASS_DATABASE:
1016  case OCLASS_TBLSPACE:
1017  case OCLASS_ROLE:
1019  case OCLASS_PARAMETER_ACL:
1020  /* no support for global objects */
1021  return false;
1022  case OCLASS_EVENT_TRIGGER:
1023  /* no support for event triggers on event triggers */
1024  return false;
1025  case OCLASS_CLASS:
1026  case OCLASS_PROC:
1027  case OCLASS_TYPE:
1028  case OCLASS_CAST:
1029  case OCLASS_COLLATION:
1030  case OCLASS_CONSTRAINT:
1031  case OCLASS_CONVERSION:
1032  case OCLASS_DEFAULT:
1033  case OCLASS_LANGUAGE:
1034  case OCLASS_LARGEOBJECT:
1035  case OCLASS_OPERATOR:
1036  case OCLASS_OPCLASS:
1037  case OCLASS_OPFAMILY:
1038  case OCLASS_AM:
1039  case OCLASS_AMOP:
1040  case OCLASS_AMPROC:
1041  case OCLASS_REWRITE:
1042  case OCLASS_TRIGGER:
1043  case OCLASS_SCHEMA:
1044  case OCLASS_STATISTIC_EXT:
1045  case OCLASS_TSPARSER:
1046  case OCLASS_TSDICT:
1047  case OCLASS_TSTEMPLATE:
1048  case OCLASS_TSCONFIG:
1049  case OCLASS_FDW:
1050  case OCLASS_FOREIGN_SERVER:
1051  case OCLASS_USER_MAPPING:
1052  case OCLASS_DEFACL:
1053  case OCLASS_EXTENSION:
1054  case OCLASS_POLICY:
1055  case OCLASS_PUBLICATION:
1058  case OCLASS_SUBSCRIPTION:
1059  case OCLASS_TRANSFORM:
1060  return true;
1061 
1062  /*
1063  * There's intentionally no default: case here; we want the
1064  * compiler to warn if a new OCLASS hasn't been handled above.
1065  */
1066  }
1067 
1068  /* Shouldn't get here, but if we do, say "no support" */
1069  return false;
1070 }
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:124
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:118
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:121
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:117
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:129
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:127
@ OCLASS_EXTENSION
Definition: dependency.h:122
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:119
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:116
@ OCLASS_ROLE_MEMBERSHIP
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:123
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:130
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:125
@ OCLASS_USER_MAPPING
Definition: dependency.h:120
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:128
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:126
@ OCLASS_AMOP
Definition: dependency.h:104

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_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_ROLE_MEMBERSHIP, 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().

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 935 of file event_trigger.c.

936 {
937  switch (obtype)
938  {
939  case OBJECT_DATABASE:
940  case OBJECT_TABLESPACE:
941  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:
978  case OBJECT_ROUTINE:
979  case OBJECT_RULE:
980  case OBJECT_SCHEMA:
981  case OBJECT_SEQUENCE:
982  case OBJECT_SUBSCRIPTION:
985  case OBJECT_TABLE:
986  case OBJECT_TRANSFORM:
987  case OBJECT_TRIGGER:
989  case OBJECT_TSDICTIONARY:
990  case OBJECT_TSPARSER:
991  case OBJECT_TSTEMPLATE:
992  case OBJECT_TYPE:
993  case OBJECT_USER_MAPPING:
994  case OBJECT_VIEW:
995  return true;
996 
997  /*
998  * There's intentionally no default: case here; we want the
999  * compiler to warn if a new ObjectType hasn't been handled above.
1000  */
1001  }
1002 
1003  /* Shouldn't get here, but if we do, say "no support" */
1004  return false;
1005 }
@ OBJECT_FDW
Definition: parsenodes.h:1985
@ OBJECT_TSPARSER
Definition: parsenodes.h:2016
@ OBJECT_COLLATION
Definition: parsenodes.h:1976
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2019
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:1969
@ OBJECT_OPCLASS
Definition: parsenodes.h:1993
@ OBJECT_DEFACL
Definition: parsenodes.h:1980
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1970
@ OBJECT_MATVIEW
Definition: parsenodes.h:1992
@ OBJECT_SCHEMA
Definition: parsenodes.h:2005
@ OBJECT_POLICY
Definition: parsenodes.h:1997
@ OBJECT_OPERATOR
Definition: parsenodes.h:1994
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1987
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2014
@ OBJECT_OPFAMILY
Definition: parsenodes.h:1995
@ OBJECT_DOMAIN
Definition: parsenodes.h:1981
@ OBJECT_COLUMN
Definition: parsenodes.h:1975
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2011
@ OBJECT_ROLE
Definition: parsenodes.h:2002
@ OBJECT_ROUTINE
Definition: parsenodes.h:2003
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1991
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2000
@ OBJECT_PROCEDURE
Definition: parsenodes.h:1998
@ OBJECT_EXTENSION
Definition: parsenodes.h:1984
@ OBJECT_INDEX
Definition: parsenodes.h:1989
@ OBJECT_DEFAULT
Definition: parsenodes.h:1979
@ OBJECT_DATABASE
Definition: parsenodes.h:1978
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2006
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2017
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1990
@ OBJECT_AMOP
Definition: parsenodes.h:1971
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2001
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1986
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2015
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1973
@ OBJECT_PUBLICATION
Definition: parsenodes.h:1999
@ OBJECT_RULE
Definition: parsenodes.h:2004
@ OBJECT_CONVERSION
Definition: parsenodes.h:1977
@ OBJECT_AMPROC
Definition: parsenodes.h:1972
@ OBJECT_TABLE
Definition: parsenodes.h:2010
@ OBJECT_VIEW
Definition: parsenodes.h:2020
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:1996
@ OBJECT_TYPE
Definition: parsenodes.h:2018
@ OBJECT_FUNCTION
Definition: parsenodes.h:1988
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2009
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1982
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2007
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2008
@ OBJECT_CAST
Definition: parsenodes.h:1974
@ OBJECT_TRIGGER
Definition: parsenodes.h:2013
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2012

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_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, 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().

◆ EventTriggerTableRewrite()

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

Definition at line 807 of file event_trigger.c.

808 {
809  List *runlist;
810  EventTriggerData trigdata;
811 
812  /*
813  * See EventTriggerDDLCommandStart for a discussion about why event
814  * triggers are disabled in single user mode.
815  */
816  if (!IsUnderPostmaster)
817  return;
818 
819  /*
820  * Also do nothing if our state isn't set up, which it won't be if there
821  * weren't any relevant event triggers at the start of the current DDL
822  * command. This test might therefore seem optional, but it's
823  * *necessary*, because EventTriggerCommonSetup might find triggers that
824  * didn't exist at the time the command started.
825  */
827  return;
828 
829  runlist = EventTriggerCommonSetup(parsetree,
831  "table_rewrite",
832  &trigdata);
833  if (runlist == NIL)
834  return;
835 
836  /*
837  * Make sure pg_event_trigger_table_rewrite_oid only works when running
838  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
839  * when one trigger fails. (This is perhaps not necessary, as the
840  * currentState variable will be removed shortly by our caller, but it
841  * seems better to play safe.)
842  */
845 
846  /* Run the triggers. */
847  PG_TRY();
848  {
849  EventTriggerInvoke(runlist, &trigdata);
850  }
851  PG_FINALLY();
852  {
855  }
856  PG_END_TRY();
857 
858  /* Cleanup. */
859  list_free(runlist);
860 
861  /*
862  * Make sure anything the event triggers did will be visible to the main
863  * command.
864  */
866 }
@ EVT_TableRewrite
Definition: evtcache.h:25

References CommandCounterIncrement(), currentEventTriggerState, 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().

◆ EventTriggerUndoInhibitCommandCollection()

void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1461 of file event_trigger.c.

1462 {
1464  return;
1465 
1467 }

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ get_event_trigger_oid()

Oid get_event_trigger_oid ( const char *  trigname,
bool  missing_ok 
)

Definition at line 505 of file event_trigger.c.

506 {
507  Oid oid;
508 
509  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
510  CStringGetDatum(trigname));
511  if (!OidIsValid(oid) && !missing_ok)
512  ereport(ERROR,
513  (errcode(ERRCODE_UNDEFINED_OBJECT),
514  errmsg("event trigger \"%s\" does not exist", trigname)));
515  return oid;
516 }
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:197

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

Referenced by get_object_address_unqualified().

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1141 of file event_trigger.c.

1142 {
1143  /*
1144  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1145  * exists
1146  */
1147  return (EventCacheLookup(EVT_SQLDrop) != NIL) ||
1150 }
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64

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

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().