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

Go to the source code of this file.

Data Structures

struct  EventTriggerData
 

Macros

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

Typedefs

typedef struct EventTriggerData EventTriggerData
 

Functions

Oid CreateEventTrigger (CreateEventTrigStmt *stmt)
 
Oid get_event_trigger_oid (const char *trigname, bool missing_ok)
 
Oid AlterEventTrigger (AlterEventTrigStmt *stmt)
 
ObjectAddress AlterEventTriggerOwner (const char *name, Oid newOwnerId)
 
void AlterEventTriggerOwner_oid (Oid, Oid newOwnerId)
 
bool EventTriggerSupportsObjectType (ObjectType obtype)
 
bool EventTriggerSupportsObject (const ObjectAddress *object)
 
void EventTriggerDDLCommandStart (Node *parsetree)
 
void EventTriggerDDLCommandEnd (Node *parsetree)
 
void EventTriggerSQLDrop (Node *parsetree)
 
void EventTriggerTableRewrite (Node *parsetree, Oid tableOid, int reason)
 
void EventTriggerOnLogin (void)
 
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)
 

Variables

PGDLLIMPORT bool event_triggers
 

Macro Definition Documentation

◆ AT_REWRITE_ACCESS_METHOD

#define AT_REWRITE_ACCESS_METHOD   0x08

Definition at line 43 of file event_trigger.h.

◆ AT_REWRITE_ALTER_PERSISTENCE

#define AT_REWRITE_ALTER_PERSISTENCE   0x01

Definition at line 40 of file event_trigger.h.

◆ AT_REWRITE_COLUMN_REWRITE

#define AT_REWRITE_COLUMN_REWRITE   0x04

Definition at line 42 of file event_trigger.h.

◆ AT_REWRITE_DEFAULT_VAL

#define AT_REWRITE_DEFAULT_VAL   0x02

Definition at line 41 of file event_trigger.h.

◆ CALLED_AS_EVENT_TRIGGER

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

Definition at line 49 of file event_trigger.h.

Typedef Documentation

◆ EventTriggerData

Function Documentation

◆ AlterEventTrigger()

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 423 of file event_trigger.c.

424 {
425  Relation tgrel;
426  HeapTuple tup;
427  Oid trigoid;
428  Form_pg_event_trigger evtForm;
429  char tgenabled = stmt->tgenabled;
430 
431  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
432 
433  tup = SearchSysCacheCopy1(EVENTTRIGGERNAME,
434  CStringGetDatum(stmt->trigname));
435  if (!HeapTupleIsValid(tup))
436  ereport(ERROR,
437  (errcode(ERRCODE_UNDEFINED_OBJECT),
438  errmsg("event trigger \"%s\" does not exist",
439  stmt->trigname)));
440 
441  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
442  trigoid = evtForm->oid;
443 
444  if (!object_ownercheck(EventTriggerRelationId, trigoid, GetUserId()))
446  stmt->trigname);
447 
448  /* tuple is a copy, so we can modify it below */
449  evtForm->evtenabled = tgenabled;
450 
451  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
452 
453  /*
454  * Login event triggers have an additional flag in pg_database to enable
455  * faster lookups in hot codepaths. Set the flag unless already True.
456  */
457  if (namestrcmp(&evtForm->evtevent, "login") == 0 &&
458  tgenabled != TRIGGER_DISABLED)
460 
461  InvokeObjectPostAlterHook(EventTriggerRelationId,
462  trigoid, 0);
463 
464  /* clean up */
465  heap_freetuple(tup);
467 
468  return trigoid;
469 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2622
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4064
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static void SetDatabaseHasLoginEventTriggers(void)
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1434
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
#define stmt
Definition: indent_codes.h:59
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:313
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:524
int namestrcmp(Name name, const char *str)
Definition: name.c:247
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:197
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2282
FormData_pg_event_trigger * Form_pg_event_trigger
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
unsigned int Oid
Definition: postgres_ext.h:31
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:91
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
#define TRIGGER_DISABLED
Definition: trigger.h:152

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), heap_freetuple(), HeapTupleIsValid, InvokeObjectPostAlterHook, namestrcmp(), OBJECT_EVENT_TRIGGER, object_ownercheck(), RowExclusiveLock, SearchSysCacheCopy1, SetDatabaseHasLoginEventTriggers(), stmt, HeapTupleData::t_self, table_close(), table_open(), and TRIGGER_DISABLED.

Referenced by standard_ProcessUtility().

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 475 of file event_trigger.c.

