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)
 
void RemoveEventTriggerById (Oid trigOid)
 
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 31 of file event_trigger.h.

Referenced by ATPrepCmd().

◆ AT_REWRITE_COLUMN_REWRITE

#define AT_REWRITE_COLUMN_REWRITE   0x04

Definition at line 33 of file event_trigger.h.

Referenced by ATPrepAlterColumnType().

◆ AT_REWRITE_DEFAULT_VAL

#define AT_REWRITE_DEFAULT_VAL   0x02

Definition at line 32 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 503 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().

504 {
505  Relation tgrel;
506  HeapTuple tup;
507  Oid trigoid;
508  Form_pg_event_trigger evtForm;
509  char tgenabled = stmt->tgenabled;
510 
511  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
512 
514  CStringGetDatum(stmt->trigname));
515  if (!HeapTupleIsValid(tup))
516  ereport(ERROR,
517  (errcode(ERRCODE_UNDEFINED_OBJECT),
518  errmsg("event trigger \"%s\" does not exist",
519  stmt->trigname)));
520 
521  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
522  trigoid = evtForm->oid;
523 
524  if (!pg_event_trigger_ownercheck(trigoid, GetUserId()))
526  stmt->trigname);
527 
528  /* tuple is a copy, so we can modify it below */
529  evtForm->evtenabled = tgenabled;
530 
531  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
532 
533  InvokeObjectPostAlterHook(EventTriggerRelationId,
534  trigoid, 0);
535 
536  /* clean up */
537  heap_freetuple(tup);
539 
540  return trigoid;
541 }
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:380
int errcode(int sqlerrcode)
Definition: elog.c:608
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:3352
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5145
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:163
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:224
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
int errmsg(const char *fmt,...)
Definition: elog.c:822
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 547 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().

548 {
549  Oid evtOid;
550  HeapTuple tup;
551  Form_pg_event_trigger evtForm;
552  Relation rel;
553  ObjectAddress address;
554 
555  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
556 
558 
559  if (!HeapTupleIsValid(tup))
560  ereport(ERROR,
561  (errcode(ERRCODE_UNDEFINED_OBJECT),
562  errmsg("event trigger \"%s\" does not exist", name)));
563 
564  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
565  evtOid = evtForm->oid;
566 
567  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
568 
569  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
570 
571  heap_freetuple(tup);
572 
574 
575  return address;
576 }
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:608
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, rest)
Definition: elog.h:141
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
const char * name
Definition: encode.c:521
#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:822
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  ,
Oid  newOwnerId 
)

Definition at line 582 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().

583 {
584  HeapTuple tup;
585  Relation rel;
586 
587  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
588 
590 
591  if (!HeapTupleIsValid(tup))
592  ereport(ERROR,
593  (errcode(ERRCODE_UNDEFINED_OBJECT),
594  errmsg("event trigger with OID %u does not exist", trigOid)));
595 
596  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
597 
598  heap_freetuple(tup);
599 
601 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
int errcode(int sqlerrcode)
Definition: elog.c:608
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, rest)
Definition: elog.h:141
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
int errmsg(const char *fmt,...)
Definition: elog.c:822
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 169 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().

