PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_ALTER_OID   0x08
 
#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 ctrigOid)
 
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)
 
bool EventTriggerSupportsGrantObjectType (GrantObjectType objtype)
 
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

#define AT_REWRITE_ALTER_OID   0x08

Definition at line 34 of file event_trigger.h.

Referenced by ATExecAddColumn(), and ATExecDropColumn().

#define AT_REWRITE_ALTER_PERSISTENCE   0x01

Definition at line 31 of file event_trigger.h.

Referenced by ATPrepCmd().

#define AT_REWRITE_COLUMN_REWRITE   0x04

Definition at line 33 of file event_trigger.h.

Referenced by ATPrepAlterColumnType().

#define AT_REWRITE_DEFAULT_VAL   0x02

Definition at line 32 of file event_trigger.h.

Referenced by ATExecAddColumn().

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

Typedef Documentation

Function Documentation

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 499 of file event_trigger.c.

References ACL_KIND_EVENT_TRIGGER, aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, EVENTTRIGGERNAME, EventTriggerRelationId, GETSTRUCT, GetUserId(), heap_close, heap_freetuple(), heap_open(), HeapTupleGetOid, HeapTupleIsValid, InvokeObjectPostAlterHook, pg_event_trigger_ownercheck(), RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, AlterEventTrigStmt::tgenabled, and AlterEventTrigStmt::trigname.

Referenced by standard_ProcessUtility().

500 {
501  Relation tgrel;
502  HeapTuple tup;
503  Oid trigoid;
504  Form_pg_event_trigger evtForm;
505  char tgenabled = stmt->tgenabled;
506 
508 
510  CStringGetDatum(stmt->trigname));
511  if (!HeapTupleIsValid(tup))
512  ereport(ERROR,
513  (errcode(ERRCODE_UNDEFINED_OBJECT),
514  errmsg("event trigger \"%s\" does not exist",
515  stmt->trigname)));
516 
517  trigoid = HeapTupleGetOid(tup);
518 
519  if (!pg_event_trigger_ownercheck(trigoid, GetUserId()))
521  stmt->trigname);
522 
523  /* tuple is a copy, so we can modify it below */
524  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
525  evtForm->evtenabled = tgenabled;
526 
527  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
528 
530  trigoid, 0);
531 
532  /* clean up */
533  heap_freetuple(tup);
535 
536  return trigoid;
537 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:4937
ItemPointerData t_self
Definition: htup.h:65
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:163
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define EventTriggerRelationId
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:173
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 543 of file event_trigger.c.