476 {
477  Oid evtOid;
478  HeapTuple tup;
479  Form_pg_event_trigger evtForm;
480  Relation rel;
481  ObjectAddress address;
482 
483  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
484 
485  tup = SearchSysCacheCopy1(EVENTTRIGGERNAME, CStringGetDatum(name));
486 
487  if (!HeapTupleIsValid(tup))
488  ereport(ERROR,
489  (errcode(ERRCODE_UNDEFINED_OBJECT),
490  errmsg("event trigger \"%s\" does not exist", name)));
491 
492  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
493  evtOid = evtForm->oid;
494 
495  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
496 
497  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
498 
499  heap_freetuple(tup);
500 
502 
503  return address;
504 }
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
const char * name

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

Referenced by ExecAlterOwnerStmt().

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  trigOid,
Oid  newOwnerId 
)

Definition at line 510 of file event_trigger.c.

511 {
512  HeapTuple tup;
513  Relation rel;
514 
515  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
516 
517  tup = SearchSysCacheCopy1(EVENTTRIGGEROID, ObjectIdGetDatum(trigOid));
518 
519  if (!HeapTupleIsValid(tup))
520  ereport(ERROR,
521  (errcode(ERRCODE_UNDEFINED_OBJECT),
522  errmsg("event trigger with OID %u does not exist", trigOid)));
523 
524  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
525 
526  heap_freetuple(tup);
527 
529 }
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252

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

Referenced by shdepReassignOwned_Owner().

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 120 of file event_trigger.c.

121 {
122  HeapTuple tuple;
123  Oid funcoid;
124  Oid funcrettype;
125  Oid evtowner = GetUserId();
126  ListCell *lc;
127  List *tags = NULL;
128 
129  /*
130  * It would be nice to allow database owners or even regular users to do
131  * this, but there are obvious privilege escalation risks which would have
132  * to somehow be plugged first.
133  */
134  if (!superuser())
135  ereport(ERROR,
136  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
137  errmsg("permission denied to create event trigger \"%s\"",
138  stmt->trigname),
139  errhint("Must be superuser to create an event trigger.")));
140 
141  /* Validate event name. */
142  if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
143  strcmp(stmt->eventname, "ddl_command_end") != 0 &&
144  strcmp(stmt->eventname, "sql_drop") != 0 &&
145  strcmp(stmt->eventname, "login") != 0 &&
146  strcmp(stmt->eventname, "table_rewrite") != 0)
147  ereport(ERROR,
148  (errcode(ERRCODE_SYNTAX_ERROR),
149  errmsg("unrecognized event name \"%s\"",
150  stmt->eventname)));
151 
152  /* Validate filter conditions. */
153  foreach(lc, stmt->whenclause)
154  {
155  DefElem *def = (DefElem *) lfirst(lc);
156 
157  if (strcmp(def->defname, "tag") == 0)
158  {
159  if (tags != NULL)
161  tags = (List *) def->arg;
162  }
163  else
164  ereport(ERROR,
165  (errcode(ERRCODE_SYNTAX_ERROR),
166  errmsg("unrecognized filter variable \"%s\"", def->defname)));
167  }
168 
169  /* Validate tag list, if any. */
170  if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
171  strcmp(stmt->eventname, "ddl_command_end") == 0 ||
172  strcmp(stmt->eventname, "sql_drop") == 0)
173  && tags != NULL)
174  validate_ddl_tags("tag", tags);
175  else if (strcmp(stmt->eventname, "table_rewrite") == 0
176  && tags != NULL)
177  validate_table_rewrite_tags("tag", tags);
178  else if (strcmp(stmt->eventname, "login") == 0 && tags != NULL)
179  ereport(ERROR,
180  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
181  errmsg("tag filtering is not supported for login event triggers")));
182 
183  /*
184  * Give user a nice error message if an event trigger of the same name
185  * already exists.
186  */
187  tuple = SearchSysCache1(EVENTTRIGGERNAME, CStringGetDatum(stmt->trigname));
188  if (HeapTupleIsValid(tuple))
189  ereport(ERROR,
191  errmsg("event trigger \"%s\" already exists",
192  stmt->trigname)));
193 
194  /* Find and validate the trigger function. */
195  funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
196  funcrettype = get_func_rettype(funcoid);
197  if (funcrettype != EVENT_TRIGGEROID)
198  ereport(ERROR,
199  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
200  errmsg("function %s must return type %s",
201  NameListToString(stmt->funcname), "event_trigger")));
202 
203  /* Insert catalog entries. */
204  return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
205  evtowner, funcoid, tags);
206 }
int errhint(const char *fmt,...)
Definition: elog.c:1317
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
static void validate_ddl_tags(const char *filtervar, List *taglist)
static void error_duplicate_filter_variable(const char *defname)
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *taglist)
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1655
char * NameListToString(const List *names)
Definition: namespace.c:3594
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Definition: parse_func.c:2144
#define lfirst(lc)
Definition: pg_list.h:172
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:30
char * defname
Definition: parsenodes.h:817
Node * arg
Definition: parsenodes.h:818
Definition: pg_list.h:54
bool superuser(void)
Definition: superuser.c:46
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

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