170 {
171  HeapTuple tuple;
172  Oid funcoid;
173  Oid funcrettype;
174  Oid evtowner = GetUserId();
175  ListCell *lc;
176  List *tags = NULL;
177 
178  /*
179  * It would be nice to allow database owners or even regular users to do
180  * this, but there are obvious privilege escalation risks which would have
181  * to somehow be plugged first.
182  */
183  if (!superuser())
184  ereport(ERROR,
185  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
186  errmsg("permission denied to create event trigger \"%s\"",
187  stmt->trigname),
188  errhint("Must be superuser to create an event trigger.")));
189 
190  /* Validate event name. */
191  if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
192  strcmp(stmt->eventname, "ddl_command_end") != 0 &&
193  strcmp(stmt->eventname, "sql_drop") != 0 &&
194  strcmp(stmt->eventname, "table_rewrite") != 0)
195  ereport(ERROR,
196  (errcode(ERRCODE_SYNTAX_ERROR),
197  errmsg("unrecognized event name \"%s\"",
198  stmt->eventname)));
199 
200  /* Validate filter conditions. */
201  foreach(lc, stmt->whenclause)
202  {
203  DefElem *def = (DefElem *) lfirst(lc);
204 
205  if (strcmp(def->defname, "tag") == 0)
206  {
207  if (tags != NULL)
209  tags = (List *) def->arg;
210  }
211  else
212  ereport(ERROR,
213  (errcode(ERRCODE_SYNTAX_ERROR),
214  errmsg("unrecognized filter variable \"%s\"", def->defname)));
215  }
216 
217  /* Validate tag list, if any. */
218  if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
219  strcmp(stmt->eventname, "ddl_command_end") == 0 ||
220  strcmp(stmt->eventname, "sql_drop") == 0)
221  && tags != NULL)
222  validate_ddl_tags("tag", tags);
223  else if (strcmp(stmt->eventname, "table_rewrite") == 0
224  && tags != NULL)
225  validate_table_rewrite_tags("tag", tags);
226 
227  /*
228  * Give user a nice error message if an event trigger of the same name
229  * already exists.
230  */
232  if (HeapTupleIsValid(tuple))
233  ereport(ERROR,
235  errmsg("event trigger \"%s\" already exists",
236  stmt->trigname)));
237 
238  /* Find and validate the trigger function. */
239  funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
240  funcrettype = get_func_rettype(funcoid);
241  if (funcrettype != EVTTRIGGEROID)
242  ereport(ERROR,
243  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
244  errmsg("function %s must return type %s",
245  NameListToString(stmt->funcname), "event_trigger")));
246 
247  /* Insert catalog entries. */
248  return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
249  evtowner, funcoid, tags);
250 }
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:380
int errcode(int sqlerrcode)
Definition: elog.c:608
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1457
#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:2101
static void error_duplicate_filter_variable(const char *defname)
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
Node * arg
Definition: parsenodes.h:731
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3094
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *tags)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define lfirst(lc)
Definition: pg_list.h:190
int errmsg(const char *fmt,...)
Definition: elog.c:822
char * defname
Definition: parsenodes.h:730
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:31
Definition: pg_list.h:50

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1789 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(), and ProcessUtilitySlow().