References AlterEventTriggerOwner_internal(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, EVENTTRIGGERNAME, EventTriggerRelationId, heap_close, heap_freetuple(), heap_open(), HeapTupleGetOid, HeapTupleIsValid, ObjectAddressSet, RowExclusiveLock, and SearchSysCacheCopy1.

Referenced by ExecAlterOwnerStmt().

544 {
545  Oid evtOid;
546  HeapTuple tup;
547  Relation rel;
548  ObjectAddress address;
549 
551 
553 
554  if (!HeapTupleIsValid(tup))
555  ereport(ERROR,
556  (errcode(ERRCODE_UNDEFINED_OBJECT),
557  errmsg("event trigger \"%s\" does not exist", name)));
558 
559  evtOid = HeapTupleGetOid(tup);
560 
561  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
562 
563  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
564 
565  heap_freetuple(tup);
566 
568 
569  return address;
570 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
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:584
#define ereport(elevel, rest)
Definition: elog.h:122
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define EventTriggerRelationId
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:173
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
void AlterEventTriggerOwner_oid ( Oid  ,
Oid  newOwnerId 
)

Definition at line 576 of file event_trigger.c.

References AlterEventTriggerOwner_internal(), ereport, errcode(), errmsg(), ERROR, EVENTTRIGGEROID, EventTriggerRelationId, heap_close, heap_freetuple(), heap_open(), HeapTupleIsValid, ObjectIdGetDatum, RowExclusiveLock, and SearchSysCacheCopy1.

Referenced by shdepReassignOwned().

577 {
578  HeapTuple tup;
579  Relation rel;
580 
582 
584 
585  if (!HeapTupleIsValid(tup))
586  ereport(ERROR,
587  (errcode(ERRCODE_UNDEFINED_OBJECT),
588  errmsg("event trigger with OID %u does not exist", trigOid)));
589 
590  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
591 
592  heap_freetuple(tup);
593 
595 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:122
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define EventTriggerRelationId
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:173
int errmsg(const char *fmt,...)
Definition: elog.c:797
Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 167 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, EVTTRIGGEROID, 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().

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

Definition at line 1798 of file event_trigger.c.

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

Referenced by AlterTableMoveAll(), and ProcessUtilitySlow().

1799 {
1800  /* ignore if event trigger context not set, or collection disabled */
1801  if (!currentEventTriggerState ||
1803  return;
1804 
1805  /* If no subcommands, don't collect */
1807  {
1811  }
1812  else
1814 
1816 }
union CollectedCommand::@102 d
struct CollectedCommand::@102::@104 alterTable
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
void pfree(void *pointer)
Definition: mcxt.c:949
CollectedCommand * currentCommand
Definition: event_trigger.c:66
List * lappend(List *list, void *datum)
Definition: list.c:128
static int list_length(const List *l)
Definition: pg_list.h:89
void EventTriggerAlterTableRelid ( Oid  objectId)

Definition at line 1746 of file event_trigger.c.

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

Referenced by AlterTableInternal(), and ProcessUtilitySlow().

1747 {
1748  if (!currentEventTriggerState ||
1750  return;
1751 
1752  currentEventTriggerState->currentCommand->d.alterTable.objectId = objectId;
1753 }
union CollectedCommand::@102 d
struct CollectedCommand::@102::@104 alterTable
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
CollectedCommand * currentCommand
Definition: event_trigger.c:66
void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1713 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::parsetree, RelationRelationId, SCT_AlterTable, and CollectedCommand::type.

Referenced by AlterTableMoveAll(), and ProcessUtilitySlow().

1714 {
1715  MemoryContext oldcxt;
1716  CollectedCommand *command;
1717 
1718  /* ignore if event trigger context not set, or collection disabled */
1719  if (!currentEventTriggerState ||
1721  return;
1722 
1724 
1725  command = palloc(sizeof(CollectedCommand));
1726 
1727  command->type = SCT_AlterTable;
1728  command->in_extension = creating_extension;
1729 
1730  command->d.alterTable.classId = RelationRelationId;
1731  command->d.alterTable.objectId = InvalidOid;
1732  command->d.alterTable.subcmds = NIL;
1733  command->parsetree = copyObject(parsetree);
1734 
1736 
1737  MemoryContextSwitchTo(oldcxt);
1738 }
union CollectedCommand::@102 d
#define NIL
Definition: pg_list.h:69
struct CollectedCommand::@102::@104 alterTable
#define RelationRelationId
Definition: pg_class.h:29
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
CollectedCommand * currentCommand
Definition: event_trigger.c:66
#define InvalidOid
Definition: postgres_ext.h:36
bool creating_extension
Definition: extension.c:67
void * palloc(Size size)
Definition: mcxt.c:848
#define copyObject(obj)
Definition: nodes.h:623
bool EventTriggerBeginCompleteQuery ( void  )

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

1239 {
1241  MemoryContext cxt;
1242 
1243  /*
1244  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1245  * reason to have event trigger state at all; so if there are none, don't
1246  * install one.
1247  */
1249  return false;
1250 
1252  "event trigger state",
1254  state = MemoryContextAlloc(cxt, sizeof(EventTriggerQueryState));
1255  state->cxt = cxt;
1256  slist_init(&(state->SQLDropList));
1257  state->in_sql_drop = false;
1258  state->table_rewrite_oid = InvalidOid;
1259 
1262  state->currentCommand = NULL;
1263  state->commandList = NIL;
1265  currentEventTriggerState = state;
1266 
1267  return true;
1268 }
#define NIL
Definition: pg_list.h:69
bool trackDroppedObjectsNeeded(void)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
static void slist_init(slist_head *head)
Definition: ilist.h:554
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
CollectedCommand * currentCommand
Definition: event_trigger.c:66
struct EventTriggerQueryState * previous
Definition: event_trigger.c:69
MemoryContext TopMemoryContext
Definition: mcxt.c:43
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
#define InvalidOid
Definition: postgres_ext.h:36
Definition: regguts.h:298
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:706
void EventTriggerCollectAlterDefPrivs ( AlterDefaultPrivilegesStmt stmt)

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

1973 {
1974  MemoryContext oldcxt;
1975  CollectedCommand *command;
1976 
1977  /* ignore if event trigger context not set, or collection disabled */
1978  if (!currentEventTriggerState ||
1980  return;
1981 
1983 
1984  command = palloc0(sizeof(CollectedCommand));
1985  command->type = SCT_AlterDefaultPrivileges;
1986  command->d.defprivs.objtype = stmt->action->objtype;
1987  command->in_extension = creating_extension;
1988  command->parsetree = (Node *) copyObject(stmt);
1989 
1992  MemoryContextSwitchTo(oldcxt);
1993 }
union CollectedCommand::@102 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:510
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
List * lappend(List *list, void *datum)
Definition: list.c:128
void * palloc0(Size size)
Definition: mcxt.c:877
bool creating_extension
Definition: extension.c:67
GrantObjectType objtype
Definition: parsenodes.h:1861
struct CollectedCommand::@102::@109 defprivs
#define copyObject(obj)
Definition: nodes.h:623
void EventTriggerCollectAlterOpFam ( AlterOpFamilyStmt stmt,
Oid  opfamoid,
List operators,
List procedures 
)

Definition at line 1870 of file event_trigger.c.

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

Referenced by AlterOpFamilyAdd(), and AlterOpFamilyDrop().

1872 {
1873  MemoryContext oldcxt;
1874  CollectedCommand *command;
1875 
1876  /* ignore if event trigger context not set, or collection disabled */
1877  if (!currentEventTriggerState ||
1879  return;
1880 
1882 
1883  command = palloc(sizeof(CollectedCommand));
1884  command->type = SCT_AlterOpFamily;
1885  command->in_extension = creating_extension;
1886  ObjectAddressSet(command->d.opfam.address,
1887  OperatorFamilyRelationId, opfamoid);
1888  command->d.opfam.operators = operators;
1889  command->d.opfam.procedures = procedures;
1890  command->parsetree = (Node *) copyObject(stmt);
1891 
1894 
1895  MemoryContextSwitchTo(oldcxt);
1896 }
union CollectedCommand::@102 d
struct CollectedCommand::@102::@106 opfam
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:510
#define OperatorFamilyRelationId
Definition: pg_opfamily.h:29
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
List * lappend(List *list, void *datum)
Definition: list.c:128
bool creating_extension
Definition: extension.c:67
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void * palloc(Size size)
Definition: mcxt.c:848
#define copyObject(obj)
Definition: nodes.h:623
void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

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

1765 {
1766  MemoryContext oldcxt;
1768 
1769  /* ignore if event trigger context not set, or collection disabled */
1770  if (!currentEventTriggerState ||
1772  return;
1773 
1774  Assert(IsA(subcmd, AlterTableCmd));
1776 
1778 
1779  newsub = palloc(sizeof(CollectedATSubcmd));
1780  newsub->address = address;
1781  newsub->parsetree = copyObject(subcmd);
1782 
1785 
1786  MemoryContextSwitchTo(oldcxt);
1787 }
union CollectedCommand::@102 d
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
struct CollectedCommand::@102::@104 alterTable
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define OidIsValid(objectId)
Definition: c.h:532
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
CollectedCommand * currentCommand
Definition: event_trigger.c:66
List * lappend(List *list, void *datum)
Definition: list.c:128
#define Assert(condition)
Definition: c.h:681
void * palloc(Size size)
Definition: mcxt.c:848
#define copyObject(obj)
Definition: nodes.h:623
static color newsub(struct colormap *cm, color co)
Definition: regc_color.c:389
ObjectAddress address
void EventTriggerCollectAlterTSConfig ( AlterTSConfigurationStmt stmt,
Oid  cfgId,
Oid dictIds,
int  ndicts 
)

Definition at line 1937 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, TSConfigRelationId, and CollectedCommand::type.

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

1939 {
1940  MemoryContext oldcxt;
1941  CollectedCommand *command;
1942 
1943  /* ignore if event trigger context not set, or collection disabled */
1944  if (!currentEventTriggerState ||
1946  return;
1947 
1949 
1950  command = palloc0(sizeof(CollectedCommand));
1951  command->type = SCT_AlterTSConfig;
1952  command->in_extension = creating_extension;
1953  ObjectAddressSet(command->d.atscfg.address,
1954  TSConfigRelationId, cfgId);
1955  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1956  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1957  command->d.atscfg.ndicts = ndicts;
1958  command->parsetree = (Node *) copyObject(stmt);
1959 
1962 
1963  MemoryContextSwitchTo(oldcxt);
1964 }
union CollectedCommand::@102 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:510
CollectedCommandType type
unsigned int Oid
Definition: postgres_ext.h:31
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
#define TSConfigRelationId
Definition: pg_ts_config.h:31
List * lappend(List *list, void *datum)
Definition: list.c:128
void * palloc0(Size size)
Definition: mcxt.c:877
struct CollectedCommand::@102::@108 atscfg
bool creating_extension
Definition: extension.c:67
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void * palloc(Size size)
Definition: mcxt.c:848
#define copyObject(obj)
Definition: nodes.h:623
void EventTriggerCollectCreateOpClass ( CreateOpClassStmt stmt,
Oid  opcoid,
List operators,
List procedures 
)

Definition at line 1903 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, OperatorClassRelationId, palloc0(), CollectedCommand::parsetree, SCT_CreateOpClass, and CollectedCommand::type.

Referenced by DefineOpClass().

1905 {
1906  MemoryContext oldcxt;
1907  CollectedCommand *command;
1908 
1909  /* ignore if event trigger context not set, or collection disabled */
1910  if (!currentEventTriggerState ||
1912  return;
1913 
1915 
1916  command = palloc0(sizeof(CollectedCommand));
1917  command->type = SCT_CreateOpClass;
1918  command->in_extension = creating_extension;
1919  ObjectAddressSet(command->d.createopc.address,
1920  OperatorClassRelationId, opcoid);
1921  command->d.createopc.operators = operators;
1922  command->d.createopc.procedures = procedures;
1923  command->parsetree = (Node *) copyObject(stmt);
1924 
1927 
1928  MemoryContextSwitchTo(oldcxt);
1929 }
union CollectedCommand::@102 d
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define OperatorClassRelationId
Definition: pg_opclass.h:49
Definition: nodes.h:510
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
List * lappend(List *list, void *datum)
Definition: list.c:128
void * palloc0(Size size)
Definition: mcxt.c:877
bool creating_extension
Definition: extension.c:67
struct CollectedCommand::@102::@107 createopc
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define copyObject(obj)
Definition: nodes.h:623
void EventTriggerCollectGrant ( InternalGrant istmt)

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

1827 {
1828  MemoryContext oldcxt;
1829  CollectedCommand *command;
1830  InternalGrant *icopy;
1831  ListCell *cell;
1832 
1833  /* ignore if event trigger context not set, or collection disabled */
1834  if (!currentEventTriggerState ||
1836  return;
1837 
1839 
1840  /*
1841  * This is tedious, but necessary.
1842  */
1843  icopy = palloc(sizeof(InternalGrant));
1844  memcpy(icopy, istmt, sizeof(InternalGrant));
1845  icopy->objects = list_copy(istmt->objects);
1846  icopy->grantees = list_copy(istmt->grantees);
1847  icopy->col_privs = NIL;
1848  foreach(cell, istmt->col_privs)
1849  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1850 
1851  /* Now collect it, using the copied InternalGrant */
1852  command = palloc(sizeof(CollectedCommand));
1853  command->type = SCT_Grant;
1854  command->in_extension = creating_extension;
1855  command->d.grant.istmt = icopy;
1856  command->parsetree = NULL;
1857 
1860 
1861  MemoryContextSwitchTo(oldcxt);
1862 }
union CollectedCommand::@102 d
#define NIL
Definition: pg_list.h:69
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
List * list_copy(const List *oldlist)
Definition: list.c:1160
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
struct CollectedCommand::@102::@105 grant
List * lappend(List *list, void *datum)
Definition: list.c:128
bool creating_extension
Definition: extension.c:67
#define lfirst(lc)
Definition: pg_list.h:106
void * palloc(Size size)
Definition: mcxt.c:848
#define copyObject(obj)
Definition: nodes.h:623
void EventTriggerCollectSimpleCommand ( ObjectAddress  address,
ObjectAddress  secondaryObject,
Node parsetree 
)

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

1673 {
1674  MemoryContext oldcxt;
1675  CollectedCommand *command;
1676 
1677  /* ignore if event trigger context not set, or collection disabled */
1678  if (!currentEventTriggerState ||
1680  return;
1681 
1683 
1684  command = palloc(sizeof(CollectedCommand));
1685 
1686  command->type = SCT_Simple;
1687  command->in_extension = creating_extension;
1688 
1689  command->d.simple.address = address;
1690  command->d.simple.secondaryObject = secondaryObject;
1691  command->parsetree = copyObject(parsetree);
1692 
1694  command);
1695 
1696  MemoryContextSwitchTo(oldcxt);
1697 }
union CollectedCommand::@102 d
struct CollectedCommand::@102::@103 simple
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
List * lappend(List *list, void *datum)
Definition: list.c:128
bool creating_extension
Definition: extension.c:67
void * palloc(Size size)
Definition: mcxt.c:848
#define copyObject(obj)
Definition: nodes.h:623
void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 825 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

826 {
827  List *runlist;
828  EventTriggerData trigdata;
829 
830  /*
831  * See EventTriggerDDLCommandStart for a discussion about why event
832  * triggers are disabled in single user mode.
833  */
834  if (!IsUnderPostmaster)
835  return;
836 
837  runlist = EventTriggerCommonSetup(parsetree,
838  EVT_DDLCommandEnd, "ddl_command_end",
839  &trigdata);
840  if (runlist == NIL)
841  return;
842 
843  /*
844  * Make sure anything the main command did will be visible to the event
845  * triggers.
846  */
848 
849  /* Run the triggers. */
850  EventTriggerInvoke(runlist, &trigdata);
851 
852  /* Cleanup. */
853  list_free(runlist);
854 }
#define NIL
Definition: pg_list.h:69
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:101
void CommandCounterIncrement(void)
Definition: xact.c:915
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 777 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

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

Definition at line 1282 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

1283 {
1284  EventTriggerQueryState *prevstate;
1285 
1286  prevstate = currentEventTriggerState->previous;
1287 
1288  /* this avoids the need for retail pfree of SQLDropList items: */
1290 
1291  currentEventTriggerState = prevstate;
1292 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
struct EventTriggerQueryState * previous
Definition: event_trigger.c:69
void EventTriggerInhibitCommandCollection ( void  )

Definition at line 1636 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1637 {
1639  return;
1640 
1642 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
void EventTriggerSQLDrop ( Node parsetree)

Definition at line 860 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

861 {
862  List *runlist;
863  EventTriggerData trigdata;
864 
865  /*
866  * See EventTriggerDDLCommandStart for a discussion about why event
867  * triggers are disabled in single user mode.
868  */
869  if (!IsUnderPostmaster)
870  return;
871 
872  /*
873  * Use current state to determine whether this event fires at all. If
874  * there are no triggers for the sql_drop event, then we don't have
875  * anything to do here. Note that dropped object collection is disabled
876  * if this is the case, so even if we were to try to run, the list would
877  * be empty.
878  */
881  return;
882 
883  runlist = EventTriggerCommonSetup(parsetree,
884  EVT_SQLDrop, "sql_drop",
885  &trigdata);
886 
887  /*
888  * Nothing to do if run list is empty. Note this shouldn't happen,
889  * because if there are no sql_drop events, then objects-to-drop wouldn't
890  * have been collected in the first place and we would have quit above.
891  */
892  if (runlist == NIL)
893  return;
894 
895  /*
896  * Make sure anything the main command did will be visible to the event
897  * triggers.
898  */
900 
901  /*
902  * Make sure pg_event_trigger_dropped_objects only works when running
903  * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
904  * one trigger fails. (This is perhaps not necessary, as the currentState
905  * variable will be removed shortly by our caller, but it seems better to
906  * play safe.)
907  */
909 
910  /* Run the triggers. */
911  PG_TRY();
912  {
913  EventTriggerInvoke(runlist, &trigdata);
914  }
915  PG_CATCH();
916  {
918  PG_RE_THROW();
919  }
920  PG_END_TRY();
922 
923  /* Cleanup. */
924  list_free(runlist);
925 }
#define NIL
Definition: pg_list.h:69
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:101
static bool slist_is_empty(slist_head *head)
Definition: ilist.h:563
void CommandCounterIncrement(void)
Definition: xact.c:915
#define PG_CATCH()
Definition: elog.h:293
#define PG_RE_THROW()
Definition: elog.h:314
void list_free(List *list)
Definition: list.c:1133
#define PG_TRY()
Definition: elog.h:284
Definition: pg_list.h:45
#define PG_END_TRY()
Definition: elog.h:300
void EventTriggerSQLDropAddObject ( const ObjectAddress object,
bool  original,
bool  normal 
)

Definition at line 1332 of file event_trigger.c.

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert, 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_namensp_unique(), getObjectClass(), getObjectIdentityParts(), getObjectTypeDescription(), heap_close, heap_getattr, heap_open(), InvalidAttrNumber, is_objectclass_supported(), isAnyTempNamespace(), SQLDropObject::istemp, isTempNamespace(), MemoryContextSwitchTo(), NamespaceRelationId, 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(), and EventTriggerQueryState::SQLDropList.

Referenced by deleteObjectsInList(), and DropSubscription().

1333 {
1334  SQLDropObject *obj;
1335  MemoryContext oldcxt;
1336 
1338  return;
1339 
1341 
1342  /* don't report temp schemas except my own */
1343  if (object->classId == NamespaceRelationId &&
1344  (isAnyTempNamespace(object->objectId) &&
1345  !isTempNamespace(object->objectId)))
1346  return;
1347 
1349 
1350  obj = palloc0(sizeof(SQLDropObject));
1351  obj->address = *object;
1352  obj->original = original;
1353  obj->normal = normal;
1354 
1355  /*
1356  * Obtain schema names from the object's catalog tuple, if one exists;
1357  * this lets us skip objects in temp schemas. We trust that
1358  * ObjectProperty contains all object classes that can be
1359  * schema-qualified.
1360  */
1361  if (is_objectclass_supported(object->classId))
1362  {
1363  Relation catalog;
1364  HeapTuple tuple;
1365 
1366  catalog = heap_open(obj->address.classId, AccessShareLock);
1367  tuple = get_catalog_object_by_oid(catalog, obj->address.objectId);
1368 
1369  if (tuple)
1370  {
1371  AttrNumber attnum;
1372  Datum datum;
1373  bool isnull;
1374 
1376  if (attnum != InvalidAttrNumber)
1377  {
1378  datum = heap_getattr(tuple, attnum,
1379  RelationGetDescr(catalog), &isnull);
1380  if (!isnull)
1381  {
1382  Oid namespaceId;
1383 
1384  namespaceId = DatumGetObjectId(datum);
1385  /* temp objects are only reported if they are my own */
1386  if (isTempNamespace(namespaceId))
1387  {
1388  obj->schemaname = "pg_temp";
1389  obj->istemp = true;
1390  }
1391  else if (isAnyTempNamespace(namespaceId))
1392  {
1393  pfree(obj);
1394  heap_close(catalog, AccessShareLock);
1395  MemoryContextSwitchTo(oldcxt);
1396  return;
1397  }
1398  else
1399  {
1400  obj->schemaname = get_namespace_name(namespaceId);
1401  obj->istemp = false;
1402  }
1403  }
1404  }
1405 
1407  obj->address.objectSubId == 0)
1408  {
1409  attnum = get_object_attnum_name(obj->address.classId);
1410  if (attnum != InvalidAttrNumber)
1411  {
1412  datum = heap_getattr(tuple, attnum,
1413  RelationGetDescr(catalog), &isnull);
1414  if (!isnull)
1415  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1416  }
1417  }
1418  }
1419 
1420  heap_close(catalog, AccessShareLock);
1421  }
1422  else
1423  {
1424  if (object->classId == NamespaceRelationId &&
1425  isTempNamespace(object->objectId))
1426  obj->istemp = true;
1427  }
1428 
1429  /* object identity, objname and objargs */
1430  obj->objidentity =
1431  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs);
1432 
1433  /* object type */
1435 
1437 
1438  MemoryContextSwitchTo(oldcxt);
1439 }
bool get_object_namensp_unique(Oid class_id)
slist_node next
#define NamespaceRelationId
Definition: pg_namespace.h:34
ObjectAddress address
char * getObjectTypeDescription(const ObjectAddress *object)
#define RelationGetDescr(relation)
Definition: rel.h:428
const char * objname
#define DatumGetObjectId(X)
Definition: postgres.h:506
char * pstrdup(const char *in)
Definition: mcxt.c:1076
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)
#define heap_close(r, l)
Definition: heapam.h:97
const char * objidentity
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2341
const char * objecttype
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
#define DatumGetName(X)
Definition: postgres.h:591
void pfree(void *pointer)
Definition: mcxt.c:949
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3118
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
const char * schemaname
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:769
AttrNumber get_object_attnum_name(Oid class_id)
void * palloc0(Size size)
Definition: mcxt.c:877
uintptr_t Datum
Definition: postgres.h:372
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define Assert(condition)
Definition: c.h:681
HeapTuple get_catalog_object_by_oid(Relation catalog, Oid objectId)
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:493
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3156
bool is_objectclass_supported(Oid class_id)
int16 AttrNumber
Definition: attnum.h:21
bool EventTriggerSupportsGrantObjectType ( GrantObjectType  objtype)

Definition at line 1199 of file event_trigger.c.

References ACL_OBJECT_COLUMN, ACL_OBJECT_DATABASE, ACL_OBJECT_DOMAIN, ACL_OBJECT_FDW, ACL_OBJECT_FOREIGN_SERVER, ACL_OBJECT_FUNCTION, ACL_OBJECT_LANGUAGE, ACL_OBJECT_LARGEOBJECT, ACL_OBJECT_NAMESPACE, ACL_OBJECT_RELATION, ACL_OBJECT_SEQUENCE, ACL_OBJECT_TABLESPACE, and ACL_OBJECT_TYPE.

Referenced by ExecGrantStmt_oids(), and standard_ProcessUtility().

1200 {
1201  switch (objtype)
1202  {
1203  case ACL_OBJECT_DATABASE:
1204  case ACL_OBJECT_TABLESPACE:
1205  /* no support for global objects */
1206  return false;
1207 
1208  case ACL_OBJECT_COLUMN:
1209  case ACL_OBJECT_RELATION:
1210  case ACL_OBJECT_SEQUENCE:
1211  case ACL_OBJECT_DOMAIN:
1212  case ACL_OBJECT_FDW:
1214  case ACL_OBJECT_FUNCTION:
1215  case ACL_OBJECT_LANGUAGE:
1217  case ACL_OBJECT_NAMESPACE:
1218  case ACL_OBJECT_TYPE:
1219  return true;
1220 
1221  /*
1222  * There's intentionally no default: case here; we want the
1223  * compiler to warn if a new ACL class hasn't been handled above.
1224  */
1225  }
1226 
1227  /* Shouldn't get here, but if we do, say "no support" */
1228  return false;
1229 }
bool EventTriggerSupportsObjectClass ( ObjectClass  objclass)

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

1141 {
1142  switch (objclass)
1143  {
1144  case OCLASS_DATABASE:
1145  case OCLASS_TBLSPACE:
1146  case OCLASS_ROLE:
1147  /* no support for global objects */
1148  return false;
1149  case OCLASS_EVENT_TRIGGER:
1150  /* no support for event triggers on event triggers */
1151  return false;
1152  case OCLASS_CLASS:
1153  case OCLASS_PROC:
1154  case OCLASS_TYPE:
1155  case OCLASS_CAST:
1156  case OCLASS_COLLATION:
1157  case OCLASS_CONSTRAINT:
1158  case OCLASS_CONVERSION:
1159  case OCLASS_DEFAULT:
1160  case OCLASS_LANGUAGE:
1161  case OCLASS_LARGEOBJECT:
1162  case OCLASS_OPERATOR:
1163  case OCLASS_OPCLASS:
1164  case OCLASS_OPFAMILY:
1165  case OCLASS_AM:
1166  case OCLASS_AMOP:
1167  case OCLASS_AMPROC:
1168  case OCLASS_REWRITE:
1169  case OCLASS_TRIGGER:
1170  case OCLASS_SCHEMA:
1171  case OCLASS_STATISTIC_EXT:
1172  case OCLASS_TSPARSER:
1173  case OCLASS_TSDICT:
1174  case OCLASS_TSTEMPLATE:
1175  case OCLASS_TSCONFIG:
1176  case OCLASS_FDW:
1177  case OCLASS_FOREIGN_SERVER:
1178  case OCLASS_USER_MAPPING:
1179  case OCLASS_DEFACL:
1180  case OCLASS_EXTENSION:
1181  case OCLASS_POLICY:
1182  case OCLASS_PUBLICATION:
1184  case OCLASS_SUBSCRIPTION:
1185  case OCLASS_TRANSFORM:
1186  return true;
1187 
1188  /*
1189  * There's intentionally no default: case here; we want the
1190  * compiler to warn if a new OCLASS hasn't been handled above.
1191  */
1192  }
1193 
1194  /* Shouldn't get here, but if we do, say "no support" */
1195  return false;
1196 }
bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 1068 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_PUBLICATION, OBJECT_PUBLICATION_REL, OBJECT_ROLE, 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 standard_ProcessUtility().

1069 {
1070  switch (obtype)
1071  {
1072  case OBJECT_DATABASE:
1073  case OBJECT_TABLESPACE:
1074  case OBJECT_ROLE:
1075  /* no support for global objects */
1076  return false;
1077  case OBJECT_EVENT_TRIGGER:
1078  /* no support for event triggers on event triggers */
1079  return false;
1080  case OBJECT_ACCESS_METHOD:
1081  case OBJECT_AGGREGATE:
1082  case OBJECT_AMOP:
1083  case OBJECT_AMPROC:
1084  case OBJECT_ATTRIBUTE:
1085  case OBJECT_CAST:
1086  case OBJECT_COLUMN:
1087  case OBJECT_COLLATION:
1088  case OBJECT_CONVERSION:
1089  case OBJECT_DEFACL:
1090  case OBJECT_DEFAULT:
1091  case OBJECT_DOMAIN:
1092  case OBJECT_DOMCONSTRAINT:
1093  case OBJECT_EXTENSION:
1094  case OBJECT_FDW:
1095  case OBJECT_FOREIGN_SERVER:
1096  case OBJECT_FOREIGN_TABLE:
1097  case OBJECT_FUNCTION:
1098  case OBJECT_INDEX:
1099  case OBJECT_LANGUAGE:
1100  case OBJECT_LARGEOBJECT:
1101  case OBJECT_MATVIEW:
1102  case OBJECT_OPCLASS:
1103  case OBJECT_OPERATOR:
1104  case OBJECT_OPFAMILY:
1105  case OBJECT_POLICY:
1106  case OBJECT_PUBLICATION:
1108  case OBJECT_RULE:
1109  case OBJECT_SCHEMA:
1110  case OBJECT_SEQUENCE:
1111  case OBJECT_SUBSCRIPTION:
1112  case OBJECT_STATISTIC_EXT:
1113  case OBJECT_TABCONSTRAINT:
1114  case OBJECT_TABLE:
1115  case OBJECT_TRANSFORM:
1116  case OBJECT_TRIGGER:
1118  case OBJECT_TSDICTIONARY:
1119  case OBJECT_TSPARSER:
1120  case OBJECT_TSTEMPLATE:
1121  case OBJECT_TYPE:
1122  case OBJECT_USER_MAPPING:
1123  case OBJECT_VIEW:
1124  return true;
1125 
1126  /*
1127  * There's intentionally no default: case here; we want the
1128  * compiler to warn if a new ObjectType hasn't been handled above.
1129  */
1130  }
1131 
1132  /* Shouldn't get here, but if we do, say "no support" */
1133  return false;
1134 }
void EventTriggerTableRewrite ( Node parsetree,
Oid  tableOid,
int  reason 
)

Definition at line 932 of file event_trigger.c.

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

Referenced by ATRewriteTables().

933 {
934  List *runlist;
935  EventTriggerData trigdata;
936 
937  elog(DEBUG1, "EventTriggerTableRewrite(%u)", tableOid);
938 
939  /*
940  * Event Triggers are completely disabled in standalone mode. There are
941  * (at least) two reasons for this:
942  *
943  * 1. A sufficiently broken event trigger might not only render the
944  * database unusable, but prevent disabling itself to fix the situation.
945  * In this scenario, restarting in standalone mode provides an escape
946  * hatch.
947  *
948  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
949  * therefore will malfunction if pg_event_trigger's indexes are damaged.
950  * To allow recovery from a damaged index, we need some operating mode
951  * wherein event triggers are disabled. (Or we could implement
952  * heapscan-and-sort logic for that case, but having disaster recovery
953  * scenarios depend on code that's otherwise untested isn't appetizing.)
954  */
955  if (!IsUnderPostmaster)
956  return;
957 
958  runlist = EventTriggerCommonSetup(parsetree,
960  "table_rewrite",
961  &trigdata);
962  if (runlist == NIL)
963  return;
964 
965  /*
966  * Make sure pg_event_trigger_table_rewrite_oid only works when running
967  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
968  * when one trigger fails. (This is perhaps not necessary, as the
969  * currentState variable will be removed shortly by our caller, but it
970  * seems better to play safe.)
971  */
974 
975  /* Run the triggers. */
976  PG_TRY();
977  {
978  EventTriggerInvoke(runlist, &trigdata);
979  }
980  PG_CATCH();
981  {
984  PG_RE_THROW();
985  }
986  PG_END_TRY();
987 
990 
991  /* Cleanup. */
992  list_free(runlist);
993 
994  /*
995  * Make sure anything the event triggers did will be visible to the main
996  * command.
997  */
999 }
#define NIL
Definition: pg_list.h:69
#define DEBUG1
Definition: elog.h:25
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:101
void CommandCounterIncrement(void)
Definition: xact.c:915
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_CATCH()
Definition: elog.h:293
#define PG_RE_THROW()
Definition: elog.h:314
void list_free(List *list)
Definition: list.c:1133
#define elog
Definition: elog.h:219
#define PG_TRY()
Definition: elog.h:284
Definition: pg_list.h:45
#define PG_END_TRY()
Definition: elog.h:300
void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1648 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1649 {
1651  return;
1652 
1654 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:72
Oid get_event_trigger_oid ( const char *  trigname,
bool  missing_ok 
)

Definition at line 641 of file event_trigger.c.

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

Referenced by get_object_address_unqualified().

642 {
643  Oid oid;
644 
646  if (!OidIsValid(oid) && !missing_ok)
647  ereport(ERROR,
648  (errcode(ERRCODE_UNDEFINED_OBJECT),
649  errmsg("event trigger \"%s\" does not exist", trigname)));
650  return oid;
651 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:191
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void RemoveEventTriggerById ( Oid  ctrigOid)

Definition at line 477 of file event_trigger.c.

References CatalogTupleDelete(), elog, ERROR, EVENTTRIGGEROID, EventTriggerRelationId, heap_close, heap_open(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), and HeapTupleData::t_self.

Referenced by doDeletion().

478 {
479  Relation tgrel;
480  HeapTuple tup;
481 
483 
485  if (!HeapTupleIsValid(tup))
486  elog(ERROR, "cache lookup failed for event trigger %u", trigOid);
487 
488  CatalogTupleDelete(tgrel, &tup->t_self);
489 
490  ReleaseSysCache(tup);
491 
493 }
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#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:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define EventTriggerRelationId
#define elog
Definition: elog.h:219
bool trackDroppedObjectsNeeded ( void  )

Definition at line 1300 of file event_trigger.c.

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

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

1301 {
1302  /*
1303  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1304  * exists
1305  */
1306  return list_length(EventCacheLookup(EVT_SQLDrop)) > 0 ||
1309 }
static int list_length(const List *l)
Definition: pg_list.h:89
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64