Referenced by standard_ProcessUtility().

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1708 of file event_trigger.c.

1709 {
1710  CollectedCommand *parent;
1711 
1712  /* ignore if event trigger context not set, or collection disabled */
1713  if (!currentEventTriggerState ||
1715  return;
1716 
1718 
1719  /* If no subcommands, don't collect */
1721  {
1722  MemoryContext oldcxt;
1723 
1725 
1729 
1730  MemoryContextSwitchTo(oldcxt);
1731  }
1732  else
1734 
1736 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:81
List * lappend(List *list, void *datum)
Definition: list.c:339
void pfree(void *pointer)
Definition: mcxt.c:1521
#define NIL
Definition: pg_list.h:68
MemoryContextSwitchTo(old_ctx)
union CollectedCommand::@123 d
struct CollectedCommand::@123::@125 alterTable
struct CollectedCommand * parent
CollectedCommand * currentCommand
Definition: event_trigger.c:75

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

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

◆ EventTriggerAlterTableRelid()

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1621 of file event_trigger.c.

1622 {
1623  MemoryContext oldcxt;
1624  CollectedCommand *command;
1625 
1626  /* ignore if event trigger context not set, or collection disabled */
1627  if (!currentEventTriggerState ||
1629  return;
1630 
1632 
1633  command = palloc(sizeof(CollectedCommand));
1634 
1635  command->type = SCT_AlterTable;
1636  command->in_extension = creating_extension;
1637 
1638  command->d.alterTable.classId = RelationRelationId;
1639  command->d.alterTable.objectId = InvalidOid;
1640  command->d.alterTable.subcmds = NIL;
1641  command->parsetree = copyObject(parsetree);
1642 
1645 
1646  MemoryContextSwitchTo(oldcxt);
1647 }
@ SCT_AlterTable
bool creating_extension
Definition: extension.c:73
void * palloc(Size size)
Definition: mcxt.c:1317
#define copyObject(obj)
Definition: nodes.h:224
#define InvalidOid
Definition: postgres_ext.h:36
CollectedCommandType type

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

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

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1179 of file event_trigger.c.

1180 {
1182  MemoryContext cxt;
1183 
1184  /*
1185  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1186  * reason to have event trigger state at all; so if there are none, don't
1187  * install one.
1188  */
1190  return false;
1191 
1193  "event trigger state",
1196  state->cxt = cxt;
1197  slist_init(&(state->SQLDropList));
1198  state->in_sql_drop = false;
1199  state->table_rewrite_oid = InvalidOid;
1200 
1201  state->commandCollectionInhibited = currentEventTriggerState ?
1203  state->currentCommand = NULL;
1204  state->commandList = NIL;
1205  state->previous = currentEventTriggerState;
1207 
1208  return true;
1209 }
bool trackDroppedObjectsNeeded(void)
static void slist_init(slist_head *head)
Definition: ilist.h:986
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
Definition: regguts.h:323

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterDefPrivs()

void EventTriggerCollectAlterDefPrivs ( AlterDefaultPrivilegesStmt stmt)

Definition at line 1892 of file event_trigger.c.

1893 {
1894  MemoryContext oldcxt;
1895  CollectedCommand *command;
1896 
1897  /* ignore if event trigger context not set, or collection disabled */
1898  if (!currentEventTriggerState ||
1900  return;
1901 
1903 
1904  command = palloc0(sizeof(CollectedCommand));
1905  command->type = SCT_AlterDefaultPrivileges;
1906  command->d.defprivs.objtype = stmt->action->objtype;
1907  command->in_extension = creating_extension;
1908  command->parsetree = (Node *) copyObject(stmt);
1909 
1912  MemoryContextSwitchTo(oldcxt);
1913 }
@ SCT_AlterDefaultPrivileges
void * palloc0(Size size)
Definition: mcxt.c:1347
struct CollectedCommand::@123::@130 defprivs
Definition: nodes.h:129

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterOpFam()

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

Definition at line 1790 of file event_trigger.c.

1792 {
1793  MemoryContext oldcxt;
1794  CollectedCommand *command;
1795 
1796  /* ignore if event trigger context not set, or collection disabled */
1797  if (!currentEventTriggerState ||
1799  return;
1800 
1802 
1803  command = palloc(sizeof(CollectedCommand));
1804  command->type = SCT_AlterOpFamily;
1805  command->in_extension = creating_extension;
1806  ObjectAddressSet(command->d.opfam.address,
1807  OperatorFamilyRelationId, opfamoid);
1808  command->d.opfam.operators = operators;
1809  command->d.opfam.procedures = procedures;
1810  command->parsetree = (Node *) copyObject(stmt);
1811 
1814 
1815  MemoryContextSwitchTo(oldcxt);
1816 }
@ SCT_AlterOpFamily
struct CollectedCommand::@123::@127 opfam

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

Referenced by AlterOpFamilyAdd(), and AlterOpFamilyDrop().

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

Definition at line 1673 of file event_trigger.c.

1674 {
1675  MemoryContext oldcxt;
1677 
1678  /* ignore if event trigger context not set, or collection disabled */
1679  if (!currentEventTriggerState ||
1681  return;
1682 
1683  Assert(IsA(subcmd, AlterTableCmd));
1686 
1688 
1689  newsub = palloc(sizeof(CollectedATSubcmd));
1690  newsub->address = address;
1691  newsub->parsetree = copyObject(subcmd);
1692 
1695 
1696  MemoryContextSwitchTo(oldcxt);
1697 }
#define Assert(condition)
Definition: c.h:812
#define OidIsValid(objectId)
Definition: c.h:729
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static color newsub(struct colormap *cm, color co)
Definition: regc_color.c:389

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

Referenced by ATExecCmd().

◆ EventTriggerCollectAlterTSConfig()

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

Definition at line 1857 of file event_trigger.c.

1859 {
1860  MemoryContext oldcxt;
1861  CollectedCommand *command;
1862 
1863  /* ignore if event trigger context not set, or collection disabled */
1864  if (!currentEventTriggerState ||
1866  return;
1867 
1869 
1870  command = palloc0(sizeof(CollectedCommand));
1871  command->type = SCT_AlterTSConfig;
1872  command->in_extension = creating_extension;
1873  ObjectAddressSet(command->d.atscfg.address,
1874  TSConfigRelationId, cfgId);
1875  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1876  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1877  command->d.atscfg.ndicts = ndicts;
1878  command->parsetree = (Node *) copyObject(stmt);
1879 
1882 
1883  MemoryContextSwitchTo(oldcxt);
1884 }
@ SCT_AlterTSConfig
struct CollectedCommand::@123::@129 atscfg

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

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

◆ EventTriggerCollectCreateOpClass()

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

Definition at line 1823 of file event_trigger.c.

1825 {
1826  MemoryContext oldcxt;
1827  CollectedCommand *command;
1828 
1829  /* ignore if event trigger context not set, or collection disabled */
1830  if (!currentEventTriggerState ||
1832  return;
1833 
1835 
1836  command = palloc0(sizeof(CollectedCommand));
1837  command->type = SCT_CreateOpClass;
1838  command->in_extension = creating_extension;
1839  ObjectAddressSet(command->d.createopc.address,
1840  OperatorClassRelationId, opcoid);
1841  command->d.createopc.operators = operators;
1842  command->d.createopc.procedures = procedures;
1843  command->parsetree = (Node *) copyObject(stmt);
1844 
1847 
1848  MemoryContextSwitchTo(oldcxt);
1849 }
@ SCT_CreateOpClass
struct CollectedCommand::@123::@128 createopc

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

Referenced by DefineOpClass().

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1746 of file event_trigger.c.

1747 {
1748  MemoryContext oldcxt;
1749  CollectedCommand *command;
1750  InternalGrant *icopy;
1751  ListCell *cell;
1752 
1753  /* ignore if event trigger context not set, or collection disabled */
1754  if (!currentEventTriggerState ||
1756  return;
1757 
1759 
1760  /*
1761  * This is tedious, but necessary.
1762  */
1763  icopy = palloc(sizeof(InternalGrant));
1764  memcpy(icopy, istmt, sizeof(InternalGrant));
1765  icopy->objects = list_copy(istmt->objects);
1766  icopy->grantees = list_copy(istmt->grantees);
1767  icopy->col_privs = NIL;
1768  foreach(cell, istmt->col_privs)
1769  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1770 
1771  /* Now collect it, using the copied InternalGrant */
1772  command = palloc(sizeof(CollectedCommand));
1773  command->type = SCT_Grant;
1774  command->in_extension = creating_extension;
1775  command->d.grant.istmt = icopy;
1776  command->parsetree = NULL;
1777 
1780 
1781  MemoryContextSwitchTo(oldcxt);
1782 }
@ SCT_Grant
List * list_copy(const List *oldlist)
Definition: list.c:1573
struct CollectedCommand::@123::@126 grant

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

Referenced by ExecGrantStmt_oids().

◆ EventTriggerCollectSimpleCommand()

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

Definition at line 1583 of file event_trigger.c.

1586 {
1587  MemoryContext oldcxt;
1588  CollectedCommand *command;
1589 
1590  /* ignore if event trigger context not set, or collection disabled */
1591  if (!currentEventTriggerState ||
1593  return;
1594 
1596 
1597  command = palloc(sizeof(CollectedCommand));
1598 
1599  command->type = SCT_Simple;
1600  command->in_extension = creating_extension;
1601 
1602  command->d.simple.address = address;
1603  command->d.simple.secondaryObject = secondaryObject;
1604  command->parsetree = copyObject(parsetree);
1605 
1607  command);
1608 
1609  MemoryContextSwitchTo(oldcxt);
1610 }
@ SCT_Simple
struct CollectedCommand::@123::@124 simple

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

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

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 772 of file event_trigger.c.

773 {
774  List *runlist;
775  EventTriggerData trigdata;
776 
777  /*
778  * See EventTriggerDDLCommandStart for a discussion about why event
779  * triggers are disabled in single user mode or via GUC.
780  */
782  return;
783 
784  /*
785  * Also do nothing if our state isn't set up, which it won't be if there
786  * weren't any relevant event triggers at the start of the current DDL
787  * command. This test might therefore seem optional, but it's important
788  * because EventTriggerCommonSetup might find triggers that didn't exist
789  * at the time the command started. Although this function itself
790  * wouldn't crash, the event trigger functions would presumably call
791  * pg_event_trigger_ddl_commands which would fail. Better to do nothing
792  * until the next command.
793  */
795  return;
796 
797  runlist = EventTriggerCommonSetup(parsetree,
798  EVT_DDLCommandEnd, "ddl_command_end",
799  &trigdata, false);
800  if (runlist == NIL)
801  return;
802 
803  /*
804  * Make sure anything the main command did will be visible to the event
805  * triggers.
806  */
808 
809  /* Run the triggers. */
810  EventTriggerInvoke(runlist, &trigdata);
811 
812  /* Cleanup. */
813  list_free(runlist);
814 }
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata, bool unfiltered)
bool event_triggers
Definition: event_trigger.c:84
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
@ EVT_DDLCommandEnd
Definition: evtcache.h:23
bool IsUnderPostmaster
Definition: globals.c:119
void list_free(List *list)
Definition: list.c:1546
void CommandCounterIncrement(void)
Definition: xact.c:1099

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 721 of file event_trigger.c.

722 {
723  List *runlist;
724  EventTriggerData trigdata;
725 
726  /*
727  * Event Triggers are completely disabled in standalone mode. There are
728  * (at least) two reasons for this:
729  *
730  * 1. A sufficiently broken event trigger might not only render the
731  * database unusable, but prevent disabling itself to fix the situation.
732  * In this scenario, restarting in standalone mode provides an escape
733  * hatch.
734  *
735  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
736  * therefore will malfunction if pg_event_trigger's indexes are damaged.
737  * To allow recovery from a damaged index, we need some operating mode
738  * wherein event triggers are disabled. (Or we could implement
739  * heapscan-and-sort logic for that case, but having disaster recovery
740  * scenarios depend on code that's otherwise untested isn't appetizing.)
741  *
742  * Additionally, event triggers can be disabled with a superuser-only GUC
743  * to make fixing database easier as per 1 above.
744  */
746  return;
747 
748  runlist = EventTriggerCommonSetup(parsetree,
750  "ddl_command_start",
751  &trigdata, false);
752  if (runlist == NIL)
753  return;
754 
755  /* Run the triggers. */
756  EventTriggerInvoke(runlist, &trigdata);
757 
758  /* Cleanup. */
759  list_free(runlist);
760 
761  /*
762  * Make sure anything the event triggers did will be visible to the main
763  * command.
764  */
766 }
@ EVT_DDLCommandStart
Definition: evtcache.h:22

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1223 of file event_trigger.c.

1224 {
1225  EventTriggerQueryState *prevstate;
1226 
1227  prevstate = currentEventTriggerState->previous;
1228 
1229  /* this avoids the need for retail pfree of SQLDropList items: */
1231 
1232  currentEventTriggerState = prevstate;
1233 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
struct EventTriggerQueryState * previous
Definition: event_trigger.c:78

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerInhibitCommandCollection()

void EventTriggerInhibitCommandCollection ( void  )

Definition at line 1549 of file event_trigger.c.

1550 {
1552  return;
1553 
1555 }

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ EventTriggerOnLogin()

void EventTriggerOnLogin ( void  )

Definition at line 893 of file event_trigger.c.

894 {
895  List *runlist;
896  EventTriggerData trigdata;
897 
898  /*
899  * See EventTriggerDDLCommandStart for a discussion about why event
900  * triggers are disabled in single user mode or via a GUC. We also need a
901  * database connection (some background workers don't have it).
902  */
905  return;
906 
908  runlist = EventTriggerCommonSetup(NULL,
909  EVT_Login, "login",
910  &trigdata, false);
911 
912  if (runlist != NIL)
913  {
914  /*
915  * Event trigger execution may require an active snapshot.
916  */
918 
919  /* Run the triggers. */
920  EventTriggerInvoke(runlist, &trigdata);
921 
922  /* Cleanup. */
923  list_free(runlist);
924 
926  }
927 
928  /*
929  * There is no active login event trigger, but our
930  * pg_database.dathasloginevt is set. Try to unset this flag. We use the
931  * lock to prevent concurrent SetDatabaseHasLoginEventTriggers(), but we
932  * don't want to hang the connection waiting on the lock. Thus, we are
933  * just trying to acquire the lock conditionally.
934  */
935  else if (ConditionalLockSharedObject(DatabaseRelationId, MyDatabaseId,
937  {
938  /*
939  * The lock is held. Now we need to recheck that login event triggers
940  * list is still empty. Once the list is empty, we know that even if
941  * there is a backend which concurrently inserts/enables a login event
942  * trigger, it will update pg_database.dathasloginevt *afterwards*.
943  */
944  runlist = EventTriggerCommonSetup(NULL,
945  EVT_Login, "login",
946  &trigdata, true);
947 
948  if (runlist == NIL)
949  {
950  Relation pg_db = table_open(DatabaseRelationId, RowExclusiveLock);
951  HeapTuple tuple;
952  void *state;
953  Form_pg_database db;
954  ScanKeyData key[1];
955 
956  /* Fetch a copy of the tuple to scribble on */
957  ScanKeyInit(&key[0],
958  Anum_pg_database_oid,
959  BTEqualStrategyNumber, F_OIDEQ,
961 
962  systable_inplace_update_begin(pg_db, DatabaseOidIndexId, true,
963  NULL, 1, key, &tuple, &state);
964 
965  if (!HeapTupleIsValid(tuple))
966  elog(ERROR, "could not find tuple for database %u", MyDatabaseId);
967 
968  db = (Form_pg_database) GETSTRUCT(tuple);
969  if (db->dathasloginevt)
970  {
971  db->dathasloginevt = false;
972 
973  /*
974  * Do an "in place" update of the pg_database tuple. Doing
975  * this instead of regular updates serves two purposes. First,
976  * that avoids possible waiting on the row-level lock. Second,
977  * that avoids dealing with TOAST.
978  */
980  }
981  else
984  heap_freetuple(tuple);
985  }
986  else
987  {
988  list_free(runlist);
989  }
990  }
992 }
#define elog(elevel,...)
Definition: elog.h:225
@ EVT_Login
Definition: evtcache.h:26
void systable_inplace_update_cancel(void *state)
Definition: genam.c:905
void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)
Definition: genam.c:810
void systable_inplace_update_finish(void *state, HeapTuple tuple)
Definition: genam.c:886
bool MyDatabaseHasLoginEventTriggers
Definition: globals.c:97
Oid MyDatabaseId
Definition: globals.c:93
bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1096
#define AccessExclusiveLock
Definition: lockdefs.h:43
FormData_pg_database * Form_pg_database
Definition: pg_database.h:96
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:212
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:614
void PopActiveSnapshot(void)
Definition: snapmgr.c:707
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void StartTransactionCommand(void)
Definition: xact.c:3051
void CommitTransactionCommand(void)
Definition: xact.c:3149

References AccessExclusiveLock, BTEqualStrategyNumber, CommitTransactionCommand(), ConditionalLockSharedObject(), elog, ERROR, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_Login, GETSTRUCT, GetTransactionSnapshot(), heap_freetuple(), HeapTupleIsValid, IsUnderPostmaster, sort-test::key, list_free(), MyDatabaseHasLoginEventTriggers, MyDatabaseId, NIL, ObjectIdGetDatum(), OidIsValid, PopActiveSnapshot(), PushActiveSnapshot(), RowExclusiveLock, ScanKeyInit(), StartTransactionCommand(), systable_inplace_update_begin(), systable_inplace_update_cancel(), systable_inplace_update_finish(), table_close(), and table_open().

Referenced by PostgresMain().

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 820 of file event_trigger.c.

821 {
822  List *runlist;
823  EventTriggerData trigdata;
824 
825  /*
826  * See EventTriggerDDLCommandStart for a discussion about why event
827  * triggers are disabled in single user mode or via a GUC.
828  */
830  return;
831 
832  /*
833  * Use current state to determine whether this event fires at all. If
834  * there are no triggers for the sql_drop event, then we don't have
835  * anything to do here. Note that dropped object collection is disabled
836  * if this is the case, so even if we were to try to run, the list would
837  * be empty.
838  */
841  return;
842 
843  runlist = EventTriggerCommonSetup(parsetree,
844  EVT_SQLDrop, "sql_drop",
845  &trigdata, false);
846 
847  /*
848  * Nothing to do if run list is empty. Note this typically can't happen,
849  * because if there are no sql_drop events, then objects-to-drop wouldn't
850  * have been collected in the first place and we would have quit above.
851  * But it could occur if event triggers were dropped partway through.
852  */
853  if (runlist == NIL)
854  return;
855 
856  /*
857  * Make sure anything the main command did will be visible to the event
858  * triggers.
859  */
861 
862  /*
863  * Make sure pg_event_trigger_dropped_objects only works when running
864  * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
865  * one trigger fails. (This is perhaps not necessary, as the currentState
866  * variable will be removed shortly by our caller, but it seems better to
867  * play safe.)
868  */
870 
871  /* Run the triggers. */
872  PG_TRY();
873  {
874  EventTriggerInvoke(runlist, &trigdata);
875  }
876  PG_FINALLY();
877  {
879  }
880  PG_END_TRY();
881 
882  /* Cleanup. */
883  list_free(runlist);
884 }
#define PG_TRY(...)
Definition: elog.h:371
#define PG_END_TRY(...)
Definition: elog.h:396
#define PG_FINALLY(...)
Definition: elog.h:388
@ EVT_SQLDrop
Definition: evtcache.h:24
static bool slist_is_empty(const slist_head *head)
Definition: ilist.h:995

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerSQLDropAddObject()

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

Definition at line 1273 of file event_trigger.c.

1274 {
1275  SQLDropObject *obj;
1276  MemoryContext oldcxt;
1277 
1279  return;
1280 
1282 
1283  /* don't report temp schemas except my own */
1284  if (object->classId == NamespaceRelationId &&
1285  (isAnyTempNamespace(object->objectId) &&
1286  !isTempNamespace(object->objectId)))
1287  return;
1288 
1290 
1291  obj = palloc0(sizeof(SQLDropObject));
1292  obj->address = *object;
1293  obj->original = original;
1294  obj->normal = normal;
1295 
1296  /*
1297  * Obtain schema names from the object's catalog tuple, if one exists;
1298  * this lets us skip objects in temp schemas. We trust that
1299  * ObjectProperty contains all object classes that can be
1300  * schema-qualified.
1301  */
1302  if (is_objectclass_supported(object->classId))
1303  {
1304  Relation catalog;
1305  HeapTuple tuple;
1306 
1307  catalog = table_open(obj->address.classId, AccessShareLock);
1308  tuple = get_catalog_object_by_oid(catalog,
1309  get_object_attnum_oid(object->classId),
1310  obj->address.objectId);
1311 
1312  if (tuple)
1313  {
1315  Datum datum;
1316  bool isnull;
1317 
1319  if (attnum != InvalidAttrNumber)
1320  {
1321  datum = heap_getattr(tuple, attnum,
1322  RelationGetDescr(catalog), &isnull);
1323  if (!isnull)
1324  {
1325  Oid namespaceId;
1326 
1327  namespaceId = DatumGetObjectId(datum);
1328  /* temp objects are only reported if they are my own */
1329  if (isTempNamespace(namespaceId))
1330  {
1331  obj->schemaname = "pg_temp";
1332  obj->istemp = true;
1333  }
1334  else if (isAnyTempNamespace(namespaceId))
1335  {
1336  pfree(obj);
1337  table_close(catalog, AccessShareLock);
1338  MemoryContextSwitchTo(oldcxt);
1339  return;
1340  }
1341  else
1342  {
1343  obj->schemaname = get_namespace_name(namespaceId);
1344  obj->istemp = false;
1345  }
1346  }
1347  }
1348 
1350  obj->address.objectSubId == 0)
1351  {
1353  if (attnum != InvalidAttrNumber)
1354  {
1355  datum = heap_getattr(tuple, attnum,
1356  RelationGetDescr(catalog), &isnull);
1357  if (!isnull)
1358  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1359  }
1360  }
1361  }
1362 
1363  table_close(catalog, AccessShareLock);
1364  }
1365  else
1366  {
1367  if (object->classId == NamespaceRelationId &&
1368  isTempNamespace(object->objectId))
1369  obj->istemp = true;
1370  }
1371 
1372  /* object identity, objname and objargs */
1373  obj->objidentity =
1374  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
1375  false);
1376 
1377  /* object type */
1378  obj->objecttype = getObjectTypeDescription(&obj->address, false);
1379 
1381 
1382  MemoryContextSwitchTo(oldcxt);
1383 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:700
bool EventTriggerSupportsObject(const ObjectAddress *object)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:1006
#define AccessShareLock
Definition: lockdefs.h:36
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
char * pstrdup(const char *in)
Definition: mcxt.c:1696
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3649
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3687
bool get_object_namensp_unique(Oid class_id)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
bool is_objectclass_supported(Oid class_id)
int16 attnum
Definition: pg_attribute.h:74
static Name DatumGetName(Datum X)
Definition: postgres.h:360
uintptr_t Datum
Definition: postgres.h:64
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
#define RelationGetDescr(relation)
Definition: rel.h:531
ObjectAddress address
Definition: event_trigger.c:89
const char * schemaname
Definition: event_trigger.c:90
slist_node next
Definition: event_trigger.c:99
const char * objidentity
Definition: event_trigger.c:92
const char * objecttype
Definition: event_trigger.c:93
List * addrnames
Definition: event_trigger.c:94
const char * objname
Definition: event_trigger.c:91

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert, attnum, ObjectAddress::classId, currentEventTriggerState, EventTriggerQueryState::cxt, DatumGetName(), DatumGetObjectId(), EventTriggerSupportsObject(), get_catalog_object_by_oid(), get_namespace_name(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_namensp_unique(), 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().

◆ EventTriggerSupportsObject()

bool EventTriggerSupportsObject ( const ObjectAddress object)

Definition at line 1153 of file event_trigger.c.

1154 {
1155  switch (object->classId)
1156  {
1157  case DatabaseRelationId:
1158  case TableSpaceRelationId:
1159  case AuthIdRelationId:
1160  case AuthMemRelationId:
1161  case ParameterAclRelationId:
1162  /* no support for global objects (except subscriptions) */
1163  return false;
1164  case EventTriggerRelationId:
1165  /* no support for event triggers on event triggers */
1166  return false;
1167  default:
1168  return true;
1169  }
1170 }

References ObjectAddress::classId.

Referenced by deleteObjectsInList(), and EventTriggerSQLDropAddObject().

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 1129 of file event_trigger.c.

1130 {
1131  switch (obtype)
1132  {
1133  case OBJECT_DATABASE:
1134  case OBJECT_TABLESPACE:
1135  case OBJECT_ROLE:
1136  case OBJECT_PARAMETER_ACL:
1137  /* no support for global objects (except subscriptions) */
1138  return false;
1139  case OBJECT_EVENT_TRIGGER:
1140  /* no support for event triggers on event triggers */
1141  return false;
1142  default:
1143  return true;
1144  }
1145 }
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2310
@ OBJECT_ROLE
Definition: parsenodes.h:2301
@ OBJECT_DATABASE
Definition: parsenodes.h:2277
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2295

References OBJECT_DATABASE, OBJECT_EVENT_TRIGGER, OBJECT_PARAMETER_ACL, OBJECT_ROLE, and OBJECT_TABLESPACE.

Referenced by ExecGrantStmt_oids(), and standard_ProcessUtility().

◆ EventTriggerTableRewrite()

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

Definition at line 999 of file event_trigger.c.

1000 {
1001  List *runlist;
1002  EventTriggerData trigdata;
1003 
1004  /*
1005  * See EventTriggerDDLCommandStart for a discussion about why event
1006  * triggers are disabled in single user mode or via a GUC.
1007  */
1009  return;
1010 
1011  /*
1012  * Also do nothing if our state isn't set up, which it won't be if there
1013  * weren't any relevant event triggers at the start of the current DDL
1014  * command. This test might therefore seem optional, but it's
1015  * *necessary*, because EventTriggerCommonSetup might find triggers that
1016  * didn't exist at the time the command started.
1017  */
1019  return;
1020 
1021  runlist = EventTriggerCommonSetup(parsetree,
1023  "table_rewrite",
1024  &trigdata, false);
1025  if (runlist == NIL)
1026  return;
1027 
1028  /*
1029  * Make sure pg_event_trigger_table_rewrite_oid only works when running
1030  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
1031  * when one trigger fails. (This is perhaps not necessary, as the
1032  * currentState variable will be removed shortly by our caller, but it
1033  * seems better to play safe.)
1034  */
1037 
1038  /* Run the triggers. */
1039  PG_TRY();
1040  {
1041  EventTriggerInvoke(runlist, &trigdata);
1042  }
1043  PG_FINALLY();
1044  {
1047  }
1048  PG_END_TRY();
1049 
1050  /* Cleanup. */
1051  list_free(runlist);
1052 
1053  /*
1054  * Make sure anything the event triggers did will be visible to the main
1055  * command.
1056  */
1058 }
@ EVT_TableRewrite
Definition: evtcache.h:25

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

Referenced by ATRewriteTables().

◆ EventTriggerUndoInhibitCommandCollection()

void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1561 of file event_trigger.c.

1562 {
1564  return;
1565 
1567 }

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ get_event_trigger_oid()

Oid get_event_trigger_oid ( const char *  trigname,
bool  missing_ok 
)

Definition at line 575 of file event_trigger.c.

576 {
577  Oid oid;
578 
579  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
580  CStringGetDatum(trigname));
581  if (!OidIsValid(oid) && !missing_ok)
582  ereport(ERROR,
583  (errcode(ERRCODE_UNDEFINED_OBJECT),
584  errmsg("event trigger \"%s\" does not exist", trigname)));
585  return oid;
586 }
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:109

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

Referenced by get_object_address_unqualified().

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1241 of file event_trigger.c.

1242 {
1243  /*
1244  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1245  * exists
1246  */
1247  return (EventCacheLookup(EVT_SQLDrop) != NIL) ||
1250 }
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:63

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

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

Variable Documentation

◆ event_triggers