1790 {
1791  CollectedCommand *parent;
1792 
1793  /* ignore if event trigger context not set, or collection disabled */
1794  if (!currentEventTriggerState ||
1796  return;
1797 
1799 
1800  /* If no subcommands, don't collect */
1802  {
1806  }
1807  else
1809 
1811 }
union CollectedCommand::@111 d
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
List * lappend(List *list, void *datum)
Definition: list.c:322
static int list_length(const List *l)
Definition: pg_list.h:169
struct CollectedCommand::@111::@113 alterTable

◆ EventTriggerAlterTableRelid()

void EventTriggerAlterTableRelid ( Oid  objectId)

Definition at line 1736 of file event_trigger.c.

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

Referenced by AlterTableInternal(), and ProcessUtilitySlow().

1737 {
1738  if (!currentEventTriggerState ||
1740  return;
1741 
1742  currentEventTriggerState->currentCommand->d.alterTable.objectId = objectId;
1743 }
union CollectedCommand::@111 d
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct CollectedCommand::@111::@113 alterTable

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1702 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(), and ProcessUtilitySlow().

1703 {
1704  MemoryContext oldcxt;
1705  CollectedCommand *command;
1706 
1707  /* ignore if event trigger context not set, or collection disabled */
1708  if (!currentEventTriggerState ||
1710  return;
1711 
1713 
1714  command = palloc(sizeof(CollectedCommand));
1715 
1716  command->type = SCT_AlterTable;
1717  command->in_extension = creating_extension;
1718 
1719  command->d.alterTable.classId = RelationRelationId;
1720  command->d.alterTable.objectId = InvalidOid;
1721  command->d.alterTable.subcmds = NIL;
1722  command->parsetree = copyObject(parsetree);
1723 
1726 
1727  MemoryContextSwitchTo(oldcxt);
1728 }
#define NIL
Definition: pg_list.h:65
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct CollectedCommand * parent
#define InvalidOid
Definition: postgres_ext.h:36
bool creating_extension
Definition: extension.c:70
struct CollectedCommand::@111::@113 alterTable
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:641

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1230 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().

1231 {
1233  MemoryContext cxt;
1234 
1235  /*
1236  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1237  * reason to have event trigger state at all; so if there are none, don't
1238  * install one.
1239  */
1241  return false;
1242 
1244  "event trigger state",
1246  state = MemoryContextAlloc(cxt, sizeof(EventTriggerQueryState));
1247  state->cxt = cxt;
1248  slist_init(&(state->SQLDropList));
1249  state->in_sql_drop = false;
1250  state->table_rewrite_oid = InvalidOid;
1251 
1254  state->currentCommand = NULL;
1255  state->commandList = NIL;
1257  currentEventTriggerState = state;
1258 
1259  return true;
1260 }
#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 1967 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().

1968 {
1969  MemoryContext oldcxt;
1970  CollectedCommand *command;
1971 
1972  /* ignore if event trigger context not set, or collection disabled */
1973  if (!currentEventTriggerState ||
1975  return;
1976 
1978 
1979  command = palloc0(sizeof(CollectedCommand));
1980  command->type = SCT_AlterDefaultPrivileges;
1981  command->d.defprivs.objtype = stmt->action->objtype;
1982  command->in_extension = creating_extension;
1983  command->parsetree = (Node *) copyObject(stmt);
1984 
1987  MemoryContextSwitchTo(oldcxt);
1988 }
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:525
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct CollectedCommand::@111::@118 defprivs
List * lappend(List *list, void *datum)
Definition: list.c:322
void * palloc0(Size size)
Definition: mcxt.c:980
bool creating_extension
Definition: extension.c:70
ObjectType objtype
Definition: parsenodes.h:1906
#define copyObject(obj)
Definition: nodes.h:641

◆ EventTriggerCollectAlterOpFam()

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

Definition at line 1865 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().

1867 {
1868  MemoryContext oldcxt;
1869  CollectedCommand *command;
1870 
1871  /* ignore if event trigger context not set, or collection disabled */
1872  if (!currentEventTriggerState ||
1874  return;
1875 
1877 
1878  command = palloc(sizeof(CollectedCommand));
1879  command->type = SCT_AlterOpFamily;
1880  command->in_extension = creating_extension;
1881  ObjectAddressSet(command->d.opfam.address,
1882  OperatorFamilyRelationId, opfamoid);
1883  command->d.opfam.operators = operators;
1884  command->d.opfam.procedures = procedures;
1885  command->parsetree = (Node *) copyObject(stmt);
1886 
1889 
1890  MemoryContextSwitchTo(oldcxt);
1891 }
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:525
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
List * lappend(List *list, void *datum)
Definition: list.c:322
bool creating_extension
Definition: extension.c:70
struct CollectedCommand::@111::@115 opfam
#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:641

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

Definition at line 1754 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().

1755 {
1756  MemoryContext oldcxt;
1758 
1759  /* ignore if event trigger context not set, or collection disabled */
1760  if (!currentEventTriggerState ||
1762  return;
1763 
1764  Assert(IsA(subcmd, AlterTableCmd));
1767 
1769 
1770  newsub = palloc(sizeof(CollectedATSubcmd));
1771  newsub->address = address;
1772  newsub->parsetree = copyObject(subcmd);
1773 
1776 
1777  MemoryContextSwitchTo(oldcxt);
1778 }
union CollectedCommand::@111 d
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define OidIsValid(objectId)
Definition: c.h:639
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
List * lappend(List *list, void *datum)
Definition: list.c:322
#define Assert(condition)
Definition: c.h:733
struct CollectedCommand::@111::@113 alterTable
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:641
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 1932 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().

1934 {
1935  MemoryContext oldcxt;
1936  CollectedCommand *command;
1937 
1938  /* ignore if event trigger context not set, or collection disabled */
1939  if (!currentEventTriggerState ||
1941  return;
1942 
1944 
1945  command = palloc0(sizeof(CollectedCommand));
1946  command->type = SCT_AlterTSConfig;
1947  command->in_extension = creating_extension;
1948  ObjectAddressSet(command->d.atscfg.address,
1949  TSConfigRelationId, cfgId);
1950  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1951  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1952  command->d.atscfg.ndicts = ndicts;
1953  command->parsetree = (Node *) copyObject(stmt);
1954 
1957 
1958  MemoryContextSwitchTo(oldcxt);
1959 }
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:525
CollectedCommandType type
unsigned int Oid
Definition: postgres_ext.h:31
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct CollectedCommand::@111::@117 atscfg
List * lappend(List *list, void *datum)
Definition: list.c:322
void * palloc0(Size size)
Definition: mcxt.c:980
bool creating_extension
Definition: extension.c:70
#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:641

◆ EventTriggerCollectCreateOpClass()

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

Definition at line 1898 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().

1900 {
1901  MemoryContext oldcxt;
1902  CollectedCommand *command;
1903 
1904  /* ignore if event trigger context not set, or collection disabled */
1905  if (!currentEventTriggerState ||
1907  return;
1908 
1910 
1911  command = palloc0(sizeof(CollectedCommand));
1912  command->type = SCT_CreateOpClass;
1913  command->in_extension = creating_extension;
1914  ObjectAddressSet(command->d.createopc.address,
1915  OperatorClassRelationId, opcoid);
1916  command->d.createopc.operators = operators;
1917  command->d.createopc.procedures = procedures;
1918  command->parsetree = (Node *) copyObject(stmt);
1919 
1922 
1923  MemoryContextSwitchTo(oldcxt);
1924 }
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:525
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct CollectedCommand::@111::@116 createopc
List * lappend(List *list, void *datum)
Definition: list.c:322
void * palloc0(Size size)
Definition: mcxt.c:980
bool creating_extension
Definition: extension.c:70
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define copyObject(obj)
Definition: nodes.h:641

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1821 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().

1822 {
1823  MemoryContext oldcxt;
1824  CollectedCommand *command;
1825  InternalGrant *icopy;
1826  ListCell *cell;
1827 
1828  /* ignore if event trigger context not set, or collection disabled */
1829  if (!currentEventTriggerState ||
1831  return;
1832 
1834 
1835  /*
1836  * This is tedious, but necessary.
1837  */
1838  icopy = palloc(sizeof(InternalGrant));
1839  memcpy(icopy, istmt, sizeof(InternalGrant));
1840  icopy->objects = list_copy(istmt->objects);
1841  icopy->grantees = list_copy(istmt->grantees);
1842  icopy->col_privs = NIL;
1843  foreach(cell, istmt->col_privs)
1844  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1845 
1846  /* Now collect it, using the copied InternalGrant */
1847  command = palloc(sizeof(CollectedCommand));
1848  command->type = SCT_Grant;
1849  command->in_extension = creating_extension;
1850  command->d.grant.istmt = icopy;
1851  command->parsetree = NULL;
1852 
1855 
1856  MemoryContextSwitchTo(oldcxt);
1857 }
#define NIL
Definition: pg_list.h:65
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
List * list_copy(const List *oldlist)
Definition: list.c:1404
struct CollectedCommand::@111::@114 grant
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
List * lappend(List *list, void *datum)
Definition: list.c:322
bool creating_extension
Definition: extension.c:70
#define lfirst(lc)
Definition: pg_list.h:190
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:641

◆ EventTriggerCollectSimpleCommand()

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

Definition at line 1664 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().

1667 {
1668  MemoryContext oldcxt;
1669  CollectedCommand *command;
1670 
1671  /* ignore if event trigger context not set, or collection disabled */
1672  if (!currentEventTriggerState ||
1674  return;
1675 
1677 
1678  command = palloc(sizeof(CollectedCommand));
1679 
1680  command->type = SCT_Simple;
1681  command->in_extension = creating_extension;
1682 
1683  command->d.simple.address = address;
1684  command->d.simple.secondaryObject = secondaryObject;
1685  command->parsetree = copyObject(parsetree);
1686 
1688  command);
1689 
1690  MemoryContextSwitchTo(oldcxt);
1691 }
union CollectedCommand::@111 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct CollectedCommand::@111::@112 simple
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
List * lappend(List *list, void *datum)
Definition: list.c:322
bool creating_extension
Definition: extension.c:70
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:641

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 832 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

833 {
834  List *runlist;
835  EventTriggerData trigdata;
836 
837  /*
838  * See EventTriggerDDLCommandStart for a discussion about why event
839  * triggers are disabled in single user mode.
840  */
841  if (!IsUnderPostmaster)
842  return;
843 
844  /*
845  * Also do nothing if our state isn't set up, which it won't be if there
846  * weren't any relevant event triggers at the start of the current DDL
847  * command. This test might therefore seem optional, but it's important
848  * because EventTriggerCommonSetup might find triggers that didn't exist
849  * at the time the command started. Although this function itself
850  * wouldn't crash, the event trigger functions would presumably call
851  * pg_event_trigger_ddl_commands which would fail. Better to do nothing
852  * until the next command.
853  */
855  return;
856 
857  runlist = EventTriggerCommonSetup(parsetree,
858  EVT_DDLCommandEnd, "ddl_command_end",
859  &trigdata);
860  if (runlist == NIL)
861  return;
862 
863  /*
864  * Make sure anything the main command did will be visible to the event
865  * triggers.
866  */
868 
869  /* Run the triggers. */
870  EventTriggerInvoke(runlist, &trigdata);
871 
872  /* Cleanup. */
873  list_free(runlist);
874 }
#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:1005
void list_free(List *list)
Definition: list.c:1377
Definition: pg_list.h:50

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 784 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

785 {
786  List *runlist;
787  EventTriggerData trigdata;
788 
789  /*
790  * Event Triggers are completely disabled in standalone mode. There are
791  * (at least) two reasons for this:
792  *
793  * 1. A sufficiently broken event trigger might not only render the
794  * database unusable, but prevent disabling itself to fix the situation.
795  * In this scenario, restarting in standalone mode provides an escape
796  * hatch.
797  *
798  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
799  * therefore will malfunction if pg_event_trigger's indexes are damaged.
800  * To allow recovery from a damaged index, we need some operating mode
801  * wherein event triggers are disabled. (Or we could implement
802  * heapscan-and-sort logic for that case, but having disaster recovery
803  * scenarios depend on code that's otherwise untested isn't appetizing.)
804  */
805  if (!IsUnderPostmaster)
806  return;
807 
808  runlist = EventTriggerCommonSetup(parsetree,
810  "ddl_command_start",
811  &trigdata);
812  if (runlist == NIL)
813  return;
814 
815  /* Run the triggers. */
816  EventTriggerInvoke(runlist, &trigdata);
817 
818  /* Cleanup. */
819  list_free(runlist);
820 
821  /*
822  * Make sure anything the event triggers did will be visible to the main
823  * command.
824  */
826 }
#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:1005
void list_free(List *list)
Definition: list.c:1377
Definition: pg_list.h:50

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1274 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

1275 {
1276  EventTriggerQueryState *prevstate;
1277 
1278  prevstate = currentEventTriggerState->previous;
1279 
1280  /* this avoids the need for retail pfree of SQLDropList items: */
1282 
1283  currentEventTriggerState = prevstate;
1284 }
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 1630 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1631 {
1633  return;
1634 
1636 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 880 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().

881 {
882  List *runlist;
883  EventTriggerData trigdata;
884 
885  /*
886  * See EventTriggerDDLCommandStart for a discussion about why event
887  * triggers are disabled in single user mode.
888  */
889  if (!IsUnderPostmaster)
890  return;
891 
892  /*
893  * Use current state to determine whether this event fires at all. If
894  * there are no triggers for the sql_drop event, then we don't have
895  * anything to do here. Note that dropped object collection is disabled
896  * if this is the case, so even if we were to try to run, the list would
897  * be empty.
898  */
901  return;
902 
903  runlist = EventTriggerCommonSetup(parsetree,
904  EVT_SQLDrop, "sql_drop",
905  &trigdata);
906 
907  /*
908  * Nothing to do if run list is empty. Note this typically can't happen,
909  * because if there are no sql_drop events, then objects-to-drop wouldn't
910  * have been collected in the first place and we would have quit above.
911  * But it could occur if event triggers were dropped partway through.
912  */
913  if (runlist == NIL)
914  return;
915 
916  /*
917  * Make sure anything the main command did will be visible to the event
918  * triggers.
919  */
921 
922  /*
923  * Make sure pg_event_trigger_dropped_objects only works when running
924  * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
925  * one trigger fails. (This is perhaps not necessary, as the currentState
926  * variable will be removed shortly by our caller, but it seems better to
927  * play safe.)
928  */
930 
931  /* Run the triggers. */
932  PG_TRY();
933  {
934  EventTriggerInvoke(runlist, &trigdata);
935  }
936  PG_FINALLY();
937  {
939  }
940  PG_END_TRY();
941 
942  /* Cleanup. */
943  list_free(runlist);
944 }
#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:339
void CommandCounterIncrement(void)
Definition: xact.c:1005
void list_free(List *list)
Definition: list.c:1377
#define PG_TRY()
Definition: elog.h:322
Definition: pg_list.h:50
#define PG_END_TRY()
Definition: elog.h:347

◆ EventTriggerSQLDropAddObject()

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

Definition at line 1324 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().

1325 {
1326  SQLDropObject *obj;
1327  MemoryContext oldcxt;
1328 
1330  return;
1331 
1333 
1334  /* don't report temp schemas except my own */
1335  if (object->classId == NamespaceRelationId &&
1336  (isAnyTempNamespace(object->objectId) &&
1337  !isTempNamespace(object->objectId)))
1338  return;
1339 
1341 
1342  obj = palloc0(sizeof(SQLDropObject));
1343  obj->address = *object;
1344  obj->original = original;
1345  obj->normal = normal;
1346 
1347  /*
1348  * Obtain schema names from the object's catalog tuple, if one exists;
1349  * this lets us skip objects in temp schemas. We trust that
1350  * ObjectProperty contains all object classes that can be
1351  * schema-qualified.
1352  */
1353  if (is_objectclass_supported(object->classId))
1354  {
1355  Relation catalog;
1356  HeapTuple tuple;
1357 
1358  catalog = table_open(obj->address.classId, AccessShareLock);
1359  tuple = get_catalog_object_by_oid(catalog,
1360  get_object_attnum_oid(object->classId),
1361  obj->address.objectId);
1362 
1363  if (tuple)
1364  {
1366  Datum datum;
1367  bool isnull;
1368 
1370  if (attnum != InvalidAttrNumber)
1371  {
1372  datum = heap_getattr(tuple, attnum,
1373  RelationGetDescr(catalog), &isnull);
1374  if (!isnull)
1375  {
1376  Oid namespaceId;
1377 
1378  namespaceId = DatumGetObjectId(datum);
1379  /* temp objects are only reported if they are my own */
1380  if (isTempNamespace(namespaceId))
1381  {
1382  obj->schemaname = "pg_temp";
1383  obj->istemp = true;
1384  }
1385  else if (isAnyTempNamespace(namespaceId))
1386  {
1387  pfree(obj);
1388  table_close(catalog, AccessShareLock);
1389  MemoryContextSwitchTo(oldcxt);
1390  return;
1391  }
1392  else
1393  {
1394  obj->schemaname = get_namespace_name(namespaceId);
1395  obj->istemp = false;
1396  }
1397  }
1398  }
1399 
1401  obj->address.objectSubId == 0)
1402  {
1403  attnum = get_object_attnum_name(obj->address.classId);
1404  if (attnum != InvalidAttrNumber)
1405  {
1406  datum = heap_getattr(tuple, attnum,
1407  RelationGetDescr(catalog), &isnull);
1408  if (!isnull)
1409  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1410  }
1411  }
1412  }
1413 
1414  table_close(catalog, AccessShareLock);
1415  }
1416  else
1417  {
1418  if (object->classId == NamespaceRelationId &&
1419  isTempNamespace(object->objectId))
1420  obj->istemp = true;
1421  }
1422 
1423  /* object identity, objname and objargs */
1424  obj->objidentity =
1425  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs);
1426 
1427  /* object type */
1429 
1431 
1432  MemoryContextSwitchTo(oldcxt);
1433 }
bool get_object_namensp_unique(Oid class_id)
slist_node next
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
ObjectAddress address
char * getObjectTypeDescription(const ObjectAddress *object)
AttrNumber get_object_attnum_oid(Oid class_id)
#define RelationGetDescr(relation)
Definition: rel.h:449
const char * objname
#define DatumGetObjectId(X)
Definition: postgres.h:500
char * pstrdup(const char *in)
Definition: mcxt.c:1186
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs)
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
AttrNumber get_object_attnum_namespace(Oid class_id)
const char * objidentity
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2690
const char * objecttype
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:3094
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3149
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
const char * schemaname
#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:733
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:610
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3187
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 1165 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().

1166 {
1167  switch (objclass)
1168  {
1169  case OCLASS_DATABASE:
1170  case OCLASS_TBLSPACE:
1171  case OCLASS_ROLE:
1172  /* no support for global objects */
1173  return false;
1174  case OCLASS_EVENT_TRIGGER:
1175  /* no support for event triggers on event triggers */
1176  return false;
1177  case OCLASS_CLASS:
1178  case OCLASS_PROC:
1179  case OCLASS_TYPE:
1180  case OCLASS_CAST:
1181  case OCLASS_COLLATION:
1182  case OCLASS_CONSTRAINT:
1183  case OCLASS_CONVERSION:
1184  case OCLASS_DEFAULT:
1185  case OCLASS_LANGUAGE:
1186  case OCLASS_LARGEOBJECT:
1187  case OCLASS_OPERATOR:
1188  case OCLASS_OPCLASS:
1189  case OCLASS_OPFAMILY:
1190  case OCLASS_AM:
1191  case OCLASS_AMOP:
1192  case OCLASS_AMPROC:
1193  case OCLASS_REWRITE:
1194  case OCLASS_TRIGGER:
1195  case OCLASS_SCHEMA:
1196  case OCLASS_STATISTIC_EXT:
1197  case OCLASS_TSPARSER:
1198  case OCLASS_TSDICT:
1199  case OCLASS_TSTEMPLATE:
1200  case OCLASS_TSCONFIG:
1201  case OCLASS_FDW:
1202  case OCLASS_FOREIGN_SERVER:
1203  case OCLASS_USER_MAPPING:
1204  case OCLASS_DEFACL:
1205  case OCLASS_EXTENSION:
1206  case OCLASS_POLICY:
1207  case OCLASS_PUBLICATION:
1209  case OCLASS_SUBSCRIPTION:
1210  case OCLASS_TRANSFORM:
1211  return true;
1212 
1213  /*
1214  * There's intentionally no default: case here; we want the
1215  * compiler to warn if a new OCLASS hasn't been handled above.
1216  */
1217  }
1218 
1219  /* Shouldn't get here, but if we do, say "no support" */
1220  return false;
1221 }

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 1091 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().

1092 {
1093  switch (obtype)
1094  {
1095  case OBJECT_DATABASE:
1096  case OBJECT_TABLESPACE:
1097  case OBJECT_ROLE:
1098  /* no support for global objects */
1099  return false;
1100  case OBJECT_EVENT_TRIGGER:
1101  /* no support for event triggers on event triggers */
1102  return false;
1103  case OBJECT_ACCESS_METHOD:
1104  case OBJECT_AGGREGATE:
1105  case OBJECT_AMOP:
1106  case OBJECT_AMPROC:
1107  case OBJECT_ATTRIBUTE:
1108  case OBJECT_CAST:
1109  case OBJECT_COLUMN:
1110  case OBJECT_COLLATION:
1111  case OBJECT_CONVERSION:
1112  case OBJECT_DEFACL:
1113  case OBJECT_DEFAULT:
1114  case OBJECT_DOMAIN:
1115  case OBJECT_DOMCONSTRAINT:
1116  case OBJECT_EXTENSION:
1117  case OBJECT_FDW:
1118  case OBJECT_FOREIGN_SERVER:
1119  case OBJECT_FOREIGN_TABLE:
1120  case OBJECT_FUNCTION:
1121  case OBJECT_INDEX:
1122  case OBJECT_LANGUAGE:
1123  case OBJECT_LARGEOBJECT:
1124  case OBJECT_MATVIEW:
1125  case OBJECT_OPCLASS:
1126  case OBJECT_OPERATOR:
1127  case OBJECT_OPFAMILY:
1128  case OBJECT_POLICY:
1129  case OBJECT_PROCEDURE:
1130  case OBJECT_PUBLICATION:
1132  case OBJECT_ROUTINE:
1133  case OBJECT_RULE:
1134  case OBJECT_SCHEMA:
1135  case OBJECT_SEQUENCE:
1136  case OBJECT_SUBSCRIPTION:
1137  case OBJECT_STATISTIC_EXT:
1138  case OBJECT_TABCONSTRAINT:
1139  case OBJECT_TABLE:
1140  case OBJECT_TRANSFORM:
1141  case OBJECT_TRIGGER:
1143  case OBJECT_TSDICTIONARY:
1144  case OBJECT_TSPARSER:
1145  case OBJECT_TSTEMPLATE:
1146  case OBJECT_TYPE:
1147  case OBJECT_USER_MAPPING:
1148  case OBJECT_VIEW:
1149  return true;
1150 
1151  /*
1152  * There's intentionally no default: case here; we want the
1153  * compiler to warn if a new ObjectType hasn't been handled above.
1154  */
1155  }
1156 
1157  /* Shouldn't get here, but if we do, say "no support" */
1158  return false;
1159 }

◆ EventTriggerTableRewrite()

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

Definition at line 951 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().

952 {
953  List *runlist;
954  EventTriggerData trigdata;
955 
956  /*
957  * Event Triggers are completely disabled in standalone mode. There are
958  * (at least) two reasons for this:
959  *
960  * 1. A sufficiently broken event trigger might not only render the
961  * database unusable, but prevent disabling itself to fix the situation.
962  * In this scenario, restarting in standalone mode provides an escape
963  * hatch.
964  *
965  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
966  * therefore will malfunction if pg_event_trigger's indexes are damaged.
967  * To allow recovery from a damaged index, we need some operating mode
968  * wherein event triggers are disabled. (Or we could implement
969  * heapscan-and-sort logic for that case, but having disaster recovery
970  * scenarios depend on code that's otherwise untested isn't appetizing.)
971  */
972  if (!IsUnderPostmaster)
973  return;
974 
975  /*
976  * Also do nothing if our state isn't set up, which it won't be if there
977  * weren't any relevant event triggers at the start of the current DDL
978  * command. This test might therefore seem optional, but it's
979  * *necessary*, because EventTriggerCommonSetup might find triggers that
980  * didn't exist at the time the command started.
981  */
983  return;
984 
985  runlist = EventTriggerCommonSetup(parsetree,
987  "table_rewrite",
988  &trigdata);
989  if (runlist == NIL)
990  return;
991 
992  /*
993  * Make sure pg_event_trigger_table_rewrite_oid only works when running
994  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
995  * when one trigger fails. (This is perhaps not necessary, as the
996  * currentState variable will be removed shortly by our caller, but it
997  * seems better to play safe.)
998  */
1001 
1002  /* Run the triggers. */
1003  PG_TRY();
1004  {
1005  EventTriggerInvoke(runlist, &trigdata);
1006  }
1007  PG_FINALLY();
1008  {
1011  }
1012  PG_END_TRY();
1013 
1014  /* Cleanup. */
1015  list_free(runlist);
1016 
1017  /*
1018  * Make sure anything the event triggers did will be visible to the main
1019  * command.
1020  */
1022 }
#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:339
void CommandCounterIncrement(void)
Definition: xact.c:1005
#define InvalidOid
Definition: postgres_ext.h:36
void list_free(List *list)
Definition: list.c:1377
#define PG_TRY()
Definition: elog.h:322
Definition: pg_list.h:50
#define PG_END_TRY()
Definition: elog.h:347

◆ EventTriggerUndoInhibitCommandCollection()

void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1642 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1643 {
1645  return;
1646 
1648 }
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 647 of file event_trigger.c.

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

Referenced by get_object_address_unqualified().

648 {
649  Oid oid;
650 
651  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
652  CStringGetDatum(trigname));
653  if (!OidIsValid(oid) && !missing_ok)
654  ereport(ERROR,
655  (errcode(ERRCODE_UNDEFINED_OBJECT),
656  errmsg("event trigger \"%s\" does not exist", trigname)));
657  return oid;
658 }
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:192
int errcode(int sqlerrcode)
Definition: elog.c:608
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:639
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ RemoveEventTriggerById()

void RemoveEventTriggerById ( Oid  trigOid)

Definition at line 481 of file event_trigger.c.

References CatalogTupleDelete(), elog, ERROR, EVENTTRIGGEROID, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

482 {
483  Relation tgrel;
484  HeapTuple tup;
485 
486  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
487 
489  if (!HeapTupleIsValid(tup))
490  elog(ERROR, "cache lookup failed for event trigger %u", trigOid);
491 
492  CatalogTupleDelete(tgrel, &tup->t_self);
493 
494  ReleaseSysCache(tup);
495 
497 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:269
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:228
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1292 of file event_trigger.c.

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

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

1293 {
1294  /*
1295  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1296  * exists
1297  */
1298  return list_length(EventCacheLookup(EVT_SQLDrop)) > 0 ||
1301 }
static int list_length(const List *l)
Definition: pg_list.h:169
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64